forked from mtusi2026/mtusi2026lab3
Implement lab 3 level 4 failover and idempotency
This commit is contained in:
@@ -0,0 +1,32 @@
|
||||
package auth_tests
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"highload/internal/transport/http/handler"
|
||||
"highload/internal/transport/http/middleware"
|
||||
)
|
||||
|
||||
func TestStorageAuthHandlerRejectsJSONBody(t *testing.T) {
|
||||
f := newFixture(t)
|
||||
user, password := f.user(t)
|
||||
writes := f.redis.audit.writeCount()
|
||||
auth := handler.NewAuthHandler(f.auth)
|
||||
mid := middleware.NewMiddleware(f.auth, "auth-test")
|
||||
request := httptest.NewRequest(http.MethodPost, "/api/v1/auth/sessions", strings.NewReader("{}"))
|
||||
request.SetBasicAuth(user.Username, password)
|
||||
request.Header.Set("Content-Type", "application/json")
|
||||
recorder := httptest.NewRecorder()
|
||||
// Exercise the real handler independently of Router wiring.
|
||||
// This component test does not replace the end-to-end login acceptance test.
|
||||
mid.RequestID(http.HandlerFunc(auth.CreateSession)).ServeHTTP(recorder, request)
|
||||
if recorder.Code != http.StatusBadRequest {
|
||||
t.Errorf("login with JSON body must return 400; received %d", recorder.Code)
|
||||
}
|
||||
if f.redis.audit.writeCount() != writes {
|
||||
t.Error("login with forbidden JSON body attempted to create a session")
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user