Skip to content

Commit

Permalink
w
Browse files Browse the repository at this point in the history
  • Loading branch information
reinkrul committed Sep 26, 2023
1 parent 505642e commit d0ef024
Show file tree
Hide file tree
Showing 38 changed files with 695 additions and 595 deletions.
4 changes: 2 additions & 2 deletions auth/api/iam/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ type testCtx struct {
client *Wrapper
authnServices *auth.MockAuthenticationServices
vdr *vdr.MockVDR
resolver *vdr.MockDIDResolver
resolver *resolver.MockDIDResolver
}

func newTestClient(t testing.TB) *testCtx {
Expand All @@ -178,7 +178,7 @@ func newTestClient(t testing.TB) *testCtx {
ctrl := gomock.NewController(t)
authnServices := auth.NewMockAuthenticationServices(ctrl)
authnServices.EXPECT().PublicURL().Return(publicURL).AnyTimes()
resolver := vdr.NewMockDIDResolver(ctrl)
resolver := resolver.NewMockDIDResolver(ctrl)
vdr := vdr.NewMockVDR(ctrl)
vdr.EXPECT().Resolver().Return(resolver).AnyTimes()
return &testCtx{
Expand Down
5 changes: 2 additions & 3 deletions auth/services/notary/notary_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ import (
"github.com/nuts-foundation/nuts-node/jsonld"
"github.com/nuts-foundation/nuts-node/vcr"
"github.com/nuts-foundation/nuts-node/vdr"
"github.com/nuts-foundation/nuts-node/vdr/types"
irma "github.com/privacybydesign/irmago"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
Expand Down Expand Up @@ -372,7 +371,7 @@ type testContext struct {

signerMock *contract.MockSigner
vcr *vcr.MockVCR
keyResolver *types.MockKeyResolver
keyResolver *resolver.MockKeyResolver
keyStore *crypto.MockKeyStore
notary notary
}
Expand All @@ -388,7 +387,7 @@ func buildContext(t *testing.T) *testContext {
ctx := &testContext{
ctrl: ctrl,
vcr: vcr.NewMockVCR(ctrl),
keyResolver: types.NewMockKeyResolver(ctrl),
keyResolver: resolver.NewMockKeyResolver(ctrl),
keyStore: crypto.NewMockKeyStore(ctrl),
signerMock: signerMock,
}
Expand Down
9 changes: 4 additions & 5 deletions auth/services/oauth/authz_server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ import (
vcrTypes "github.com/nuts-foundation/nuts-node/vcr/types"
verifier2 "github.com/nuts-foundation/nuts-node/vcr/verifier"
"github.com/nuts-foundation/nuts-node/vdr"
"github.com/nuts-foundation/nuts-node/vdr/types"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"go.uber.org/mock/gomock"
Expand Down Expand Up @@ -855,8 +854,8 @@ type testContext struct {
contractNotary *services.MockContractNotary
keyStore *crypto.MockKeyStore
nameResolver *vcr.MockFinder
didResolver *types.MockDIDResolver
keyResolver *types.MockKeyResolver
didResolver *resolver.MockDIDResolver
keyResolver *resolver.MockKeyResolver
serviceResolver *didman.MockCompoundServiceResolver
oauthService *authzServer
verifier *verifier2.MockVerifier
Expand All @@ -869,9 +868,9 @@ var createContext = func(t *testing.T) *testContext {
contractNotaryMock := services.NewMockContractNotary(ctrl)
privateKeyStore := crypto.NewMockKeyStore(ctrl)
nameResolver := vcr.NewMockFinder(ctrl)
keyResolver := types.NewMockKeyResolver(ctrl)
keyResolver := resolver.NewMockKeyResolver(ctrl)
serviceResolver := didman.NewMockCompoundServiceResolver(ctrl)
didResolver := types.NewMockDIDResolver(ctrl)
didResolver := resolver.NewMockDIDResolver(ctrl)
verifier := verifier2.NewMockVerifier(ctrl)

return &testContext{
Expand Down
9 changes: 4 additions & 5 deletions auth/services/oauth/relying_party_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ import (
"github.com/nuts-foundation/nuts-node/didman"
"github.com/nuts-foundation/nuts-node/vcr/credential"
"github.com/nuts-foundation/nuts-node/vdr"
"github.com/nuts-foundation/nuts-node/vdr/types"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"go.uber.org/mock/gomock"
Expand Down Expand Up @@ -252,8 +251,8 @@ func TestRelyingParty_Configure(t *testing.T) {
type rpTestContext struct {
ctrl *gomock.Controller
keyStore *crypto.MockKeyStore
didResolver *types.MockDIDResolver
keyResolver *types.MockKeyResolver
didResolver *resolver.MockDIDResolver
keyResolver *resolver.MockKeyResolver
serviceResolver *didman.MockCompoundServiceResolver
relyingParty *relyingParty
audit context.Context
Expand All @@ -263,9 +262,9 @@ var createRPContext = func(t *testing.T) *rpTestContext {
ctrl := gomock.NewController(t)

privateKeyStore := crypto.NewMockKeyStore(ctrl)
keyResolver := types.NewMockKeyResolver(ctrl)
keyResolver := resolver.NewMockKeyResolver(ctrl)
serviceResolver := didman.NewMockCompoundServiceResolver(ctrl)
didResolver := types.NewMockDIDResolver(ctrl)
didResolver := resolver.NewMockDIDResolver(ctrl)

return &rpTestContext{
ctrl: ctrl,
Expand Down
5 changes: 2 additions & 3 deletions crypto/api/v1/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import (
"github.com/nuts-foundation/nuts-node/audit"
"github.com/nuts-foundation/nuts-node/core"
"github.com/nuts-foundation/nuts-node/vdr/resolver"
"github.com/nuts-foundation/nuts-node/vdr/types"
"net/http"
"testing"

Expand Down Expand Up @@ -475,14 +474,14 @@ func TestWrapper_DecryptJwe(t *testing.T) {
type mockContext struct {
ctrl *gomock.Controller
keyStore *crypto.MockKeyStore
keyResolver *types.MockKeyResolver
keyResolver *resolver.MockKeyResolver
client *Wrapper
}

func newMockContext(t *testing.T) mockContext {
ctrl := gomock.NewController(t)
keyStore := crypto.NewMockKeyStore(ctrl)
keyResolver := types.NewMockKeyResolver(ctrl)
keyResolver := resolver.NewMockKeyResolver(ctrl)
client := &Wrapper{C: keyStore, K: keyResolver}

return mockContext{
Expand Down
4 changes: 2 additions & 2 deletions didman/didman_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -974,14 +974,14 @@ type mockContext struct {
ctrl *gomock.Controller
vdr *types.MockVDR
vcr *vcr.MockFinder
didResolver *types.MockDIDResolver
didResolver *resolver.MockDIDResolver
instance Didman
audit context.Context
}

func newMockContext(t *testing.T) mockContext {
ctrl := gomock.NewController(t)
didResolver := types.NewMockDIDResolver(ctrl)
didResolver := resolver.NewMockDIDResolver(ctrl)
mockVDR := types.NewMockVDR(ctrl)
mockVDR.EXPECT().Resolver().Return(didResolver).AnyTimes()
mockVCR := vcr.NewMockFinder(ctrl)
Expand Down
4 changes: 2 additions & 2 deletions golden_hammer/module_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ func TestGoldenHammer_Fix(t *testing.T) {
t.Run("nothing to fix", func(t *testing.T) {
// vendor and care organization DIDs already have the required service, so there's nothing to fix
ctrl := gomock.NewController(t)
didResolver := types.NewMockDIDResolver(ctrl)
didResolver := resolver.NewMockDIDResolver(ctrl)
didResolver.EXPECT().Resolve(vendorDID, gomock.Any()).Return(&vendorDocumentWithBaseURL, nil, nil).MinTimes(1)
didResolver.EXPECT().Resolve(clientADID, gomock.Any()).Return(&clientDocumentWithBaseURL, nil, nil).MinTimes(1)
didResolver.EXPECT().Resolve(clientBDID, gomock.Any()).Return(&clientDocumentWithBaseURL, nil, nil).MinTimes(1)
Expand Down Expand Up @@ -218,7 +218,7 @@ func TestGoldenHammer_Fix(t *testing.T) {
})
t.Run("resolve error", func(t *testing.T) {
ctrl := gomock.NewController(t)
didResolver := types.NewMockDIDResolver(ctrl)
didResolver := resolver.NewMockDIDResolver(ctrl)
didResolver.EXPECT().Resolve(vendorDID, gomock.Any()).Return(nil, nil, fmt.Errorf("resolve error"))
vdr := types.NewMockVDR(ctrl)
vdr.EXPECT().Resolver().Return(didResolver)
Expand Down
6 changes: 5 additions & 1 deletion makefile
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,11 @@ gen-mocks:
mockgen -destination=vcr/verifier/mock.go -package=verifier -source=vcr/verifier/interface.go
mockgen -destination=vdr/didnuts/ambassador_mock.go -package=didnuts -source=vdr/didnuts/ambassador.go
mockgen -destination=vdr/didnuts/didstore/mock.go -package=didstore -source=vdr/didnuts/didstore/interface.go
mockgen -destination=vdr/types/mock.go -package=types -source=vdr/types/interface.go -self_package github.com/nuts-foundation/nuts-node/vdr/types --imports did=github.com/nuts-foundation/go-did/did
mockgen -destination=vdr/resolver/did_mock.go -package=resolver -source=vdr/resolver/did.go
mockgen -destination=vdr/resolver/service_mock.go -package=resolver -source=vdr/resolver/service.go
mockgen -destination=vdr/resolver/key_mock.go -package=resolver -source=vdr/resolver/key.go
mockgen -destination=vdr/management/management_mock.go -package=management -source=vdr/management/management.go
mockgen -destination=vdr/management/finder_mock.go -package=management -source=vdr/management/finder.go

gen-api:
oapi-codegen --config codegen/configs/common_ssi_types.yaml docs/_static/common/ssi_types.yaml | gofmt > api/ssi_types.go
Expand Down
3 changes: 1 addition & 2 deletions network/dag/keys_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import (
"github.com/nuts-foundation/go-did/did"
"github.com/nuts-foundation/nuts-node/crypto/hash"
"github.com/nuts-foundation/nuts-node/vdr/resolver"
"github.com/nuts-foundation/nuts-node/vdr/types"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"go.uber.org/mock/gomock"
Expand All @@ -34,7 +33,7 @@ import (

func TestNutsKeyResolver_ResolvePublicKey(t *testing.T) {
ctrl := gomock.NewController(t)
didResolver := types.NewMockDIDResolver(ctrl)
didResolver := resolver.NewMockDIDResolver(ctrl)
keyResolver := SourceTXKeyResolver{Resolver: didResolver}
pk, _ := ecdsa.GenerateKey(elliptic.P256(), rand.Reader)
doc := &did.Document{
Expand Down
9 changes: 4 additions & 5 deletions network/dag/pal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ import (

"github.com/nuts-foundation/go-did/did"
"github.com/nuts-foundation/nuts-node/crypto"
"github.com/nuts-foundation/nuts-node/vdr/types"
"github.com/stretchr/testify/assert"
"go.uber.org/mock/gomock"
)
Expand All @@ -47,7 +46,7 @@ func TestEncryptPal(t *testing.T) {

// Encrypt
ctrl := gomock.NewController(t)
keyResolver := types.NewMockKeyResolver(ctrl)
keyResolver := resolver.NewMockKeyResolver(ctrl)
keyResolver.EXPECT().ResolveKey(*pA, nil, resolver.KeyAgreement).Return(ssi.URI{}, pkA.Public(), nil)
keyResolver.EXPECT().ResolveKey(*pB, nil, resolver.KeyAgreement).Return(ssi.URI{}, pkB.Public(), nil)
expected := PAL{*pA, *pB}
Expand All @@ -64,22 +63,22 @@ func TestEncryptPal(t *testing.T) {
})
t.Run("ok - empty input yields empty output", func(t *testing.T) {
ctrl := gomock.NewController(t)
keyResolver := types.NewMockKeyResolver(ctrl)
keyResolver := resolver.NewMockKeyResolver(ctrl)
pal, err := PAL{}.Encrypt(keyResolver)
assert.Nil(t, pal)
assert.NoError(t, err)
})
t.Run("error - keyAgreement key type is not supported", func(t *testing.T) {
ctrl := gomock.NewController(t)
keyResolver := types.NewMockKeyResolver(ctrl)
keyResolver := resolver.NewMockKeyResolver(ctrl)
keyResolver.EXPECT().ResolveKey(*pA, nil, resolver.KeyAgreement).Return(ssi.URI{}, &rsa.PublicKey{}, nil)
pal, err := PAL{*pA}.Encrypt(keyResolver)
assert.Nil(t, pal)
assert.EqualError(t, err, "resolved keyAgreement key is not an elliptic curve key (recipient=did:nuts:A)")
})
t.Run("error - no keyAgreements", func(t *testing.T) {
ctrl := gomock.NewController(t)
keyResolver := types.NewMockKeyResolver(ctrl)
keyResolver := resolver.NewMockKeyResolver(ctrl)
keyResolver.EXPECT().ResolveKey(*pA, nil, resolver.KeyAgreement).Return(ssi.URI{}, nil, resolver.ErrKeyNotFound)
pal, err := PAL{*pA}.Encrypt(keyResolver)
assert.Nil(t, pal)
Expand Down
3 changes: 1 addition & 2 deletions network/dag/verifier_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ import (
"github.com/nuts-foundation/go-stoabs"
nutsCrypto "github.com/nuts-foundation/nuts-node/crypto"
"github.com/nuts-foundation/nuts-node/crypto/hash"
"github.com/nuts-foundation/nuts-node/vdr/types"
"github.com/stretchr/testify/assert"
"go.uber.org/mock/gomock"
)
Expand Down Expand Up @@ -125,7 +124,7 @@ func TestTransactionSignatureVerifier(t *testing.T) {
t.Run("unable to resolve key by hash", func(t *testing.T) {
d := CreateSignedTestTransaction(1, time.Now(), nil, "foo/bar", false)
ctrl := gomock.NewController(t)
keyResolver := types.NewMockNutsKeyResolver(ctrl)
keyResolver := resolver.NewMockNutsKeyResolver(ctrl)
keyResolver.EXPECT().ResolvePublicKey(gomock.Any(), gomock.Any()).Return(nil, errors.New("failed"))

err := NewTransactionSignatureVerifier(keyResolver)(nil, d)
Expand Down
14 changes: 7 additions & 7 deletions network/network_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import (
ssi "github.com/nuts-foundation/go-did"
testPKI "github.com/nuts-foundation/nuts-node/test/pki"
"github.com/nuts-foundation/nuts-node/vdr/didnuts/didstore"
"github.com/nuts-foundation/nuts-node/vdr/management"
"github.com/nuts-foundation/nuts-node/vdr/resolver"
"math"
"net/http"
Expand All @@ -54,7 +55,6 @@ import (
"github.com/nuts-foundation/nuts-node/pki"
"github.com/nuts-foundation/nuts-node/storage"
"github.com/nuts-foundation/nuts-node/test/io"
vdrTypes "github.com/nuts-foundation/nuts-node/vdr/types"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"go.uber.org/mock/gomock"
Expand All @@ -69,9 +69,9 @@ type networkTestContext struct {
didStore *didstore.MockStore
keyStore crypto.KeyStore
keyStorage spi.Storage
keyResolver *vdrTypes.MockKeyResolver
keyResolver *resolver.MockKeyResolver
protocol *transport.MockProtocol
docFinder *vdrTypes.MockDocFinder
docFinder *management.MockDocFinder
eventPublisher *events.MockEvent
pkiValidator *pki.MockValidator
}
Expand Down Expand Up @@ -1082,7 +1082,7 @@ func Test_connectToKnownNodes(t *testing.T) {

// Use actual test instance because the unit test's createNetwork mocks too much for us
network := NewTestNetworkInstance(t)
docFinder := vdrTypes.NewMockDocFinder(ctrl)
docFinder := management.NewMockDocFinder(ctrl)
network.didDocumentFinder = docFinder
network.config.EnableDiscovery = true

Expand All @@ -1107,7 +1107,7 @@ func Test_connectToKnownNodes(t *testing.T) {

// Use actual test instance because the unit test's createNetwork mocks too much for us
network := NewTestNetworkInstance(t)
docFinder := vdrTypes.NewMockDocFinder(ctrl)
docFinder := management.NewMockDocFinder(ctrl)
network.didDocumentFinder = docFinder
network.config.EnableDiscovery = true
connectionManager := transport.NewMockConnectionManager(ctrl)
Expand Down Expand Up @@ -1319,8 +1319,8 @@ func createNetwork(t *testing.T, ctrl *gomock.Controller, cfgFn ...func(config *
}
keyStorage := crypto.NewMemoryStorage()
keyStore := crypto.NewTestCryptoInstance(keyStorage)
keyResolver := vdrTypes.NewMockKeyResolver(ctrl)
docFinder := vdrTypes.NewMockDocFinder(ctrl)
keyResolver := resolver.NewMockKeyResolver(ctrl)
docFinder := management.NewMockDocFinder(ctrl)
didStore := didstore.NewMockStore(ctrl)
eventPublisher := events.NewMockEvent(ctrl)
storageEngine := storage.NewTestStorageEngine(t)
Expand Down
11 changes: 5 additions & 6 deletions network/transport/grpc/authenticator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ import (
ssi "github.com/nuts-foundation/go-did"
"github.com/nuts-foundation/go-did/did"
"github.com/nuts-foundation/nuts-node/network/transport"
"github.com/nuts-foundation/nuts-node/vdr/types"
"github.com/stretchr/testify/assert"
"go.uber.org/mock/gomock"
)
Expand All @@ -49,7 +48,7 @@ func Test_tlsAuthenticator_Authenticate(t *testing.T) {

t.Run("ok", func(t *testing.T) {
ctrl := gomock.NewController(t)
serviceResolver := types.NewMockServiceResolver(ctrl)
serviceResolver := resolver.NewMockServiceResolver(ctrl)
serviceResolver.EXPECT().Resolve(query, gomock.Any()).Return(did.Service{ServiceEndpoint: "grpc://nuts.nl:5555"}, nil)
authenticator := NewTLSAuthenticator(serviceResolver)

Expand All @@ -60,7 +59,7 @@ func Test_tlsAuthenticator_Authenticate(t *testing.T) {
})
t.Run("ok - case insensitive comparison", func(t *testing.T) {
ctrl := gomock.NewController(t)
serviceResolver := types.NewMockServiceResolver(ctrl)
serviceResolver := resolver.NewMockServiceResolver(ctrl)
serviceResolver.EXPECT().Resolve(query, gomock.Any()).Return(did.Service{ServiceEndpoint: "grpc://Nuts.nl:5555"}, nil)
authenticator := NewTLSAuthenticator(serviceResolver)

Expand All @@ -71,7 +70,7 @@ func Test_tlsAuthenticator_Authenticate(t *testing.T) {
})
t.Run("ok - wildcard comparison", func(t *testing.T) {
ctrl := gomock.NewController(t)
serviceResolver := types.NewMockServiceResolver(ctrl)
serviceResolver := resolver.NewMockServiceResolver(ctrl)
serviceResolver.EXPECT().Resolve(query, gomock.Any()).Return(did.Service{ServiceEndpoint: "grpc://node.nuts.nl:5555"}, nil)
authenticator := NewTLSAuthenticator(serviceResolver)
expectedPeer := transport.Peer{
Expand All @@ -89,7 +88,7 @@ func Test_tlsAuthenticator_Authenticate(t *testing.T) {
transportPeer := transport.Peer{ID: "peer", Certificate: cert}
t.Run("DNS names do not match", func(t *testing.T) {
ctrl := gomock.NewController(t)
serviceResolver := types.NewMockServiceResolver(ctrl)
serviceResolver := resolver.NewMockServiceResolver(ctrl)
serviceResolver.EXPECT().Resolve(query, gomock.Any()).Return(did.Service{ServiceEndpoint: "grpc://nootjes.nl:5555"}, nil)
authenticator := NewTLSAuthenticator(serviceResolver)

Expand All @@ -106,7 +105,7 @@ func Test_tlsAuthenticator_Authenticate(t *testing.T) {
})
t.Run("DID document not found", func(t *testing.T) {
ctrl := gomock.NewController(t)
serviceResolver := types.NewMockServiceResolver(ctrl)
serviceResolver := resolver.NewMockServiceResolver(ctrl)
serviceResolver.EXPECT().Resolve(query, gomock.Any()).Return(did.Service{}, resolver.ErrNotFound)
authenticator := NewTLSAuthenticator(serviceResolver)

Expand Down
6 changes: 3 additions & 3 deletions network/transport/v2/protocol_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"errors"
"fmt"
"github.com/nuts-foundation/go-stoabs"
"github.com/nuts-foundation/nuts-node/vdr/resolver"
"github.com/stretchr/testify/require"
"go.uber.org/goleak"
"strings"
Expand All @@ -43,14 +44,13 @@ import (
"github.com/nuts-foundation/nuts-node/network/dag"
"github.com/nuts-foundation/nuts-node/network/transport"
"github.com/nuts-foundation/nuts-node/network/transport/grpc"
vdr "github.com/nuts-foundation/nuts-node/vdr/types"
)

type protocolMocks struct {
Controller *gomock.Controller
State *dag.MockState
PayloadScheduler *dag.MockNotifier
DIDResolver *vdr.MockDIDResolver
DIDResolver *resolver.MockDIDResolver
Decrypter *crypto.MockDecrypter
Gossip *gossip.MockManager
ConnectionList *grpc.MockConnectionList
Expand Down Expand Up @@ -79,7 +79,7 @@ func newTestProtocol(t *testing.T, nodeDID *did.DID) (*protocol, protocolMocks)
ctrl := gomock.NewController(t)
dirname := io.TestDirectory(t)

didResolver := vdr.NewMockDIDResolver(ctrl)
didResolver := resolver.NewMockDIDResolver(ctrl)
decrypter := crypto.NewMockDecrypter(ctrl)
state := dag.NewMockState(ctrl)
gMan := gossip.NewMockManager(ctrl)
Expand Down
Loading

0 comments on commit d0ef024

Please sign in to comment.