From d8a04c3e35d545ebfdfe156625450afb4ec42309 Mon Sep 17 00:00:00 2001 From: Volodymyr Kubiv <62515092+vkubiv@users.noreply.github.com> Date: Tue, 13 Feb 2024 18:17:32 +0200 Subject: [PATCH] feat(sdk): api for offering metadata (#721) feat(sdk): simplified api for offering display data. Signed-off-by: Volodymyr Kubiv --- cmd/wallet-sdk-gomobile/api/stringarray.go | 53 +++++++++++++++++++ .../api/stringarray_test.go | 25 +++++++++ cmd/wallet-sdk-gomobile/display/resolve.go | 15 ++++++ .../display/resolve_test.go | 34 ++++++++++-- .../openid4ci/issuerinitiatedinteraction.go | 5 ++ .../issuerinitiatedinteraction_test.go | 11 ++++ .../openid4ci/issuermetadata.go | 10 ++++ pkg/credentialschema/credentialdisplay.go | 28 ++++++++-- pkg/credentialschema/credentialschema.go | 17 ++++++ pkg/credentialschema/credentialschema_test.go | 21 +++++++- pkg/openid4ci/issuerinitiatedinteraction.go | 5 ++ .../issuerinitiatedinteraction_test.go | 4 ++ test/integration/openid4ci_test.go | 12 ++++- test/integration/pkg/helpers/displaydata.go | 8 +-- test/integration/pkg/helpers/openid4ci.go | 9 +++- 15 files changed, 242 insertions(+), 15 deletions(-) diff --git a/cmd/wallet-sdk-gomobile/api/stringarray.go b/cmd/wallet-sdk-gomobile/api/stringarray.go index e5a6cea7..b450266d 100644 --- a/cmd/wallet-sdk-gomobile/api/stringarray.go +++ b/cmd/wallet-sdk-gomobile/api/stringarray.go @@ -42,3 +42,56 @@ func (s *StringArray) AtIndex(index int) string { return s.Strings[index] } + +// StringArrayArray represents an array of StringArray. +type StringArrayArray struct { + stringArrays []*StringArray +} + +// NewStringArrayArray creates new StringArrayArray. +func NewStringArrayArray() *StringArrayArray { + return &StringArrayArray{} +} + +// Add adds new item to underlying array. +func (a *StringArrayArray) Add(cred *StringArray) *StringArrayArray { + a.stringArrays = append(a.stringArrays, cred) + + return a +} + +// Length returns the number of StringArrays contained within this StringArrayArray. +func (a *StringArrayArray) Length() int { + return len(a.stringArrays) +} + +// AtIndex returns the StringArray at the given index. +// If the index passed in is out of bounds, then nil is returned. +func (a *StringArrayArray) AtIndex(index int) *StringArray { + maxIndex := len(a.stringArrays) - 1 + if index > maxIndex || index < 0 { + return nil + } + + return a.stringArrays[index] +} + +// StringArrayArrayToGoArray converts StringArrayArray to [][]string. +func StringArrayArrayToGoArray(arrayArray *StringArrayArray) [][]string { + var result [][]string + for _, arr := range arrayArray.stringArrays { + result = append(result, arr.Strings) + } + + return result +} + +// StringArrayArrayFromGoArray converts [][]string to StringArrayArray. +func StringArrayArrayFromGoArray(arrayArray [][]string) *StringArrayArray { + result := NewStringArrayArray() + for _, arr := range arrayArray { + result.Add(&StringArray{Strings: arr}) + } + + return result +} diff --git a/cmd/wallet-sdk-gomobile/api/stringarray_test.go b/cmd/wallet-sdk-gomobile/api/stringarray_test.go index 8b6b7ac4..8e8cbbca 100644 --- a/cmd/wallet-sdk-gomobile/api/stringarray_test.go +++ b/cmd/wallet-sdk-gomobile/api/stringarray_test.go @@ -30,3 +30,28 @@ func TestStringArray_Append(t *testing.T) { require.Equal(t, "string1", stringArray.AtIndex(0)) require.Equal(t, "string2", stringArray.AtIndex(1)) } + +func TestStringArrayArray_Append(t *testing.T) { + stringArray := api.NewStringArray() + stringArrayArray := api.NewStringArrayArray() + + require.Equal(t, 0, stringArray.Length()) + require.Equal(t, 0, stringArrayArray.Length()) + + stringArray.Append("string1") + stringArrayArray.Add(stringArray) + + require.Equal(t, 1, stringArrayArray.Length()) + require.Equal(t, "string1", stringArrayArray.AtIndex(0).AtIndex(0)) + + require.Nil(t, stringArrayArray.AtIndex(-1)) +} + +func TestStringArrayArrayToGoArray(t *testing.T) { + strings := [][]string{ + {"str11", "str12"}, + {"str21", "str22"}, + } + result := api.StringArrayArrayToGoArray(api.StringArrayArrayFromGoArray(strings)) + require.ElementsMatch(t, strings, result) +} diff --git a/cmd/wallet-sdk-gomobile/display/resolve.go b/cmd/wallet-sdk-gomobile/display/resolve.go index 06e3f8ad..72416928 100644 --- a/cmd/wallet-sdk-gomobile/display/resolve.go +++ b/cmd/wallet-sdk-gomobile/display/resolve.go @@ -12,6 +12,8 @@ import ( "github.com/trustbloc/vc-go/proof/defaults" + "github.com/trustbloc/wallet-sdk/cmd/wallet-sdk-gomobile/api" + "github.com/trustbloc/wallet-sdk/cmd/wallet-sdk-gomobile/openid4ci" "github.com/trustbloc/wallet-sdk/pkg/common" afgoverifiable "github.com/trustbloc/vc-go/verifiable" @@ -40,6 +42,19 @@ func Resolve(vcs *verifiable.CredentialsArray, issuerURI string, opts *Opts) (*D return &Data{resolvedDisplayData: resolvedDisplayData}, nil } +// ResolveCredentialOffer resolves display information for some offered credentials based on an issuer's metadata. +// The CredentialDisplays in the returned ResolvedDisplayData object correspond to the offered credential types +// passed in and are in the same order. +func ResolveCredentialOffer( + issuerMetadata *openid4ci.IssuerMetadata, offeredTypes *api.StringArrayArray, preferredLocale string, +) *Data { + resolvedDisplayData := goapicredentialschema.ResolveCredentialOffer(openid4ci.IssuerMetadataToGoImpl(issuerMetadata), + api.StringArrayArrayToGoArray(offeredTypes), + preferredLocale) + + return &Data{resolvedDisplayData: resolvedDisplayData} +} + func generateGoAPIOpts(vcs *verifiable.CredentialsArray, issuerURI string, opts *Opts, ) ([]goapicredentialschema.ResolveOpt, error) { diff --git a/cmd/wallet-sdk-gomobile/display/resolve_test.go b/cmd/wallet-sdk-gomobile/display/resolve_test.go index e5a3923b..525766b6 100644 --- a/cmd/wallet-sdk-gomobile/display/resolve_test.go +++ b/cmd/wallet-sdk-gomobile/display/resolve_test.go @@ -9,12 +9,15 @@ package display_test import ( _ "embed" + "encoding/json" "net/http" "net/http/httptest" "strconv" "testing" "github.com/trustbloc/wallet-sdk/cmd/wallet-sdk-gomobile/did" + "github.com/trustbloc/wallet-sdk/cmd/wallet-sdk-gomobile/openid4ci" + "github.com/trustbloc/wallet-sdk/pkg/models/issuer" "github.com/stretchr/testify/require" @@ -200,6 +203,23 @@ func TestResolve(t *testing.T) { }) } +func TestResolveCredentialOffer(t *testing.T) { + metadata := &issuer.Metadata{} + + require.NoError(t, json.Unmarshal(sampleIssuerMetadata, metadata)) + + resolvedDisplayData := display.ResolveCredentialOffer( + openid4ci.IssuerMetadataFromGoImpl(metadata), api.NewStringArrayArray().Add( + api.NewStringArray().Append("UniversityDegreeCredential")), "") + + checkIssuerDisplay(t, resolvedDisplayData.IssuerDisplay()) + + require.Equal(t, 1, resolvedDisplayData.CredentialDisplaysLength()) + + credentialDisplay := resolvedDisplayData.CredentialDisplayAtIndex(0) + checkCredentialOverview(t, credentialDisplay) +} + func checkResolvedDisplayData(t *testing.T, resolvedDisplayData *display.Data) { t.Helper() @@ -221,6 +241,16 @@ func checkIssuerDisplay(t *testing.T, issuerDisplay *display.IssuerDisplay) { func checkCredentialDisplay(t *testing.T, credentialDisplay *display.CredentialDisplay) { t.Helper() + checkCredentialOverview(t, credentialDisplay) + + require.Equal(t, 6, credentialDisplay.ClaimsLength()) + + checkClaims(t, credentialDisplay) +} + +func checkCredentialOverview(t *testing.T, credentialDisplay *display.CredentialDisplay) { + t.Helper() + credentialOverview := credentialDisplay.Overview() require.Equal(t, "University Credential", credentialOverview.Name()) require.Equal(t, "en-US", credentialOverview.Locale()) @@ -228,10 +258,6 @@ func checkCredentialDisplay(t *testing.T, credentialDisplay *display.CredentialD require.Equal(t, "a square logo of a university", credentialOverview.Logo().AltText()) require.Equal(t, "#12107c", credentialOverview.BackgroundColor()) require.Equal(t, "#FFFFFF", credentialOverview.TextColor()) - - require.Equal(t, 6, credentialDisplay.ClaimsLength()) - - checkClaims(t, credentialDisplay) } func checkClaims(t *testing.T, credentialDisplay *display.CredentialDisplay) { //nolint:gocyclo // Test file diff --git a/cmd/wallet-sdk-gomobile/openid4ci/issuerinitiatedinteraction.go b/cmd/wallet-sdk-gomobile/openid4ci/issuerinitiatedinteraction.go index 7e0e6123..edbdd0ff 100644 --- a/cmd/wallet-sdk-gomobile/openid4ci/issuerinitiatedinteraction.go +++ b/cmd/wallet-sdk-gomobile/openid4ci/issuerinitiatedinteraction.go @@ -234,6 +234,11 @@ func (i *IssuerInitiatedInteraction) DynamicClientRegistrationEndpoint() (string return endpoint, nil } +// OfferedCredentialsTypes returns types of offered credentials. +func (i *IssuerInitiatedInteraction) OfferedCredentialsTypes() *api.StringArrayArray { + return api.StringArrayArrayFromGoArray(i.goAPIInteraction.OfferedCredentialsTypes()) +} + // IssuerMetadata returns the issuer's metadata. func (i *IssuerInitiatedInteraction) IssuerMetadata() (*IssuerMetadata, error) { goAPIIssuerMetadata, err := i.goAPIInteraction.IssuerMetadata() diff --git a/cmd/wallet-sdk-gomobile/openid4ci/issuerinitiatedinteraction_test.go b/cmd/wallet-sdk-gomobile/openid4ci/issuerinitiatedinteraction_test.go index 256e4ac3..da07065c 100644 --- a/cmd/wallet-sdk-gomobile/openid4ci/issuerinitiatedinteraction_test.go +++ b/cmd/wallet-sdk-gomobile/openid4ci/issuerinitiatedinteraction_test.go @@ -30,6 +30,7 @@ import ( goapi "github.com/trustbloc/wallet-sdk/pkg/api" "github.com/trustbloc/wallet-sdk/pkg/did/creator" "github.com/trustbloc/wallet-sdk/pkg/models" + "github.com/trustbloc/wallet-sdk/pkg/models/issuer" goapiopenid4ci "github.com/trustbloc/wallet-sdk/pkg/openid4ci" ) @@ -597,6 +598,12 @@ func TestIssuerInitiatedInteractionAlias(t *testing.T) { require.NotNil(t, issuerMetadata) } +func TestIssuerMetadataFromToGoImpl(t *testing.T) { + goImpl := &issuer.Metadata{} + restored := openid4ci.IssuerMetadataToGoImpl(openid4ci.IssuerMetadataFromGoImpl(goImpl)) + require.Equal(t, goImpl, restored) +} + func doRequestCredentialTest(t *testing.T, additionalHeaders *api.Headers, disableTLSVerification bool, ) { @@ -635,6 +642,10 @@ func doRequestCredentialTestExt(t *testing.T, additionalHeaders *api.Headers, additionalHeaders, disableTLSVerification) + offeringTypes := api.StringArrayArrayToGoArray(interaction.OfferedCredentialsTypes()) + require.Len(t, offeringTypes, 1) + require.Contains(t, offeringTypes[0], "VerifiedEmployee") + keyHandle, err := kms.Create(arieskms.ED25519) require.NoError(t, err) diff --git a/cmd/wallet-sdk-gomobile/openid4ci/issuermetadata.go b/cmd/wallet-sdk-gomobile/openid4ci/issuermetadata.go index 7ea9a0be..a3fd152d 100644 --- a/cmd/wallet-sdk-gomobile/openid4ci/issuermetadata.go +++ b/cmd/wallet-sdk-gomobile/openid4ci/issuermetadata.go @@ -31,6 +31,16 @@ func (i *IssuerMetadata) LocalizedIssuerDisplays() *LocalizedIssuerDisplays { return &LocalizedIssuerDisplays{localizedIssuerDisplays: i.issuerMetadata.LocalizedIssuerDisplays} } +// IssuerMetadataToGoImpl unwrap original issuer.Metadata from IssuerMetadata wrapper. +func IssuerMetadataToGoImpl(wrapped *IssuerMetadata) *issuer.Metadata { + return wrapped.issuerMetadata +} + +// IssuerMetadataFromGoImpl wrap original issuer.Metadata into IssuerMetadata wrapper. +func IssuerMetadataFromGoImpl(goAPIIssuerMetadata *issuer.Metadata) *IssuerMetadata { + return &IssuerMetadata{issuerMetadata: goAPIIssuerMetadata} +} + // IssuerTrustInfo represent issuer trust information. type IssuerTrustInfo struct { DID string diff --git a/pkg/credentialschema/credentialdisplay.go b/pkg/credentialschema/credentialdisplay.go index ba16c82a..553652ab 100644 --- a/pkg/credentialschema/credentialdisplay.go +++ b/pkg/credentialschema/credentialdisplay.go @@ -42,7 +42,7 @@ func buildCredentialDisplays(vcs []*verifiable.Credential, credentialsSupported var foundMatchingType bool for i := range credentialsSupported { - if !haveMatchingTypes(&credentialsSupported[i], displayVC) { + if !haveMatchingTypes(&credentialsSupported[i], displayVC.Contents().Types) { continue } @@ -72,10 +72,32 @@ func buildCredentialDisplays(vcs []*verifiable.Credential, credentialsSupported return credentialDisplays, nil } +func buildCredentialOfferingDisplays(offeringTypes [][]string, credentialsSupported []issuer.SupportedCredential, + preferredLocale string, +) []CredentialDisplay { + var credentialDisplays []CredentialDisplay + + for _, vcTypes := range offeringTypes { + for i := range credentialsSupported { + if !haveMatchingTypes(&credentialsSupported[i], vcTypes) { + continue + } + + credentialDisplay := &CredentialDisplay{Overview: getOverviewDisplay(&credentialsSupported[i], preferredLocale)} + + credentialDisplays = append(credentialDisplays, *credentialDisplay) + + break + } + } + + return credentialDisplays +} + // The VC is considered to be a match for the supportedCredential if the VC has at least one type that's the same as // the type specified by the supportCredential (excluding the "VerifiableCredential" type that all VCs have). -func haveMatchingTypes(supportedCredential *issuer.SupportedCredential, vc *verifiable.Credential) bool { - for _, typeFromVC := range vc.Contents().Types { +func haveMatchingTypes(supportedCredential *issuer.SupportedCredential, vcTypes []string) bool { + for _, typeFromVC := range vcTypes { // We expect the types in the VC and SupportedCredential to always include VerifiableCredential, // so we skip this case. if strings.EqualFold(typeFromVC, "VerifiableCredential") { diff --git a/pkg/credentialschema/credentialschema.go b/pkg/credentialschema/credentialschema.go index 20e1a847..7da113e9 100644 --- a/pkg/credentialschema/credentialschema.go +++ b/pkg/credentialschema/credentialschema.go @@ -7,6 +7,8 @@ SPDX-License-Identifier: Apache-2.0 // Package credentialschema contains a function that can be used to resolve display values per the OpenID4CI spec. package credentialschema +import "github.com/trustbloc/wallet-sdk/pkg/models/issuer" + // Resolve resolves display information for some issued credentials based on an issuer's metadata. // The CredentialDisplays in the returned ResolvedDisplayData object correspond to the VCs passed in and are in the // same order. @@ -35,3 +37,18 @@ func Resolve(opts ...ResolveOpt) (*ResolvedDisplayData, error) { CredentialDisplays: credentialDisplays, }, nil } + +// ResolveCredentialOffer resolves display information for some offered credentials based on an issuer's metadata. +// The CredentialDisplays in the returned ResolvedDisplayData object correspond to the offered credential types +// passed in and are in the same order. +func ResolveCredentialOffer( + metadata *issuer.Metadata, offeredCredentialTypes [][]string, preferredLocale string, +) *ResolvedDisplayData { + issuerOverview := getIssuerDisplay(metadata.LocalizedIssuerDisplays, preferredLocale) + + return &ResolvedDisplayData{ + IssuerDisplay: issuerOverview, + CredentialDisplays: buildCredentialOfferingDisplays(offeredCredentialTypes, + metadata.CredentialsSupported, preferredLocale), + } +} diff --git a/pkg/credentialschema/credentialschema_test.go b/pkg/credentialschema/credentialschema_test.go index b3e9051c..cf5a2c48 100644 --- a/pkg/credentialschema/credentialschema_test.go +++ b/pkg/credentialschema/credentialschema_test.go @@ -444,7 +444,20 @@ func TestResolve(t *testing.T) { //nolint: gocognit // Test file }) } -func checkSuccessCaseMatchedDisplayData(t *testing.T, resolvedDisplayData *credentialschema.ResolvedDisplayData) { +func TestResolveCredentialOffer(t *testing.T) { + var issuerMetadata issuer.Metadata + err := json.Unmarshal(sampleIssuerMetadata, &issuerMetadata) + require.NoError(t, err) + + t.Run("Success", func(t *testing.T) { + resolvedDisplayData := credentialschema.ResolveCredentialOffer( + &issuerMetadata, [][]string{{"UniversityDegreeCredential"}}, "") + + checkSuccessCaseMatchedOverviewData(t, resolvedDisplayData) + }) +} + +func checkSuccessCaseMatchedOverviewData(t *testing.T, resolvedDisplayData *credentialschema.ResolvedDisplayData) { t.Helper() require.Equal(t, "Example University", resolvedDisplayData.IssuerDisplay.Name) @@ -460,6 +473,12 @@ func checkSuccessCaseMatchedDisplayData(t *testing.T, resolvedDisplayData *crede resolvedDisplayData.CredentialDisplays[0].Overview.Logo.AltText) require.Equal(t, "#12107c", resolvedDisplayData.CredentialDisplays[0].Overview.BackgroundColor) require.Equal(t, "#FFFFFF", resolvedDisplayData.CredentialDisplays[0].Overview.TextColor) +} + +func checkSuccessCaseMatchedDisplayData(t *testing.T, resolvedDisplayData *credentialschema.ResolvedDisplayData) { + t.Helper() + + checkSuccessCaseMatchedOverviewData(t, resolvedDisplayData) expectedIDOrder := 0 expectedGivenNameOrder := 1 diff --git a/pkg/openid4ci/issuerinitiatedinteraction.go b/pkg/openid4ci/issuerinitiatedinteraction.go index b111708b..5a67d0d3 100644 --- a/pkg/openid4ci/issuerinitiatedinteraction.go +++ b/pkg/openid4ci/issuerinitiatedinteraction.go @@ -260,6 +260,11 @@ func (i *IssuerInitiatedInteraction) IssuerMetadata() (*issuer.Metadata, error) return i.interaction.issuerMetadata, nil } +// OfferedCredentialsTypes returns types of offered credentials. +func (i *IssuerInitiatedInteraction) OfferedCredentialsTypes() [][]string { + return i.credentialTypes +} + // VerifyIssuer verifies the issuer via its issuer metadata. If successful, then the service URL is returned. // An error means that either the issuer failed the verification check, or something went wrong during the // process (and so a verification status could not be determined). diff --git a/pkg/openid4ci/issuerinitiatedinteraction_test.go b/pkg/openid4ci/issuerinitiatedinteraction_test.go index 6c45f059..c68aa732 100644 --- a/pkg/openid4ci/issuerinitiatedinteraction_test.go +++ b/pkg/openid4ci/issuerinitiatedinteraction_test.go @@ -449,6 +449,10 @@ func TestIssuerInitiatedInteraction_RequestCredential(t *testing.T) { interaction := newIssuerInitiatedInteraction(t, createCredentialOfferIssuanceURI(t, server.URL, false, true)) + offeredCredentialsTypes := interaction.OfferedCredentialsTypes() + require.Len(t, offeredCredentialsTypes, 1) + require.Contains(t, offeredCredentialsTypes[0], "VerifiedEmployee") + credentials, err := interaction.RequestCredentialWithPreAuth(&jwtSignerMock{ keyID: mockKeyID, }, openid4ci.WithPIN("1234")) diff --git a/test/integration/openid4ci_test.go b/test/integration/openid4ci_test.go index 28968871..eb68d484 100644 --- a/test/integration/openid4ci_test.go +++ b/test/integration/openid4ci_test.go @@ -243,6 +243,17 @@ func doPreAuthCodeFlowTest(t *testing.T) { require.False(t, preAuthorizedCodeGrantParams.PINRequired()) + issuerMetadata, err := interaction.IssuerMetadata() + require.NoError(t, err) + + offeringDisplayData := display.ResolveCredentialOffer( + issuerMetadata, + interaction.OfferedCredentialsTypes(), + "", + ) + + helpers.CheckResolvedDisplayData(t, offeringDisplayData, tc.expectedDisplayData, false) + vm, err := testHelper.DIDDoc.AssertionMethod() require.NoError(t, err) @@ -306,7 +317,6 @@ func doPreAuthCodeFlowTest(t *testing.T) { testHelper.CheckActivityLogAfterOpenID4CIFlow(t, vcsAPIDirectURL, tc.issuerProfileID, subID) - testHelper.CheckMetricsLoggerAfterOpenID4CIFlow(t, tc.issuerProfileID) } require.Len(t, traceIDs, len(preAuthTests)) diff --git a/test/integration/pkg/helpers/displaydata.go b/test/integration/pkg/helpers/displaydata.go index 5b8631b9..7b1978bf 100644 --- a/test/integration/pkg/helpers/displaydata.go +++ b/test/integration/pkg/helpers/displaydata.go @@ -37,15 +37,15 @@ func ResolveDisplayData(t *testing.T, credentials *verifiable.CredentialsArray, displayData, err := display.Resolve(credentials, issuerURI, opts) require.NoError(t, err) - checkResolvedDisplayData(t, displayData, expectedDisplayData) + CheckResolvedDisplayData(t, displayData, expectedDisplayData, true) checkResolveMetricsEvent(t, metricsLogger, issuerProfileID) } -// For now, this function assumes that the display data object has only a single credential display. +// CheckResolvedDisplayData function assumes that the display data object has only a single credential display. // In the event we add a test case where there are multiple credential displays, then this function will need to be // updated accordingly. -func checkResolvedDisplayData(t *testing.T, actualDisplayData, expectedDisplayData *display.Data) { +func CheckResolvedDisplayData(t *testing.T, actualDisplayData, expectedDisplayData *display.Data, checkClaims bool) { t.Helper() checkIssuerDisplay(t, actualDisplayData.IssuerDisplay(), expectedDisplayData.IssuerDisplay()) @@ -55,7 +55,7 @@ func checkResolvedDisplayData(t *testing.T, actualDisplayData, expectedDisplayDa actualCredentialDisplay := actualDisplayData.CredentialDisplayAtIndex(0) expectedCredentialDisplay := expectedDisplayData.CredentialDisplayAtIndex(0) - checkCredentialDisplay(t, actualCredentialDisplay, expectedCredentialDisplay) + checkCredentialDisplay(t, actualCredentialDisplay, expectedCredentialDisplay, checkClaims) } func checkResolveMetricsEvent(t *testing.T, metricsLogger *metricslogger.MetricsLogger, issuerProfileID string) { diff --git a/test/integration/pkg/helpers/openid4ci.go b/test/integration/pkg/helpers/openid4ci.go index c295f981..8465e088 100644 --- a/test/integration/pkg/helpers/openid4ci.go +++ b/test/integration/pkg/helpers/openid4ci.go @@ -115,7 +115,7 @@ func (h *CITestHelper) CheckMetricsLoggerAfterOpenID4CIFlow(t *testing.T, issuer checkInteractionInstantiationMetricsEvent(t, h.MetricsLogger.Events[0]) checkFetchIssuerMetadataMetricsEvent(t, h.MetricsLogger.Events[1], - "Request credential(s) from issuer", issuerProfileID) + "Get issuer metadata", issuerProfileID) checkFetchOpenIDConfigMetricsEvent(t, h.MetricsLogger.Events[2], issuerProfileID) @@ -135,7 +135,8 @@ func checkIssuerDisplay(t *testing.T, actualIssuerDisplay, expectedIssuerDisplay require.Equal(t, expectedIssuerDisplay.Locale(), actualIssuerDisplay.Locale()) } -func checkCredentialDisplay(t *testing.T, actualCredentialDisplay, expectedCredentialDisplay *display.CredentialDisplay) { +func checkCredentialDisplay(t *testing.T, actualCredentialDisplay, + expectedCredentialDisplay *display.CredentialDisplay, checkClaims bool) { t.Helper() actualCredentialOverview := actualCredentialDisplay.Overview() @@ -148,6 +149,10 @@ func checkCredentialDisplay(t *testing.T, actualCredentialDisplay, expectedCrede require.Equal(t, expectedCredentialOverview.BackgroundColor(), actualCredentialOverview.BackgroundColor()) require.Equal(t, expectedCredentialOverview.TextColor(), actualCredentialOverview.TextColor()) + if !checkClaims { + return + } + require.Equal(t, expectedCredentialDisplay.ClaimsLength(), actualCredentialDisplay.ClaimsLength()) // Since the claims object in the supported_credentials object from the issuer is a map which effectively gets