cacert-gosigner/x509/revoking/revoking_test.go

37 lines
839 B
Go
Raw Normal View History

package revoking
import (
"crypto/rand"
"math/big"
"testing"
"github.com/stretchr/testify/assert"
)
type testRepo struct {
revoked []big.Int
}
func (t *testRepo) StoreRevocation(revoked *CertificateRevoked) error {
t.revoked = append(t.revoked, *revoked.serialNumber)
return nil
}
func TestRevoking(t *testing.T) {
testRepository := testRepo{revoked: make([]big.Int, 0)}
r := NewX509Revoking(&testRepository)
serial, err := rand.Int(rand.Reader, new(big.Int).Lsh(big.NewInt(1), 128))
if err != nil {
t.Errorf("could not create random serial: %v", err)
}
revoke, err := r.Revoke(&RevokeCertificate{serialNumber: serial, reason: "for testing"})
assert.NoError(t, err)
assert.Equal(t, "for testing", revoke.reason)
assert.Equal(t, serial, revoke.serialNumber)
assert.Contains(t, testRepository.revoked, *serial)
}