fix test
Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
This commit is contained in:
parent
c1c27b6d1d
commit
eb8c1332f0
@ -94,7 +94,7 @@ func NewIntermediate(cacrt *x509.Certificate, cakey crypto.PrivateKey, opts ...C
|
||||
// SignCSR sign certificate request and return signed pubkey
|
||||
func SignCSR(rawcsr []byte, cacrt *x509.Certificate, cakey crypto.PrivateKey, opts ...CertificateOption) ([]byte, error) {
|
||||
if cacrt == nil {
|
||||
opts = append(opts, CertificateIsCA(false))
|
||||
opts = append(opts, CertificateIsCA(true))
|
||||
}
|
||||
|
||||
options := NewCertificateOptions(opts...)
|
||||
@ -124,7 +124,7 @@ func SignCSR(rawcsr []byte, cacrt *x509.Certificate, cakey crypto.PrivateKey, op
|
||||
IsCA: options.IsCA,
|
||||
}
|
||||
|
||||
if !options.IsCA {
|
||||
if options.IsCA {
|
||||
cacrt = tpl
|
||||
} else {
|
||||
tpl.Issuer = cacrt.Subject
|
||||
|
@ -10,6 +10,7 @@ func TestNewCa(t *testing.T) {
|
||||
bcrt, key, err := NewCA(
|
||||
CertificateOrganization("test_org"),
|
||||
CertificateOrganizationalUnit("test_unit"),
|
||||
CertificateIsCA(true),
|
||||
)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
@ -23,7 +24,7 @@ func TestNewCa(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if crt.IsCA {
|
||||
if !crt.IsCA {
|
||||
t.Fatalf("crt IsCA invalid %v", crt)
|
||||
}
|
||||
if crt.Subject.Organization[0] != "test_org" {
|
||||
@ -33,3 +34,40 @@ func TestNewCa(t *testing.T) {
|
||||
t.Fatalf("crt subject invalid %v", crt.Subject)
|
||||
}
|
||||
}
|
||||
|
||||
func TestNewIntermediate(t *testing.T) {
|
||||
bcrt, cakey, err := NewCA(
|
||||
CertificateOrganization("test_org"),
|
||||
CertificateOrganizationalUnit("test_unit"),
|
||||
)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
cacrt, err := x509.ParseCertificate(bcrt)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
bcrt, ikey, err := NewIntermediate(cacrt, cakey,
|
||||
CertificateOrganization("test_org"),
|
||||
CertificateOrganizationalUnit("test_unit"),
|
||||
)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
_ = ikey
|
||||
icrt, err := x509.ParseCertificate(bcrt)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if icrt.IsCA {
|
||||
t.Fatalf("crt IsCA invalid %v", icrt)
|
||||
}
|
||||
if icrt.Subject.Organization[0] != "test_org" {
|
||||
t.Fatalf("crt subject invalid %v", icrt.Subject)
|
||||
}
|
||||
if icrt.Subject.OrganizationalUnit[0] != "test_unit" {
|
||||
t.Fatalf("crt subject invalid %v", icrt.Subject)
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user