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

Function TestIDPDefaultSignatureMethod

idp_coverage_test.go:492–534  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

490}
491
492func TestIDPDefaultSignatureMethod(t *testing.T) {
493 test := NewIdentityProviderTest(t, applyKey)
494
495 t.Run("RSA", func(t *testing.T) {
496 req := IdpAuthnRequest{IDP: &test.IDP}
497 ctx, err := req.signingContext()
498 assert.NilError(t, err)
499 assert.Check(t, is.Equal(dsig.RSASHA256SignatureMethod, ctx.GetSignatureMethodIdentifier()))
500 })
501
502 t.Run("ECDSA", func(t *testing.T) {
503 key, err := ecdsa.GenerateKey(elliptic.P256(), rand.Reader)
504 assert.NilError(t, err)
505 tmpl := &x509.Certificate{
506 SerialNumber: big.NewInt(1),
507 Subject: pkix.Name{CommonName: "idp.example.com"},
508 NotBefore: time.Date(2015, 1, 1, 0, 0, 0, 0, time.UTC),
509 NotAfter: time.Date(2035, 1, 1, 0, 0, 0, 0, time.UTC),
510 }
511 der, err := x509.CreateCertificate(rand.Reader, tmpl, tmpl, &key.PublicKey, key)
512 assert.NilError(t, err)
513 cert, err := x509.ParseCertificate(der)
514 assert.NilError(t, err)
515
516 idp := test.IDP
517 idp.Key = nil
518 idp.Signer = key
519 idp.Certificate = cert
520 req := IdpAuthnRequest{IDP: &idp}
521 ctx, err := req.signingContext()
522 assert.NilError(t, err)
523 assert.Check(t, is.Equal(dsig.ECDSASHA256SignatureMethod, ctx.GetSignatureMethodIdentifier()))
524 })
525
526 t.Run("Explicit", func(t *testing.T) {
527 idp := test.IDP
528 idp.SignatureMethod = dsig.RSASHA512SignatureMethod
529 req := IdpAuthnRequest{IDP: &idp}
530 ctx, err := req.signingContext()
531 assert.NilError(t, err)
532 assert.Check(t, is.Equal(dsig.RSASHA512SignatureMethod, ctx.GetSignatureMethodIdentifier()))
533 })
534}
535
536// TestIDPSigningWithNilKey is a regression test for
537// https://github.com/crewjam/saml/issues/405: a nil or typed-nil key used to

Callers

nothing calls this directly

Calls 2

signingContextMethod · 0.95
NewIdentityProviderTestFunction · 0.85

Tested by

no test coverage detected