feat: implement CORS support with configurable allowed origins
This commit is contained in:
@@ -0,0 +1,37 @@
|
||||
package config
|
||||
|
||||
import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestLoadReadsCORSAllowedOrigins(t *testing.T) {
|
||||
path := filepath.Join(t.TempDir(), "config.yaml")
|
||||
content := []byte(`server:
|
||||
port: 8083
|
||||
cors:
|
||||
allowedOrigins:
|
||||
- https://console.example.com
|
||||
- http://localhost:3000
|
||||
`)
|
||||
if err := os.WriteFile(path, content, 0600); err != nil {
|
||||
t.Fatalf("WriteFile() error = %v", err)
|
||||
}
|
||||
|
||||
cfg, err := Load(path)
|
||||
if err != nil {
|
||||
t.Fatalf("Load() error = %v", err)
|
||||
}
|
||||
|
||||
got := cfg.Server.CORS.AllowedOrigins
|
||||
want := []string{"https://console.example.com", "http://localhost:3000"}
|
||||
if len(got) != len(want) {
|
||||
t.Fatalf("len(AllowedOrigins)=%d want %d", len(got), len(want))
|
||||
}
|
||||
for i := range want {
|
||||
if got[i] != want[i] {
|
||||
t.Fatalf("AllowedOrigins[%d]=%q want %q", i, got[i], want[i])
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user