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

Function TestLogoutErrorKinds

errors_test.go:204–270  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

202}
203
204func TestLogoutErrorKinds(t *testing.T) {
205 e := spcovSetup(t)
206 old := spcovNow.Add(-time.Hour)
207
208 t.Run("LogoutResponse", func(t *testing.T) {
209 tests := []struct {
210 name string
211 mutate func(r *LogoutResponse)
212 want error
213 }{
214 {"Destination", func(r *LogoutResponse) { r.Destination = "https://elsewhere.example.com/slo" }, ErrDestinationMismatch},
215 {"IssueInstant", func(r *LogoutResponse) { r.IssueInstant = old }, ErrExpired},
216 {"Issuer", func(r *LogoutResponse) { r.Issuer = nil }, ErrIssuerMismatch},
217 }
218 for _, tc := range tests {
219 t.Run(tc.name, func(t *testing.T) {
220 r := e.logoutResponse()
221 tc.mutate(r)
222 checkOnlyKind(t, e.sp.validateLogoutResponse(r), tc.want)
223 })
224 }
225
226 t.Run("Status", func(t *testing.T) {
227 r := e.logoutResponse()
228 r.Status.StatusCode.Value = "urn:oasis:names:tc:SAML:2.0:status:Requester"
229 err := e.sp.validateLogoutResponse(r)
230 assert.Error(t, err, "status code was not "+StatusSuccess)
231 var badStatus ErrBadStatus
232 assert.Assert(t, errors.As(err, &badStatus))
233 assert.Equal(t, "urn:oasis:names:tc:SAML:2.0:status:Requester", badStatus.Status)
234 })
235 })
236
237 t.Run("LogoutRequest", func(t *testing.T) {
238 request := func() *LogoutRequest {
239 return &LogoutRequest{
240 ID: "id-logout-request",
241 Version: "2.0",
242 IssueInstant: spcovNow,
243 Destination: e.sp.SloURL.String(),
244 Issuer: &Issuer{Value: spcovIDPEntityID},
245 NameID: &NameID{Value: "alice@example.com"},
246 }
247 }
248 assert.NilError(t, e.sp.validateLogoutRequest(request()))
249
250 tests := []struct {
251 name string
252 mutate func(r *LogoutRequest)
253 want error
254 }{
255 {"Destination", func(r *LogoutRequest) { r.Destination = "https://elsewhere.example.com/slo" }, ErrDestinationMismatch},
256 {"IssueInstant old", func(r *LogoutRequest) { r.IssueInstant = old }, ErrExpired},
257 {"IssueInstant future", func(r *LogoutRequest) { r.IssueInstant = spcovNow.Add(time.Hour) }, ErrNotYetValid},
258 {"NotOnOrAfter", func(r *LogoutRequest) { r.NotOnOrAfter = &old }, ErrExpired},
259 {"Issuer", func(r *LogoutRequest) { r.Issuer.Value = "https://other-idp.example.com" }, ErrIssuerMismatch},
260 {"NameID", func(r *LogoutRequest) { r.NameID = nil }, ErrMissingElement},
261 }

Callers

nothing calls this directly

Calls 7

spcovSetupFunction · 0.85
checkOnlyKindFunction · 0.85
StringMethod · 0.80
validateLogoutRequestMethod · 0.80
logoutResponseMethod · 0.45
ErrorMethod · 0.45

Tested by

no test coverage detected