storj/pkg/provider/cert_authority_test.go
Bryan White 8b9711cb5e
better waitlist-gating (#557)
* better waitlist-gating

(cherry picked from commit 490fe02b7c3558da18678dfb651c92ec9c4a75b5)

* fix broken test

* linter fixes

* linter fixes

* make extension verification optional

* add certifcate gating script for captplanet

* fixing tests

* linter fixes

* linter fixes?

* moar linter fixes

* Revert "moar linter fixes"

This reverts commit 8139ccbd73cbbead987b7667567844f50f7df2c8.

* just kill me

* refactor

* refactor tests

* liniter...

* cleanup
2018-11-01 16:48:43 +01:00

72 lines
1.5 KiB
Go

// Copyright (C) 2018 Storj Labs, Inc.
// See LICENSE for copying information.
package provider
import (
"context"
"testing"
"github.com/stretchr/testify/assert"
)
func TestNewCA(t *testing.T) {
expectedDifficulty := uint16(4)
ca, err := NewCA(context.Background(), NewCAOptions{
Difficulty: expectedDifficulty,
Concurrency: 5,
})
assert.NoError(t, err)
assert.NotEmpty(t, ca)
actualDifficulty := ca.ID.Difficulty()
assert.True(t, actualDifficulty >= expectedDifficulty)
}
func TestFullCertificateAuthority_NewIdentity(t *testing.T) {
check := func(err error, v interface{}) {
if !assert.NoError(t, err) || !assert.NotEmpty(t, v) {
t.Fail()
}
}
ca, err := NewTestCA(context.Background())
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)
}
func NewCABenchmark(b *testing.B, difficulty uint16, concurrency uint) {
for i := 0; i < b.N; i++ {
_, _ = NewCA(context.Background(), NewCAOptions{
Difficulty: difficulty,
Concurrency: concurrency,
})
}
}
func BenchmarkNewCA_Difficulty8_Concurrency1(b *testing.B) {
NewCABenchmark(b, 8, 1)
}
func BenchmarkNewCA_Difficulty8_Concurrency2(b *testing.B) {
NewCABenchmark(b, 8, 2)
}
func BenchmarkNewCA_Difficulty8_Concurrency5(b *testing.B) {
NewCABenchmark(b, 8, 5)
}
func BenchmarkNewCA_Difficulty8_Concurrency10(b *testing.B) {
NewCABenchmark(b, 8, 10)
}