Пример #1
0
func TestRevocation(t *testing.T) {
	db, err := prepDB()
	if err != nil {
		t.Fatal(err)
	}

	resp, body := testRevokeCert(t, db, "1", "5")

	if resp.StatusCode != http.StatusOK {
		t.Fatal("unexpected HTTP status code; expected OK", string(body))
	}
	message := new(api.Response)
	err = json.Unmarshal(body, message)
	if err != nil {
		t.Fatalf("failed to read response body: %v", err)
	}

	cert, err := certdb.GetCertificate(db, "1")
	if err != nil {
		t.Fatal("failed to get certificate ", err)
	}

	if cert.Status != "revoked" || cert.Reason != 5 {
		t.Fatal("cert was not correctly revoked")
	}
}
Пример #2
0
func TestRevokeMain(t *testing.T) {
	db, err := prepDB()
	if err != nil {
		t.Fatal(err)
	}

	err = revokeMain([]string{}, cli.Config{Serial: "1", DBConfigFile: "../testdata/db-config.json"})
	if err != nil {
		t.Fatal(err)
	}

	var crs *certdb.CertificateRecord
	crs, err = certdb.GetCertificate(db, "1")
	if err != nil {
		t.Fatal("Failed to get certificate")
	}

	if crs.Status != "revoked" {
		t.Fatal("Certificate not marked revoked after we revoked it")
	}

	err = revokeMain([]string{}, cli.Config{Serial: "1", Reason: "2", DBConfigFile: "../testdata/db-config.json"})
	if err != nil {
		t.Fatal(err)
	}

	crs, err = certdb.GetCertificate(db, "1")
	if err != nil {
		t.Fatal("Failed to get certificate")
	}

	if crs.Reason != 2 {
		t.Fatal("Certificate revocation reason incorrect")
	}

	err = revokeMain([]string{}, cli.Config{Serial: "1", Reason: "Superseded", DBConfigFile: "../testdata/db-config.json"})
	if err != nil {
		t.Fatal(err)
	}

	crs, err = certdb.GetCertificate(db, "1")
	if err != nil {
		t.Fatal("Failed to get certificate")
	}

	if crs.Reason != ocsp.Superseded {
		t.Fatal("Certificate revocation reason incorrect")
	}

	err = revokeMain([]string{}, cli.Config{Serial: "1", Reason: "invalid_reason", DBConfigFile: "../testdata/db-config.json"})
	if err == nil {
		t.Fatal("Expected error from invalid reason")
	}

	err = revokeMain([]string{}, cli.Config{Serial: "1", Reason: "999", DBConfigFile: "../testdata/db-config.json"})
	if err == nil {
		t.Fatal("Expected error from invalid reason")
	}

	err = revokeMain([]string{}, cli.Config{Serial: "2", DBConfigFile: "../testdata/db-config.json"})
	if err == nil {
		t.Fatal("Expected error from unrecognized serial number")
	}

	err = revokeMain([]string{}, cli.Config{DBConfigFile: "../testdata/db-config.json"})
	if err == nil {
		t.Fatal("Expected error from missing serial number")
	}

	err = revokeMain([]string{}, cli.Config{Serial: "1"})
	if err == nil {
		t.Fatal("Expected error from missing db config")
	}
}