From 6bb43d1c4440708b97de93d1915109487cd0d616 Mon Sep 17 00:00:00 2001 From: Dimitris Tsiflitzis Date: Thu, 18 Jan 2024 15:14:13 +0200 Subject: [PATCH] [fix] wallet updates --- Tests/Constants/TestsConstants.swift | 12 +++---- Tests/Helpers/Wallet.swift | 48 ++++++++++++++++++---------- 2 files changed, 37 insertions(+), 23 deletions(-) diff --git a/Tests/Constants/TestsConstants.swift b/Tests/Constants/TestsConstants.swift index cebb839..d7b25e5 100644 --- a/Tests/Constants/TestsConstants.swift +++ b/Tests/Constants/TestsConstants.swift @@ -17,13 +17,13 @@ import Foundation @testable import OpenID4VCI //let CredentialIssuer_URL = "http://localhost:8080" -//let CredentialIssuer_URL = "https://preprod.issuer.eudiw.dev/oidc" -let CredentialIssuer_URL = "https://eudi.netcompany-intrasoft.com/pid-issuer" +let CredentialIssuer_URL = "https://preprod.issuer.eudiw.dev/oidc" +//let CredentialIssuer_URL = "https://eudi.netcompany-intrasoft.com/pid-issuer" -let PID_SdJwtVC_SCOPE = "eu.europa.ec.eudiw.pid_vc_sd_jwt" -let PID_MsoMdoc_SCOPE = "eu.europa.ec.eudiw.pid_mso_mdoc" -//let PID_SdJwtVC_SCOPE = "eu.europa.ec.eudiw.pid_jwt_vc_json" -//let PID_MsoMdoc_SCOPE = "eu.europa.ec.eudiw.pid_mdoc" +//let PID_SdJwtVC_SCOPE = "eu.europa.ec.eudiw.pid_vc_sd_jwt" +//let PID_MsoMdoc_SCOPE = "eu.europa.ec.eudiw.pid_mso_mdoc" +let PID_SdJwtVC_SCOPE = "eu.europa.ec.eudiw.pid_jwt_vc_json" +let PID_MsoMdoc_SCOPE = "eu.europa.ec.eudiw.pid_mdoc" let All_Supported_CredentialOffer = """ { diff --git a/Tests/Helpers/Wallet.swift b/Tests/Helpers/Wallet.swift index aa2bffe..9cb4047 100644 --- a/Tests/Helpers/Wallet.swift +++ b/Tests/Helpers/Wallet.swift @@ -22,6 +22,11 @@ struct Wallet { let bindingKey: BindingKey } +enum WalletMode { + case doesNorRequireIntervention + case requiresIntervention +} + extension Wallet { func issueByCredentialIdentifier(_ identifier: String) async throws -> String { let credentialIdentifier = try CredentialIdentifier(value: identifier) @@ -239,25 +244,34 @@ extension Wallet { case let .par(parRequested) = request { print("--> [AUTHORIZATION] Placed PAR. Get authorization code URL is: \(parRequested.getAuthorizationCodeURL)") -// let authorizationCode = try await loginUserAndGetAuthCode( -// getAuthorizationCodeUrl: parRequested.getAuthorizationCodeURL.url, -// actingUser: actingUser -// ) ?? { throw ValidationError.error(reason: "Could not retrieve authorization code") }() - var authorizationCode = "" - print("--> [AUTHORIZATION] Authorization code retrieved: \(authorizationCode)") - - var issuanceAuthorization: IssuanceAuthorization = .authorizationCode(authorizationCode: authorizationCode) - - let unAuthorized = await issuer.handleAuthorizationCode( - parRequested: request, - code: &authorizationCode - ) + var unAuthorized: Result + var authorizationCode: String -// let unAuthorized = await issuer.handleAuthorizationCode( -// parRequested: request, -// authorizationCode: issuanceAuthorization -// ) + // Depending on the mode selected, changes might be + // required on the tests constants file (endpoints, scopes) + let walletMode: WalletMode = .requiresIntervention + switch walletMode { + case .doesNorRequireIntervention: + authorizationCode = try await loginUserAndGetAuthCode( + getAuthorizationCodeUrl: parRequested.getAuthorizationCodeURL.url, + actingUser: actingUser + ) ?? { throw ValidationError.error(reason: "Could not retrieve authorization code") }() + let issuanceAuthorization: IssuanceAuthorization = .authorizationCode(authorizationCode: authorizationCode) + unAuthorized = await issuer.handleAuthorizationCode( + parRequested: request, + authorizationCode: issuanceAuthorization + ) + + case .requiresIntervention: + authorizationCode = "" + unAuthorized = await issuer.handleAuthorizationCode( + parRequested: request, + code: &authorizationCode + ) + } + + print("--> [AUTHORIZATION] Authorization code retrieved: \(authorizationCode)") switch unAuthorized { case .success(let request):