feat: simplify SOP to immediate-effect configuration

This commit is contained in:
Eric 1549169735@qq.com
2026-08-18 16:27:02 +08:00
parent c5ab886b70
commit 8de48fb05e
150 changed files with 6764 additions and 1626 deletions

View File

@@ -0,0 +1,44 @@
package httpserver
import (
"net/http"
"net/http/httptest"
"testing"
"testing/fstest"
"git.iwork-ai.com/xdc/iqudo-top1/internal/auth"
"git.iwork-ai.com/xdc/iqudo-top1/internal/config"
"github.com/gin-gonic/gin"
"go.uber.org/zap"
)
func TestSDKFilesAreServedOverHTTP(t *testing.T) {
gin.SetMode(gin.TestMode)
frontend := fstest.MapFS{
"index.html": &fstest.MapFile{Data: []byte("<html>ok</html>")},
}
sdkFS := fstest.MapFS{
"index.js": &fstest.MapFile{Data: []byte("export function create() {}")},
"index.iife.js": &fstest.MapFile{Data: []byte("var IqudooSalesScenario = {};")},
}
handler := New(nil, auth.NewService(nil, config.AuthConfig{}), frontend, sdkFS, zap.NewNop(), "test")
for _, path := range []string{"/sdk/index.js", "/sdk/index.iife.js"} {
req := httptest.NewRequest(http.MethodGet, path, nil)
rec := httptest.NewRecorder()
handler.ServeHTTP(rec, req)
if rec.Code != http.StatusOK {
t.Fatalf("GET %s status = %d, want %d", path, rec.Code, http.StatusOK)
}
if rec.Header().Get("Access-Control-Allow-Origin") != "*" {
t.Fatalf("GET %s missing open CORS header", path)
}
if got := rec.Header().Get("Content-Type"); got != "text/javascript; charset=utf-8" {
t.Fatalf("GET %s Content-Type = %q, want text/javascript", path, got)
}
if rec.Body.Len() == 0 {
t.Fatalf("GET %s returned empty body", path)
}
}
}