@@ -176,7 +176,7 @@ func TestService_Handle_Inviter(t *testing.T) {
176176 require .NoError (t , err )
177177
178178 completedFlag := make (chan struct {})
179- respondedFlag := make (chan struct {} )
179+ respondedFlag := make (chan string )
180180
181181 go msgEventListener (t , statusCh , respondedFlag , completedFlag )
182182
@@ -247,7 +247,153 @@ func TestService_Handle_Inviter(t *testing.T) {
247247 validateState (t , s , thid , findNamespace (AckMsgType ), (& completed {}).Name ())
248248}
249249
250- func msgEventListener (t * testing.T , statusCh chan service.StateMsg , respondedFlag , completedFlag chan struct {}) {
250+ func TestService_Handle_Inviter_With_ProblemReport (t * testing.T ) {
251+ mockStore := & mockstorage.MockStore {Store : make (map [string ]mockstorage.DBEntry )}
252+ storeProv := mockstorage .NewCustomMockStoreProvider (mockStore )
253+ k := newKMS (t , storeProv )
254+ prov := & protocol.MockProvider {
255+ StoreProvider : storeProv ,
256+ ServiceMap : map [string ]interface {}{
257+ mediator .Coordination : & mockroute.MockMediatorSvc {},
258+ },
259+ CustomKMS : k ,
260+ KeyTypeValue : kms .ED25519Type ,
261+ KeyAgreementTypeValue : kms .X25519ECDHKWType ,
262+ }
263+
264+ ctx := & context {
265+ outboundDispatcher : prov .OutboundDispatcher (),
266+ crypto : & tinkcrypto.Crypto {},
267+ kms : k ,
268+ keyType : kms .ED25519Type ,
269+ keyAgreementType : kms .X25519ECDHKWType ,
270+ }
271+
272+ _ , pubKey , err := ctx .kms .CreateAndExportPubKeyBytes (kms .ED25519Type )
273+ require .NoError (t , err )
274+
275+ ctx .vdRegistry = & mockvdr.MockVDRegistry {CreateValue : createDIDDocWithKey (pubKey )}
276+
277+ connRec , err := connection .NewRecorder (prov )
278+ require .NoError (t , err )
279+ require .NotNil (t , connRec )
280+
281+ ctx .connectionRecorder = connRec
282+
283+ doc , err := ctx .vdRegistry .Create (testMethod , nil )
284+ require .NoError (t , err )
285+
286+ s , err := New (prov )
287+ require .NoError (t , err )
288+
289+ actionCh := make (chan service.DIDCommAction , 10 )
290+ err = s .RegisterActionEvent (actionCh )
291+ require .NoError (t , err )
292+
293+ statusCh := make (chan service.StateMsg , 10 )
294+ err = s .RegisterMsgEvent (statusCh )
295+ require .NoError (t , err )
296+
297+ completedFlag := make (chan struct {})
298+ respondedFlag := make (chan string )
299+
300+ go msgEventListener (t , statusCh , respondedFlag , completedFlag )
301+ go func () { service .AutoExecuteActionEvent (actionCh ) }()
302+
303+ invitation := & Invitation {
304+ Type : InvitationMsgType ,
305+ ID : randomString (),
306+ Label : "Bob" ,
307+ RecipientKeys : []string {base58 .Encode (pubKey )},
308+ ServiceEndpoint : "http://alice.agent.example.com:8081" ,
309+ }
310+
311+ err = ctx .connectionRecorder .SaveInvitation (invitation .ID , invitation )
312+ require .NoError (t , err )
313+
314+ thid := randomString ()
315+
316+ // Invitation was previously sent by Alice to Bob.
317+ // Bob now sends a connection Request
318+ connRequest , err := json .Marshal (
319+ & Request {
320+ Type : RequestMsgType ,
321+ ID : thid ,
322+ Label : "Bob" ,
323+ Thread : & decorator.Thread {
324+ PID : invitation .ID ,
325+ },
326+ Connection : & Connection {
327+ DID : doc .DIDDocument .ID ,
328+ DIDDoc : doc .DIDDocument ,
329+ },
330+ })
331+ require .NoError (t , err )
332+ requestMsg , err := service .ParseDIDCommMsgMap (connRequest )
333+ require .NoError (t , err )
334+ _ , err = s .HandleInbound (requestMsg , service .NewDIDCommContext (doc .DIDDocument .ID , "" , nil ))
335+ require .NoError (t , err )
336+
337+ var connID string
338+ select {
339+ case connID = <- respondedFlag :
340+ case <- time .After (2 * time .Second ):
341+ require .Fail (t , "didn't receive connection ID" )
342+ }
343+
344+ connRecord , err := s .connectionRecorder .GetConnectionRecord (connID )
345+ require .NoError (t , err )
346+
347+ // Alice automatically sends connection Response to Bob
348+ // Bob replies with Problem Report
349+ prbRpt , err := json .Marshal (
350+ & problemReport {
351+ ID : randomString (),
352+ Type : ProblemReportMsgType ,
353+ Thread : & decorator.Thread {ID : connRecord .ThreadID },
354+ })
355+ require .NoError (t , err )
356+
357+ prbRptMsg , err := service .ParseDIDCommMsgMap (prbRpt )
358+ require .NoError (t , err )
359+
360+ _ , err = s .HandleInbound (prbRptMsg , service .NewDIDCommContext (doc .DIDDocument .ID , "" , nil ))
361+ require .NoError (t , err )
362+
363+ validateState (t , s , thid , findNamespace (RequestMsgType ), (& responded {}).Name ())
364+
365+ _ , err = ctx .connectionRecorder .GetConnectionRecord (connID )
366+ require .ErrorContains (t , err , "data not found" )
367+
368+ _ , err = s .HandleInbound (requestMsg , service .NewDIDCommContext (doc .DIDDocument .ID , "" , nil ))
369+ require .NoError (t , err )
370+
371+ // Finally Bob replies with an ACK
372+ ack , err := json .Marshal (
373+ & model.Ack {
374+ Type : AckMsgType ,
375+ ID : randomString (),
376+ Status : "OK" ,
377+ Thread : & decorator.Thread {ID : connRecord .ThreadID },
378+ })
379+ require .NoError (t , err )
380+
381+ ackMsg , err := service .ParseDIDCommMsgMap (ack )
382+ require .NoError (t , err )
383+
384+ _ , err = s .HandleInbound (ackMsg , service .NewDIDCommContext (doc .DIDDocument .ID , "" , nil ))
385+ require .NoError (t , err )
386+
387+ select {
388+ case <- completedFlag :
389+ case <- time .After (4 * time .Second ):
390+ require .Fail (t , "didn't receive post event complete" )
391+ }
392+
393+ validateState (t , s , connRecord .ThreadID , findNamespace (AckMsgType ), (& completed {}).Name ())
394+ }
395+
396+ func msgEventListener (t * testing.T , statusCh chan service.StateMsg , respondedFlag chan string , completedFlag chan struct {}) { //nolint: lll
251397 for e := range statusCh {
252398 require .Equal (t , LegacyConnection , e .ProtocolName )
253399
@@ -272,11 +418,11 @@ func msgEventListener(t *testing.T, statusCh chan service.StateMsg, respondedFla
272418 close (completedFlag )
273419 }
274420
275- if e .StateID == "responded" {
421+ if e .StateID == "responded" && e . Msg . Type () != ProblemReportMsgType {
276422 // validate connectionID received during state transition with original connectionID
277423 require .NotNil (t , prop .ConnectionID ())
278424 require .NotNil (t , prop .InvitationID ())
279- close ( respondedFlag )
425+ respondedFlag <- prop . ConnectionID ( )
280426 }
281427 }
282428 }
0 commit comments