-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathclient_store_test.go
More file actions
75 lines (62 loc) · 1.83 KB
/
client_store_test.go
File metadata and controls
75 lines (62 loc) · 1.83 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
package oidc
import (
"net/http"
"net/http/httptest"
"testing"
"github.com/labstack/echo/v4"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestAuthHandler(t *testing.T) {
client := oidcClient{
client: mockRelyingParty{isPKCE: false, tokenURL: "https://token.url"},
id: "renku",
}
store := ClientStore{
"renku": client,
}
handler, err := store.AuthHandler("renku", "abcde-12345")
require.NoError(t, err)
e := echo.New()
req := httptest.NewRequest(http.MethodGet, "/", nil)
rec := httptest.NewRecorder()
c := e.NewContext(req, rec)
err = echo.WrapHandler(handler)(c)
require.NoError(t, err)
assert.Equal(t, http.StatusFound, rec.Code)
assert.Contains(t, rec.Header().Get("location"), "client_id=mock-client&response_type=code&state=abcde-12345")
}
func TestAuthHandlerInvalidProvider(t *testing.T) {
client := oidcClient{
client: mockRelyingParty{isPKCE: false, tokenURL: "https://token.url"},
id: "renku",
}
store := ClientStore{
"renku": client,
}
_, err := store.AuthHandler("another", "abcde-12345")
assert.ErrorContains(t, err, "cannot find the provider with ID another")
}
func TestUserProfileURL(t *testing.T) {
client := oidcClient{
client: mockRelyingParty{isPKCE: false, tokenURL: "https://token.url"},
id: "renku",
}
store := ClientStore{
"renku": client,
}
profileURL, err := store.UserProfileURL("renku")
require.NoError(t, err)
assert.Equal(t, "https://token.url/account?referrer=renku", profileURL.String())
}
func TestUserProfileURLInvalidProvider(t *testing.T) {
client := oidcClient{
client: mockRelyingParty{isPKCE: false, tokenURL: "https://token.url"},
id: "renku",
}
store := ClientStore{
"renku": client,
}
_, err := store.UserProfileURL("another")
assert.ErrorContains(t, err, "cannot find the provider with ID another")
}