Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions backend/internal/service/admin_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -3339,12 +3339,13 @@ func runProxyQualityTarget(ctx context.Context, client *http.Client, target prox
}

if _, ok := target.AllowedStatuses[resp.StatusCode]; ok {
// 白名单内的状态码均代表目标可达:2xx 表示接口直接可用,
// 401/405 等是无鉴权探测的预期结果,同样视为连通正常,不再扣分。
item.Status = "pass"
if resp.StatusCode >= http.StatusOK && resp.StatusCode < http.StatusMultipleChoices {
item.Status = "pass"
item.Message = fmt.Sprintf("HTTP %d", resp.StatusCode)
} else {
item.Status = "warn"
item.Message = fmt.Sprintf("HTTP %d(目标可达,但鉴权或方法受限)", resp.StatusCode)
item.Message = fmt.Sprintf("HTTP %d(目标可达)", resp.StatusCode)
}
return item
}
Expand Down
4 changes: 2 additions & 2 deletions backend/internal/service/admin_service_proxy_quality_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ func TestRunProxyQualityTarget_AllowedStatusPass(t *testing.T) {
require.Equal(t, http.StatusOK, item.HTTPStatus)
}

func TestRunProxyQualityTarget_AllowedStatusWarnForUnauthorized(t *testing.T) {
func TestRunProxyQualityTarget_AllowedStatusPassForUnauthorized(t *testing.T) {
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
w.WriteHeader(http.StatusUnauthorized)
_, _ = w.Write([]byte(`{"error":"unauthorized"}`))
Expand All @@ -89,7 +89,7 @@ func TestRunProxyQualityTarget_AllowedStatusWarnForUnauthorized(t *testing.T) {
}

item := runProxyQualityTarget(context.Background(), server.Client(), target)
require.Equal(t, "warn", item.Status)
require.Equal(t, "pass", item.Status)
require.Equal(t, http.StatusUnauthorized, item.HTTPStatus)
require.Contains(t, item.Message, "目标可达")
}
Loading