From 47cfc96af9a3a87d3736dbce6cfe05d90fa78747 Mon Sep 17 00:00:00 2001 From: Michael Avoyan Date: Tue, 26 Dec 2023 12:30:02 +0200 Subject: [PATCH 1/2] Error code: sdk_error --- VCL/build.gradle | 4 +-- .../api/entities/error/VCLError.kt | 24 ++++++++++------- .../api/entities/error/VCLErrorCode.kt | 6 +++-- .../impl/VclBlocksProvider.kt | 8 +++--- .../verifiers/CredentialIssuerVerifierImpl.kt | 26 +++++++++---------- ...redentialManifestByDeepLinkVerifierImpl.kt | 2 +- .../CredentialsByDeepLinkVerifierImpl.kt | 2 +- .../verifiers/OffersByDeepLinkVerifierImpl.kt | 2 +- ...esentationRequestByDeepLinkVerifierImpl.kt | 2 +- 9 files changed, 42 insertions(+), 34 deletions(-) diff --git a/VCL/build.gradle b/VCL/build.gradle index 2656fe8b..17d163e7 100644 --- a/VCL/build.gradle +++ b/VCL/build.gradle @@ -13,8 +13,8 @@ android { defaultConfig { minSdk 24 targetSdk 33 - versionName "1.22.0" - versionCode 118 + versionName "1.23.0" + versionCode 119 testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" consumerProguardFiles "consumer-rules.pro" } diff --git a/VCL/src/main/java/io/velocitycareerlabs/api/entities/error/VCLError.kt b/VCL/src/main/java/io/velocitycareerlabs/api/entities/error/VCLError.kt index e748cbed..daa3ea51 100644 --- a/VCL/src/main/java/io/velocitycareerlabs/api/entities/error/VCLError.kt +++ b/VCL/src/main/java/io/velocitycareerlabs/api/entities/error/VCLError.kt @@ -10,39 +10,45 @@ package io.velocitycareerlabs.api.entities.error import io.velocitycareerlabs.impl.extensions.toJsonObject import org.json.JSONObject -class VCLError( -): Error() { +class VCLError(): Error() { var payload: String? = null var error: String? = null - var errorCode: String? = null + var errorCode: String = VCLErrorCode.SdkError.value override var message: String? = null var statusCode: Int? = null constructor( error: String? = null, - errorCode: String? = null, + errorCode: VCLErrorCode = VCLErrorCode.SdkError, message: String? = null, statusCode: Int? = null, ) : this() { this.error = error - this.errorCode = errorCode + this.errorCode = errorCode.value this.message = message this.statusCode = statusCode } - constructor(payload: String?, errorCode: String? = null): this() { + constructor( + payload: String?, + errorCode: VCLErrorCode = VCLErrorCode.SdkError + ): this() { val payloadJson = payload?.toJsonObject() this.payload = payload this.error = payloadJson?.optString(KeyError) - this.errorCode = errorCode ?: payloadJson?.optString(KeyErrorCode) + this.errorCode = payloadJson?.optString(KeyErrorCode) ?: errorCode.value this.message = payloadJson?.optString(KeyMessage) this.statusCode = payloadJson?.optInt(KeyStatusCode) } - constructor(exception: Exception, statusCode: Int? = null): this() { + constructor( + exception: Exception, + errorCode: VCLErrorCode = VCLErrorCode.SdkError, + statusCode: Int? = null + ): this() { this.payload = null this.error = null - this.errorCode = null + this.errorCode = errorCode.value this.message = exception.toString() this.statusCode = statusCode } diff --git a/VCL/src/main/java/io/velocitycareerlabs/api/entities/error/VCLErrorCode.kt b/VCL/src/main/java/io/velocitycareerlabs/api/entities/error/VCLErrorCode.kt index 874c4d00..b39aac20 100644 --- a/VCL/src/main/java/io/velocitycareerlabs/api/entities/error/VCLErrorCode.kt +++ b/VCL/src/main/java/io/velocitycareerlabs/api/entities/error/VCLErrorCode.kt @@ -7,7 +7,7 @@ package io.velocitycareerlabs.api.entities.error -internal enum class VCLErrorCode(val value: String) { +enum class VCLErrorCode(val value: String) { // Initialization RemoteServicesUrlsNotFount("remote_services_urls_not_found"), InjectedServicesNotFount("injected_services_not_found"), @@ -22,5 +22,7 @@ internal enum class VCLErrorCode(val value: String) { MismatchedRequestIssuerDid("mismatched_request_issuer_did"), MismatchedOfferIssuerDid("mismatched_offer_issuer_did"), MismatchedCredentialIssuerDid("mismatched_credential_issuer_did"), - MismatchedPresentationRequestInspectorDid("mismatched_presentation_request_inspector_did") + MismatchedPresentationRequestInspectorDid("mismatched_presentation_request_inspector_did"), + // General error + SdkError("sdk_error") } \ No newline at end of file diff --git a/VCL/src/main/java/io/velocitycareerlabs/impl/VclBlocksProvider.kt b/VCL/src/main/java/io/velocitycareerlabs/impl/VclBlocksProvider.kt index 3c005032..d3837d40 100644 --- a/VCL/src/main/java/io/velocitycareerlabs/impl/VclBlocksProvider.kt +++ b/VCL/src/main/java/io/velocitycareerlabs/impl/VclBlocksProvider.kt @@ -61,12 +61,12 @@ internal object VclBlocksProvider { keyServiceUrls ) } - ?: throw VCLError(errorCode = VCLErrorCode.RemoteServicesUrlsNotFount.value) + ?: throw VCLError(errorCode = VCLErrorCode.RemoteServicesUrlsNotFount) } VCLCryptoServiceType.Injected -> cryptoServicesDescriptor.injectedCryptoServicesDescriptor?.keyService?.let { keyService -> return keyService - } ?: throw VCLError(errorCode = VCLErrorCode.InjectedServicesNotFount.value) + } ?: throw VCLError(errorCode = VCLErrorCode.InjectedServicesNotFount) } } @@ -89,11 +89,11 @@ internal object VclBlocksProvider { jwtSignServiceUrl ) } - ?: throw VCLError(errorCode = VCLErrorCode.RemoteServicesUrlsNotFount.value) + ?: throw VCLError(errorCode = VCLErrorCode.RemoteServicesUrlsNotFount) VCLCryptoServiceType.Injected -> cryptoServicesDescriptor.injectedCryptoServicesDescriptor?.jwtSignService?.let { jwtSignService -> return jwtSignService - } ?: throw VCLError(errorCode = VCLErrorCode.InjectedServicesNotFount.value) + } ?: throw VCLError(errorCode = VCLErrorCode.InjectedServicesNotFount) } } diff --git a/VCL/src/main/java/io/velocitycareerlabs/impl/data/verifiers/CredentialIssuerVerifierImpl.kt b/VCL/src/main/java/io/velocitycareerlabs/impl/data/verifiers/CredentialIssuerVerifierImpl.kt index 1fb8ef69..4560bc78 100644 --- a/VCL/src/main/java/io/velocitycareerlabs/impl/data/verifiers/CredentialIssuerVerifierImpl.kt +++ b/VCL/src/main/java/io/velocitycareerlabs/impl/data/verifiers/CredentialIssuerVerifierImpl.kt @@ -42,7 +42,7 @@ internal class CredentialIssuerVerifierImpl( if (jwtCredentials.isEmpty()) /* nothing to verify */ { completionBlock(VCLResult.Success(true)) } else if (finalizeOffersDescriptor.serviceTypes.all.isEmpty()) { - completionBlock(VCLResult.Failure(VCLError(errorCode = VCLErrorCode.CredentialTypeNotRegistered.value))) + completionBlock(VCLResult.Failure(VCLError(errorCode = VCLErrorCode.CredentialTypeNotRegistered))) } else { var globalError: VCLError? = null val completableFutures = jwtCredentials.map { jwtCredential -> @@ -66,11 +66,11 @@ internal class CredentialIssuerVerifierImpl( } } ?: run { globalError = - VCLError(errorCode = VCLErrorCode.CredentialTypeNotRegistered.value) + VCLError(errorCode = VCLErrorCode.CredentialTypeNotRegistered) } } ?: run { globalError = - VCLError(errorCode = VCLErrorCode.CredentialTypeNotRegistered.value) + VCLError(errorCode = VCLErrorCode.CredentialTypeNotRegistered) } } } @@ -124,7 +124,7 @@ internal class CredentialIssuerVerifierImpl( completionBlock(VCLResult.Success(true)) } else { onError( - VCLError(errorCode = VCLErrorCode.IssuerRequiresIdentityPermission.value), + VCLError(errorCode = VCLErrorCode.IssuerRequiresIdentityPermission), completionBlock ) } @@ -152,7 +152,7 @@ internal class CredentialIssuerVerifierImpl( onError( VCLError( payload = error.payload, - errorCode = VCLErrorCode.InvalidCredentialSubjectContext.value + errorCode = VCLErrorCode.InvalidCredentialSubjectContext ), completionBlock ) @@ -160,19 +160,19 @@ internal class CredentialIssuerVerifierImpl( } } ?: run { onError( - VCLError(errorCode = VCLErrorCode.InvalidCredentialSubjectContext.value), + VCLError(errorCode = VCLErrorCode.InvalidCredentialSubjectContext), completionBlock ) } } ?: run { onError( - VCLError(errorCode = VCLErrorCode.InvalidCredentialSubjectContext.value), + VCLError(errorCode = VCLErrorCode.InvalidCredentialSubjectContext), completionBlock ) } } else { onError( - VCLError(errorCode = VCLErrorCode.IssuerUnexpectedPermissionFailure.value), + VCLError(errorCode = VCLErrorCode.IssuerUnexpectedPermissionFailure), completionBlock ) } @@ -226,7 +226,7 @@ internal class CredentialIssuerVerifierImpl( if (completeContexts.isEmpty()) { onError( - VCLError(errorCode = VCLErrorCode.InvalidCredentialSubjectContext.value), + VCLError(errorCode = VCLErrorCode.InvalidCredentialSubjectContext), completionBlock = completionBlock ) } else { @@ -254,11 +254,11 @@ internal class CredentialIssuerVerifierImpl( isCredentialVerified = true } else { globalError = - VCLError(errorCode = VCLErrorCode.IssuerRequiresNotaryPermission.value) + VCLError(errorCode = VCLErrorCode.IssuerRequiresNotaryPermission) } } ?: run { globalError = - VCLError(errorCode = VCLErrorCode.IssuerRequiresNotaryPermission.value) + VCLError(errorCode = VCLErrorCode.IssuerRequiresNotaryPermission) } } ?: run { // When K is null, the credential will pass these checks: @@ -276,12 +276,12 @@ internal class CredentialIssuerVerifierImpl( completionBlock( VCLResult.Failure( globalError - ?: VCLError(errorCode = VCLErrorCode.IssuerUnexpectedPermissionFailure.value) + ?: VCLError(errorCode = VCLErrorCode.IssuerUnexpectedPermissionFailure) ) ) } ?: run { onError( - VCLError(errorCode = VCLErrorCode.InvalidCredentialSubjectType.value), + VCLError(errorCode = VCLErrorCode.InvalidCredentialSubjectType), completionBlock = completionBlock ) } diff --git a/VCL/src/main/java/io/velocitycareerlabs/impl/data/verifiers/CredentialManifestByDeepLinkVerifierImpl.kt b/VCL/src/main/java/io/velocitycareerlabs/impl/data/verifiers/CredentialManifestByDeepLinkVerifierImpl.kt index a4177df5..2436481a 100644 --- a/VCL/src/main/java/io/velocitycareerlabs/impl/data/verifiers/CredentialManifestByDeepLinkVerifierImpl.kt +++ b/VCL/src/main/java/io/velocitycareerlabs/impl/data/verifiers/CredentialManifestByDeepLinkVerifierImpl.kt @@ -26,7 +26,7 @@ class CredentialManifestByDeepLinkVerifierImpl: CredentialManifestByDeepLinkVeri completionBlock(VCLResult.Success(true)) } else { VCLLog.e(TAG, "credential manifest: ${credentialManifest.jwt.encodedJwt} \ndeepLink: ${deepLink.value}") - completionBlock((VCLResult.Failure(VCLError(errorCode = VCLErrorCode.MismatchedRequestIssuerDid.value)))) + completionBlock((VCLResult.Failure(VCLError(errorCode = VCLErrorCode.MismatchedRequestIssuerDid)))) } } } \ No newline at end of file diff --git a/VCL/src/main/java/io/velocitycareerlabs/impl/data/verifiers/CredentialsByDeepLinkVerifierImpl.kt b/VCL/src/main/java/io/velocitycareerlabs/impl/data/verifiers/CredentialsByDeepLinkVerifierImpl.kt index 22591f92..741097df 100644 --- a/VCL/src/main/java/io/velocitycareerlabs/impl/data/verifiers/CredentialsByDeepLinkVerifierImpl.kt +++ b/VCL/src/main/java/io/velocitycareerlabs/impl/data/verifiers/CredentialsByDeepLinkVerifierImpl.kt @@ -24,7 +24,7 @@ class CredentialsByDeepLinkVerifierImpl: CredentialsByDeepLinkVerifier { ) { jwtCredentials.find { it.iss != deepLink.did }?.let { mismatchedCredential -> VCLLog.e(TAG, "mismatched credential: ${mismatchedCredential.encodedJwt} \ndeepLink: ${deepLink.value}") - completionBlock(VCLResult.Failure(VCLError(errorCode = VCLErrorCode.MismatchedCredentialIssuerDid.value))) + completionBlock(VCLResult.Failure(VCLError(errorCode = VCLErrorCode.MismatchedCredentialIssuerDid))) } ?: run { completionBlock(VCLResult.Success(true)) } diff --git a/VCL/src/main/java/io/velocitycareerlabs/impl/data/verifiers/OffersByDeepLinkVerifierImpl.kt b/VCL/src/main/java/io/velocitycareerlabs/impl/data/verifiers/OffersByDeepLinkVerifierImpl.kt index aaca3e5e..5ea3ad13 100644 --- a/VCL/src/main/java/io/velocitycareerlabs/impl/data/verifiers/OffersByDeepLinkVerifierImpl.kt +++ b/VCL/src/main/java/io/velocitycareerlabs/impl/data/verifiers/OffersByDeepLinkVerifierImpl.kt @@ -24,7 +24,7 @@ class OffersByDeepLinkVerifierImpl: OffersByDeepLinkVerifier { ) { offers.all.find { it.issuerId != deepLink.did }?.let { mismatchedOffer -> VCLLog.e(TAG, "mismatched offer: ${mismatchedOffer.payload} \ndeepLink: ${deepLink.value}") - completionBlock(VCLResult.Failure(VCLError(errorCode = VCLErrorCode.MismatchedOfferIssuerDid.value))) + completionBlock(VCLResult.Failure(VCLError(errorCode = VCLErrorCode.MismatchedOfferIssuerDid))) } ?: run { completionBlock(VCLResult.Success(true)) } diff --git a/VCL/src/main/java/io/velocitycareerlabs/impl/data/verifiers/PresentationRequestByDeepLinkVerifierImpl.kt b/VCL/src/main/java/io/velocitycareerlabs/impl/data/verifiers/PresentationRequestByDeepLinkVerifierImpl.kt index 25b846c5..39f721be 100644 --- a/VCL/src/main/java/io/velocitycareerlabs/impl/data/verifiers/PresentationRequestByDeepLinkVerifierImpl.kt +++ b/VCL/src/main/java/io/velocitycareerlabs/impl/data/verifiers/PresentationRequestByDeepLinkVerifierImpl.kt @@ -27,7 +27,7 @@ class PresentationRequestByDeepLinkVerifierImpl: PresentationRequestByDeepLinkVe } else { VCLLog.e(TAG, "presentation request: ${presentationRequest.jwt.encodedJwt} \ndeepLink: ${deepLink.value}") completionBlock(VCLResult.Failure( - VCLError(errorCode = VCLErrorCode.MismatchedPresentationRequestInspectorDid.value) + VCLError(errorCode = VCLErrorCode.MismatchedPresentationRequestInspectorDid) )) } } From 7c0eac554a15ad46e62c3240639a023ccc9c1953 Mon Sep 17 00:00:00 2001 From: Michael Avoyan Date: Mon, 1 Jan 2024 12:47:11 +0200 Subject: [PATCH 2/2] cont --- .../api/entities/error/VCLError.kt | 22 ++++----- .../impl/VclBlocksProvider.kt | 8 ++-- .../repositories/SubmissionRepositoryImpl.kt | 12 ++--- .../verifiers/CredentialIssuerVerifierImpl.kt | 26 +++++------ ...redentialManifestByDeepLinkVerifierImpl.kt | 2 +- .../CredentialsByDeepLinkVerifierImpl.kt | 2 +- .../verifiers/OffersByDeepLinkVerifierImpl.kt | 2 +- ...esentationRequestByDeepLinkVerifierImpl.kt | 2 +- .../resources/valid/DeepLinkMocks.kt | 12 ++--- .../valid/PresentationRequestMocks.kt | 9 ---- .../usecases/CountriesUseCaseTest.kt | 31 +++++++++++-- .../usecases/CredentialManifestUseCaseTest.kt | 45 +++++++++++++++++-- .../CredentialTypeSchemaUseCaseTest.kt | 3 +- .../CredentialTypesUIFormSchemaUseCaseTest.kt | 34 ++++++++++++-- .../usecases/CredentialTypesUseCaseTest.kt | 28 +++++++++++- .../usecases/ExchangeProgressUseCaseTest.kt | 27 ++++++++++- .../usecases/FinalizeOffersUseCaseTest.kt | 40 ++++++++++++++++- .../usecases/GenerateOffersUseCaseTest.kt | 12 ++--- .../usecases/JwtServiceUseCaseTest.kt | 3 +- .../usecases/KeyServiceUseCaseTest.kt | 5 ++- .../usecases/OrganizationsUseCaseTest.kt | 9 ++-- .../PresentationRequestUseCaseTest.kt | 44 +++++++++++++++--- .../PresentationSubmissionUseCaseTest.kt | 4 +- .../usecases/VerifiedProfileUseCaseTest.kt | 12 ++--- ...redentialManifestByDeepLinkVerifierTest.kt | 6 +-- .../verifiers/OffersByDeepLinkVerifierTest.kt | 7 +-- ...esentationRequestByDeepLinkVerifierTest.kt | 11 ++--- 27 files changed, 308 insertions(+), 110 deletions(-) diff --git a/VCL/src/main/java/io/velocitycareerlabs/api/entities/error/VCLError.kt b/VCL/src/main/java/io/velocitycareerlabs/api/entities/error/VCLError.kt index daa3ea51..5677b6d8 100644 --- a/VCL/src/main/java/io/velocitycareerlabs/api/entities/error/VCLError.kt +++ b/VCL/src/main/java/io/velocitycareerlabs/api/entities/error/VCLError.kt @@ -10,7 +10,8 @@ package io.velocitycareerlabs.api.entities.error import io.velocitycareerlabs.impl.extensions.toJsonObject import org.json.JSONObject -class VCLError(): Error() { +class VCLError( +): Error() { var payload: String? = null var error: String? = null var errorCode: String = VCLErrorCode.SdkError.value @@ -19,36 +20,29 @@ class VCLError(): Error() { constructor( error: String? = null, - errorCode: VCLErrorCode = VCLErrorCode.SdkError, + errorCode: String = VCLErrorCode.SdkError.value, message: String? = null, statusCode: Int? = null, ) : this() { this.error = error - this.errorCode = errorCode.value + this.errorCode = errorCode this.message = message this.statusCode = statusCode } - constructor( - payload: String?, - errorCode: VCLErrorCode = VCLErrorCode.SdkError - ): this() { + constructor(payload: String?, errorCode: String? = null): this() { val payloadJson = payload?.toJsonObject() this.payload = payload this.error = payloadJson?.optString(KeyError) - this.errorCode = payloadJson?.optString(KeyErrorCode) ?: errorCode.value + this.errorCode = errorCode ?: payloadJson?.optString(KeyErrorCode) ?: VCLErrorCode.SdkError.value this.message = payloadJson?.optString(KeyMessage) this.statusCode = payloadJson?.optInt(KeyStatusCode) } - constructor( - exception: Exception, - errorCode: VCLErrorCode = VCLErrorCode.SdkError, - statusCode: Int? = null - ): this() { + constructor(exception: Exception, statusCode: Int? = null): this() { this.payload = null this.error = null - this.errorCode = errorCode.value + this.errorCode = VCLErrorCode.SdkError.value this.message = exception.toString() this.statusCode = statusCode } diff --git a/VCL/src/main/java/io/velocitycareerlabs/impl/VclBlocksProvider.kt b/VCL/src/main/java/io/velocitycareerlabs/impl/VclBlocksProvider.kt index d3837d40..3c005032 100644 --- a/VCL/src/main/java/io/velocitycareerlabs/impl/VclBlocksProvider.kt +++ b/VCL/src/main/java/io/velocitycareerlabs/impl/VclBlocksProvider.kt @@ -61,12 +61,12 @@ internal object VclBlocksProvider { keyServiceUrls ) } - ?: throw VCLError(errorCode = VCLErrorCode.RemoteServicesUrlsNotFount) + ?: throw VCLError(errorCode = VCLErrorCode.RemoteServicesUrlsNotFount.value) } VCLCryptoServiceType.Injected -> cryptoServicesDescriptor.injectedCryptoServicesDescriptor?.keyService?.let { keyService -> return keyService - } ?: throw VCLError(errorCode = VCLErrorCode.InjectedServicesNotFount) + } ?: throw VCLError(errorCode = VCLErrorCode.InjectedServicesNotFount.value) } } @@ -89,11 +89,11 @@ internal object VclBlocksProvider { jwtSignServiceUrl ) } - ?: throw VCLError(errorCode = VCLErrorCode.RemoteServicesUrlsNotFount) + ?: throw VCLError(errorCode = VCLErrorCode.RemoteServicesUrlsNotFount.value) VCLCryptoServiceType.Injected -> cryptoServicesDescriptor.injectedCryptoServicesDescriptor?.jwtSignService?.let { jwtSignService -> return jwtSignService - } ?: throw VCLError(errorCode = VCLErrorCode.InjectedServicesNotFount) + } ?: throw VCLError(errorCode = VCLErrorCode.InjectedServicesNotFount.value) } } diff --git a/VCL/src/main/java/io/velocitycareerlabs/impl/data/repositories/SubmissionRepositoryImpl.kt b/VCL/src/main/java/io/velocitycareerlabs/impl/data/repositories/SubmissionRepositoryImpl.kt index f22bfce9..57b8fa6c 100644 --- a/VCL/src/main/java/io/velocitycareerlabs/impl/data/repositories/SubmissionRepositoryImpl.kt +++ b/VCL/src/main/java/io/velocitycareerlabs/impl/data/repositories/SubmissionRepositoryImpl.kt @@ -12,6 +12,7 @@ import io.velocitycareerlabs.api.entities.error.VCLError import io.velocitycareerlabs.impl.data.infrastructure.network.Request import io.velocitycareerlabs.impl.domain.repositories.SubmissionRepository import io.velocitycareerlabs.impl.domain.infrastructure.network.NetworkService +import io.velocitycareerlabs.impl.extensions.toJsonObject import org.json.JSONObject import java.lang.Exception @@ -34,9 +35,8 @@ internal class SubmissionRepositoryImpl( completionBlock = { result -> result.handleResult({ submissionResponse -> try { - val jsonObj = JSONObject(submissionResponse.payload) - val submissionResult = - parse(jsonObj, submission.jti, submission.submissionId) + val jsonObj = submissionResponse.payload.toJsonObject() + val submissionResult = parse(jsonObj, submission.jti, submission.submissionId) completionBlock(VCLResult.Success(submissionResult)) } catch (ex: Exception) { completionBlock(VCLResult.Failure(VCLError(ex))) @@ -51,13 +51,13 @@ internal class SubmissionRepositoryImpl( } private fun parse( - jsonObj: JSONObject, + jsonObj: JSONObject?, jti: String, submissionId: String ): VCLSubmissionResult { - val exchangeJsonObj = jsonObj.optJSONObject(VCLSubmissionResult.KeyExchange) + val exchangeJsonObj = jsonObj?.optJSONObject(VCLSubmissionResult.KeyExchange) return VCLSubmissionResult( - sessionToken = VCLToken(jsonObj.optString(VCLSubmissionResult.KeyToken)), + sessionToken = VCLToken(jsonObj?.optString(VCLSubmissionResult.KeyToken) ?: ""), exchange = parseExchange(exchangeJsonObj), jti = jti, submissionId = submissionId diff --git a/VCL/src/main/java/io/velocitycareerlabs/impl/data/verifiers/CredentialIssuerVerifierImpl.kt b/VCL/src/main/java/io/velocitycareerlabs/impl/data/verifiers/CredentialIssuerVerifierImpl.kt index 4560bc78..1fb8ef69 100644 --- a/VCL/src/main/java/io/velocitycareerlabs/impl/data/verifiers/CredentialIssuerVerifierImpl.kt +++ b/VCL/src/main/java/io/velocitycareerlabs/impl/data/verifiers/CredentialIssuerVerifierImpl.kt @@ -42,7 +42,7 @@ internal class CredentialIssuerVerifierImpl( if (jwtCredentials.isEmpty()) /* nothing to verify */ { completionBlock(VCLResult.Success(true)) } else if (finalizeOffersDescriptor.serviceTypes.all.isEmpty()) { - completionBlock(VCLResult.Failure(VCLError(errorCode = VCLErrorCode.CredentialTypeNotRegistered))) + completionBlock(VCLResult.Failure(VCLError(errorCode = VCLErrorCode.CredentialTypeNotRegistered.value))) } else { var globalError: VCLError? = null val completableFutures = jwtCredentials.map { jwtCredential -> @@ -66,11 +66,11 @@ internal class CredentialIssuerVerifierImpl( } } ?: run { globalError = - VCLError(errorCode = VCLErrorCode.CredentialTypeNotRegistered) + VCLError(errorCode = VCLErrorCode.CredentialTypeNotRegistered.value) } } ?: run { globalError = - VCLError(errorCode = VCLErrorCode.CredentialTypeNotRegistered) + VCLError(errorCode = VCLErrorCode.CredentialTypeNotRegistered.value) } } } @@ -124,7 +124,7 @@ internal class CredentialIssuerVerifierImpl( completionBlock(VCLResult.Success(true)) } else { onError( - VCLError(errorCode = VCLErrorCode.IssuerRequiresIdentityPermission), + VCLError(errorCode = VCLErrorCode.IssuerRequiresIdentityPermission.value), completionBlock ) } @@ -152,7 +152,7 @@ internal class CredentialIssuerVerifierImpl( onError( VCLError( payload = error.payload, - errorCode = VCLErrorCode.InvalidCredentialSubjectContext + errorCode = VCLErrorCode.InvalidCredentialSubjectContext.value ), completionBlock ) @@ -160,19 +160,19 @@ internal class CredentialIssuerVerifierImpl( } } ?: run { onError( - VCLError(errorCode = VCLErrorCode.InvalidCredentialSubjectContext), + VCLError(errorCode = VCLErrorCode.InvalidCredentialSubjectContext.value), completionBlock ) } } ?: run { onError( - VCLError(errorCode = VCLErrorCode.InvalidCredentialSubjectContext), + VCLError(errorCode = VCLErrorCode.InvalidCredentialSubjectContext.value), completionBlock ) } } else { onError( - VCLError(errorCode = VCLErrorCode.IssuerUnexpectedPermissionFailure), + VCLError(errorCode = VCLErrorCode.IssuerUnexpectedPermissionFailure.value), completionBlock ) } @@ -226,7 +226,7 @@ internal class CredentialIssuerVerifierImpl( if (completeContexts.isEmpty()) { onError( - VCLError(errorCode = VCLErrorCode.InvalidCredentialSubjectContext), + VCLError(errorCode = VCLErrorCode.InvalidCredentialSubjectContext.value), completionBlock = completionBlock ) } else { @@ -254,11 +254,11 @@ internal class CredentialIssuerVerifierImpl( isCredentialVerified = true } else { globalError = - VCLError(errorCode = VCLErrorCode.IssuerRequiresNotaryPermission) + VCLError(errorCode = VCLErrorCode.IssuerRequiresNotaryPermission.value) } } ?: run { globalError = - VCLError(errorCode = VCLErrorCode.IssuerRequiresNotaryPermission) + VCLError(errorCode = VCLErrorCode.IssuerRequiresNotaryPermission.value) } } ?: run { // When K is null, the credential will pass these checks: @@ -276,12 +276,12 @@ internal class CredentialIssuerVerifierImpl( completionBlock( VCLResult.Failure( globalError - ?: VCLError(errorCode = VCLErrorCode.IssuerUnexpectedPermissionFailure) + ?: VCLError(errorCode = VCLErrorCode.IssuerUnexpectedPermissionFailure.value) ) ) } ?: run { onError( - VCLError(errorCode = VCLErrorCode.InvalidCredentialSubjectType), + VCLError(errorCode = VCLErrorCode.InvalidCredentialSubjectType.value), completionBlock = completionBlock ) } diff --git a/VCL/src/main/java/io/velocitycareerlabs/impl/data/verifiers/CredentialManifestByDeepLinkVerifierImpl.kt b/VCL/src/main/java/io/velocitycareerlabs/impl/data/verifiers/CredentialManifestByDeepLinkVerifierImpl.kt index 2436481a..a4177df5 100644 --- a/VCL/src/main/java/io/velocitycareerlabs/impl/data/verifiers/CredentialManifestByDeepLinkVerifierImpl.kt +++ b/VCL/src/main/java/io/velocitycareerlabs/impl/data/verifiers/CredentialManifestByDeepLinkVerifierImpl.kt @@ -26,7 +26,7 @@ class CredentialManifestByDeepLinkVerifierImpl: CredentialManifestByDeepLinkVeri completionBlock(VCLResult.Success(true)) } else { VCLLog.e(TAG, "credential manifest: ${credentialManifest.jwt.encodedJwt} \ndeepLink: ${deepLink.value}") - completionBlock((VCLResult.Failure(VCLError(errorCode = VCLErrorCode.MismatchedRequestIssuerDid)))) + completionBlock((VCLResult.Failure(VCLError(errorCode = VCLErrorCode.MismatchedRequestIssuerDid.value)))) } } } \ No newline at end of file diff --git a/VCL/src/main/java/io/velocitycareerlabs/impl/data/verifiers/CredentialsByDeepLinkVerifierImpl.kt b/VCL/src/main/java/io/velocitycareerlabs/impl/data/verifiers/CredentialsByDeepLinkVerifierImpl.kt index 741097df..22591f92 100644 --- a/VCL/src/main/java/io/velocitycareerlabs/impl/data/verifiers/CredentialsByDeepLinkVerifierImpl.kt +++ b/VCL/src/main/java/io/velocitycareerlabs/impl/data/verifiers/CredentialsByDeepLinkVerifierImpl.kt @@ -24,7 +24,7 @@ class CredentialsByDeepLinkVerifierImpl: CredentialsByDeepLinkVerifier { ) { jwtCredentials.find { it.iss != deepLink.did }?.let { mismatchedCredential -> VCLLog.e(TAG, "mismatched credential: ${mismatchedCredential.encodedJwt} \ndeepLink: ${deepLink.value}") - completionBlock(VCLResult.Failure(VCLError(errorCode = VCLErrorCode.MismatchedCredentialIssuerDid))) + completionBlock(VCLResult.Failure(VCLError(errorCode = VCLErrorCode.MismatchedCredentialIssuerDid.value))) } ?: run { completionBlock(VCLResult.Success(true)) } diff --git a/VCL/src/main/java/io/velocitycareerlabs/impl/data/verifiers/OffersByDeepLinkVerifierImpl.kt b/VCL/src/main/java/io/velocitycareerlabs/impl/data/verifiers/OffersByDeepLinkVerifierImpl.kt index 5ea3ad13..aaca3e5e 100644 --- a/VCL/src/main/java/io/velocitycareerlabs/impl/data/verifiers/OffersByDeepLinkVerifierImpl.kt +++ b/VCL/src/main/java/io/velocitycareerlabs/impl/data/verifiers/OffersByDeepLinkVerifierImpl.kt @@ -24,7 +24,7 @@ class OffersByDeepLinkVerifierImpl: OffersByDeepLinkVerifier { ) { offers.all.find { it.issuerId != deepLink.did }?.let { mismatchedOffer -> VCLLog.e(TAG, "mismatched offer: ${mismatchedOffer.payload} \ndeepLink: ${deepLink.value}") - completionBlock(VCLResult.Failure(VCLError(errorCode = VCLErrorCode.MismatchedOfferIssuerDid))) + completionBlock(VCLResult.Failure(VCLError(errorCode = VCLErrorCode.MismatchedOfferIssuerDid.value))) } ?: run { completionBlock(VCLResult.Success(true)) } diff --git a/VCL/src/main/java/io/velocitycareerlabs/impl/data/verifiers/PresentationRequestByDeepLinkVerifierImpl.kt b/VCL/src/main/java/io/velocitycareerlabs/impl/data/verifiers/PresentationRequestByDeepLinkVerifierImpl.kt index 39f721be..25b846c5 100644 --- a/VCL/src/main/java/io/velocitycareerlabs/impl/data/verifiers/PresentationRequestByDeepLinkVerifierImpl.kt +++ b/VCL/src/main/java/io/velocitycareerlabs/impl/data/verifiers/PresentationRequestByDeepLinkVerifierImpl.kt @@ -27,7 +27,7 @@ class PresentationRequestByDeepLinkVerifierImpl: PresentationRequestByDeepLinkVe } else { VCLLog.e(TAG, "presentation request: ${presentationRequest.jwt.encodedJwt} \ndeepLink: ${deepLink.value}") completionBlock(VCLResult.Failure( - VCLError(errorCode = VCLErrorCode.MismatchedPresentationRequestInspectorDid) + VCLError(errorCode = VCLErrorCode.MismatchedPresentationRequestInspectorDid.value) )) } } diff --git a/VCL/src/test/java/io/velocitycareerlabs/infrastructure/resources/valid/DeepLinkMocks.kt b/VCL/src/test/java/io/velocitycareerlabs/infrastructure/resources/valid/DeepLinkMocks.kt index 879113ac..0ee4a7fa 100644 --- a/VCL/src/test/java/io/velocitycareerlabs/infrastructure/resources/valid/DeepLinkMocks.kt +++ b/VCL/src/test/java/io/velocitycareerlabs/infrastructure/resources/valid/DeepLinkMocks.kt @@ -24,16 +24,16 @@ class DeepLinkMocks { const val OpenidInitiateIssuanceStrDev = "openid-initiate-issuance://?issuer=$Issuer" - const val InspectorDid = "did:ion:EiByBvq95tfmhl41DOxJeaa26HjSxAUoz908PITFwMRDNA" + const val InspectorDid = "did:velocity:0xd4df29726d500f9b85bc6c7f1b3c021f16305692" const val PresentationRequestVendorOriginContext = "{\"SubjectKey\":{\"BusinessUnit\":\"ZC\",\"KeyCode\":\"54514480\"},\"Token\":\"832077a4\"}" var PresentationRequestRequestDecodedUriStr = - "https://agent.velocitycareerlabs.io/api/holder/v0.6/org/$InspectorDid/inspect/get-presentation-request?id=62e0e80c5ebfe73230b0becc&inspectorDid=${InspectorDid.encode()}&vendorOriginContext=%7B%22SubjectKey%22%3A%7B%22BusinessUnit%22%3A%22ZC%22,%22KeyCode%22%3A%2254514480%22%7D,%22Token%22%3A%22832077a4%22%7D".decode() + "https://agent.velocitycareerlabs.io/api/holder/v0.6/org/$InspectorDid/inspect/get-presentation-request?id=62e0e80c5ebfe73230b0becc&inspectorDid=${InspectorDid}&vendorOriginContext=%7B%22SubjectKey%22%3A%7B%22BusinessUnit%22%3A%22ZC%22,%22KeyCode%22%3A%2254514480%22%7D,%22Token%22%3A%22832077a4%22%7D".decode() const val PresentationRequestRequestUriStr = - "https%3A%2F%2Fagent.velocitycareerlabs.io%2Fapi%2Fholder%2Fv0.6%2Forg%2Fdid%3Aion%3AEiByBvq95tfmhl41DOxJeaa26HjSxAUoz908PITFwMRDNA%2Finspect%2Fget-presentation-request%3Fid%3D62e0e80c5ebfe73230b0becc&inspectorDid=did%3Aion%3AEiByBvq95tfmhl41DOxJeaa26HjSxAUoz908PITFwMRDNA&vendorOriginContext=%7B%22SubjectKey%22%3A%7B%22BusinessUnit%22%3A%22ZC%22,%22KeyCode%22%3A%2254514480%22%7D,%22Token%22%3A%22832077a4%22%7D" + "https%3A%2F%2Fagent.velocitycareerlabs.io%2Fapi%2Fholder%2Fv0.6%2Forg%2Fdid%3Avelocity%3A0xd4df29726d500f9b85bc6c7f1b3c021f16305692%2Finspect%2Fget-presentation-request%3Fid%3D62e0e80c5ebfe73230b0becc%26inspectorDid%3Ddid%3Avelocity%3A0xd4df29726d500f9b85bc6c7f1b3c021f16305692%26vendorOriginContext%3D%7B%22SubjectKey%22%3A%7B%22BusinessUnit%22%3A%22ZC%22%2C%22KeyCode%22%3A%2254514480%22%7D%2C%22Token%22%3A%22832077a4%22%7D" const val PresentationRequestDeepLinkDevNetStr = "$DevNetProtocol://inspect?request_uri=$PresentationRequestRequestUriStr" @@ -42,13 +42,13 @@ class DeepLinkMocks { const val PresentationRequestDeepLinkMainNetStr = "$MainNetProtocol://inspect?request_uri=$PresentationRequestRequestUriStr" - const val IssuerDid = "did:velocity:0xd4df29726d500f9b85bc6c7f1b3c021f16305692" + const val IssuerDid = "did:ion:EiApMLdMb4NPb8sae9-hXGHP79W1gisApVSE80USPEbtJA" const val CredentialManifestRequestDecodedUriStr = - "https://devagent.velocitycareerlabs.io/api/holder/v0.6/org/$IssuerDid/issue/get-credential-manifest?id=611b5836e93d08000af6f1bc&credential_types=PastEmploymentPosition&issuerDid=did:velocity:0xd4df29726d500f9b85bc6c7f1b3c021f16305692" + "https://devagent.velocitycareerlabs.io/api/holder/v0.6/org/$IssuerDid/issue/get-credential-manifest?id=611b5836e93d08000af6f1bc&credential_types=PastEmploymentPosition&issuerDid=$IssuerDid" const val CredentialManifestRequestUriStr = - "https%3A%2F%2Fdevagent.velocitycareerlabs.io%2Fapi%2Fholder%2Fv0.6%2Forg%2Fdid%3Avelocity%3A0xd4df29726d500f9b85bc6c7f1b3c021f16305692%2Fissue%2Fget-credential-manifest%3Fid%3D611b5836e93d08000af6f1bc%26credential_types%3DPastEmploymentPosition%26issuerDid%3Ddid%3Avelocity%3A0xd4df29726d500f9b85bc6c7f1b3c021f16305692" + "https%3A%2F%2Fdevagent.velocitycareerlabs.io%2Fapi%2Fholder%2Fv0.6%2Forg%2Fdid%3Aion%3AEiApMLdMb4NPb8sae9-hXGHP79W1gisApVSE80USPEbtJA%2Fissue%2Fget-credential-manifest%3Fid%3D611b5836e93d08000af6f1bc%26credential_types%3DPastEmploymentPosition%26issuerDid%3Ddid%3Aion%3AEiApMLdMb4NPb8sae9-hXGHP79W1gisApVSE80USPEbtJA" const val CredentialManifestDeepLinkDevNetStr = "$DevNetProtocol://issue?request_uri=$CredentialManifestRequestUriStr" const val CredentialManifestDeepLinkTestNetStr = "$TestNetProtocol://issue?request_uri=$CredentialManifestRequestUriStr" diff --git a/VCL/src/test/java/io/velocitycareerlabs/infrastructure/resources/valid/PresentationRequestMocks.kt b/VCL/src/test/java/io/velocitycareerlabs/infrastructure/resources/valid/PresentationRequestMocks.kt index 98da3f5e..45e1048f 100644 --- a/VCL/src/test/java/io/velocitycareerlabs/infrastructure/resources/valid/PresentationRequestMocks.kt +++ b/VCL/src/test/java/io/velocitycareerlabs/infrastructure/resources/valid/PresentationRequestMocks.kt @@ -20,15 +20,6 @@ class PresentationRequestMocks { const val EncodedPresentationRequestResponse = "{\"presentation_request\":\"$EncodedPresentationRequest\"}" - const val PresentationRequestJwtDecodedHeaderJson = - "{ \"typ\": \"JWT\", \"kid\": \"did:velocity:0xd4df29726d500f9b85bc6c7f1b3c021f16305692#key-1\", \"alg\": \"ES256K\" }" - - const val PresentationRequestJwtDecodedPayloadJson = - "{ \"exchange_id\": \"60ec1f766d274e00086748ca\", \"metadata\": { \"client_name\": \"Microsoft Corporation\", \"logo_uri\": \"https://agsol.com/wp-content/uploads/2018/09/new-microsoft-logo-SIZED-SQUARE.jpg\", \"tos_uri\": \"https://www.velocityexperiencecenter.com/terms-and-conditions-vnf\", \"max_retention_period\": \"6m\" }, \"presentation_definition\": { \"id\": \"60ec1f766d274e00086748ca.60ec143e6d274e00086748bc\", \"purpose\": \"Id Check\", \"format\": { \"jwt_vp\": { \"alg\": [ \"secp256k1\" ] } }, \"input_descriptors\": [ { \"id\": \"IdDocument\", \"schema\": [ { \"uri\": \"https://devservices.velocitycareerlabs.io/api/v0.6/schemas/id-document.v1.schema.json\" } ] }, { \"id\": \"Email\", \"schema\": [ { \"uri\": \"https://devservices.velocitycareerlabs.io/api/v0.6/schemas/email.schema.json\" } ] }, { \"id\": \"Phone\", \"schema\": [ { \"uri\": \"https://devservices.velocitycareerlabs.io/api/v0.6/schemas/phone.schema.json\" } ] }, { \"id\": \"PastEmploymentPosition\", \"schema\": [ { \"uri\": \"https://devservices.velocitycareerlabs.io/api/v0.6/schemas/past-employment-position.schema.json\" } ] }, { \"id\": \"CurrentEmploymentPosition\", \"schema\": [ { \"uri\": \"https://devservices.velocitycareerlabs.io/api/v0.6/schemas/current-employment-position.schema.json\" } ] }, { \"id\": \"EducationDegree\", \"schema\": [ { \"uri\": \"https://devservices.velocitycareerlabs.io/api/v0.6/schemas/education-degree.schema.json\" } ] } ] }, \"iss\": \"did:velocity:0xd4df29726d500f9b85bc6c7f1b3c021f16305692\", \"iat\": 1626087286, \"exp\": 1626692086, \"nbf\": 1626087286 }" - - const val PresentationRequestJwtSignature = - "BSQnMNNJyicCsh6zeh7k5GBHC6T9QgPNV4SHhSXsnz3sBJMwNBFz7v4axLCoCiKHtIxNj5" - val PresentationRequestJwt = VCLJwt( encodedJwt = EncodedPresentationRequest ) diff --git a/VCL/src/test/java/io/velocitycareerlabs/usecases/CountriesUseCaseTest.kt b/VCL/src/test/java/io/velocitycareerlabs/usecases/CountriesUseCaseTest.kt index e93293ba..0cfbe545 100644 --- a/VCL/src/test/java/io/velocitycareerlabs/usecases/CountriesUseCaseTest.kt +++ b/VCL/src/test/java/io/velocitycareerlabs/usecases/CountriesUseCaseTest.kt @@ -7,7 +7,9 @@ package io.velocitycareerlabs.usecases +import android.os.Build import io.velocitycareerlabs.api.entities.VCLCountries +import io.velocitycareerlabs.api.entities.error.VCLErrorCode import io.velocitycareerlabs.api.entities.handleResult import io.velocitycareerlabs.impl.data.infrastructure.executors.ExecutorImpl import io.velocitycareerlabs.impl.data.repositories.CountriesRepositoryImpl @@ -15,13 +17,12 @@ import io.velocitycareerlabs.impl.data.usecases.CountriesUseCaseImpl import io.velocitycareerlabs.impl.domain.usecases.CountriesUseCase import io.velocitycareerlabs.infrastructure.resources.EmptyCacheService import io.velocitycareerlabs.infrastructure.network.NetworkServiceSuccess +import io.velocitycareerlabs.infrastructure.resources.EmptyExecutor import io.velocitycareerlabs.infrastructure.resources.valid.CountriesMocks import org.junit.After import org.junit.Before import org.junit.Test -//@RunWith(RobolectricTestRunner::class) -//@Config(sdk = [Build.VERSION_CODES.O_MR1]) class CountriesUseCaseTest { internal lateinit var subject: CountriesUseCase @@ -59,7 +60,31 @@ class CountriesUseCaseTest { assert(afghanistanRegions.all[2].code == CountriesMocks.AfghanistanRegion3Code) }, errorHandler = { - assert(false) { "$it" } + assert(false) { "${it.toJsonObject()}" } + } + ) + } + } + + @Test + fun testGetCountriesFailure() { + subject = CountriesUseCaseImpl( + CountriesRepositoryImpl( + NetworkServiceSuccess( + "wrong payload" + ), + EmptyCacheService() + ), + EmptyExecutor() + ) + + subject.getCountries(0) { + it.handleResult( + successHandler = { + assert(false) { "${VCLErrorCode.SdkError.value} error code is expected" } + }, + errorHandler = { error -> + assert(error.errorCode == VCLErrorCode.SdkError.value) } ) } diff --git a/VCL/src/test/java/io/velocitycareerlabs/usecases/CredentialManifestUseCaseTest.kt b/VCL/src/test/java/io/velocitycareerlabs/usecases/CredentialManifestUseCaseTest.kt index e805d8e7..453daefd 100644 --- a/VCL/src/test/java/io/velocitycareerlabs/usecases/CredentialManifestUseCaseTest.kt +++ b/VCL/src/test/java/io/velocitycareerlabs/usecases/CredentialManifestUseCaseTest.kt @@ -9,6 +9,7 @@ package io.velocitycareerlabs.usecases import android.os.Build import io.velocitycareerlabs.api.entities.* +import io.velocitycareerlabs.api.entities.error.VCLErrorCode import io.velocitycareerlabs.impl.data.infrastructure.executors.ExecutorImpl import io.velocitycareerlabs.impl.keys.VCLKeyServiceLocalImpl import io.velocitycareerlabs.impl.data.repositories.CredentialManifestRepositoryImpl @@ -22,6 +23,7 @@ import io.velocitycareerlabs.impl.jwt.local.VCLJwtSignServiceLocalImpl import io.velocitycareerlabs.impl.jwt.local.VCLJwtVerifyServiceLocalImpl import io.velocitycareerlabs.infrastructure.db.SecretStoreServiceMock import io.velocitycareerlabs.infrastructure.network.NetworkServiceSuccess +import io.velocitycareerlabs.infrastructure.resources.EmptyExecutor import io.velocitycareerlabs.infrastructure.resources.valid.CredentialManifestMocks import io.velocitycareerlabs.infrastructure.resources.valid.DeepLinkMocks import io.velocitycareerlabs.infrastructure.resources.valid.VerifiedProfileMocks @@ -45,7 +47,7 @@ internal class CredentialManifestUseCaseTest { } @Test - fun testGetCredentialManifest() { + fun testGetCredentialManifestSuccess() { // Arrange subject = CredentialManifestUseCaseImpl( CredentialManifestRepositoryImpl( @@ -59,7 +61,7 @@ internal class CredentialManifestUseCaseTest { VCLJwtVerifyServiceLocalImpl() ), CredentialManifestByDeepLinkVerifierImpl(), - ExecutorImpl() + EmptyExecutor() ) subject.getCredentialManifest( @@ -91,7 +93,44 @@ internal class CredentialManifestUseCaseTest { assert(credentialManifest.jwt.signature.toString() == CredentialManifestMocks.Signature) }, { - assert(false) { "$it" } + assert(false) { "${it.toJsonObject()}" } + } + ) + } + } + + @Test + fun testGetCredentialManifestFailure() { + // Arrange + subject = CredentialManifestUseCaseImpl( + CredentialManifestRepositoryImpl( + NetworkServiceSuccess("wrong payload") + ), + ResolveKidRepositoryImpl( + NetworkServiceSuccess(CredentialManifestMocks.JWK) + ), + JwtServiceRepositoryImpl( + VCLJwtSignServiceLocalImpl(VCLKeyServiceLocalImpl(SecretStoreServiceMock.Instance)), + VCLJwtVerifyServiceLocalImpl() + ), + CredentialManifestByDeepLinkVerifierImpl(), + EmptyExecutor() + ) + + subject.getCredentialManifest( + credentialManifestDescriptor = VCLCredentialManifestDescriptorByDeepLink( + deepLink = DeepLinkMocks.CredentialManifestDeepLinkDevNet, + issuingType = VCLIssuingType.Career + ), + verifiedProfile = VCLVerifiedProfile(VerifiedProfileMocks.VerifiedProfileIssuerJsonStr1.toJsonObject()!!), + remoteCryptoServicesToken = null + ) { + it.handleResult( + successHandler = { + assert(false) { "${VCLErrorCode.SdkError.value} error code is expected" } + }, + errorHandler = { error -> + assert(error.errorCode == VCLErrorCode.SdkError.value) } ) } diff --git a/VCL/src/test/java/io/velocitycareerlabs/usecases/CredentialTypeSchemaUseCaseTest.kt b/VCL/src/test/java/io/velocitycareerlabs/usecases/CredentialTypeSchemaUseCaseTest.kt index a47359d1..2f974490 100644 --- a/VCL/src/test/java/io/velocitycareerlabs/usecases/CredentialTypeSchemaUseCaseTest.kt +++ b/VCL/src/test/java/io/velocitycareerlabs/usecases/CredentialTypeSchemaUseCaseTest.kt @@ -14,6 +14,7 @@ import io.velocitycareerlabs.impl.data.usecases.CredentialTypeSchemasUseCaseImpl import io.velocitycareerlabs.impl.domain.usecases.CredentialTypeSchemasUseCase import io.velocitycareerlabs.infrastructure.resources.EmptyCacheService import io.velocitycareerlabs.infrastructure.network.NetworkServiceSuccess +import io.velocitycareerlabs.infrastructure.resources.EmptyExecutor import io.velocitycareerlabs.infrastructure.resources.valid.CredentialTypeSchemaMocks import org.json.JSONObject import org.junit.After @@ -36,7 +37,7 @@ internal class CredentialTypeSchemaUseCaseTest { EmptyCacheService() ), CredentialTypeSchemaMocks.CredentialTypes, - ExecutorImpl() + EmptyExecutor() ) subject.getCredentialTypeSchemas(0) { diff --git a/VCL/src/test/java/io/velocitycareerlabs/usecases/CredentialTypesUIFormSchemaUseCaseTest.kt b/VCL/src/test/java/io/velocitycareerlabs/usecases/CredentialTypesUIFormSchemaUseCaseTest.kt index 58ec0409..616a0e31 100644 --- a/VCL/src/test/java/io/velocitycareerlabs/usecases/CredentialTypesUIFormSchemaUseCaseTest.kt +++ b/VCL/src/test/java/io/velocitycareerlabs/usecases/CredentialTypesUIFormSchemaUseCaseTest.kt @@ -8,11 +8,13 @@ package io.velocitycareerlabs.usecases import io.velocitycareerlabs.api.entities.* +import io.velocitycareerlabs.api.entities.error.VCLErrorCode import io.velocitycareerlabs.impl.data.infrastructure.executors.ExecutorImpl import io.velocitycareerlabs.impl.data.repositories.CredentialTypesUIFormSchemaRepositoryImpl import io.velocitycareerlabs.impl.data.usecases.CredentialTypesUIFormSchemaUseCaseImpl import io.velocitycareerlabs.impl.domain.usecases.CredentialTypesUIFormSchemaUseCase import io.velocitycareerlabs.infrastructure.network.NetworkServiceSuccess +import io.velocitycareerlabs.infrastructure.resources.EmptyExecutor import io.velocitycareerlabs.infrastructure.resources.valid.CredentialTypesUIFormSchemaMocks import org.json.JSONArray import org.json.JSONObject @@ -36,7 +38,7 @@ internal class CredentialTypesUIFormSchemaUseCaseTest { CredentialTypesUIFormSchemaRepositoryImpl( NetworkServiceSuccess(CredentialTypesUIFormSchemaMocks.UISchemaFormJsonFull) ), - ExecutorImpl() + EmptyExecutor() ) subject.getCredentialTypesUIFormSchema( @@ -79,7 +81,7 @@ internal class CredentialTypesUIFormSchemaUseCaseTest { CredentialTypesUIFormSchemaRepositoryImpl( NetworkServiceSuccess(CredentialTypesUIFormSchemaMocks.UISchemaFormJsonOnlyCountries) ), - ExecutorImpl() + EmptyExecutor() ) subject.getCredentialTypesUIFormSchema( @@ -122,7 +124,7 @@ internal class CredentialTypesUIFormSchemaUseCaseTest { CredentialTypesUIFormSchemaRepositoryImpl( NetworkServiceSuccess(CredentialTypesUIFormSchemaMocks.UISchemaFormJsonOnlyRegions) ), - ExecutorImpl() + EmptyExecutor() ) subject.getCredentialTypesUIFormSchema( @@ -165,7 +167,7 @@ internal class CredentialTypesUIFormSchemaUseCaseTest { CredentialTypesUIFormSchemaRepositoryImpl( NetworkServiceSuccess(CredentialTypesUIFormSchemaMocks.UISchemaFormJsonOnlyEnums) ), - ExecutorImpl() + EmptyExecutor() ) subject.getCredentialTypesUIFormSchema( @@ -203,6 +205,30 @@ internal class CredentialTypesUIFormSchemaUseCaseTest { } } + @Test + fun testCredentialTypesFormSchemaFailure() { + subject = CredentialTypesUIFormSchemaUseCaseImpl( + CredentialTypesUIFormSchemaRepositoryImpl( + NetworkServiceSuccess("wrong payload") + ), + EmptyExecutor() + ) + + subject.getCredentialTypesUIFormSchema( + VCLCredentialTypesUIFormSchemaDescriptor("some type", VCLCountries.CA), + mockedCountries + ) { + it.handleResult( + successHandler = { + assert(false) { "${VCLErrorCode.SdkError.value} error code is expected" } + }, + errorHandler = { error -> + assert(error.errorCode == VCLErrorCode.SdkError.value) + } + ) + } + } + private fun jsonArrToCountries(countriesJsonArr: JSONArray): VCLCountries { val countries = mutableListOf() for (i in 0 until countriesJsonArr.length()) { diff --git a/VCL/src/test/java/io/velocitycareerlabs/usecases/CredentialTypesUseCaseTest.kt b/VCL/src/test/java/io/velocitycareerlabs/usecases/CredentialTypesUseCaseTest.kt index 95423b1f..a62407a5 100644 --- a/VCL/src/test/java/io/velocitycareerlabs/usecases/CredentialTypesUseCaseTest.kt +++ b/VCL/src/test/java/io/velocitycareerlabs/usecases/CredentialTypesUseCaseTest.kt @@ -8,12 +8,14 @@ package io.velocitycareerlabs.usecases import io.velocitycareerlabs.api.entities.* +import io.velocitycareerlabs.api.entities.error.VCLErrorCode import io.velocitycareerlabs.impl.data.infrastructure.executors.ExecutorImpl import io.velocitycareerlabs.impl.data.repositories.CredentialTypesRepositoryImpl import io.velocitycareerlabs.impl.data.usecases.CredentialTypesUseCaseImpl import io.velocitycareerlabs.impl.domain.usecases.CredentialTypesUseCase import io.velocitycareerlabs.infrastructure.resources.EmptyCacheService import io.velocitycareerlabs.infrastructure.network.NetworkServiceSuccess +import io.velocitycareerlabs.infrastructure.resources.EmptyExecutor import io.velocitycareerlabs.infrastructure.resources.valid.CredentialTypesMocks import org.json.JSONObject import org.junit.After @@ -29,13 +31,13 @@ internal class CredentialTypesUseCaseTest { } @Test - fun testGetCredentialTypes() { + fun testGetCredentialTypesSuccess() { subject = CredentialTypesUseCaseImpl( CredentialTypesRepositoryImpl( NetworkServiceSuccess(CredentialTypesMocks.CredentialTypesJson), EmptyCacheService() ), - ExecutorImpl() + EmptyExecutor() ) subject.getCredentialTypes(0) { @@ -51,6 +53,28 @@ internal class CredentialTypesUseCaseTest { } } + @Test + fun testGetCredentialTypesFailure() { + subject = CredentialTypesUseCaseImpl( + CredentialTypesRepositoryImpl( + NetworkServiceSuccess("wrong payload"), + EmptyCacheService() + ), + EmptyExecutor() + ) + + subject.getCredentialTypes(0) { + it.handleResult( + successHandler = { + assert(false) { "${VCLErrorCode.SdkError.value} error code is expected" } + }, + errorHandler = { error -> + assert(error.errorCode == VCLErrorCode.SdkError.value) + } + ) + } + } + private fun compareCredentialTypes( credentialTypesArr1: List, credentialTypesArr2: List diff --git a/VCL/src/test/java/io/velocitycareerlabs/usecases/ExchangeProgressUseCaseTest.kt b/VCL/src/test/java/io/velocitycareerlabs/usecases/ExchangeProgressUseCaseTest.kt index f1dd45ad..ce47fe8e 100644 --- a/VCL/src/test/java/io/velocitycareerlabs/usecases/ExchangeProgressUseCaseTest.kt +++ b/VCL/src/test/java/io/velocitycareerlabs/usecases/ExchangeProgressUseCaseTest.kt @@ -9,11 +9,13 @@ package io.velocitycareerlabs.usecases import io.velocitycareerlabs.api.entities.* import io.velocitycareerlabs.api.entities.VCLExchangeDescriptor +import io.velocitycareerlabs.api.entities.error.VCLErrorCode import io.velocitycareerlabs.impl.data.infrastructure.executors.ExecutorImpl import io.velocitycareerlabs.impl.data.repositories.ExchangeProgressRepositoryImpl import io.velocitycareerlabs.impl.data.usecases.ExchangeProgressUseCaseImpl import io.velocitycareerlabs.impl.domain.usecases.ExchangeProgressUseCase import io.velocitycareerlabs.infrastructure.network.NetworkServiceSuccess +import io.velocitycareerlabs.infrastructure.resources.EmptyExecutor import io.velocitycareerlabs.infrastructure.resources.valid.ExchangeProgressMocks import org.json.JSONObject import org.junit.After @@ -38,12 +40,12 @@ internal class ExchangeProgressUseCaseTest { } @Test - fun testGetExchangeProgress() { + fun testGetExchangeProgressSuccess() { subject = ExchangeProgressUseCaseImpl( ExchangeProgressRepositoryImpl( NetworkServiceSuccess(ExchangeProgressMocks.ExchangeProgressJson) ), - ExecutorImpl() + EmptyExecutor() ) subject.getExchangeProgress(exchangeDescriptor) { @@ -58,6 +60,27 @@ internal class ExchangeProgressUseCaseTest { } } + @Test + fun testGetExchangeProgressFailure() { + subject = ExchangeProgressUseCaseImpl( + ExchangeProgressRepositoryImpl( + NetworkServiceSuccess("wrong payload") + ), + EmptyExecutor() + ) + + subject.getExchangeProgress(exchangeDescriptor) { + it.handleResult( + successHandler = { + assert(false) { "${VCLErrorCode.SdkError.value} error code is expected" } + }, + errorHandler = { error -> + assert(error.errorCode == VCLErrorCode.SdkError.value) + } + ) + } + } + private fun expectedExchange(exchangeJsonObj: JSONObject) = VCLExchange( id = exchangeJsonObj.getString(VCLExchange.KeyId), diff --git a/VCL/src/test/java/io/velocitycareerlabs/usecases/FinalizeOffersUseCaseTest.kt b/VCL/src/test/java/io/velocitycareerlabs/usecases/FinalizeOffersUseCaseTest.kt index 03dd320e..ad99ff0b 100644 --- a/VCL/src/test/java/io/velocitycareerlabs/usecases/FinalizeOffersUseCaseTest.kt +++ b/VCL/src/test/java/io/velocitycareerlabs/usecases/FinalizeOffersUseCaseTest.kt @@ -9,6 +9,7 @@ package io.velocitycareerlabs.usecases import android.os.Build import io.velocitycareerlabs.api.entities.* +import io.velocitycareerlabs.api.entities.error.VCLErrorCode import io.velocitycareerlabs.impl.keys.VCLKeyServiceLocalImpl import io.velocitycareerlabs.impl.data.repositories.FinalizeOffersRepositoryImpl import io.velocitycareerlabs.impl.data.repositories.GenerateOffersRepositoryImpl @@ -17,7 +18,6 @@ import io.velocitycareerlabs.impl.data.usecases.FinalizeOffersUseCaseImpl import io.velocitycareerlabs.impl.data.usecases.GenerateOffersUseCaseImpl import io.velocitycareerlabs.impl.data.verifiers.CredentialDidVerifierImpl import io.velocitycareerlabs.impl.data.verifiers.CredentialIssuerVerifierImpl -import io.velocitycareerlabs.impl.data.verifiers.CredentialManifestByDeepLinkVerifierImpl import io.velocitycareerlabs.impl.data.verifiers.CredentialsByDeepLinkVerifierImpl import io.velocitycareerlabs.impl.data.verifiers.OffersByDeepLinkVerifierImpl import io.velocitycareerlabs.impl.domain.usecases.FinalizeOffersUseCase @@ -258,4 +258,42 @@ internal class FinalizeOffersUseCaseTest { ) } } + + @Test + fun testFailure() { + subject = FinalizeOffersUseCaseImpl( + FinalizeOffersRepositoryImpl( + NetworkServiceSuccess("wrong payload") + ), + JwtServiceRepositoryImpl( + VCLJwtSignServiceLocalImpl(keyService), + VCLJwtVerifyServiceLocalImpl() + ), + CredentialIssuerVerifierImpl( + CredentialTypesModelMock( + issuerCategory = CredentialTypesModelMock.issuerCategoryRegularIssuer + ), + NetworkServiceSuccess(validResponse = JsonLdMocks.Layer1v10Jsonld), + ), + CredentialDidVerifierImpl(), + CredentialsByDeepLinkVerifierImpl(), + EmptyExecutor() + ) + + subject.finalizeOffers( + finalizeOffersDescriptor = finalizeOffersDescriptorPassed, + didJwk = didJwk, + sessionToken = VCLToken(value = ""), + remoteCryptoServicesToken = null + ) { + it.handleResult( + successHandler = { + assert(false) { "${VCLErrorCode.SdkError.value} error code is expected" } + }, + errorHandler = { error -> + assert(error.errorCode == VCLErrorCode.SdkError.value) + } + ) + } + } } \ No newline at end of file diff --git a/VCL/src/test/java/io/velocitycareerlabs/usecases/GenerateOffersUseCaseTest.kt b/VCL/src/test/java/io/velocitycareerlabs/usecases/GenerateOffersUseCaseTest.kt index 7f5fb515..60e36bbc 100644 --- a/VCL/src/test/java/io/velocitycareerlabs/usecases/GenerateOffersUseCaseTest.kt +++ b/VCL/src/test/java/io/velocitycareerlabs/usecases/GenerateOffersUseCaseTest.kt @@ -9,6 +9,7 @@ package io.velocitycareerlabs.usecases import android.os.Build import io.velocitycareerlabs.api.entities.* +import io.velocitycareerlabs.api.entities.error.VCLErrorCode import io.velocitycareerlabs.impl.data.infrastructure.executors.ExecutorImpl import io.velocitycareerlabs.impl.data.repositories.GenerateOffersRepositoryImpl import io.velocitycareerlabs.impl.data.usecases.GenerateOffersUseCaseImpl @@ -18,6 +19,7 @@ import io.velocitycareerlabs.impl.extensions.toJsonArray import io.velocitycareerlabs.impl.extensions.toJsonObject import io.velocitycareerlabs.infrastructure.network.NetworkServiceSuccess import io.velocitycareerlabs.infrastructure.resources.CommonMocks +import io.velocitycareerlabs.infrastructure.resources.EmptyExecutor import io.velocitycareerlabs.infrastructure.resources.valid.GenerateOffersMocks import io.velocitycareerlabs.infrastructure.resources.valid.VerifiedProfileMocks import org.junit.After @@ -39,7 +41,7 @@ internal class GenerateOffersUseCaseTest { NetworkServiceSuccess(validResponse = GenerateOffersMocks.GeneratedOffers) ), OffersByDeepLinkVerifierImpl(), - ExecutorImpl() + EmptyExecutor() ) val generateOffersDescriptor = VCLGenerateOffersDescriptor( @@ -74,7 +76,7 @@ internal class GenerateOffersUseCaseTest { NetworkServiceSuccess(validResponse = GenerateOffersMocks.GeneratedOffersEmptyJsonObj) ), OffersByDeepLinkVerifierImpl(), - ExecutorImpl() + EmptyExecutor() ) val generateOffersDescriptor = VCLGenerateOffersDescriptor( @@ -91,7 +93,7 @@ internal class GenerateOffersUseCaseTest { ) { it.handleResult( {offers -> - assert(offers.all == "[]".toJsonArray()) + assert(offers.all == listOf()) }, { assert(false) { "${it.toJsonObject()}" } @@ -107,7 +109,7 @@ internal class GenerateOffersUseCaseTest { NetworkServiceSuccess(validResponse = GenerateOffersMocks.GeneratedOffersEmptyJsonArr) ), OffersByDeepLinkVerifierImpl(), - ExecutorImpl() + EmptyExecutor() ) val generateOffersDescriptor = VCLGenerateOffersDescriptor( @@ -124,7 +126,7 @@ internal class GenerateOffersUseCaseTest { ) { it.handleResult( { offers -> - assert(offers.all == GenerateOffersMocks.GeneratedOffersEmptyJsonArr.toJsonArray()) + assert(offers.all == listOf()) }, { assert(false) { "${it.toJsonObject()}" } diff --git a/VCL/src/test/java/io/velocitycareerlabs/usecases/JwtServiceUseCaseTest.kt b/VCL/src/test/java/io/velocitycareerlabs/usecases/JwtServiceUseCaseTest.kt index 4f8835cf..f483bb7c 100644 --- a/VCL/src/test/java/io/velocitycareerlabs/usecases/JwtServiceUseCaseTest.kt +++ b/VCL/src/test/java/io/velocitycareerlabs/usecases/JwtServiceUseCaseTest.kt @@ -20,6 +20,7 @@ import io.velocitycareerlabs.impl.extensions.toPublicJwk import io.velocitycareerlabs.impl.jwt.local.VCLJwtSignServiceLocalImpl import io.velocitycareerlabs.impl.jwt.local.VCLJwtVerifyServiceLocalImpl import io.velocitycareerlabs.infrastructure.db.SecretStoreServiceMock +import io.velocitycareerlabs.infrastructure.resources.EmptyExecutor import io.velocitycareerlabs.infrastructure.resources.valid.JwtServiceMocks import org.junit.After import org.junit.Before @@ -43,7 +44,7 @@ internal class JwtServiceUseCaseTest { VCLJwtSignServiceLocalImpl(keyService), VCLJwtVerifyServiceLocalImpl() ), - ExecutorImpl() + EmptyExecutor() ) } diff --git a/VCL/src/test/java/io/velocitycareerlabs/usecases/KeyServiceUseCaseTest.kt b/VCL/src/test/java/io/velocitycareerlabs/usecases/KeyServiceUseCaseTest.kt index 217157c4..e937892c 100644 --- a/VCL/src/test/java/io/velocitycareerlabs/usecases/KeyServiceUseCaseTest.kt +++ b/VCL/src/test/java/io/velocitycareerlabs/usecases/KeyServiceUseCaseTest.kt @@ -18,6 +18,7 @@ import io.velocitycareerlabs.impl.data.repositories.KeyServiceRepositoryImpl import io.velocitycareerlabs.impl.data.usecases.KeyServiceUseCaseImpl import io.velocitycareerlabs.impl.domain.usecases.KeyServiceUseCase import io.velocitycareerlabs.infrastructure.db.SecretStoreServiceMock +import io.velocitycareerlabs.infrastructure.resources.EmptyExecutor import org.junit.Before import org.junit.Test import org.junit.runner.RunWith @@ -37,7 +38,7 @@ class KeyServiceUseCaseTest { KeyServiceRepositoryImpl( VCLKeyServiceLocalImpl(SecretStoreServiceMock.Instance) ), - ExecutorImpl() + EmptyExecutor() ) } @@ -58,7 +59,7 @@ class KeyServiceUseCaseTest { assert(jwkJsonObj.optString("y") != null) }, errorHandler = { - assert(false) { "$it" } + assert(false) { "${it.toJsonObject()}" } } ) } diff --git a/VCL/src/test/java/io/velocitycareerlabs/usecases/OrganizationsUseCaseTest.kt b/VCL/src/test/java/io/velocitycareerlabs/usecases/OrganizationsUseCaseTest.kt index 12c59e80..5314a883 100644 --- a/VCL/src/test/java/io/velocitycareerlabs/usecases/OrganizationsUseCaseTest.kt +++ b/VCL/src/test/java/io/velocitycareerlabs/usecases/OrganizationsUseCaseTest.kt @@ -7,18 +7,15 @@ package io.velocitycareerlabs.usecases -import io.velocitycareerlabs.api.entities.VCLOrganizations -import io.velocitycareerlabs.api.entities.VCLResult import io.velocitycareerlabs.api.entities.VCLService -import io.velocitycareerlabs.api.entities.data import io.velocitycareerlabs.api.entities.VCLOrganizationsSearchDescriptor import io.velocitycareerlabs.api.entities.handleResult -import io.velocitycareerlabs.impl.data.infrastructure.executors.ExecutorImpl import io.velocitycareerlabs.impl.data.repositories.OrganizationsRepositoryImpl import io.velocitycareerlabs.impl.data.usecases.OrganizationsUseCaseImpl import io.velocitycareerlabs.impl.domain.usecases.OrganizationsUseCase import io.velocitycareerlabs.impl.extensions.toList import io.velocitycareerlabs.infrastructure.network.NetworkServiceSuccess +import io.velocitycareerlabs.infrastructure.resources.EmptyExecutor import io.velocitycareerlabs.infrastructure.resources.valid.OrganizationsMocks import org.json.JSONObject import org.junit.After @@ -41,7 +38,7 @@ internal class OrganizationsUseCaseTest { OrganizationsMocks.OrganizationJsonResult ), ), - ExecutorImpl() + EmptyExecutor() ) val serviceJsonMock = JSONObject(OrganizationsMocks.ServiceJsonStr) @@ -60,7 +57,7 @@ internal class OrganizationsUseCaseTest { assert(serviceCredentialAgentIssuer.serviceEndpoint == OrganizationsMocks.ServiceEndpoint) }, { - assert(false) { "$it" } + assert(false) { "${it.toJsonObject()}" } } ) } diff --git a/VCL/src/test/java/io/velocitycareerlabs/usecases/PresentationRequestUseCaseTest.kt b/VCL/src/test/java/io/velocitycareerlabs/usecases/PresentationRequestUseCaseTest.kt index b6ce1197..d51f3e06 100644 --- a/VCL/src/test/java/io/velocitycareerlabs/usecases/PresentationRequestUseCaseTest.kt +++ b/VCL/src/test/java/io/velocitycareerlabs/usecases/PresentationRequestUseCaseTest.kt @@ -9,6 +9,7 @@ package io.velocitycareerlabs.usecases import android.os.Build import io.velocitycareerlabs.api.entities.* +import io.velocitycareerlabs.api.entities.error.VCLErrorCode import io.velocitycareerlabs.impl.data.infrastructure.executors.ExecutorImpl import io.velocitycareerlabs.impl.keys.VCLKeyServiceLocalImpl import io.velocitycareerlabs.impl.data.repositories.JwtServiceRepositoryImpl @@ -22,6 +23,7 @@ import io.velocitycareerlabs.impl.jwt.local.VCLJwtSignServiceLocalImpl import io.velocitycareerlabs.impl.jwt.local.VCLJwtVerifyServiceLocalImpl import io.velocitycareerlabs.infrastructure.db.SecretStoreServiceMock import io.velocitycareerlabs.infrastructure.network.NetworkServiceSuccess +import io.velocitycareerlabs.infrastructure.resources.EmptyExecutor import io.velocitycareerlabs.infrastructure.resources.valid.DeepLinkMocks import io.velocitycareerlabs.infrastructure.resources.valid.PresentationRequestMocks import org.junit.Test @@ -36,8 +38,7 @@ internal class PresentationRequestUseCaseTest { lateinit var subject: PresentationRequestUseCase @Test - fun testCountryCodesSuccess() { - // Arrange + fun testGetPresentationRequestSuccess() { val pushUrl = "push_url" val pushToken = "push_token" subject = PresentationRequestUseCaseImpl( @@ -52,10 +53,9 @@ internal class PresentationRequestUseCaseTest { VCLJwtVerifyServiceLocalImpl() ), PresentationRequestByDeepLinkVerifierImpl(), - ExecutorImpl() + EmptyExecutor() ) - // Action subject.getPresentationRequest( presentationRequestDescriptor = VCLPresentationRequestDescriptor( deepLink = DeepLinkMocks.PresentationRequestDeepLinkDevNet, @@ -89,7 +89,41 @@ internal class PresentationRequestUseCaseTest { assert(presentationRequest.pushDelegate!!.pushToken == pushToken) }, errorHandler = { - assert(false) { "$it" } + assert(false) { "${it.toJsonObject()}" } + } + ) + } + } + + @Test + fun testGetPresentationRequestFailure() { + subject = PresentationRequestUseCaseImpl( + PresentationRequestRepositoryImpl( + NetworkServiceSuccess(validResponse = "wrong payload") + ), + ResolveKidRepositoryImpl( + NetworkServiceSuccess(validResponse = PresentationRequestMocks.JWK) + ), + JwtServiceRepositoryImpl( + VCLJwtSignServiceLocalImpl(VCLKeyServiceLocalImpl(SecretStoreServiceMock.Instance)), + VCLJwtVerifyServiceLocalImpl() + ), + PresentationRequestByDeepLinkVerifierImpl(), + EmptyExecutor() + ) + + subject.getPresentationRequest( + presentationRequestDescriptor = VCLPresentationRequestDescriptor( + deepLink = DeepLinkMocks.PresentationRequestDeepLinkDevNet + ), + null + ) { + it.handleResult( + successHandler = { + assert(false) { "${VCLErrorCode.SdkError.value} error code is expected" } + }, + errorHandler = { error -> + assert(error.errorCode == VCLErrorCode.SdkError.value) } ) } diff --git a/VCL/src/test/java/io/velocitycareerlabs/usecases/PresentationSubmissionUseCaseTest.kt b/VCL/src/test/java/io/velocitycareerlabs/usecases/PresentationSubmissionUseCaseTest.kt index dbd555f2..f6314c2d 100644 --- a/VCL/src/test/java/io/velocitycareerlabs/usecases/PresentationSubmissionUseCaseTest.kt +++ b/VCL/src/test/java/io/velocitycareerlabs/usecases/PresentationSubmissionUseCaseTest.kt @@ -9,7 +9,6 @@ package io.velocitycareerlabs.usecases import android.os.Build import io.velocitycareerlabs.api.entities.* -import io.velocitycareerlabs.impl.data.infrastructure.executors.ExecutorImpl import io.velocitycareerlabs.impl.keys.VCLKeyServiceLocalImpl import io.velocitycareerlabs.impl.data.repositories.JwtServiceRepositoryImpl import io.velocitycareerlabs.impl.data.repositories.PresentationSubmissionRepositoryImpl @@ -21,6 +20,7 @@ import io.velocitycareerlabs.impl.jwt.local.VCLJwtVerifyServiceLocalImpl import io.velocitycareerlabs.infrastructure.db.SecretStoreServiceMock import io.velocitycareerlabs.infrastructure.network.NetworkServiceSuccess import io.velocitycareerlabs.infrastructure.resources.CommonMocks +import io.velocitycareerlabs.infrastructure.resources.EmptyExecutor import io.velocitycareerlabs.infrastructure.resources.valid.PresentationSubmissionMocks import org.json.JSONObject import org.junit.After @@ -60,7 +60,7 @@ internal class PresentationSubmissionUseCaseTest { VCLJwtSignServiceLocalImpl(keyService), VCLJwtVerifyServiceLocalImpl() ), - ExecutorImpl() + EmptyExecutor() ) val presentationSubmission = VCLPresentationSubmission( presentationRequest = VCLPresentationRequest( diff --git a/VCL/src/test/java/io/velocitycareerlabs/usecases/VerifiedProfileUseCaseTest.kt b/VCL/src/test/java/io/velocitycareerlabs/usecases/VerifiedProfileUseCaseTest.kt index 75616d7d..fc9faf44 100644 --- a/VCL/src/test/java/io/velocitycareerlabs/usecases/VerifiedProfileUseCaseTest.kt +++ b/VCL/src/test/java/io/velocitycareerlabs/usecases/VerifiedProfileUseCaseTest.kt @@ -8,11 +8,11 @@ package io.velocitycareerlabs.usecases import io.velocitycareerlabs.api.entities.* -import io.velocitycareerlabs.impl.data.infrastructure.executors.ExecutorImpl import io.velocitycareerlabs.impl.data.repositories.VerifiedProfileRepositoryImpl import io.velocitycareerlabs.impl.data.usecases.VerifiedProfileUseCaseImpl import io.velocitycareerlabs.impl.domain.usecases.VerifiedProfileUseCase import io.velocitycareerlabs.infrastructure.network.NetworkServiceSuccess +import io.velocitycareerlabs.infrastructure.resources.EmptyExecutor import io.velocitycareerlabs.infrastructure.resources.valid.VerifiedProfileMocks import org.junit.Test @@ -26,7 +26,7 @@ internal class VerifiedProfileUseCaseTest { VerifiedProfileRepositoryImpl( NetworkServiceSuccess(VerifiedProfileMocks.VerifiedProfileIssuerJsonStr1) ), - ExecutorImpl() + EmptyExecutor() ) subject.getVerifiedProfile( @@ -53,7 +53,7 @@ internal class VerifiedProfileUseCaseTest { VerifiedProfileRepositoryImpl( NetworkServiceSuccess(VerifiedProfileMocks.VerifiedProfileIssuerInspectorJsonStr) ), - ExecutorImpl() + EmptyExecutor() ) subject.getVerifiedProfile( @@ -80,7 +80,7 @@ internal class VerifiedProfileUseCaseTest { VerifiedProfileRepositoryImpl( NetworkServiceSuccess(VerifiedProfileMocks.VerifiedProfileIssuerInspectorJsonStr) ), - ExecutorImpl() + EmptyExecutor() ) subject.getVerifiedProfile( @@ -107,7 +107,7 @@ internal class VerifiedProfileUseCaseTest { VerifiedProfileRepositoryImpl( NetworkServiceSuccess(VerifiedProfileMocks.VerifiedProfileNotaryIssuerJsonStr) ), - ExecutorImpl() + EmptyExecutor() ) subject.getVerifiedProfile( @@ -134,7 +134,7 @@ internal class VerifiedProfileUseCaseTest { VerifiedProfileRepositoryImpl( NetworkServiceSuccess(VerifiedProfileMocks.VerifiedProfileNotaryIssuerJsonStr) ), - ExecutorImpl() + EmptyExecutor() ) subject.getVerifiedProfile( diff --git a/VCL/src/test/java/io/velocitycareerlabs/verifiers/CredentialManifestByDeepLinkVerifierTest.kt b/VCL/src/test/java/io/velocitycareerlabs/verifiers/CredentialManifestByDeepLinkVerifierTest.kt index cbcd7872..956f9525 100644 --- a/VCL/src/test/java/io/velocitycareerlabs/verifiers/CredentialManifestByDeepLinkVerifierTest.kt +++ b/VCL/src/test/java/io/velocitycareerlabs/verifiers/CredentialManifestByDeepLinkVerifierTest.kt @@ -22,12 +22,12 @@ import org.junit.Test class CredentialManifestByDeepLinkVerifierTest { private val subject = CredentialManifestByDeepLinkVerifierImpl() private val credentialManifest = VCLCredentialManifest( - jwt = VCLJwt(CredentialManifestMocks.JwtCredentialManifestFromRegularIssuer), + jwt = VCLJwt(CredentialManifestMocks.JwtCredentialManifest1), verifiedProfile = VCLVerifiedProfile(VerifiedProfileMocks.VerifiedProfileOfRegularIssuer.toJsonObject()!!) ) - private val correctDeepLink = + private val correctDeepLink = DeepLinkMocks.CredentialManifestDeepLinkDevNet + private val wrongDeepLink = VCLDeepLink("velocity-network-devnet://issue?request_uri=https%3A%2F%2Fdevagent.velocitycareerlabs.io%2Fapi%2Fholder%2Fv0.6%2Forg%2Fdid%3Aion%3AEiBMsw27IKRYIdwUOfDeBd0LnWVeG2fPxxJi9L1fvjM20g%2Fissue%2Fget-credential-manifest%3Fid%3D611b5836e93d08000af6f1bc%26credential_types%3DPastEmploymentPosition%26issuerDid%3Ddid%3Aion%3AEiBMsw27IKRYIdwUOfDeBd0LnWVeG2fPxxJi9L1fvjM20g") - private val wrongDeepLink = DeepLinkMocks.CredentialManifestDeepLinkDevNet @Test fun testVerifyCredentialManifestSuccess() { diff --git a/VCL/src/test/java/io/velocitycareerlabs/verifiers/OffersByDeepLinkVerifierTest.kt b/VCL/src/test/java/io/velocitycareerlabs/verifiers/OffersByDeepLinkVerifierTest.kt index 6c035a17..2298e7e3 100644 --- a/VCL/src/test/java/io/velocitycareerlabs/verifiers/OffersByDeepLinkVerifierTest.kt +++ b/VCL/src/test/java/io/velocitycareerlabs/verifiers/OffersByDeepLinkVerifierTest.kt @@ -34,9 +34,10 @@ class OffersByDeepLinkVerifierTest { sessionToken = VCLToken(""), challenge = "" ) - private val correctDeepLink = - VCLDeepLink("velocity-network-devnet://issue?request_uri=https%3A%2F%2Fdevagent.velocitycareerlabs.io%2Fapi%2Fholder%2Fv0.6%2Forg%2Fdid%3Aion%3AEiApMLdMb4NPb8sae9-hXGHP79W1gisApVSE80USPEbtJA%2Fissue%2Fget-credential-manifest%3Fid%3D611b5836e93d08000af6f1bc%26credential_types%3DPastEmploymentPosition%26issuerDid%3Ddid%3Aion%3AEiApMLdMb4NPb8sae9-hXGHP79W1gisApVSE80USPEbtJA") - private val wrongDeepLink = DeepLinkMocks.CredentialManifestDeepLinkDevNet + private val correctDeepLink = DeepLinkMocks.CredentialManifestDeepLinkDevNet + private val wrongDeepLink = VCLDeepLink( + "velocity-network-devnet://issue?request_uri=https%3A%2F%2Fdevagent.velocitycareerlabs.io%2Fapi%2Fholder%2Fv0.6%2Forg%2Fdid%3Aion%3AEiApMLdMb4NPb8sae9-hXGHP79W1gisApVSE80USPEbt%2Fissue%2Fget-credential-manifest%3Fid%3D611b5836e93d08000af6f1bc%26credential_types%3DPastEmploymentPosition%26issuerDid%3Ddid%3Aion%3AEiApMLdMb4NPb8sae9-hXGHP79W1gisApVSE80USPEbt" + ) @Test fun verifyOffersSuccess() { diff --git a/VCL/src/test/java/io/velocitycareerlabs/verifiers/PresentationRequestByDeepLinkVerifierTest.kt b/VCL/src/test/java/io/velocitycareerlabs/verifiers/PresentationRequestByDeepLinkVerifierTest.kt index d40d8cfd..fdc0e26b 100644 --- a/VCL/src/test/java/io/velocitycareerlabs/verifiers/PresentationRequestByDeepLinkVerifierTest.kt +++ b/VCL/src/test/java/io/velocitycareerlabs/verifiers/PresentationRequestByDeepLinkVerifierTest.kt @@ -12,12 +12,13 @@ class PresentationRequestByDeepLinkVerifierTest { private val subject = PresentationRequestByDeepLinkVerifierImpl() private val presentationRequest = PresentationRequestMocks.PresentationRequest - private val correctDeepLink = - VCLDeepLink("velocity-network-devnet://inspect?request_uri=https%3A%2F%2Fdevagent.velocitycareerlabs.io%2Fapi%2Fholder%2Fv0.6%2Forg%2Fdid%3Avelocity%3A0xd4df29726d500f9b85bc6c7f1b3c021f16305692%2Fissue%2Fget-credential-manifest%3Fid%3D611b5836e93d08000af6f1bc%26credential_types%3DPastEmploymentPosition%26issuerDid%3Ddid%3Avelocity%3A0xd4df29726d500f9b85bc6c7f1b3c021f16305692") - private val wrongDeepLink = DeepLinkMocks.PresentationRequestDeepLinkDevNet + private val correctDeepLink = DeepLinkMocks.PresentationRequestDeepLinkDevNet + private val wrongDeepLink = VCLDeepLink( + "velocity-network-devnet://inspect?request_uri=https%3A%2F%2Fagent.velocitycareerlabs.io%2Fapi%2Fholder%2Fv0.6%2Forg%2Fdid%3Avelocity%3A0xd4df29726d500f9b85bc6c7f1b3c021f163056%2Finspect%2Fget-presentation-request%3Fid%3D62e0e80c5ebfe73230b0becc%26inspectorDid%3Ddid%3Avelocity%3A0xd4df29726d500f9b85bc6c7f1b3c021f163056%26vendorOriginContext%3D%7B%22SubjectKey%22%3A%7B%22BusinessUnit%22%3A%22ZC%22%2C%22KeyCode%22%3A%2254514480%22%7D%2C%22Token%22%3A%22832077a4%22%7D" + ) @Test - fun testVerifyCredentialManifestSuccess() { + fun testVerifyPresentationRequestSuccess() { subject.verifyPresentationRequest( presentationRequest, correctDeepLink @@ -31,7 +32,7 @@ class PresentationRequestByDeepLinkVerifierTest { } @Test - fun testVerifyCredentialManifestError() { + fun testVerifyPresentationRequestError() { subject.verifyPresentationRequest( presentationRequest, wrongDeepLink