forked from crewjam/saml
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathschema_test.go
48 lines (42 loc) · 1.24 KB
/
schema_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
package saml
import (
"encoding/xml"
"testing"
"github.com/beevik/etree"
"github.com/stretchr/testify/assert"
)
func TestAttributeXMLRoundTrip(t *testing.T) {
expected := Attribute{
FriendlyName: "TestFriendlyName",
Name: "TestName",
NameFormat: "urn:oasis:names:tc:SAML:2.0:attrname-format:basic",
Values: []AttributeValue{{
Type: "xs:string",
Value: "test",
}},
}
doc := etree.NewDocument()
doc.SetRoot(expected.Element())
x, err := doc.WriteToBytes()
assert.NoError(t, err)
assert.Equal(t,
"<saml:Attribute FriendlyName=\"TestFriendlyName\" Name=\"TestName\" NameFormat=\"urn:oasis:names:tc:SAML:2.0:attrname-format:basic\"><saml:AttributeValue xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\" xsi:type=\"xs:string\">test</saml:AttributeValue></saml:Attribute>",
string(x))
var actual Attribute
err = xml.Unmarshal(x, &actual)
assert.NoError(t, err)
assert.Equal(t, expected, actual)
}
func TestNameIDFormat(t *testing.T) {
var emptyString string
el := NameIDPolicy{
Format: &emptyString,
}
doc := etree.NewDocument()
doc.SetRoot(el.Element())
x, err := doc.WriteToBytes()
assert.NoError(t, err)
assert.Equal(t,
"<samlp:NameIDPolicy/>",
string(x))
}