1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93
|
package gencert
import (
"testing"
"github.com/cloudflare/cfssl/cli"
)
func TestGencertMain(t *testing.T) {
c := cli.Config{
IsCA: true,
}
err := gencertMain([]string{"../testdata/csr.json"}, c)
if err != nil {
t.Fatal(err)
}
c = cli.Config{
IsCA: true,
CAKeyFile: "../testdata/ca-key.pem",
}
err = gencertMain([]string{"../testdata/csr.json"}, c)
if err != nil {
t.Fatal(err)
}
c = cli.Config{
CAFile: "../testdata/ca.pem",
CAKeyFile: "../testdata/ca-key.pem",
}
err = gencertMain([]string{"../testdata/csr.json"}, c)
if err != nil {
t.Fatal(err)
}
c = cli.Config{
RenewCA: true,
CAFile: "../testdata/ca.pem",
CAKeyFile: "../testdata/ca-key.pem",
}
err = gencertMain([]string{}, c)
if err != nil {
t.Fatal(err)
}
}
func TestBadGencertMain(t *testing.T) {
err := gencertMain([]string{"../testdata/csr.json"}, cli.Config{})
if err != nil {
t.Fatal(err)
}
err = gencertMain([]string{"../testdata/csr.json"}, cli.Config{CAFile: "../testdata/ca.pem"})
if err != nil {
t.Fatal(err)
}
err = gencertMain([]string{}, cli.Config{RenewCA: true})
if err == nil {
t.Fatal("No CA or Key provided, should report error")
}
err = gencertMain([]string{}, cli.Config{})
if err == nil {
t.Fatal("Not enough argument, should report error")
}
err = gencertMain([]string{"../testdata/bad_csr.json"}, cli.Config{})
if err == nil {
t.Fatal("Bad CSR JSON, should report error")
}
err = gencertMain([]string{"../testdata/nothing"}, cli.Config{})
if err == nil {
t.Fatal("Trying to read a non-existance file, should report error")
}
err = gencertMain([]string{"../testdata/csr.json"}, cli.Config{IsCA: true, CAKeyFile: "../../testdata/garbage.crt"})
if err == nil {
t.Fatal("Bad CA, should report error")
}
err = gencertMain([]string{"../testdata/csr.json"}, cli.Config{CAFile: "../testdata/ca.pem", Remote: "123::::123"})
if err == nil {
t.Fatal("Invalid remote, should reort error")
}
}
|