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

Commit b1decdf

Browse files
authored
feat: Add BDD test for legacy-connection protocol (edge to edge through 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 <abdulbois.tursunov@avast.com> Signed-off-by: Abdulbois <abdulbois.tursunov@avast.com>
1 parent ece4258 commit b1decdf

File tree

6 files changed

+763
-10
lines changed

6 files changed

+763
-10
lines changed

pkg/didcomm/protocol/legacyconnection/service.go

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import (
1010
"encoding/json"
1111
"errors"
1212
"fmt"
13-
"strings"
1413

1514
"github.com/google/uuid"
1615

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

723-
if !strings.HasPrefix(connRecord.TheirDID, "did") {
724-
connRecord.TheirDID = "did:peer:" + connRecord.TheirDID
725-
}
726-
727722
if err := s.connectionRecorder.SaveConnectionRecord(connRecord); err != nil {
728723
return nil, err
729724
}

pkg/didcomm/protocol/legacyconnection/states.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -375,7 +375,10 @@ func (ctx *context) handleInboundRequest(request *Request, options *options,
375375
connRec.MyDID = responseDidDoc.ID
376376
connRec.TheirDID = request.Connection.DID
377377
connRec.TheirLabel = request.Label
378-
connRec.RecipientKeys = destination.RecipientKeys
378+
379+
if len(responseDidDoc.Service) > 0 {
380+
connRec.RecipientKeys = responseDidDoc.Service[0].RecipientKeys
381+
}
379382

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

607610
func (ctx *context) addRouterKeys(doc *did.Doc, routerConnections []string) error {
608-
svc, ok := did.LookupService(doc, didCommServiceType)
611+
svc, ok := did.LookupService(doc, legacyDIDCommServiceType)
609612
if ok {
610613
for _, recKey := range svc.RecipientKeys {
611614
for _, connID := range routerConnections {

pkg/didcomm/protocol/legacyconnection/states_test.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1215,8 +1215,10 @@ func TestGetDIDDocAndConnection(t *testing.T) {
12151215
require.NoError(t, err)
12161216
customKMS := newKMS(t, mockstorage.NewMockStoreProvider())
12171217
ctx := context{
1218-
kms: customKMS,
1219-
vdRegistry: &mockvdr.MockVDRegistry{CreateValue: mockdiddoc.GetMockDIDDoc(t, false)},
1218+
kms: customKMS,
1219+
vdRegistry: &mockvdr.MockVDRegistry{
1220+
CreateValue: mockdiddoc.GetLegacyInteropMockDIDDoc(t, "1234567abcdefg", []byte("key")),
1221+
},
12201222
connectionRecorder: connRec,
12211223
routeSvc: &mockroute.MockMediatorSvc{
12221224
Connections: []string{"xyz"},
@@ -1225,7 +1227,7 @@ func TestGetDIDDocAndConnection(t *testing.T) {
12251227
keyType: kms.ED25519Type,
12261228
keyAgreementType: kms.X25519ECDHKWType,
12271229
}
1228-
didDoc, err := ctx.getMyDIDDoc("", []string{"xyz"}, didCommServiceType)
1230+
didDoc, err := ctx.getMyDIDDoc("", []string{"xyz"}, legacyDIDCommServiceType)
12291231
require.Error(t, err)
12301232
require.Contains(t, err.Error(), "did doc - add key to the router")
12311233
require.Nil(t, didDoc)

test/bdd/bddtests_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import (
2828
"github.com/hyperledger/aries-framework-go/test/bdd/pkg/issuecredential"
2929
"github.com/hyperledger/aries-framework-go/test/bdd/pkg/jwt"
3030
"github.com/hyperledger/aries-framework-go/test/bdd/pkg/ld"
31+
"github.com/hyperledger/aries-framework-go/test/bdd/pkg/legacyconnection"
3132
"github.com/hyperledger/aries-framework-go/test/bdd/pkg/mediator"
3233
"github.com/hyperledger/aries-framework-go/test/bdd/pkg/messaging"
3334
"github.com/hyperledger/aries-framework-go/test/bdd/pkg/outofband"
@@ -219,5 +220,6 @@ func features() []feature {
219220
waci.NewIssuanceDIDCommV1SDKSteps(),
220221
waci.NewIssuanceDIDCommV2SDKSteps(),
221222
walletjsonld.NewSDKSteps(),
223+
legacyconnection.NewLegacyConnectionControllerSteps(),
222224
}
223225
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#
2+
# Copyright Avast Software. All Rights Reserved.
3+
#
4+
# SPDX-License-Identifier: Apache-2.0
5+
#
6+
# Reference : https://github.com/hyperledger/aries-rfcs/tree/main/features/0160-connection-protocol
7+
8+
@all
9+
@controller
10+
@legacyconnection_e2e_controller
11+
Feature: Establishing DIDComm V1 using Connection RFC-0160 protocol between the agents using controller API
12+
13+
Scenario: legacy connection e2e flow using controller api
14+
Given "Alice" agent is running on "localhost" port "8081" with controller "https://localhost:8082"
15+
And "Bob" agent is running on "localhost" port "9081" with controller "https://localhost:9082"
16+
17+
When "Alice" creates legacy invitation through controller with label "alice-agent"
18+
And "Bob" receives legacy invitation from "Alice" through controller
19+
And "Bob" approves connection invitation through controller
20+
And "Alice" approves connection request through controller
21+
And "Alice" waits for legacy post state event "completed" to web notifier
22+
And "Bob" waits for legacy post state event "completed" to web notifier
23+
24+
Then "Alice" retrieves connection record through controller and validates that legacy connection state is "completed"
25+
And "Bob" retrieves connection record through controller and validates that legacy connection state is "completed"

0 commit comments

Comments
 (0)