(t *testing.T)
| 100 | } |
| 101 | |
| 102 | func TestParseXMLResponseErrorKinds(t *testing.T) { |
| 103 | e := spcovSetup(t) |
| 104 | old := spcovNow.Add(-time.Hour) |
| 105 | future := spcovNow.Add(time.Hour) |
| 106 | |
| 107 | tests := []struct { |
| 108 | name string |
| 109 | mutate func(r *Response, a *Assertion) |
| 110 | want error |
| 111 | }{ |
| 112 | {"response Destination", func(r *Response, _ *Assertion) { r.Destination = "https://elsewhere.example.com/acs" }, ErrDestinationMismatch}, |
| 113 | {"response IssueInstant", func(r *Response, _ *Assertion) { r.IssueInstant = old }, ErrExpired}, |
| 114 | {"response Issuer", func(r *Response, _ *Assertion) { r.Issuer.Value = "https://other-idp.example.com" }, ErrIssuerMismatch}, |
| 115 | {"response InResponseTo", func(r *Response, _ *Assertion) { r.InResponseTo = "id-other" }, ErrRequestIDMismatch}, |
| 116 | {"no Assertion", func(r *Response, _ *Assertion) { r.Assertion = nil }, ErrMissingElement}, |
| 117 | {"assertion Subject", func(_ *Response, a *Assertion) { a.Subject = nil }, ErrMissingElement}, |
| 118 | {"assertion Conditions", func(_ *Response, a *Assertion) { a.Conditions = nil }, ErrMissingElement}, |
| 119 | {"assertion bearer", func(_ *Response, a *Assertion) { a.Subject.SubjectConfirmations[0].Method = "urn:other" }, ErrMissingElement}, |
| 120 | {"assertion IssueInstant", func(_ *Response, a *Assertion) { a.IssueInstant = old }, ErrExpired}, |
| 121 | {"assertion SubjectConfirmationData NotOnOrAfter", func(_ *Response, a *Assertion) { |
| 122 | a.Subject.SubjectConfirmations[0].SubjectConfirmationData.NotOnOrAfter = old |
| 123 | }, ErrExpired}, |
| 124 | {"assertion Conditions NotOnOrAfter", func(_ *Response, a *Assertion) { a.Conditions.NotOnOrAfter = old }, ErrExpired}, |
| 125 | {"assertion Conditions NotBefore", func(_ *Response, a *Assertion) { a.Conditions.NotBefore = future }, ErrNotYetValid}, |
| 126 | {"assertion SubjectConfirmationData NotBefore", func(_ *Response, a *Assertion) { |
| 127 | a.Subject.SubjectConfirmations[0].SubjectConfirmationData.NotBefore = future |
| 128 | }, ErrNotYetValid}, |
| 129 | {"assertion Issuer", func(_ *Response, a *Assertion) { a.Issuer.Value = "https://other-idp.example.com" }, ErrIssuerMismatch}, |
| 130 | {"assertion Recipient", func(_ *Response, a *Assertion) { |
| 131 | a.Subject.SubjectConfirmations[0].SubjectConfirmationData.Recipient = "https://elsewhere.example.com/acs" |
| 132 | }, ErrDestinationMismatch}, |
| 133 | {"assertion InResponseTo", func(_ *Response, a *Assertion) { |
| 134 | a.Subject.SubjectConfirmations[0].SubjectConfirmationData.InResponseTo = "id-other" |
| 135 | }, ErrRequestIDMismatch}, |
| 136 | {"assertion audience", func(_ *Response, a *Assertion) { |
| 137 | a.Conditions.AudienceRestrictions[0].Audience.Value = "https://other-sp.example.com" |
| 138 | }, ErrAudienceMismatch}, |
| 139 | {"assertion no AudienceRestriction", func(_ *Response, a *Assertion) { a.Conditions.AudienceRestrictions = nil }, ErrAudienceMismatch}, |
| 140 | } |
| 141 | for _, tc := range tests { |
| 142 | t.Run(tc.name, func(t *testing.T) { |
| 143 | r := e.response() |
| 144 | r.Assertion = e.assertion() |
| 145 | tc.mutate(r, r.Assertion) |
| 146 | buf := spcovSerialize(t, e.idpSign(t, r.Element())) |
| 147 | _, err := e.sp.ParseXMLResponse(buf, []string{spcovRequestID}, e.sp.AcsURL) |
| 148 | var ire *InvalidResponseError |
| 149 | assert.Assert(t, errors.As(err, &ire)) |
| 150 | checkOnlyKind(t, err, tc.want) |
| 151 | }) |
| 152 | } |
| 153 | |
| 154 | t.Run("AuthnContextClassRef", func(t *testing.T) { |
| 155 | password := "urn:oasis:names:tc:SAML:2.0:ac:classes:Password" //nolint:gosec // an AuthnContextClassRef URI, not a credential |
| 156 | mfa := "https://refeds.org/profile/mfa" |
| 157 | r := e.response() |
| 158 | r.Assertion = e.assertion() |
| 159 | r.Assertion.AuthnStatements = []AuthnStatement{{ |
nothing calls this directly
no test coverage detected