2018-08-13 09:39:45 +01:00
|
|
|
// Copyright (C) 2018 Storj Labs, Inc.
|
|
|
|
// See LICENSE for copying information.
|
|
|
|
|
|
|
|
package provider
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
)
|
|
|
|
|
2018-08-23 15:08:26 +01:00
|
|
|
func TestNewCA(t *testing.T) {
|
2018-08-13 09:39:45 +01:00
|
|
|
expectedDifficulty := uint16(4)
|
|
|
|
|
2018-11-01 15:48:43 +00:00
|
|
|
ca, err := NewCA(context.Background(), NewCAOptions{
|
|
|
|
Difficulty: expectedDifficulty,
|
|
|
|
Concurrency: 5,
|
|
|
|
})
|
2018-08-13 09:39:45 +01:00
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.NotEmpty(t, ca)
|
|
|
|
|
|
|
|
actualDifficulty := ca.ID.Difficulty()
|
|
|
|
assert.True(t, actualDifficulty >= expectedDifficulty)
|
|
|
|
}
|
|
|
|
|
2018-08-27 23:23:48 +01:00
|
|
|
func TestFullCertificateAuthority_NewIdentity(t *testing.T) {
|
|
|
|
check := func(err error, v interface{}) {
|
|
|
|
if !assert.NoError(t, err) || !assert.NotEmpty(t, v) {
|
|
|
|
t.Fail()
|
|
|
|
}
|
2018-08-13 09:39:45 +01:00
|
|
|
}
|
2018-08-27 23:23:48 +01:00
|
|
|
|
2018-11-01 15:48:43 +00:00
|
|
|
ca, err := NewTestCA(context.Background())
|
2018-08-27 23:23:48 +01:00
|
|
|
check(err, ca)
|
|
|
|
fi, err := ca.NewIdentity()
|
|
|
|
check(err, fi)
|
|
|
|
|
|
|
|
assert.Equal(t, ca.Cert, fi.CA)
|
|
|
|
assert.Equal(t, ca.ID, fi.ID)
|
|
|
|
assert.NotEqual(t, ca.Key, fi.Key)
|
|
|
|
assert.NotEqual(t, ca.Cert, fi.Leaf)
|
|
|
|
|
|
|
|
err = fi.Leaf.CheckSignatureFrom(ca.Cert)
|
|
|
|
assert.NoError(t, err)
|
2018-08-13 09:39:45 +01:00
|
|
|
}
|
|
|
|
|
2018-08-27 23:23:48 +01:00
|
|
|
func NewCABenchmark(b *testing.B, difficulty uint16, concurrency uint) {
|
2018-08-13 09:39:45 +01:00
|
|
|
for i := 0; i < b.N; i++ {
|
2018-11-01 15:48:43 +00:00
|
|
|
_, _ = NewCA(context.Background(), NewCAOptions{
|
|
|
|
Difficulty: difficulty,
|
|
|
|
Concurrency: concurrency,
|
|
|
|
})
|
2018-08-13 09:39:45 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-08-27 23:23:48 +01:00
|
|
|
func BenchmarkNewCA_Difficulty8_Concurrency1(b *testing.B) {
|
|
|
|
NewCABenchmark(b, 8, 1)
|
|
|
|
}
|
|
|
|
|
|
|
|
func BenchmarkNewCA_Difficulty8_Concurrency2(b *testing.B) {
|
|
|
|
NewCABenchmark(b, 8, 2)
|
|
|
|
}
|
|
|
|
|
2018-08-23 15:08:26 +01:00
|
|
|
func BenchmarkNewCA_Difficulty8_Concurrency5(b *testing.B) {
|
2018-08-27 23:23:48 +01:00
|
|
|
NewCABenchmark(b, 8, 5)
|
2018-08-13 09:39:45 +01:00
|
|
|
}
|
|
|
|
|
2018-08-23 15:08:26 +01:00
|
|
|
func BenchmarkNewCA_Difficulty8_Concurrency10(b *testing.B) {
|
2018-08-27 23:23:48 +01:00
|
|
|
NewCABenchmark(b, 8, 10)
|
2018-08-13 09:39:45 +01:00
|
|
|
}
|