2021-08-23 18:53:43 +00:00
|
|
|
package revoking
|
|
|
|
|
|
|
|
import (
|
2022-04-21 18:01:35 +00:00
|
|
|
"crypto/rand"
|
2021-08-23 18:53:43 +00:00
|
|
|
"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)
|
|
|
|
|
2022-04-21 18:01:35 +00:00
|
|
|
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)
|
|
|
|
}
|
2021-08-23 18:53:43 +00:00
|
|
|
|
|
|
|
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)
|
|
|
|
}
|