mirror of
https://github.com/gocsaf/csaf.git
synced 2025-12-22 11:55:40 +01:00
Improve LoadCertificate unit test (#692)
* fix `LoadCertificate` unit test replaced certificate with invalid dns name, which is rejected by stdlib of Go version >=1.25.2. Change in Go introduced by https://github.com/golang/go/issues/75715 * code review: add script to generate certificates, remove `greenbone` org entry * code review: add license header * rework cert creation and fix one filename --------- Co-authored-by: Marius Goetze <marius.goetze@greenbone.net>
This commit is contained in:
parent
05eae0a9ae
commit
c6bad42c24
7 changed files with 311 additions and 261 deletions
|
|
@ -20,13 +20,13 @@ func TestLoadCertificates(t *testing.T) {
|
|||
passphrase = "qwer"
|
||||
missingCert = "data/testclientcert_missing.crt"
|
||||
missingTestkey = "data/testclientkey_missing.pem"
|
||||
privateKey = "data/privated.pem"
|
||||
privateKey = "data/private.pem"
|
||||
privateCert = "data/cert.crt"
|
||||
)
|
||||
|
||||
// Try to load cert that is not protected, expect success.
|
||||
if cert, err := LoadCertificate(&testCert, &testKey, nil); cert == nil || err != nil {
|
||||
t.Errorf("Failure: Couldn't load supposedly valid certificate.")
|
||||
t.Errorf("Failure: Couldn't load supposedly valid certificate. Got error: %v", err)
|
||||
}
|
||||
// Try to load no cert, expect error.
|
||||
if cert, err := LoadCertificate(nil, &testKey, nil); cert != nil || err == nil {
|
||||
|
|
@ -46,7 +46,7 @@ func TestLoadCertificates(t *testing.T) {
|
|||
}
|
||||
// Try to load encrypted cert, expecting success.
|
||||
if cert, err := LoadCertificate(&privateCert, &privateKey, &passphrase); cert == nil || err != nil {
|
||||
t.Errorf("Failure: Couldn't load supposedly valid encrypted certificate.")
|
||||
t.Errorf("Failure: Couldn't load supposedly valid encrypted certificate. Got error: %v", err)
|
||||
}
|
||||
// Try to load wrong encrypted cert, expecting error.
|
||||
if cert, err := LoadCertificate(&testKey, &privateKey, &passphrase); cert != nil || err == nil {
|
||||
|
|
@ -56,8 +56,8 @@ func TestLoadCertificates(t *testing.T) {
|
|||
if cert, err := LoadCertificate(&missingCert, &privateKey, &passphrase); cert != nil || err == nil {
|
||||
t.Errorf("Failure: No Failure while loading nonexistens certificate.")
|
||||
}
|
||||
// Try to load nonexistent encrypted cert, expecting error.
|
||||
// Try to load nonexistent encrypted cert, expecting success.
|
||||
if cert, err := LoadCertificate(nil, nil, nil); cert != nil || err != nil {
|
||||
t.Errorf("Failure: Expected nil return.")
|
||||
t.Errorf("Failure: Expected nil return. Got error: %v", err)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue