mirror of
https://github.com/OliveTin/OliveTin
synced 2025-12-18 12:05:32 +00:00
Some checks failed
Build Snapshot / build-snapshot (push) Waiting to run
DevSkim / DevSkim (push) Waiting to run
Buf CI / buf (push) Has been cancelled
CodeQL / Analyze (go) (push) Has been cancelled
CodeQL / Analyze (javascript) (push) Has been cancelled
Codestyle checks / codestyle (push) Has been cancelled
23 lines
505 B
Go
23 lines
505 B
Go
package cors
|
|
|
|
import (
|
|
"github.com/stretchr/testify/assert"
|
|
"net/http"
|
|
"net/http/httptest"
|
|
"testing"
|
|
)
|
|
|
|
func TestCors(t *testing.T) {
|
|
req, _ := http.NewRequest("GET", "/health-check", nil)
|
|
req.Header.Add("Origin", "1.2.3.4")
|
|
|
|
blat := AllowCors(http.FileServer(http.Dir(".")))
|
|
|
|
rr := httptest.NewRecorder()
|
|
|
|
blat.ServeHTTP(rr, req)
|
|
|
|
assert.Equal(t, http.StatusNotFound, rr.Code, "HTTP 404 on CORS")
|
|
assert.Equal(t, "1.2.3.4", rr.Header().Get("Access-Control-Allow-Origin"), "CORS Header set")
|
|
}
|