diff --git a/go/lib/infra/modules/trust/v2/BUILD.bazel b/go/lib/infra/modules/trust/v2/BUILD.bazel index cb0187e82b..7efada00fc 100644 --- a/go/lib/infra/modules/trust/v2/BUILD.bazel +++ b/go/lib/infra/modules/trust/v2/BUILD.bazel @@ -42,7 +42,6 @@ go_library( go_test( name = "go_default_test", srcs = [ - "export_test.go", "handlers_test.go", "inserter_test.go", "inspector_test.go", diff --git a/go/lib/infra/modules/trust/v2/export_test.go b/go/lib/infra/modules/trust/v2/export_test.go deleted file mode 100644 index ed24577f73..0000000000 --- a/go/lib/infra/modules/trust/v2/export_test.go +++ /dev/null @@ -1,70 +0,0 @@ -// Copyright 2019 Anapaya Systems -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package trust - -import "github.com/scionproto/scion/go/lib/infra" - -var ( - // NewChainPushHandler allows instantiating the private chain push handler for black-box - // testing. - NewChainPushHandler = newTestChainPushHandler - // NewTRCPushHandler allows instantiating the private TRC push handler for black-box - // testing. - NewTRCPushHandler = newTestTRCPushHandler - // NewChainReqHandler allows instantiating the private certificate chain - // request handler for black-box testing. - NewChainReqHandler = newTestChainReqHandler - // NewTRCReqHandler allows instantiating the private trc request handler for - // black-box testing. - NewTRCReqHandler = newTestTRCReqResolver -) - -// newTestChainReqHandler returns a new resolver for testing. -func newTestChainReqHandler(request *infra.Request, provider CryptoProvider) *chainReqHandler { - return &chainReqHandler{ - request: request, - provider: provider, - } -} - -// newTestResolver returns a new resolver for testing. -func newTestTRCReqResolver(request *infra.Request, provider CryptoProvider) *trcReqHandler { - return &trcReqHandler{ - request: request, - provider: provider, - } -} - -// newChainPushHandler returns a new chain push handler for testing. -func newTestChainPushHandler(request *infra.Request, provider CryptoProvider, - inserter Inserter) *chainPushHandler { - - return &chainPushHandler{ - request: request, - provider: provider, - inserter: inserter, - } -} - -// newTRCPushHandler returns a new TRC push handler for testing. -func newTestTRCPushHandler(request *infra.Request, provider CryptoProvider, - inserter Inserter) *trcPushHandler { - - return &trcPushHandler{ - request: request, - provider: provider, - inserter: inserter, - } -} diff --git a/go/lib/infra/modules/trust/v2/handlers_test.go b/go/lib/infra/modules/trust/v2/handlers_test.go index 99fee4e751..c94f280763 100644 --- a/go/lib/infra/modules/trust/v2/handlers_test.go +++ b/go/lib/infra/modules/trust/v2/handlers_test.go @@ -150,11 +150,10 @@ func TestChainReqHandler(t *testing.T) { t.Parallel() ctrl := gomock.NewController(t) defer ctrl.Finish() - handler := trust.NewChainReqHandler( - test.Request(ctrl), - test.Provider(ctrl), - ) - result := handler.Handle() + store := trust.Store{ + CryptoProvider: test.Provider(ctrl), + } + result := store.NewChainReqHandler().Handle(test.Request(ctrl)) assert.Equal(t, test.ExpectedResult, result) }) } @@ -277,11 +276,10 @@ func TestTRCReqHandler(t *testing.T) { t.Parallel() ctrl := gomock.NewController(t) defer ctrl.Finish() - handler := trust.NewTRCReqHandler( - test.Request(ctrl), - test.Provider(ctrl), - ) - result := handler.Handle() + store := trust.Store{ + CryptoProvider: test.Provider(ctrl), + } + result := store.NewTRCReqHandler().Handle(test.Request(ctrl)) assert.Equal(t, test.ExpectedResult, result) }) } @@ -451,20 +449,18 @@ func TestChainPushHandler(t *testing.T) { }, } - for _, test := range testCases { - tc := test - t.Run(tc.Name, func(t *testing.T) { + for _, tc := range testCases { + test := tc + t.Run(test.Name, func(t *testing.T) { t.Parallel() ctrl := gomock.NewController(t) defer ctrl.Finish() - chainPushHandler := trust.NewChainPushHandler( - tc.Request(ctrl), - nil, - tc.Inserter(ctrl), - ) - result := chainPushHandler.Handle() - assert.Equal(t, tc.ExpectedResult, result) + store := trust.Store{ + Inserter: test.Inserter(ctrl), + } + result := store.NewChainPushHandler().Handle(test.Request(ctrl)) + assert.Equal(t, test.ExpectedResult, result) }) } } @@ -633,20 +629,18 @@ func TestTRCPushHandler(t *testing.T) { }, } - for _, test := range testCases { - tc := test - t.Run(tc.Name, func(t *testing.T) { + for _, tc := range testCases { + test := tc + t.Run(test.Name, func(t *testing.T) { t.Parallel() ctrl := gomock.NewController(t) defer ctrl.Finish() - trcPushHandler := trust.NewTRCPushHandler( - tc.Request(ctrl), - nil, - tc.Inserter(ctrl), - ) - result := trcPushHandler.Handle() - assert.Equal(t, tc.ExpectedResult, result) + store := trust.Store{ + Inserter: test.Inserter(ctrl), + } + result := store.NewTRCPushHandler().Handle(test.Request(ctrl)) + assert.Equal(t, test.ExpectedResult, result) }) } } diff --git a/go/lib/infra/modules/trust/v2/store_test.go b/go/lib/infra/modules/trust/v2/store_test.go index 3e003cc404..e3f7c890c0 100644 --- a/go/lib/infra/modules/trust/v2/store_test.go +++ b/go/lib/infra/modules/trust/v2/store_test.go @@ -23,9 +23,11 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" + "github.com/scionproto/scion/go/lib/addr" "github.com/scionproto/scion/go/lib/infra" "github.com/scionproto/scion/go/lib/infra/modules/trust/v2" "github.com/scionproto/scion/go/lib/infra/modules/trust/v2/trustdbsqlite" + "github.com/scionproto/scion/go/lib/scrypto" "github.com/scionproto/scion/go/lib/xtest" ) @@ -96,11 +98,20 @@ func TestStoreLoadCryptoMaterial(t *testing.T) { if err != nil { return } - id := trust.TRCID{ISD: 1, Version: 1} - opts := infra.TRCOpts{AllowInactive: true} - raw, err := store.GetRawTRC(context.Background(), id, opts) - assert.NoError(t, err) - assert.Equal(t, loadTRC(t, trc1v1).Raw, raw) + trcOpts := infra.TRCOpts{AllowInactive: true} + for v := scrypto.Version(1); v < 5; v++ { + id := trust.TRCID{ISD: 1, Version: v} + raw, err := store.GetRawTRC(context.Background(), id, trcOpts) + assert.NoError(t, err) + assert.Equal(t, loadTRC(t, TRCDesc{ISD: 1, Version: v}).Raw, raw) + } + chainOpts := infra.ChainOpts{AllowInactive: true} + for _, ia := range []addr.IA{ia110, ia120, ia122, ia130, ia210} { + id := trust.ChainID{IA: ia, Version: 1} + raw, err := store.GetRawChain(context.Background(), id, chainOpts) + assert.NoError(t, err) + assert.Equal(t, loadChain(t, ChainDesc{IA: ia, Version: 1}).Raw, raw) + } }) } } @@ -124,10 +135,10 @@ func collectChains(t *testing.T, origDir, outDir string) { chains, err := filepath.Glob(filepath.Join(origDir, "ISD*/AS*/certs/*.crt")) require.NoError(t, err, help) require.Greater(t, len(chains), 0) - for _, trc := range chains { - raw, err := ioutil.ReadFile(trc) + for _, chain := range chains { + raw, err := ioutil.ReadFile(chain) require.NoError(t, err) - _, file := filepath.Split(trc) + _, file := filepath.Split(chain) err = ioutil.WriteFile(filepath.Join(outDir, file), raw, 0x777) require.NoError(t, err) }