An assertion missing its optional elements fails validation with an error instead of a nil-pointer panic.
(t *testing.T)
| 47 | // An assertion missing its optional elements fails validation with an error |
| 48 | // instead of a nil-pointer panic. |
| 49 | func 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. |
| 95 | func TestValidateLogoutResponseWithoutIssuer(t *testing.T) { |
nothing calls this directly
no test coverage detected