mirror of
https://github.com/pomerium/pomerium.git
synced 2025-06-11 07:12:59 +02:00
integration-tests: add CORS test (#662)
This commit is contained in:
parent
f9399df1bd
commit
3f4a22a10d
2 changed files with 65 additions and 0 deletions
53
integration/cors_test.go
Normal file
53
integration/cors_test.go
Normal file
|
@ -0,0 +1,53 @@
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"net/http"
|
||||||
|
"testing"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestCORS(t *testing.T) {
|
||||||
|
ctx := mainCtx
|
||||||
|
ctx, clearTimeout := context.WithTimeout(ctx, time.Second*30)
|
||||||
|
defer clearTimeout()
|
||||||
|
|
||||||
|
t.Run("enabled", func(t *testing.T) {
|
||||||
|
client := testcluster.NewHTTPClient()
|
||||||
|
|
||||||
|
req, err := http.NewRequestWithContext(ctx, "OPTIONS", "https://httpdetails.localhost.pomerium.io/cors-enabled", nil)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
req.Header.Set("Access-Control-Request-Method", "GET")
|
||||||
|
req.Header.Set("Origin", "https://httpdetails.localhost.pomerium.io")
|
||||||
|
|
||||||
|
res, err := client.Do(req)
|
||||||
|
if !assert.NoError(t, err, "unexpected http error") {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
defer res.Body.Close()
|
||||||
|
|
||||||
|
assert.Equal(t, http.StatusOK, res.StatusCode, "unexpected status code")
|
||||||
|
})
|
||||||
|
t.Run("disabled", func(t *testing.T) {
|
||||||
|
client := testcluster.NewHTTPClient()
|
||||||
|
|
||||||
|
req, err := http.NewRequestWithContext(ctx, "OPTIONS", "https://httpdetails.localhost.pomerium.io/cors-disabled", nil)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
req.Header.Set("Access-Control-Request-Method", "GET")
|
||||||
|
req.Header.Set("Origin", "https://httpdetails.localhost.pomerium.io")
|
||||||
|
|
||||||
|
res, err := client.Do(req)
|
||||||
|
if !assert.NoError(t, err, "unexpected http error") {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
defer res.Body.Close()
|
||||||
|
|
||||||
|
assert.NotEqual(t, http.StatusOK, res.StatusCode, "unexpected status code")
|
||||||
|
})
|
||||||
|
}
|
|
@ -20,6 +20,18 @@ local PomeriumPolicy = function() std.flattenArrays([
|
||||||
to: 'http://' + domain + '.default.svc.cluster.local',
|
to: 'http://' + domain + '.default.svc.cluster.local',
|
||||||
allowed_groups: ['admin'],
|
allowed_groups: ['admin'],
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
from: 'http://' + domain + '.localhost.pomerium.io',
|
||||||
|
to: 'http://' + domain + '.default.svc.cluster.local',
|
||||||
|
prefix: '/cors-enabled',
|
||||||
|
cors_allow_preflight: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
from: 'http://' + domain + '.localhost.pomerium.io',
|
||||||
|
to: 'http://' + domain + '.default.svc.cluster.local',
|
||||||
|
prefix: '/cors-disabled',
|
||||||
|
cors_allow_preflight: false,
|
||||||
|
},
|
||||||
{
|
{
|
||||||
from: 'http://' + domain + '.localhost.pomerium.io',
|
from: 'http://' + domain + '.localhost.pomerium.io',
|
||||||
to: 'http://' + domain + '.default.svc.cluster.local',
|
to: 'http://' + domain + '.default.svc.cluster.local',
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue