Implement lab 3 level 4 failover and idempotency

This commit is contained in:
2026-10-29 23:35:04 +03:00
parent 0ab3a341aa
commit a2cb1ad2ae
338 changed files with 37821 additions and 22 deletions
@@ -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")
}
}