(t *testing.T)
| 453 | } |
| 454 | |
| 455 | func TestIdentityProviderOnError(t *testing.T) { |
| 456 | type call struct { |
| 457 | status int |
| 458 | err error |
| 459 | } |
| 460 | setup := func(t *testing.T) (*IdentityProviderTest, *[]call) { |
| 461 | test := idpcovNewTest(t) |
| 462 | test.IDP.SessionProvider = &mockSessionProvider{GetSessionFunc: idpcovAliceSession} |
| 463 | var calls []call |
| 464 | test.IDP.OnError = func(w http.ResponseWriter, _ *http.Request, status int, err error) { |
| 465 | calls = append(calls, call{status, err}) |
| 466 | w.WriteHeader(http.StatusTeapot) |
| 467 | } |
| 468 | return test, &calls |
| 469 | } |
| 470 | spMetadata := func(test *IdentityProviderTest, mutate func(*EntityDescriptor)) { |
| 471 | test.IDP.ServiceProviderProvider = &mockServiceProviderProvider{ |
| 472 | GetServiceProviderFunc: func(_ *http.Request, id string) (*EntityDescriptor, error) { |
| 473 | if id != test.SP.MetadataURL.String() { |
| 474 | return nil, os.ErrNotExist |
| 475 | } |
| 476 | md := test.SP.Metadata() |
| 477 | mutate(md) |
| 478 | return md, nil |
| 479 | }, |
| 480 | } |
| 481 | } |
| 482 | badEncryptionCert := func(md *EntityDescriptor) { |
| 483 | md.SPSSODescriptors[0].KeyDescriptors = []KeyDescriptor{idpcovCertKeyDescriptor("encryption", "!!!")} |
| 484 | } |
| 485 | |
| 486 | t.Run("ServeSSO unparseable request", func(t *testing.T) { |
| 487 | test, calls := setup(t) |
| 488 | w := httptest.NewRecorder() |
| 489 | test.IDP.ServeSSO(w, httptest.NewRequest("PUT", "https://idp.example.com/saml/sso", nil)) |
| 490 | assert.Equal(t, http.StatusTeapot, w.Code) |
| 491 | assert.Assert(t, len(*calls) == 1) |
| 492 | assert.Equal(t, http.StatusBadRequest, (*calls)[0].status) |
| 493 | assert.Error(t, (*calls)[0].err, "failed to parse request: method not allowed") |
| 494 | assert.Check(t, errors.Is((*calls)[0].err, ErrUnsupported)) |
| 495 | }) |
| 496 | |
| 497 | t.Run("ServeSSO invalid request", func(t *testing.T) { |
| 498 | test, calls := setup(t) |
| 499 | r := idpcovSSORequest(t, test) |
| 500 | test.IDP.ServiceProviderProvider = &mockServiceProviderProvider{ |
| 501 | GetServiceProviderFunc: func(*http.Request, string) (*EntityDescriptor, error) { return nil, os.ErrNotExist }, |
| 502 | } |
| 503 | test.IDP.ServeSSO(httptest.NewRecorder(), r) |
| 504 | assert.Assert(t, len(*calls) == 1) |
| 505 | assert.Equal(t, http.StatusBadRequest, (*calls)[0].status) |
| 506 | assert.Check(t, errors.Is((*calls)[0].err, ErrUnknownServiceProvider)) |
| 507 | }) |
| 508 | |
| 509 | t.Run("ServeSSO bad SP encryption certificate", func(t *testing.T) { |
| 510 | test, calls := setup(t) |
| 511 | spMetadata(test, badEncryptionCert) |
| 512 | test.IDP.ServeSSO(httptest.NewRecorder(), idpcovSSORequest(t, test)) |
nothing calls this directly
no test coverage detected