Skip to content

Commit

Permalink
chore: BDD test fix for event payload check
Browse files Browse the repository at this point in the history
Signed-off-by: Misha Sizov <[email protected]>
  • Loading branch information
mishasizov-SK committed Oct 24, 2024
1 parent 3616094 commit 53b8f58
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 5 deletions.
21 changes: 17 additions & 4 deletions test/bdd/pkg/v1/oidc4vc/oidc4vci.go
Original file line number Diff line number Diff line change
Expand Up @@ -1184,9 +1184,19 @@ func (s *Steps) setExpectedCredentialsAmountForVP(expectedCredentialsAmount stri
}

func checkEventInteractionDetailsClaim(event *spi.Event) error {
eventData, ok := event.Data.(map[string]interface{})
if !ok {
return fmt.Errorf("event payload has unexpected type: %v", event.Data)
var eventData map[string]interface{}

if v, t := event.Data.(map[string]interface{}); t {
eventData = v
} else {
jsonData, err := base64.StdEncoding.DecodeString(event.Data.(string))
if err != nil {
return fmt.Errorf("failed to decode event %v: %w", event.Data, err)
}

if err = json.Unmarshal(jsonData, &eventData); err != nil {
return fmt.Errorf("invalid event payload %v: %w", event.Data, err)
}
}

interactionDetails, ok := eventData["interaction_details"].(map[string]interface{})
Expand Down Expand Up @@ -1468,7 +1478,10 @@ func (s *Steps) waitForOIDC4CIEvent(eventType spi.EventType) error {
}

switch eventType {
case spi.IssuerOIDCInteractionAckSucceeded, spi.IssuerOIDCInteractionAckFailed, spi.IssuerOIDCInteractionAckRejected:
case spi.IssuerOIDCInteractionAckSucceeded,
spi.IssuerOIDCInteractionAckFailed,
spi.IssuerOIDCInteractionAckRejected,
spi.IssuerOIDCInteractionAckExpired:
if err = checkEventInteractionDetailsClaim(event); err != nil {
return err
}
Expand Down
5 changes: 4 additions & 1 deletion test/bdd/pkg/v1/oidc4vc/oidc4vp.go
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,10 @@ func (s *Steps) waitForOIDC4VPEvent(eventType string) error {
s.vpClaimsTransactionID = event.TransactionID

switch spi.EventType(eventType) {
case spi.VerifierOIDCInteractionSucceeded, spi.VerifierOIDCInteractionNoConsent, spi.VerifierOIDCInteractionNoMatchFound:
case spi.VerifierOIDCInteractionSucceeded,
spi.VerifierOIDCInteractionNoConsent,
spi.VerifierOIDCInteractionNoMatchFound,
spi.VerifierOIDCInteractionExpired:
if err = checkEventInteractionDetailsClaim(event); err != nil {
return err
}
Expand Down

0 comments on commit 53b8f58

Please sign in to comment.