cacert-gosigner/x509/revoking/revoking_test.go

37 lines
762 B
Go
Raw Normal View History

package revoking
import (
"math/big"
"math/rand"
"testing"
"time"
"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)
rand.Seed(time.Now().Unix())
serial := big.NewInt(rand.Int63())
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)
}