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

Function TestInvalidCertificateErrorKinds

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

Source from the content-addressed store, hash-verified

414}
415
416func TestInvalidCertificateErrorKinds(t *testing.T) {
417 t.Run("IdP: SP encryption certificate", func(t *testing.T) {
418 test := idpcovNewTest(t)
419 for _, data := range []string{"!!!", base64.StdEncoding.EncodeToString([]byte("not a certificate"))} {
420 req := idpcovMadeAssertion(t, test)
421 req.SPSSODescriptor.KeyDescriptors = []KeyDescriptor{idpcovCertKeyDescriptor("encryption", data)}
422 _, err := req.getSPEncryptionCert()
423 checkOnlyKind(t, err, ErrInvalidCertificate)
424 checkOnlyKind(t, req.MakeAssertionEl(), ErrInvalidCertificate)
425 }
426 })
427
428 e := spcovSetup(t)
429 notACert := base64.StdEncoding.EncodeToString([]byte("not a certificate"))
430 tests := []struct {
431 name string
432 mutate func(sp *ServiceProvider)
433 }{
434 {"SP: IdP metadata certificate base64", func(sp *ServiceProvider) {
435 sp.IDPMetadata.IDPSSODescriptors[0].KeyDescriptors[0].KeyInfo.X509Data.X509Certificates[0].Data = "!!!"
436 }},
437 {"SP: IdP metadata certificate", func(sp *ServiceProvider) {
438 sp.IDPMetadata.IDPSSODescriptors[0].KeyDescriptors[0].KeyInfo.X509Data.X509Certificates[0].Data = notACert
439 }},
440 {"SP: IDPCertificate", func(sp *ServiceProvider) { sp.IDPCertificate = &notACert }},
441 }
442 for _, tc := range tests {
443 t.Run(tc.name, func(t *testing.T) {
444 sp := *e.sp
445 sp.IDPMetadata = spcovIDPMetadata(e.idpCert)
446 tc.mutate(&sp)
447 _, err := sp.ParseXMLResponse(e.signedResponse(t), []string{spcovRequestID}, sp.AcsURL)
448 assert.Check(t, errors.Is(err, ErrInvalidCertificate))
449 assert.Check(t, errors.Is(err, ErrInvalidSignature))
450 assert.Check(t, !errors.Is(err, ErrUntrustedCertificate))
451 })
452 }
453}
454
455func TestIdentityProviderOnError(t *testing.T) {
456 type call struct {

Callers

nothing calls this directly

Calls 10

idpcovNewTestFunction · 0.85
idpcovMadeAssertionFunction · 0.85
idpcovCertKeyDescriptorFunction · 0.85
checkOnlyKindFunction · 0.85
spcovSetupFunction · 0.85
spcovIDPMetadataFunction · 0.85
getSPEncryptionCertMethod · 0.80
MakeAssertionElMethod · 0.80
ParseXMLResponseMethod · 0.80
signedResponseMethod · 0.80

Tested by

no test coverage detected