summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authormo khan <mo@mokhan.ca>2025-03-10 14:54:11 -0600
committermo khan <mo@mokhan.ca>2025-03-10 14:54:11 -0600
commit9a865953c4a95137faa336ca1d228d3ab2bc305f (patch)
treeb8aa151300e51a0be43d5719e1dee0b2b9a9fbfb /test
parentef02c044c73c31e92ff044fe61ad58e7e767402c (diff)
test: add e2e spec for OIDC login
Diffstat (limited to 'test')
-rw-r--r--test/e2e_test.go26
1 files changed, 26 insertions, 0 deletions
diff --git a/test/e2e_test.go b/test/e2e_test.go
index 14648ecc..f14410a0 100644
--- a/test/e2e_test.go
+++ b/test/e2e_test.go
@@ -2,14 +2,23 @@ package main
import (
"net/http"
+ "strings"
"testing"
"github.com/playwright-community/playwright-go"
"github.com/stretchr/testify/assert"
"github.com/xlgmokha/x/pkg/env"
+ "github.com/xlgmokha/x/pkg/serde"
"github.com/xlgmokha/x/pkg/x"
)
+type OAuthTokens struct {
+ AccessToken string `json:"access_token"`
+ TokenType string `json:"token_type"`
+ ExpiresIn uint64 `json:"expires_in"`
+ RefreshToken string `json:"refresh_token"`
+}
+
func TestHelloWorld(t *testing.T) {
_ = playwright.Install()
@@ -52,4 +61,21 @@ func TestHelloWorld(t *testing.T) {
})
})
})
+
+ t.Run("OIDC", func(t *testing.T) {
+ t.Run("Performs an OIDC login", func(t *testing.T) {
+ x.Must(page.Goto("http://ui.example.com:8080/oidc/new"))
+ assert.Contains(t, page.URL(), "http://idp.example.com:8080/oauth/authorize")
+ assert.NoError(t, page.Locator("#submit-button").Click())
+
+ assert.Contains(t, page.URL(), "http://ui.example.com:8080/oauth/callback")
+ content := x.Must(page.Locator("pre").First().InnerText())
+ item := x.Must(serde.FromJSON[OAuthTokens](strings.NewReader(content)))
+ assert.NotEmpty(t, item.AccessToken)
+ assert.Equal(t, "Bearer", item.TokenType)
+ assert.NotEmpty(t, item.RefreshToken)
+ // header = { 'Authorization' => "Bearer #{token}" }
+ // http.Get("http://api.example.com:8080/projects.json")
+ })
+ })
}