chore: finalize lab7 security verification
CI / verify (pull_request) Successful in 14m53s

This commit is contained in:
2026-11-06 22:00:42 +03:00
parent 5ac64f51fa
commit a8edaf058d
53 changed files with 1130 additions and 224 deletions
+17
View File
@@ -16,6 +16,7 @@ import (
"gitea.privcloud.tech/dizi/mtusi2026lab7/internal/messenger/attachment"
"gitea.privcloud.tech/dizi/mtusi2026lab7/internal/model"
"gitea.privcloud.tech/dizi/mtusi2026lab7/internal/password"
)
var errDependency = errors.New("dependency unavailable")
@@ -254,6 +255,22 @@ func (s *MessengerSuite) TestSessionCreationReturnsRateLimitWithRetryAfter() {
s.Contains(response.Body.String(), `"code":"rate_limited"`)
}
func (s *MessengerSuite) TestPasswordOperationLimitReturnsRateLimit() {
registration := s.newTestServer(messengerStoreStub{}, sessionStub{}, passwordsStub{hashErr: password.ErrBusy})
response := serveRequest(registration, http.MethodPost, "/api/v1/users", `{"username":"student","display_name":"Student","password":"T3st-password-123"}`)
s.Equal(http.StatusTooManyRequests, response.Code)
s.Equal("1", response.Header().Get("Retry-After"))
store := messengerStoreStub{credentials: model.UserCredentials{PasswordHash: "hash"}}
login := s.newTestServer(store, sessionStub{}, passwordsStub{err: password.ErrBusy})
request := httptest.NewRequest(http.MethodPost, "/api/v1/auth/sessions", nil)
request.SetBasicAuth("student", "T3st-password-123")
response = httptest.NewRecorder()
login.Handler().ServeHTTP(response, request)
s.Equal(http.StatusTooManyRequests, response.Code)
s.Equal("1", response.Header().Get("Retry-After"))
}
func (s *MessengerSuite) TestSessionCreationRehashesPasswordWithCompareAndSwap() {
var updated []string
store := messengerStoreStub{