-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathresource_test.go
More file actions
78 lines (65 loc) · 1.69 KB
/
resource_test.go
File metadata and controls
78 lines (65 loc) · 1.69 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
76
77
78
package caddy_oidc
import (
"testing"
"github.com/caddyserver/caddy/v2/caddyconfig/caddyfile"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestProtectedResourceMetadataConfiguration_UnmarshalCaddyfile(t *testing.T) {
t.Parallel()
tests := []struct {
name string
input string
expect *ProtectedResourceMetadataConfiguration
shouldErr bool
}{
{
name: "empty",
input: `protected_resource_metadata { }`,
expect: &ProtectedResourceMetadataConfiguration{},
},
{
name: "disable",
input: `protected_resource_metadata off`,
expect: &ProtectedResourceMetadataConfiguration{
Disable: true,
},
},
{
name: "audience",
input: `protected_resource_metadata {
audience
}`,
expect: &ProtectedResourceMetadataConfiguration{
Audience: true,
},
},
{
name: "unexpected arg",
input: `protected_resource_metadata value`,
shouldErr: true,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
t.Parallel()
metaConfig := new(ProtectedResourceMetadataConfiguration)
d := caddyfile.NewTestDispenser(tt.input)
err := metaConfig.UnmarshalCaddyfile(d)
if tt.shouldErr {
assert.Error(t, err)
return
}
require.NoError(t, err)
assert.Equal(t, tt.expect, metaConfig)
})
}
}
func TestOAuthProtectedResource_WWWAuthenticate(t *testing.T) {
t.Parallel()
md := &OAuthProtectedResource{
Resource: "http://example.com",
ScopesSupported: []string{"openid", "profile", "email"},
}
assert.Equal(t, "Bearer resource_metadata=\"http://example.com/.well-known/oauth-protected-resource\", scope=\"openid profile email\"", md.WWWAuthenticate())
}