mirror of
https://github.com/steveiliop56/tinyauth.git
synced 2025-10-28 04:35:40 +00:00
tests: test invalid json in user controller
This commit is contained in:
@@ -137,6 +137,13 @@ func TestLoginHandler(t *testing.T) {
|
|||||||
assert.NilError(t, err)
|
assert.NilError(t, err)
|
||||||
assert.Equal(t, string(loginResJson), recorder.Body.String())
|
assert.Equal(t, string(loginResJson), recorder.Body.String())
|
||||||
|
|
||||||
|
// Test invalid json
|
||||||
|
recorder = httptest.NewRecorder()
|
||||||
|
req = httptest.NewRequest("POST", "/api/user/login", strings.NewReader("{invalid json}"))
|
||||||
|
router.ServeHTTP(recorder, req)
|
||||||
|
|
||||||
|
assert.Equal(t, 400, recorder.Code)
|
||||||
|
|
||||||
// Test rate limiting
|
// Test rate limiting
|
||||||
loginReq = controller.LoginRequest{
|
loginReq = controller.LoginRequest{
|
||||||
Username: "testuser",
|
Username: "testuser",
|
||||||
@@ -219,6 +226,13 @@ func TestTotpHandler(t *testing.T) {
|
|||||||
assert.Equal(t, "tinyauth-session", cookie.Name)
|
assert.Equal(t, "tinyauth-session", cookie.Name)
|
||||||
assert.Assert(t, cookie.Value != "")
|
assert.Assert(t, cookie.Value != "")
|
||||||
|
|
||||||
|
// Test invalid json
|
||||||
|
recorder = httptest.NewRecorder()
|
||||||
|
req = httptest.NewRequest("POST", "/api/user/totp", strings.NewReader("{invalid json}"))
|
||||||
|
router.ServeHTTP(recorder, req)
|
||||||
|
|
||||||
|
assert.Equal(t, 400, recorder.Code)
|
||||||
|
|
||||||
// Test rate limiting
|
// Test rate limiting
|
||||||
totpReq = controller.TotpRequest{
|
totpReq = controller.TotpRequest{
|
||||||
Code: "000000",
|
Code: "000000",
|
||||||
|
|||||||
Reference in New Issue
Block a user