-
Notifications
You must be signed in to change notification settings - Fork 96
/
Copy pathlogout_request_test.go
94 lines (78 loc) · 3.07 KB
/
logout_request_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
package cas
import (
"encoding/xml"
"testing"
"time"
)
func TestParseLogoutRequest(t *testing.T) {
xml := `<samlp:LogoutRequest xmlns:samlp="urn:oasis:names:tc:SAML:2.0:protocol"
ID="8r7834d6r78346s7823d46678235d" Version="2.0" IssueInstant="Fri, 27 Feb 2015 13:31:34 -0000">
<saml:NameID xmlns:saml="urn:oasis:names:tc:SAML:2.0:assertion">
@NOT_USED@
</saml:NameID>
<samlp:SessionIndex>ST-io34f34vr7823vcr82346r782c4b78i2364i76cvr72364rv7263</samlp:SessionIndex>
</samlp:LogoutRequest>`
l, err := parseLogoutRequest([]byte(xml))
if err != nil {
t.Errorf("parseLogoutRequest returned error: %v", err)
}
if l.Version != "2.0" {
t.Errorf("Expected Version to be %q, got %q", "2.0", l.Version)
}
if l.ID != "8r7834d6r78346s7823d46678235d" {
t.Errorf("Expected ID to be %q, got %q",
"8r7834d6r78346s7823d46678235d", l.ID)
}
if l.NameID != "@NOT_USED@" {
t.Errorf("Expected NameID to be %q, got %q", "@NOT_USED@", l.NameID)
}
ticketName := "ST-io34f34vr7823vcr82346r782c4b78i2364i76cvr72364rv7263"
if l.SessionIndex != ticketName {
t.Errorf("Expected SessionIndex to be %q, got %q", ticketName, l.SessionIndex)
}
instant := time.Date(2015, 02, 27, 13, 31, 34, 0, time.UTC)
if !instant.Equal(l.IssueInstant) {
t.Errorf("Expected IssueInstant to be <%v>, got <%v>",
instant, l.IssueInstant)
}
}
func TestXmlLayoutRequest(t *testing.T) {
// Unwrapping the xmlLayoutRequest() function so we can test the generated XML
l := &logoutRequest{
Version: "2.0",
IssueInstant: time.Date(2015, 02, 27, 13, 31, 34, 0, time.UTC),
ID: "8r7834d6r78346s7823d46678235d",
NameID: "@NOT_USED@",
SessionIndex: "ST-io34f34vr7823vcr82346r782c4b78i2364i76cvr72364rv7263",
}
l.RawIssueInstant = l.IssueInstant.Format(time.RFC1123Z)
bytes, err := xml.MarshalIndent(l, "", " ")
if err != nil {
t.Errorf("xml.MarshalIndent returned error: %v", err)
}
expected := `<LogoutRequest xmlns="urn:oasis:names:tc:SAML:2.0:protocol" Version="2.0" IssueInstant="Fri, 27 Feb 2015 13:31:34 +0000" ID="8r7834d6r78346s7823d46678235d">
<NameID xmlns="urn:oasis:names:tc:SAML:2.0:assertion">@NOT_USED@</NameID>
<SessionIndex>ST-io34f34vr7823vcr82346r782c4b78i2364i76cvr72364rv7263</SessionIndex>
</LogoutRequest>`
if string(bytes) != expected {
t.Errorf("Expected XML to be \n%v\ngot\n%v\n", expected, string(bytes))
}
}
func TestParseLogoutRequestWithISO8601(t *testing.T) {
xml := `<samlp:LogoutRequest xmlns:samlp="urn:oasis:names:tc:SAML:2.0:protocol"
ID="8r7834d6r78346s7823d46678235d" Version="2.0" IssueInstant="2018-03-22T10:52:57Z">
<saml:NameID xmlns:saml="urn:oasis:names:tc:SAML:2.0:assertion">
@NOT_USED@
</saml:NameID>
<samlp:SessionIndex>ST-io34f34vr7823vcr82346r782c4b78i2364i76cvr72364rv7263</samlp:SessionIndex>
</samlp:LogoutRequest>`
l, err := parseLogoutRequest([]byte(xml))
if err != nil {
t.Errorf("parseLogoutRequest returned error: %v", err)
}
instant := time.Date(2018, 03, 22, 10, 52, 57, 0, time.UTC)
if !instant.Equal(l.IssueInstant) {
t.Errorf("Expected IssueInstant to be <%v>, got <%v>",
instant, l.IssueInstant)
}
}