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

Function TestGetIDPEncryptionCertUnspecifiedUse

logout_request_identifiers_test.go:103–126  ·  view source on GitHub ↗

A certificate published with no use is used for encryption when there is none with use="encryption".

(t *testing.T)

Source from the content-addressed store, hash-verified

101// A certificate published with no use is used for encryption when there is
102// none with use="encryption".
103func TestGetIDPEncryptionCertUnspecifiedUse(t *testing.T) {
104 test := newSLOTest(t)
105 _, cert := aqKeyPair(t)
106 test.SP.IDPMetadata.IDPSSODescriptors[0].KeyDescriptors = []KeyDescriptor{
107 {Use: "signing", KeyInfo: keyInfo(test.IDP.Certificate.Raw)},
108 {KeyInfo: keyInfo(cert.Raw)},
109 }
110 got, _, err := test.SP.getIDPEncryptionCert()
111 assert.NilError(t, err)
112 assert.Check(t, got.Equal(cert))
113
114 test.SP.IDPMetadata.IDPSSODescriptors[0].KeyDescriptors = append(
115 test.SP.IDPMetadata.IDPSSODescriptors[0].KeyDescriptors,
116 KeyDescriptor{Use: "encryption", KeyInfo: keyInfo(test.IDP.Certificate.Raw)})
117 got, _, err = test.SP.getIDPEncryptionCert()
118 assert.NilError(t, err)
119 assert.Check(t, got.Equal(test.IDP.Certificate))
120
121 test.SP.IDPMetadata.IDPSSODescriptors[0].KeyDescriptors = []KeyDescriptor{
122 {Use: "encryption", KeyInfo: KeyInfo{X509Data: X509Data{X509Certificates: []X509Certificate{{Data: "not base64!"}}}}},
123 }
124 _, _, err = test.SP.getIDPEncryptionCert()
125 assert.Check(t, errors.Is(err, ErrInvalidCertificate), "%v", err)
126}
127
128func keyInfo(der []byte) KeyInfo {
129 return KeyInfo{X509Data: X509Data{X509Certificates: []X509Certificate{{Data: base64.StdEncoding.EncodeToString(der)}}}}

Callers

nothing calls this directly

Calls 4

newSLOTestFunction · 0.85
aqKeyPairFunction · 0.85
keyInfoFunction · 0.85
getIDPEncryptionCertMethod · 0.80

Tested by

no test coverage detected