2019-01-24 20:15:10 +00:00
|
|
|
// Copyright (C) 2019 Storj Labs, Inc.
|
2019-01-02 10:23:25 +00:00
|
|
|
// See LICENSE for copying information.
|
|
|
|
|
2019-02-11 11:17:32 +00:00
|
|
|
package tlsopts_test
|
2019-01-02 10:23:25 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"io/ioutil"
|
|
|
|
"reflect"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
2019-02-25 07:38:03 +00:00
|
|
|
"github.com/stretchr/testify/require"
|
2019-01-02 10:23:25 +00:00
|
|
|
|
|
|
|
"storj.io/storj/internal/testcontext"
|
2019-02-25 07:38:03 +00:00
|
|
|
"storj.io/storj/internal/testplanet"
|
2019-01-02 10:23:25 +00:00
|
|
|
"storj.io/storj/pkg/peertls"
|
2019-02-11 11:17:32 +00:00
|
|
|
"storj.io/storj/pkg/peertls/tlsopts"
|
2019-01-02 10:23:25 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestNewOptions(t *testing.T) {
|
|
|
|
ctx := testcontext.New(t)
|
|
|
|
defer ctx.Cleanup()
|
|
|
|
|
2019-02-25 07:38:03 +00:00
|
|
|
fi, err := testplanet.PregeneratedIdentity(0)
|
|
|
|
require.NoError(t, err)
|
2019-01-02 10:23:25 +00:00
|
|
|
|
|
|
|
whitelistPath := ctx.File("whitelist.pem")
|
|
|
|
|
|
|
|
chainData, err := peertls.ChainBytes(fi.CA)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
|
|
|
|
err = ioutil.WriteFile(whitelistPath, chainData, 0644)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
|
|
|
|
cases := []struct {
|
|
|
|
testID string
|
2019-02-11 11:17:32 +00:00
|
|
|
config tlsopts.Config
|
2019-01-02 10:23:25 +00:00
|
|
|
pcvFuncsLen int
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
"default",
|
2019-02-11 11:17:32 +00:00
|
|
|
tlsopts.Config{},
|
2019-01-02 10:23:25 +00:00
|
|
|
0,
|
|
|
|
}, {
|
|
|
|
"revocation processing",
|
2019-02-11 11:17:32 +00:00
|
|
|
tlsopts.Config{
|
2019-01-02 10:23:25 +00:00
|
|
|
RevocationDBURL: "bolt://" + ctx.File("revocation1.db"),
|
|
|
|
Extensions: peertls.TLSExtConfig{
|
|
|
|
Revocation: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
2,
|
|
|
|
}, {
|
|
|
|
"ca whitelist verification",
|
2019-02-11 11:17:32 +00:00
|
|
|
tlsopts.Config{
|
2019-01-02 10:23:25 +00:00
|
|
|
PeerCAWhitelistPath: whitelistPath,
|
2019-01-17 17:36:45 +00:00
|
|
|
UsePeerCAWhitelist: true,
|
2019-01-02 10:23:25 +00:00
|
|
|
},
|
|
|
|
1,
|
|
|
|
}, {
|
|
|
|
"ca whitelist verification and whitelist signed leaf verification",
|
2019-02-11 11:17:32 +00:00
|
|
|
tlsopts.Config{
|
2019-01-02 10:23:25 +00:00
|
|
|
// NB: file doesn't actually exist
|
|
|
|
PeerCAWhitelistPath: whitelistPath,
|
2019-01-17 17:36:45 +00:00
|
|
|
UsePeerCAWhitelist: true,
|
2019-01-02 10:23:25 +00:00
|
|
|
Extensions: peertls.TLSExtConfig{
|
|
|
|
WhitelistSignedLeaf: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
2,
|
|
|
|
}, {
|
|
|
|
"revocation processing and whitelist verification",
|
2019-02-11 11:17:32 +00:00
|
|
|
tlsopts.Config{
|
2019-01-02 10:23:25 +00:00
|
|
|
// NB: file doesn't actually exist
|
|
|
|
PeerCAWhitelistPath: whitelistPath,
|
2019-01-17 17:36:45 +00:00
|
|
|
UsePeerCAWhitelist: true,
|
2019-01-02 10:23:25 +00:00
|
|
|
RevocationDBURL: "bolt://" + ctx.File("revocation2.db"),
|
|
|
|
Extensions: peertls.TLSExtConfig{
|
|
|
|
Revocation: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
3,
|
|
|
|
}, {
|
|
|
|
"revocation processing, whitelist, and signed leaf verification",
|
2019-02-11 11:17:32 +00:00
|
|
|
tlsopts.Config{
|
2019-01-02 10:23:25 +00:00
|
|
|
// NB: file doesn't actually exist
|
|
|
|
PeerCAWhitelistPath: whitelistPath,
|
2019-01-17 17:36:45 +00:00
|
|
|
UsePeerCAWhitelist: true,
|
2019-01-02 10:23:25 +00:00
|
|
|
RevocationDBURL: "bolt://" + ctx.File("revocation3.db"),
|
|
|
|
Extensions: peertls.TLSExtConfig{
|
|
|
|
Revocation: true,
|
|
|
|
WhitelistSignedLeaf: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
3,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, c := range cases {
|
|
|
|
t.Log(c.testID)
|
2019-02-11 11:17:32 +00:00
|
|
|
opts, err := tlsopts.NewOptions(fi, c.config)
|
2019-01-02 10:23:25 +00:00
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.True(t, reflect.DeepEqual(fi, opts.Ident))
|
|
|
|
assert.Equal(t, c.config, opts.Config)
|
|
|
|
assert.Len(t, opts.PCVFuncs, c.pcvFuncsLen)
|
|
|
|
}
|
|
|
|
}
|