forked from crewjam/saml
-
Notifications
You must be signed in to change notification settings - Fork 2
/
metadata_test.go
167 lines (156 loc) · 5.42 KB
/
metadata_test.go
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
package saml
import (
"encoding/xml"
"testing"
"time"
"gotest.tools/assert"
is "gotest.tools/assert/cmp"
"gotest.tools/golden"
)
func TestCanParseMetadata(t *testing.T) {
buf := golden.Get(t, "TestCanParseMetadata_metadata.xml")
metadata := EntityDescriptor{}
err := xml.Unmarshal(buf, &metadata)
assert.Check(t, err)
var False = false
var True = true
expected := EntityDescriptor{
EntityID: "https://dev.aa.kndr.org/users/auth/saml/metadata",
ID: "_af805d1c-c2e3-444e-9cf5-efc664eeace6",
ValidUntil: time.Date(2001, time.February, 3, 4, 5, 6, 789000000, time.UTC),
CacheDuration: time.Hour,
SPSSODescriptors: []SPSSODescriptor{
{
XMLName: xml.Name{Space: "urn:oasis:names:tc:SAML:2.0:metadata", Local: "SPSSODescriptor"},
SSODescriptor: SSODescriptor{
RoleDescriptor: RoleDescriptor{
ProtocolSupportEnumeration: "urn:oasis:names:tc:SAML:2.0:protocol",
},
},
AuthnRequestsSigned: &False,
WantAssertionsSigned: &False,
AssertionConsumerServices: []IndexedEndpoint{
{
Binding: "urn:oasis:names:tc:SAML:2.0:bindings:HTTP-POST",
Location: "https://dev.aa.kndr.org/users/auth/saml/callback",
Index: 0,
IsDefault: &True,
},
},
AttributeConsumingServices: []AttributeConsumingService{
{
Index: 1,
IsDefault: &True,
ServiceNames: []LocalizedName{{Lang: "en", Value: "Required attributes"}},
RequestedAttributes: []RequestedAttribute{
{
Attribute: Attribute{
FriendlyName: "Email address",
Name: "email",
NameFormat: "urn:oasis:names:tc:SAML:2.0:attrname-format:basic",
},
},
{
Attribute: Attribute{
FriendlyName: "Full name",
Name: "name",
NameFormat: "urn:oasis:names:tc:SAML:2.0:attrname-format:basic",
},
},
{
Attribute: Attribute{
FriendlyName: "Given name",
Name: "first_name",
NameFormat: "urn:oasis:names:tc:SAML:2.0:attrname-format:basic",
},
},
{
Attribute: Attribute{
FriendlyName: "Family name",
Name: "last_name",
NameFormat: "urn:oasis:names:tc:SAML:2.0:attrname-format:basic",
},
},
},
},
},
},
},
}
assert.Check(t, is.DeepEqual(expected, metadata))
}
func TestCanProduceSPMetadata(t *testing.T) {
validUntil, _ := time.Parse("2006-01-02T15:04:05.000000", "2013-03-10T00:32:19.104000")
AuthnRequestsSigned := true
WantAssertionsSigned := true
metadata := EntityDescriptor{
EntityID: "http://localhost:5000/e087a985171710fb9fb30f30f41384f9/saml2/metadata/",
ValidUntil: validUntil,
CacheDuration: time.Hour,
SPSSODescriptors: []SPSSODescriptor{
{
AuthnRequestsSigned: &AuthnRequestsSigned,
WantAssertionsSigned: &WantAssertionsSigned,
SSODescriptor: SSODescriptor{
RoleDescriptor: RoleDescriptor{
ProtocolSupportEnumeration: "urn:oasis:names:tc:SAML:2.0:protocol",
KeyDescriptors: []KeyDescriptor{
{
Use: "encryption",
KeyInfo: KeyInfo{
X509Data: X509Data{
X509Certificates: []X509Certificate{
{
Data: `MIIB7zCCAVgCCQDFzbKIp7b3MTANBgkqhkiG9w0BAQUFADA8MQswCQYDVQQGEwJVUzELMAkGA1UE
CAwCR0ExDDAKBgNVBAoMA2ZvbzESMBAGA1UEAwwJbG9jYWxob3N0MB4XDTEzMTAwMjAwMDg1MVoX
DTE0MTAwMjAwMDg1MVowPD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gQCMMlIO+GNcGekevKgkakpMdAqJfs24maGb90Dv
TLbRZRD7Xvn1MnVBBS9hzlXiFLYOInXACMW5gcoRFfeTQLSouMM8o57h0uKjfTmuoWHLQLi6hnF+
cvCsEFiJZ4AbF+DgmO6TarJ8O05t8zvnOwJlNCASPZRH/JmF8tX0hoHuAQ==`,
},
},
},
},
},
},
},
SingleLogoutServices: []Endpoint{{
Binding: "urn:oasis:names:tc:SAML:2.0:bindings:HTTP-Redirect",
Location: "http://localhost:5000/e087a985171710fb9fb30f30f41384f9/saml2/ls/",
}},
},
AssertionConsumerServices: []IndexedEndpoint{{
Binding: "urn:oasis:names:tc:SAML:2.0:bindings:HTTP-POST",
Location: "http://localhost:5000/e087a985171710fb9fb30f30f41384f9/saml2/ls/",
Index: 1,
}},
},
},
}
buf, err := xml.MarshalIndent(metadata, "", " ")
assert.Check(t, err)
golden.Assert(t, string(buf), "TestCanProduceSPMetadata_expected")
}