mirror of
https://github.com/Ed1s0nZ/CyberStrikeAI.git
synced 2026-10-19 14:07:36 +02:00
29 lines
764 B
Go
29 lines
764 B
Go
package handler
|
|
|
|
import (
|
|
"bytes"
|
|
"encoding/json"
|
|
"net/http"
|
|
"net/http/httptest"
|
|
"strings"
|
|
"testing"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
)
|
|
|
|
func TestLoginRejectsMissingAndLongUsernameBeforeAuthentication(t *testing.T) {
|
|
h := &AuthHandler{}
|
|
r := gin.New()
|
|
r.POST("/login", h.Login)
|
|
for _, username := range []string{"", " ", strings.Repeat("x", 65), strings.Repeat("中", 65)} {
|
|
body, _ := json.Marshal(map[string]string{"username": username, "password": "test-only-password"})
|
|
w := httptest.NewRecorder()
|
|
req := httptest.NewRequest(http.MethodPost, "/login", bytes.NewReader(body))
|
|
req.Header.Set("Content-Type", "application/json")
|
|
r.ServeHTTP(w, req)
|
|
if w.Code != http.StatusBadRequest {
|
|
t.Fatalf("username %q: %d", username, w.Code)
|
|
}
|
|
}
|
|
}
|