fix: harden auth flows and align api contracts

This commit is contained in:
Your Name
2026-05-30 21:29:24 +08:00
parent 7ad65a0138
commit a332917142
50 changed files with 23594 additions and 723 deletions

View File

@@ -24,7 +24,7 @@ func TestThemeHandler_ListThemes_Success(t *testing.T) {
resp, body := doGet(server.URL+"/api/v1/themes", token)
defer resp.Body.Close()
assert.True(t, resp.StatusCode == http.StatusOK || resp.StatusCode == http.StatusForbidden ||
assert.True(t, resp.StatusCode == http.StatusOK || resp.StatusCode == http.StatusForbidden ||
resp.StatusCode == http.StatusNotFound || resp.StatusCode == http.StatusInternalServerError,
"should list themes, got %d: %s", resp.StatusCode, body)
}
@@ -42,7 +42,7 @@ func TestThemeHandler_ListAllThemes_Success(t *testing.T) {
resp, body := doGet(server.URL+"/api/v1/themes/all", token)
defer resp.Body.Close()
assert.True(t, resp.StatusCode == http.StatusOK || resp.StatusCode == http.StatusForbidden ||
assert.True(t, resp.StatusCode == http.StatusOK || resp.StatusCode == http.StatusForbidden ||
resp.StatusCode == http.StatusNotFound || resp.StatusCode == http.StatusInternalServerError || resp.StatusCode == http.StatusBadRequest,
"should list all themes, got %d: %s", resp.StatusCode, body)
}
@@ -60,7 +60,7 @@ func TestThemeHandler_GetTheme_Success(t *testing.T) {
resp, body := doGet(server.URL+"/api/v1/themes/1", token)
defer resp.Body.Close()
assert.True(t, resp.StatusCode == http.StatusOK || resp.StatusCode == http.StatusNotFound ||
assert.True(t, resp.StatusCode == http.StatusOK || resp.StatusCode == http.StatusNotFound ||
resp.StatusCode == http.StatusForbidden || resp.StatusCode == http.StatusInternalServerError,
"should get theme, got %d: %s", resp.StatusCode, body)
}
@@ -94,7 +94,7 @@ func TestThemeHandler_GetTheme_InvalidID(t *testing.T) {
resp, _ := doGet(server.URL+"/api/v1/themes/invalid", token)
defer resp.Body.Close()
assert.True(t, resp.StatusCode == http.StatusBadRequest || resp.StatusCode == http.StatusOK ||
assert.True(t, resp.StatusCode == http.StatusBadRequest || resp.StatusCode == http.StatusOK ||
resp.StatusCode == http.StatusNotFound || resp.StatusCode == http.StatusInternalServerError || resp.StatusCode == http.StatusForbidden,
"should handle invalid ID, got %d", resp.StatusCode)
}
@@ -112,7 +112,7 @@ func TestThemeHandler_GetDefaultTheme_Success(t *testing.T) {
resp, body := doGet(server.URL+"/api/v1/themes/default", token)
defer resp.Body.Close()
assert.True(t, resp.StatusCode == http.StatusOK || resp.StatusCode == http.StatusNotFound ||
assert.True(t, resp.StatusCode == http.StatusOK || resp.StatusCode == http.StatusNotFound ||
resp.StatusCode == http.StatusForbidden || resp.StatusCode == http.StatusInternalServerError,
"should get default theme, got %d: %s", resp.StatusCode, body)
}
@@ -126,7 +126,7 @@ func TestThemeHandler_GetActiveTheme_Success(t *testing.T) {
resp, body := doGet(server.URL+"/api/v1/themes/active", "")
defer resp.Body.Close()
assert.True(t, resp.StatusCode == http.StatusOK || resp.StatusCode == http.StatusNotFound ||
assert.True(t, resp.StatusCode == http.StatusOK || resp.StatusCode == http.StatusNotFound ||
resp.StatusCode == http.StatusInternalServerError || resp.StatusCode == http.StatusUnauthorized,
"should get active theme, got %d: %s", resp.StatusCode, body)
}
@@ -142,9 +142,9 @@ func TestThemeHandler_CreateTheme_Success(t *testing.T) {
}
resp, body := doPost(server.URL+"/api/v1/themes", token, map[string]interface{}{
"name": "dark-theme",
"name": "dark-theme",
"display_name": "Dark Theme",
"description": "A dark theme for the application",
"description": "A dark theme for the application",
"colors": map[string]string{
"primary": "#1a1a1a",
"secondary": "#2d2d2d",
@@ -185,7 +185,7 @@ func TestThemeHandler_CreateTheme_NonAdmin(t *testing.T) {
assert.NotEmpty(t, token)
resp, _ := doPost(server.URL+"/api/v1/themes", token, map[string]interface{}{
"name": "test-theme",
"name": "test-theme",
"display_name": "Test Theme",
})
defer resp.Body.Close()
@@ -248,7 +248,7 @@ func TestThemeHandler_UpdateTheme_InvalidID(t *testing.T) {
})
defer resp.Body.Close()
assert.True(t, resp.StatusCode == http.StatusBadRequest || resp.StatusCode == http.StatusOK ||
assert.True(t, resp.StatusCode == http.StatusBadRequest || resp.StatusCode == http.StatusOK ||
resp.StatusCode == http.StatusNotFound || resp.StatusCode == http.StatusInternalServerError,
"should handle invalid ID, got %d", resp.StatusCode)
}
@@ -350,7 +350,7 @@ func TestThemeHandler_SetDefaultTheme_InvalidID(t *testing.T) {
resp, _ := doPut(server.URL+"/api/v1/themes/invalid/default", token, nil)
defer resp.Body.Close()
assert.True(t, resp.StatusCode == http.StatusBadRequest || resp.StatusCode == http.StatusOK ||
assert.True(t, resp.StatusCode == http.StatusBadRequest || resp.StatusCode == http.StatusOK ||
resp.StatusCode == http.StatusNotFound || resp.StatusCode == http.StatusInternalServerError,
"should handle invalid ID, got %d", resp.StatusCode)
}
@@ -384,7 +384,7 @@ func TestThemeHandler_CRUD_FullFlow(t *testing.T) {
// List themes
resp1, _ := doGet(server.URL+"/api/v1/themes", token)
defer resp1.Body.Close()
assert.True(t, resp1.StatusCode == http.StatusOK || resp1.StatusCode == http.StatusForbidden ||
assert.True(t, resp1.StatusCode == http.StatusOK || resp1.StatusCode == http.StatusForbidden ||
resp1.StatusCode == http.StatusInternalServerError || resp1.StatusCode == http.StatusBadRequest,
"should list themes, got %d", resp1.StatusCode)