feat: complete remaining Go backend modules
This commit is contained in:
1 parent
cea2751dc5
commit
aef5a97165
145 files changed
+18376
-199
No files matched your search
@@ -0,0 +1,39 @@
|
||||
package httpapi
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestAuthCompatibilityEndpoints(t *testing.T) {
|
||||
handler := NewAuthCompatibilityHandler()
|
||||
cases := []struct {
|
||||
path string
|
||||
status int
|
||||
location string
|
||||
body string
|
||||
}{
|
||||
{"/api/auth/login", http.StatusTemporaryRedirect, "https://example.test/auth/login", ""},
|
||||
{"/api/auth/callback", http.StatusTemporaryRedirect, "https://example.test/auth/login?error=callback_failed", ""},
|
||||
{"/api/auth/captcha", http.StatusOK, "", `{"enabled":false,"message":"平台账号登录不使用外部验证码。"}` + "\n"},
|
||||
}
|
||||
for _, tc := range cases {
|
||||
t.Run(tc.path, func(t *testing.T) {
|
||||
r := httptest.NewRequest(http.MethodGet, "https://example.test"+tc.path, nil)
|
||||
w := httptest.NewRecorder()
|
||||
handler.ServeHTTP(w, r)
|
||||
if w.Code != tc.status || w.Header().Get("Location") != tc.location || w.Body.String() != tc.body {
|
||||
t.Fatalf("status=%d location=%q body=%q", w.Code, w.Header().Get("Location"), w.Body.String())
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestAuthCompatibilityRejectsUnsupportedMethods(t *testing.T) {
|
||||
w := httptest.NewRecorder()
|
||||
NewAuthCompatibilityHandler().ServeHTTP(w, httptest.NewRequest(http.MethodPost, "/api/auth/captcha", nil))
|
||||
if w.Code != http.StatusMethodNotAllowed || w.Header().Get("Allow") != http.MethodGet {
|
||||
t.Fatalf("status=%d allow=%q", w.Code, w.Header().Get("Allow"))
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user