MCPcopy Create free account
hub / github.com/crewjam/saml / TestValidateAssertionMissingElements

Function TestValidateAssertionMissingElements

assertion_shape_test.go:49–92  ·  view source on GitHub ↗

An assertion missing its optional elements fails validation with an error instead of a nil-pointer panic.

(t *testing.T)

Source from the content-addressed store, hash-verified

47// An assertion missing its optional elements fails validation with an error
48// instead of a nil-pointer panic.
49func TestValidateAssertionMissingElements(t *testing.T) {
50 now := TimeNow()
51 sp := ServiceProvider{
52 EntityID: "https://sp.example.com/metadata",
53 AcsURL: mustParseURL("https://sp.example.com/acs"),
54 IDPMetadata: &EntityDescriptor{EntityID: "https://idp.example.com/"},
55 }
56 full := func() *Assertion {
57 return &Assertion{
58 Version: "2.0",
59 IssueInstant: now,
60 Issuer: Issuer{Value: "https://idp.example.com/"},
61 Subject: &Subject{NameID: &NameID{Value: "alice"}, SubjectConfirmations: []SubjectConfirmation{{
62 Method: bearerSubjectConfirmationMethod,
63 SubjectConfirmationData: &SubjectConfirmationData{
64 InResponseTo: "id-1", Recipient: "https://sp.example.com/acs", NotOnOrAfter: now.Add(time.Minute),
65 },
66 }}},
67 Conditions: &Conditions{
68 NotBefore: now.Add(-time.Minute), NotOnOrAfter: now.Add(time.Minute),
69 AudienceRestrictions: []AudienceRestriction{{Audience: Audience{Value: "https://sp.example.com/metadata"}}},
70 },
71 AuthnStatements: []AuthnStatement{{AuthnInstant: now}},
72 }
73 }
74 assert.Check(t, sp.validateAssertion(full(), []string{"id-1"}, now))
75
76 a := full()
77 a.Subject = nil
78 assert.Check(t, is.Error(sp.validateAssertion(a, []string{"id-1"}, now), "assertion has no Subject"))
79
80 a = full()
81 a.Conditions = nil
82 assert.Check(t, is.Error(sp.validateAssertion(a, []string{"id-1"}, now), "assertion has no Conditions"))
83
84 a = full()
85 a.Subject.SubjectConfirmations[0].SubjectConfirmationData = nil
86 assert.Check(t, is.Error(sp.validateAssertion(a, []string{"id-1"}, now),
87 "assertion SubjectConfirmation has no SubjectConfirmationData"))
88
89 a = full()
90 a.Issuer = Issuer{}
91 assert.Check(t, is.Error(sp.validateAssertion(a, []string{"id-1"}, now), `issuer is not "https://idp.example.com/"`))
92}
93
94// A LogoutResponse without an Issuer is refused instead of panicking.
95func TestValidateLogoutResponseWithoutIssuer(t *testing.T) {

Callers

nothing calls this directly

Calls 3

validateAssertionMethod · 0.95
mustParseURLFunction · 0.50
ErrorMethod · 0.45

Tested by

no test coverage detected