Scert/backend/internal/httpapi/password_reset_account_test.go

28 lines
874 B
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package httpapi
import (
"net/http"
"net/http/httptest"
"strings"
"testing"
"git.pcux.cn/xuans/Scert/backend/internal/config"
)
func TestPasswordResetResolutionRejectsTrailingJSON(t *testing.T) {
server := New(Dependencies{Config: config.Default(t.TempDir()), Repository: &stubDomainRepository{}})
tests := []string{
`{"identifier":"admin","unexpected":true}`,
`{"identifier":"admin"}{"identifier":"again"}`,
}
for _, body := range tests {
request := httptest.NewRequest(http.MethodPost, "/api/v1/password-reset/resolve", strings.NewReader(body))
request.Header.Set("Content-Type", "application/json")
response := httptest.NewRecorder()
server.Handler().ServeHTTP(response, request)
if response.Code != http.StatusBadRequest {
t.Fatalf("无效密码重置请求应返回 400,实际为 %d:%s", response.Code, response.Body.String())
}
}
}