-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
202 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,74 @@ | ||
package server | ||
package server_test | ||
|
||
import ( | ||
"testing" | ||
|
||
server "github.com/canonical/gocert/api" | ||
) | ||
|
||
func TestNewServerSuccess(t *testing.T) { | ||
testCases := []struct { | ||
desc string | ||
cert string | ||
key string | ||
}{ | ||
{ | ||
desc: "Correct certificate and key", | ||
cert: "Should be a valid cert", | ||
key: "Should be a valid key", | ||
}, | ||
{ | ||
desc: "Empty certificate", | ||
cert: "", | ||
key: "Should be a valid key", | ||
}, | ||
{ | ||
desc: "Empty key", | ||
cert: "Should be a valid cert", | ||
key: "", | ||
}, | ||
{ | ||
desc: "Empty certificate and key", | ||
cert: "", | ||
key: "", | ||
}, | ||
} | ||
for _, tC := range testCases { | ||
t.Run(tC.desc, func(t *testing.T) { | ||
s, err := server.NewServer(tC.cert, tC.key) | ||
if err != nil { | ||
t.Errorf("Error occured: %s", err) | ||
} | ||
if s.TLSConfig.Certificates == nil { | ||
t.Errorf("No certificates were configured for server") | ||
} | ||
}) | ||
} | ||
} | ||
|
||
func TestNewServerFail(t *testing.T) { | ||
testCases := []struct { | ||
desc string | ||
cert string | ||
key string | ||
}{ | ||
{ | ||
desc: "Wrong certificate", | ||
cert: "Should be invalid", | ||
key: "Should be valid", | ||
}, | ||
{ | ||
desc: "Wrong key", | ||
cert: "Should be valid", | ||
key: "Should be invalid", | ||
}, | ||
} | ||
for _, tC := range testCases { | ||
t.Run(tC.desc, func(t *testing.T) { | ||
_, err := server.NewServer(tC.cert, tC.key) | ||
if err != nil { | ||
t.Errorf("Expected error") | ||
} | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,16 @@ | ||
package main | ||
|
||
import "testing" | ||
|
||
func TestMain(t *testing.T) { | ||
// run gocert | ||
// run gocert --cert openable path | ||
// run gocert --key openable path | ||
// run gocert --cert openable path --key openable path --db unopenable path | ||
// run gocert --cert openable path --key openable path --db openable path | ||
// parametrize below | ||
// run gocert --cert unopenable path --key unopenable path | ||
// run gocert --cert unopenable path --key openable path | ||
// run gocert --cert openable path --key unopenable path | ||
// run gocert --cert openable path --key openable path | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,109 @@ | ||
package certificates_test | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/canonical/gocert/internal/certificates" | ||
) | ||
|
||
func TestGenerateSelfSignedCertificateSuccess(t *testing.T) { | ||
testCases := []struct { | ||
desc string | ||
}{ | ||
{ | ||
desc: "", | ||
}, | ||
} | ||
for _, tC := range testCases { | ||
t.Run(tC.desc, func(t *testing.T) { | ||
|
||
}) | ||
} | ||
} | ||
|
||
func TestGenerateSelfSignedCertificateFail(t *testing.T) { | ||
testCases := []struct { | ||
desc string | ||
}{ | ||
{ | ||
desc: "", | ||
}, | ||
} | ||
for _, tC := range testCases { | ||
t.Run(tC.desc, func(t *testing.T) { | ||
|
||
}) | ||
} | ||
} | ||
|
||
func TestParseCertificateSuccess(t *testing.T) { | ||
testCases := []struct { | ||
desc string | ||
}{ | ||
{ | ||
desc: "", | ||
}, | ||
} | ||
for _, tC := range testCases { | ||
t.Run(tC.desc, func(t *testing.T) { | ||
|
||
}) | ||
} | ||
} | ||
|
||
func TestParseCertificateFail(t *testing.T) { | ||
testCases := []struct { | ||
desc string | ||
}{ | ||
{ | ||
desc: "", | ||
}, | ||
} | ||
for _, tC := range testCases { | ||
t.Run(tC.desc, func(t *testing.T) { | ||
|
||
}) | ||
} | ||
} | ||
|
||
func TestParsePKCS1PrivateKeySuccess(t *testing.T) { | ||
testCases := []struct { | ||
desc string | ||
}{ | ||
{ | ||
desc: "", | ||
}, | ||
} | ||
for _, tC := range testCases { | ||
t.Run(tC.desc, func(t *testing.T) { | ||
|
||
}) | ||
} | ||
} | ||
|
||
func TestParsePKCS1PrivateKeyFail(t *testing.T) { | ||
testCases := []struct { | ||
desc string | ||
}{ | ||
{ | ||
desc: "", | ||
}, | ||
} | ||
for _, tC := range testCases { | ||
t.Run(tC.desc, func(t *testing.T) { | ||
|
||
}) | ||
} | ||
} | ||
func TestGenerateCACertificateSuccess(t *testing.T) { | ||
caCertPEM, caPKPEM, err := certificates.GenerateCACertificate() | ||
if err != nil { | ||
t.Fatalf("could not generate CA cert and PK") | ||
} | ||
if _, err := certificates.ParseCertificate(caCertPEM); err != nil { | ||
t.Fatalf("generate CA cert cannot be parsed") | ||
} | ||
if _, err := certificates.ParsePKCS1PrivateKey(caPKPEM); err != nil { | ||
t.Fatalf("generate CA private key cannot be parsed") | ||
} | ||
} |