Skip to content

Commit

Permalink
feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
oncilla committed Dec 18, 2019
1 parent 09ef8d2 commit 70e85d2
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 109 deletions.
1 change: 0 additions & 1 deletion go/lib/infra/modules/trust/v2/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
70 changes: 0 additions & 70 deletions go/lib/infra/modules/trust/v2/export_test.go

This file was deleted.

54 changes: 24 additions & 30 deletions go/lib/infra/modules/trust/v2/handlers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
})
}
Expand Down Expand Up @@ -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)
})
}
Expand Down Expand Up @@ -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)
})
}
}
Expand Down Expand Up @@ -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)
})
}
}
27 changes: 19 additions & 8 deletions go/lib/infra/modules/trust/v2/store_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down Expand Up @@ -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)
}
})
}
}
Expand All @@ -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)
}
Expand Down

0 comments on commit 70e85d2

Please sign in to comment.