diff options
| author | mo khan <mo@mokhan.ca> | 2025-03-13 16:43:47 -0600 |
|---|---|---|
| committer | mo khan <mo@mokhan.ca> | 2025-03-13 16:43:47 -0600 |
| commit | c9f394fe7fa0a5a6504b5b80ae7019cffdf4bb14 (patch) | |
| tree | da1ef1c59264221c2c483ddd76401ee19cd1015c /pkg/prxy/prxy_test.go | |
| parent | b55a6617971fa50bb064480f78343e6c0bc59dbe (diff) | |
refactor: extract authz interface to test out different PaC libraries
Diffstat (limited to 'pkg/prxy/prxy_test.go')
| -rw-r--r-- | pkg/prxy/prxy_test.go | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/pkg/prxy/prxy_test.go b/pkg/prxy/prxy_test.go new file mode 100644 index 0000000..6f37974 --- /dev/null +++ b/pkg/prxy/prxy_test.go @@ -0,0 +1,49 @@ +package prxy + +import ( + "net/http" + "net/http/httptest" + "net/url" + "testing" + + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" + "github.com/xlgmokha/x/pkg/x" + "gitlab.com/mokhax/spike/pkg/test" +) + +func TestProxy(t *testing.T) { + t.Run("http://idp.test", func(t *testing.T) { + var lastIdPRequest *http.Request + var lastUiRequest *http.Request + + idp := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + lastIdPRequest = r + w.WriteHeader(http.StatusOK) + })) + defer idp.Close() + + ui := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + lastUiRequest = r + w.WriteHeader(http.StatusTeapot) + })) + defer ui.Close() + + subject := New(map[string]string{ + "idp.test": idp.URL, + "ui.test": ui.URL, + }) + + r, w := test.RequestResponse("GET", "http://idp.test:8080/saml/new") + + subject.ServeHTTP(w, r) + + url := x.Must(url.Parse(idp.URL)) + + assert.Nil(t, lastUiRequest) + assert.Equal(t, http.StatusOK, w.Code) + + require.NotNil(t, lastIdPRequest) + assert.Equal(t, url.Host, lastIdPRequest.Host) + }) +} |
