Skip to content
This repository has been archived by the owner on Mar 27, 2024. It is now read-only.

Commit

Permalink
feat: Add BDD test for legacy-connection protocol (edge to edge throu…
Browse files Browse the repository at this point in the history
…gh controller). Make a few refactoring (#3353)

- Add BDD test for legacy-connection protocol. Edge to edge case is fully implemented. Case through mediator is implemented partially (Only steps are added. Need to add .feature file to run test)
- Make a few refactoring

Signed-off-by: Abdulbois <[email protected]>

Signed-off-by: Abdulbois <[email protected]>
  • Loading branch information
Abdulbois authored Aug 29, 2022
1 parent ece4258 commit b1decdf
Show file tree
Hide file tree
Showing 6 changed files with 763 additions and 10 deletions.
5 changes: 0 additions & 5 deletions pkg/didcomm/protocol/legacyconnection/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (
"encoding/json"
"errors"
"fmt"
"strings"

"github.com/google/uuid"

Expand Down Expand Up @@ -720,10 +719,6 @@ func (s *Service) requestMsgRecord(msg service.DIDCommMsg, ctx service.DIDCommCo
DIDCommVersion: service.V1,
}

if !strings.HasPrefix(connRecord.TheirDID, "did") {
connRecord.TheirDID = "did:peer:" + connRecord.TheirDID
}

if err := s.connectionRecorder.SaveConnectionRecord(connRecord); err != nil {
return nil, err
}
Expand Down
7 changes: 5 additions & 2 deletions pkg/didcomm/protocol/legacyconnection/states.go
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,10 @@ func (ctx *context) handleInboundRequest(request *Request, options *options,
connRec.MyDID = responseDidDoc.ID
connRec.TheirDID = request.Connection.DID
connRec.TheirLabel = request.Label
connRec.RecipientKeys = destination.RecipientKeys

if len(responseDidDoc.Service) > 0 {
connRec.RecipientKeys = responseDidDoc.Service[0].RecipientKeys
}

accept, err := destination.ServiceEndpoint.Accept()
if err != nil {
Expand Down Expand Up @@ -605,7 +608,7 @@ func (ctx *context) getMyDIDDoc(pubDID string, routerConnections []string, servi
}

func (ctx *context) addRouterKeys(doc *did.Doc, routerConnections []string) error {
svc, ok := did.LookupService(doc, didCommServiceType)
svc, ok := did.LookupService(doc, legacyDIDCommServiceType)
if ok {
for _, recKey := range svc.RecipientKeys {
for _, connID := range routerConnections {
Expand Down
8 changes: 5 additions & 3 deletions pkg/didcomm/protocol/legacyconnection/states_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1215,8 +1215,10 @@ func TestGetDIDDocAndConnection(t *testing.T) {
require.NoError(t, err)
customKMS := newKMS(t, mockstorage.NewMockStoreProvider())
ctx := context{
kms: customKMS,
vdRegistry: &mockvdr.MockVDRegistry{CreateValue: mockdiddoc.GetMockDIDDoc(t, false)},
kms: customKMS,
vdRegistry: &mockvdr.MockVDRegistry{
CreateValue: mockdiddoc.GetLegacyInteropMockDIDDoc(t, "1234567abcdefg", []byte("key")),
},
connectionRecorder: connRec,
routeSvc: &mockroute.MockMediatorSvc{
Connections: []string{"xyz"},
Expand All @@ -1225,7 +1227,7 @@ func TestGetDIDDocAndConnection(t *testing.T) {
keyType: kms.ED25519Type,
keyAgreementType: kms.X25519ECDHKWType,
}
didDoc, err := ctx.getMyDIDDoc("", []string{"xyz"}, didCommServiceType)
didDoc, err := ctx.getMyDIDDoc("", []string{"xyz"}, legacyDIDCommServiceType)
require.Error(t, err)
require.Contains(t, err.Error(), "did doc - add key to the router")
require.Nil(t, didDoc)
Expand Down
2 changes: 2 additions & 0 deletions test/bdd/bddtests_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (
"github.com/hyperledger/aries-framework-go/test/bdd/pkg/issuecredential"
"github.com/hyperledger/aries-framework-go/test/bdd/pkg/jwt"
"github.com/hyperledger/aries-framework-go/test/bdd/pkg/ld"
"github.com/hyperledger/aries-framework-go/test/bdd/pkg/legacyconnection"
"github.com/hyperledger/aries-framework-go/test/bdd/pkg/mediator"
"github.com/hyperledger/aries-framework-go/test/bdd/pkg/messaging"
"github.com/hyperledger/aries-framework-go/test/bdd/pkg/outofband"
Expand Down Expand Up @@ -219,5 +220,6 @@ func features() []feature {
waci.NewIssuanceDIDCommV1SDKSteps(),
waci.NewIssuanceDIDCommV2SDKSteps(),
walletjsonld.NewSDKSteps(),
legacyconnection.NewLegacyConnectionControllerSteps(),
}
}
25 changes: 25 additions & 0 deletions test/bdd/features/legacyconnection_e2e_controller.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#
# Copyright Avast Software. All Rights Reserved.
#
# SPDX-License-Identifier: Apache-2.0
#
# Reference : https://github.com/hyperledger/aries-rfcs/tree/main/features/0160-connection-protocol

@all
@controller
@legacyconnection_e2e_controller
Feature: Establishing DIDComm V1 using Connection RFC-0160 protocol between the agents using controller API

Scenario: legacy connection e2e flow using controller api
Given "Alice" agent is running on "localhost" port "8081" with controller "https://localhost:8082"
And "Bob" agent is running on "localhost" port "9081" with controller "https://localhost:9082"

When "Alice" creates legacy invitation through controller with label "alice-agent"
And "Bob" receives legacy invitation from "Alice" through controller
And "Bob" approves connection invitation through controller
And "Alice" approves connection request through controller
And "Alice" waits for legacy post state event "completed" to web notifier
And "Bob" waits for legacy post state event "completed" to web notifier

Then "Alice" retrieves connection record through controller and validates that legacy connection state is "completed"
And "Bob" retrieves connection record through controller and validates that legacy connection state is "completed"
Loading

0 comments on commit b1decdf

Please sign in to comment.