A certificate published with no use is used for encryption when there is none with use="encryption".
(t *testing.T)
| 101 | // A certificate published with no use is used for encryption when there is |
| 102 | // none with use="encryption". |
| 103 | func 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 | |
| 128 | func keyInfo(der []byte) KeyInfo { |
| 129 | return KeyInfo{X509Data: X509Data{X509Certificates: []X509Certificate{{Data: base64.StdEncoding.EncodeToString(der)}}}} |
nothing calls this directly
no test coverage detected