sign_test.go 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. package sign
  2. import (
  3. "testing"
  4. "github.com/cloudflare/cfssl/certdb/sql"
  5. "github.com/cloudflare/cfssl/certdb/testdb"
  6. "github.com/cloudflare/cfssl/cli"
  7. )
  8. func TestSignFromConfig(t *testing.T) {
  9. _, err := SignerFromConfig(cli.Config{CAFile: "../../testdata/server.crt",
  10. CAKeyFile: "../../testdata/server.key", Hostname: "www.cloudflare.com", Remote: "127.0.0.1:8888"})
  11. if err != nil {
  12. t.Fatal(err)
  13. }
  14. }
  15. func TestSignerMain(t *testing.T) {
  16. err := signerMain([]string{"../../testdata/server.csr"}, cli.Config{CAFile: "../../testdata/server.crt",
  17. CAKeyFile: "../../testdata/server.key", Hostname: "www.cloudflare.com"})
  18. if err != nil {
  19. t.Fatal(err)
  20. }
  21. }
  22. func TestBadSigner(t *testing.T) {
  23. err := signerMain([]string{"../../testdata/server.csr"}, cli.Config{CAFile: "", CAKeyFile: ""})
  24. if err != nil {
  25. t.Fatal(err)
  26. }
  27. err = signerMain([]string{"../../testdata/server.csr"},
  28. cli.Config{CAFile: "../../testdata/server.crt", CAKeyFile: ""})
  29. if err != nil {
  30. t.Fatal(err)
  31. }
  32. }
  33. func TestSignerWithDB(t *testing.T) {
  34. db := testdb.SQLiteDB("../../certdb/testdb/certstore_development.db")
  35. err := signerMain([]string{"../../testdata/server.csr"},
  36. cli.Config{
  37. CAFile: "../../testdata/server.crt",
  38. CAKeyFile: "../../testdata/server.key",
  39. Hostname: "www.cloudflare.com",
  40. DBConfigFile: "../testdata/db-config.json"})
  41. if err != nil {
  42. t.Fatal(err)
  43. }
  44. dbAccessor := sql.NewAccessor(db)
  45. crs, err := dbAccessor.GetUnexpiredCertificates()
  46. if err != nil {
  47. t.Fatal("Failed to get unexpired certificates")
  48. }
  49. if len(crs) != 1 {
  50. t.Fatal("Expected 1 unexpired certificate in the database after signing 1")
  51. }
  52. }