this repo has no description
1package oauth
2
3import (
4 "context"
5 "encoding/json"
6 "testing"
7
8 "github.com/stretchr/testify/assert"
9)
10
11var (
12 ctx = context.Background()
13 oauthClient = newTestOauthClient()
14)
15
16func newTestOauthClient() *OauthClient {
17 prefix := "testing"
18 testKey, err := GenerateKey(&prefix)
19 if err != nil {
20 panic(err)
21 }
22
23 b, err := json.Marshal(testKey)
24 if err != nil {
25 panic(err)
26 }
27
28 c, err := NewOauthClient(OauthClientArgs{
29 ClientJwk: b,
30 })
31 if err != nil {
32 panic(err)
33 }
34
35 return c
36}
37
38func TestResolvePDSAuthServer(t *testing.T) {
39 assert := assert.New(t)
40
41 authServer, err := oauthClient.ResolvePDSAuthServer(ctx, "https://pds.haileyok.com")
42
43 assert.NoError(err)
44 assert.NotEmpty(authServer)
45 assert.Equal("https://pds.haileyok.com", authServer)
46}
47
48func TestFetchAuthServerMetadata(t *testing.T) {
49 assert := assert.New(t)
50
51 meta, err := oauthClient.FetchAuthServerMetadata(ctx, "https://pds.haileyok.com")
52
53 assert.NoError(err)
54 assert.IsType(OauthAuthorizationMetadata{}, meta)
55}
56
57func TestGenerateKey(t *testing.T) {
58 assert := assert.New(t)
59
60 prefix := "testing"
61 _, err := GenerateKey(&prefix)
62 assert.NoError(err)
63}