diff --git a/VCL/VCL.xcodeproj/project.pbxproj b/VCL/VCL.xcodeproj/project.pbxproj index f25cd19..b0e147e 100644 --- a/VCL/VCL.xcodeproj/project.pbxproj +++ b/VCL/VCL.xcodeproj/project.pbxproj @@ -1892,7 +1892,7 @@ buildSettings = { CODE_SIGN_IDENTITY = "Apple Development"; CODE_SIGN_STYLE = Automatic; - CURRENT_PROJECT_VERSION = 121; + CURRENT_PROJECT_VERSION = 123; DEFINES_MODULE = YES; DEVELOPMENT_TEAM = 7DDDGP43MJ; DYLIB_COMPATIBILITY_VERSION = 1; @@ -1905,7 +1905,7 @@ "@executable_path/Frameworks", "@loader_path/Frameworks", ); - MARKETING_VERSION = 1.23.2; + MARKETING_VERSION = 1.23.3; PRODUCT_BUNDLE_IDENTIFIER = io.velocitycareerlabs.VCL; PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)"; PROVISIONING_PROFILE_SPECIFIER = ""; @@ -1922,7 +1922,7 @@ buildSettings = { CODE_SIGN_IDENTITY = "Apple Development"; CODE_SIGN_STYLE = Automatic; - CURRENT_PROJECT_VERSION = 121; + CURRENT_PROJECT_VERSION = 123; DEFINES_MODULE = YES; DEVELOPMENT_TEAM = 7DDDGP43MJ; DYLIB_COMPATIBILITY_VERSION = 1; @@ -1935,7 +1935,7 @@ "@executable_path/Frameworks", "@loader_path/Frameworks", ); - MARKETING_VERSION = 1.23.2; + MARKETING_VERSION = 1.23.3; PRODUCT_BUNDLE_IDENTIFIER = io.velocitycareerlabs.VCL; PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)"; PROVISIONING_PROFILE_SPECIFIER = ""; diff --git a/VCL/VCL/impl/data/utils/Utils.swift b/VCL/VCL/impl/data/utils/Utils.swift index 04f1bba..c41ed73 100644 --- a/VCL/VCL/impl/data/utils/Utils.swift +++ b/VCL/VCL/impl/data/utils/Utils.swift @@ -28,15 +28,15 @@ class Utils { var identifier: String? = nil var stack = [[String: Any]]() stack.append(jsonObject) - + while (stack.isEmpty == false) { let obj = stack.remove(at: stack.count - 1) - + identifier = getPrimaryIdentifier(obj[primaryOrgProp!]) if (identifier != nil) { break } - + obj.forEach { _, value in if let valueDict = value as? [String: Any] { stack.append(valueDict) @@ -53,15 +53,19 @@ class Utils { return credentialSubject as? String } return (credentialSubject as? [String: Any])?["identifier"] as? String - ?? (credentialSubject as? [String: Any])?["id"] as? String + ?? (credentialSubject as? [String: Any])?["id"] as? String } static func offersFromJsonArray(offersJsonArray: [[String: Any]]) -> [VCLOffer] { var allOffers = [VCLOffer]() - offersJsonArray.forEach { + offersJsonArray.forEach { allOffers.append(VCLOffer(payload: $0)) } return allOffers } - + + static func getCredentialIssuerId(jwtCredential: VCLJwt) -> String? { + let vc: [String: Any]? = jwtCredential.payload?["vc"] as? [String: Any] + return (vc?["issuer"] as? [String: Any])?["id"] as? String ?? vc?["issuer"] as? String + } } diff --git a/VCL/VCL/impl/data/verifiers/CredentialIssuerVerifierImpl.swift b/VCL/VCL/impl/data/verifiers/CredentialIssuerVerifierImpl.swift index 753be00..853fb07 100644 --- a/VCL/VCL/impl/data/verifiers/CredentialIssuerVerifierImpl.swift +++ b/VCL/VCL/impl/data/verifiers/CredentialIssuerVerifierImpl.swift @@ -262,7 +262,11 @@ class CredentialIssuerVerifierImpl: CredentialIssuerVerifier { let activeContext = (((completeContext[CodingKeys.KeyContext] as? [String: Any])?[credentialSubjectType] as? [String: Any]))?[CodingKeys.KeyContext] as? [String: Any] ?? completeContext if let K = findKeyForPrimaryOrganizationValue(activeContext) { if let did = Utils.getIdentifier(K, credentialSubject) { - if (jwtCredential.iss == did) { +// Comparing issuer.id instead of iss +// https://velocitycareerlabs.atlassian.net/browse/VL-6178?focusedCommentId=46933 +// https://velocitycareerlabs.atlassian.net/browse/VL-6988 +// if (jwtCredential.iss == did) + if (Utils.getCredentialIssuerId(jwtCredential: jwtCredential) == did) { isCredentialVerified = true completeConetxDispatcher.leave() } else { diff --git a/VCL/VCLTests/infrastructure/resources/valid/CredentialMocks.swift b/VCL/VCLTests/infrastructure/resources/valid/CredentialMocks.swift index 1c2923a..26e6d31 100644 --- a/VCL/VCLTests/infrastructure/resources/valid/CredentialMocks.swift +++ b/VCL/VCLTests/infrastructure/resources/valid/CredentialMocks.swift @@ -37,6 +37,13 @@ class CredentialMocks { static let JwtCredentialDriversLicenseFromIdentityIssuer = "eyJ0eXAiOiJKV1QiLCJqd2siOnsiY3J2Ijoic2VjcDI1NmsxIiwieCI6ImxkU2gybmdRempJSnhwSktMVkpvbVpEdGQtX1JRMGpzVlgzMFB5ZmdMUEUiLCJ5IjoicEJleVJuMnFYZFNELVhTaG5WVGJCa08tb0VFRmgyV2hneU1VYTRCMHV6RSIsImt0eSI6IkVDIiwia2lkIjoiUXNiZUMzTjVHN2M0NEFQS2dKdWc2X3lhS3ZrR1lQd3B5RjRHVS1sWVpVSSIsImFsZyI6IkVTMjU2SyIsInVzZSI6InNpZyJ9LCJhbGciOiJFUzI1NksifQ.eyJ2YyI6eyJAY29udGV4dCI6WyJodHRwczovL3d3dy53My5vcmcvMjAxOC9jcmVkZW50aWFscy92MSJdLCJ0eXBlIjpbIkRyaXZlcnNMaWNlbnNlVjEuMCIsIlZlcmlmaWFibGVDcmVkZW50aWFsIl0sImNyZWRlbnRpYWxTdWJqZWN0Ijp7ImZpcnN0TmFtZSI6eyJsb2NhbGl6ZWQiOnsiZW4iOiJBZGFtIn19LCJsYXN0TmFtZSI6eyJsb2NhbGl6ZWQiOnsiZW4iOiJTbWl0aCJ9fSwia2luZCI6IkRyaXZlcnNMaWNlbnNlIiwiYXV0aG9yaXR5Ijp7ImxvY2FsaXplZCI6eyJlbiI6IkNhbGlmb3JuaWEgRE1WIn19LCJsb2NhdGlvbiI6eyJjb3VudHJ5Q29kZSI6IlVTIiwicmVnaW9uQ29kZSI6IkNBIn0sImRvYiI6eyJkYXkiOjIwLCJtb250aCI6NiwieWVhciI6MTk2Nn0sImlkZW50aXR5TnVtYmVyIjoiMTIzMTAzMTIzMTIifX0sImlzcy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aW5hbC9pbWFnZXMvaW1zZ2xvYmFsLWxvZ28ucG5nIiwidHlwZSI6IkJhZGdlQ2xhc3MiLCJkZXNjcmlwdGlvbiI6ImNyZWRlbnRpYWxTdWJqZWN0Lmhhc0NyZWRlbnRpYWwuaXNzdWVyLmlkICE9IGlzc3Vlci5pZCDihpIgVFJVU1RFRF9JU1NVRVI6IEZBSUwiLCJpc3N1ZXIiOnsibmFtZSI6IlVuaXZlcnNhbCBJc3N1ZXIiLCJ0eXBlIjoiUHJvZmlsZSIsImlkIjoiVGVzdCJ9LCJjcml0ZXJpYSI6Imh0dHBzOi8vd3d3LmFldHNvZnQubmV0IiwidGFncyI6WyJzYW1wbGUtdGFnIl19LCJ0eXBlIjoiQmFkZ2UiLCJAY29udGV4dCI6WyJodHRwczovL3d3dy53My5vcmcvMjAxOC9jcmVkZW50aWFscy92MSIsImh0dHBzOi8vcWFsaWIudmVsb2NpdHluZXR3b3JrLmZvdW5kYXRpb24vY29udGV4dHMvbGF5ZXIxLXYxLjEuanNvbmxkLmpzb24iXX19LCJuYmYiOjE3MDMxNDQyMjEsImp0aSI6ImRpZDp2ZWxvY2l0eTp2MjoweDU3NTcyY2VhNTZmYjQwM2RjMTNjNjBjYmJjNjM3MTUwMGUxMTQ2NTY6MjM0NTc3OTQwMjM2MzYwOjc3NTYiLCJpc3MiOiJkaWQ6aW9uOkVpRFVJMGRhS3J0b0tIWHk0emFFeTZPM0k2Z01xeV95TXRJbDBPZTNtejk4VlEiLCJpYXQiOjE3MDMxNDQyMjF9.cExeY-Qu9WaYV9U5mWKDirdIMilVoPmixDgSkZsmOZCBt99vgfHtlPfyAW-Ez3HlcCwK0v5E8xjhV-IixR36NQ" + + static let JwtCredentialsFromRegularIssuer = "[\"\(JwtCredentialEducationDegreeRegistrationFromRegularIssuer)\", \"\(JwtCredentialEmploymentPastFromRegularIssuer)\"]" @@ -49,5 +56,9 @@ class CredentialMocks { static let JwtCredentialsWithoutSubject = "[\"\(JwtCredEmailWithoutSubjectJwt)\", \"\(JwtCredPhoneWithoutSubjectJwt)\"]" + static let JwtCredentialsOpenBadgeValid = "[\"\(JwtCredentialOpenBadgeValid)\"]" + + static let JwtCredentialsOpenBadgeInvalid = "[\"\(JwtCredentialOpenBadgeInvalid)\"]" + static let JwtEmptyCredentials = "[]" } diff --git a/VCL/VCLTests/verifiers/CredentialIssuerVerifierTest.swift b/VCL/VCLTests/verifiers/CredentialIssuerVerifierTest.swift index bf8113a..471441c 100644 --- a/VCL/VCLTests/verifiers/CredentialIssuerVerifierTest.swift +++ b/VCL/VCLTests/verifiers/CredentialIssuerVerifierTest.swift @@ -13,7 +13,19 @@ import XCTest class CredentialIssuerVerifierTest: XCTestCase { - private var subject: CredentialIssuerVerifier! + private var subject1: CredentialIssuerVerifier! + private var subject2: CredentialIssuerVerifier! + private var subject3: CredentialIssuerVerifier! + private var subject4: CredentialIssuerVerifier! + private var subject5: CredentialIssuerVerifier! + private var subject6: CredentialIssuerVerifier! + private var subject7: CredentialIssuerVerifier! + private var subject8: CredentialIssuerVerifier! + private var subject9: CredentialIssuerVerifier! + private var subject10: CredentialIssuerVerifier! + private var subject11: CredentialIssuerVerifier! + private var subject12: CredentialIssuerVerifier! + private var subject13: CredentialIssuerVerifier! private let OffersMock = VCLOffers(payload: [:], all: [], responseCode: 1, sessionToken: VCLToken(value: ""), challenge: "") @@ -30,6 +42,11 @@ class CredentialIssuerVerifierTest: XCTestCase { private var credentialManifestFromIdentityIssuer: VCLCredentialManifest! override func setUp() { + setUpSubjectProperties() + setUpSubjects() + } + + func setUpSubjectProperties() { credentialManifestWithoutPermittedServices = VCLCredentialManifest( jwt: VCLJwt(encodedJwt: CredentialManifestMocks.JwtCredentialManifestFromNotaryIssuer), verifiedProfile: VCLVerifiedProfile(payload: VerifiedProfileMocks.VerifiedProfileWithoutServices.toDictionary()!) @@ -74,16 +91,121 @@ class CredentialIssuerVerifierTest: XCTestCase { rejectedOfferIds: [] ) } - - func testVerifyNotaryIssuerSuccess() { - subject = CredentialIssuerVerifierImpl( + + func setUpSubjects() { + subject1 = CredentialIssuerVerifierImpl( + CredentialTypesModelMock( + issuerCategory: CredentialTypesModelMock.IssuerCategoryNotaryIssuer + ), + NetworkServiceSuccess(validResponse: JsonLdMocks.Layer1v10Jsonld) + ) + subject2 = CredentialIssuerVerifierImpl( + CredentialTypesModelMock( + issuerCategory: CredentialTypesModelMock.issuerCategoryRegularIssuer + ), + NetworkServiceSuccess(validResponse: JsonLdMocks.Layer1v10Jsonld) + ) + subject3 = CredentialIssuerVerifierImpl( + CredentialTypesModelMock( + issuerCategory: CredentialTypesModelMock.IssuerCategoryNotaryIssuer + ), + NetworkServiceSuccess(validResponse: JsonLdMocks.Layer1v10Jsonld) + ) + subject4 = CredentialIssuerVerifierImpl( + CredentialTypesModelMock( + issuerCategory: CredentialTypesModelMock.IssuerCategoryNotaryIssuer + ), + NetworkServiceSuccess(validResponse: JsonLdMocks.Layer1v10Jsonld) + ) + subject5 = CredentialIssuerVerifierImpl( + CredentialTypesModelMock( + issuerCategory: CredentialTypesModelMock.issuerCategoryRegularIssuer + ), + NetworkServiceSuccess(validResponse: JsonLdMocks.Layer1v10Jsonld) + ) + subject6 = CredentialIssuerVerifierImpl( + CredentialTypesModelMock( + issuerCategory: CredentialTypesModelMock.issuerCategoryRegularIssuer + ), + NetworkServiceSuccess(validResponse: JsonLdMocks.Layer1v10Jsonld) + ) + subject7 = CredentialIssuerVerifierImpl( CredentialTypesModelMock( issuerCategory: CredentialTypesModelMock.IssuerCategoryNotaryIssuer ), NetworkServiceSuccess(validResponse: JsonLdMocks.Layer1v10Jsonld) ) + subject8 = CredentialIssuerVerifierImpl( + CredentialTypesModelMock( + issuerCategory: CredentialTypesModelMock.issuerCategoryRegularIssuer + ), + NetworkServiceSuccess(validResponse: JsonLdMocks.Layer1v10Jsonld) + ) + subject9 = CredentialIssuerVerifierImpl( + CredentialTypesModelMock( + issuerCategory: CredentialTypesModelMock.IssuerCategoryIdDocumentIssuer + ), + NetworkServiceSuccess(validResponse: JsonLdMocks.Layer1v10Jsonld) + ) + subject10 = CredentialIssuerVerifierImpl( + CredentialTypesModelMock( + issuerCategory: CredentialTypesModelMock.IssuerCategoryNotaryContactIssuer + ), + NetworkServiceSuccess(validResponse: JsonLdMocks.Layer1v10Jsonld) + ) + subject11 = CredentialIssuerVerifierImpl( + CredentialTypesModelMock( + issuerCategory: CredentialTypesModelMock.issuerCategoryRegularIssuer + ), + NetworkServiceSuccess(validResponse: JsonLdMocks.Layer1v10Jsonld) + ) + subject12 = CredentialIssuerVerifierImpl( + CredentialTypesModelMock( + issuerCategory: CredentialTypesModelMock.issuerCategoryRegularIssuer + ), + NetworkServiceSuccess(validResponse: "") + ) + subject13 = CredentialIssuerVerifierImpl( + CredentialTypesModelMock( + issuerCategory: CredentialTypesModelMock.issuerCategoryRegularIssuer + ), + NetworkServiceSuccess(validResponse: JsonLdMocks.Layer1v10JsonldWithoutPrimaryOrganization) + ) + } + +// func testVerifyOpenBadgeCredentialSuccess() { +// subject1.verifyCredentials( +// jwtCredentials: CredentialMocks.JwtCredentialsOpenBadgeValid.toJwtList()!, +// finalizeOffersDescriptor: finalizeOffersDescriptorOfNotaryIssuer +// ) { +// do { +// let isVerified = try $0.get() +// assert(isVerified) +// } catch { +// XCTFail("\(error)") +// } +// } +// } + +// @Test +// fun testVerifyOpenBadgeCredentialError() { +// subject2.verifyCredentials( +// jwtCredentials = CredentialMocks.JwtCredentialsOpenBadgeInvalid.toJwtList()!!, +// finalizeOffersDescriptor = finalizeOffersDescriptorOfRegularIssuer, +// ) { verificationResult -> +// verificationResult.handleResult( +// successHandler = { +// assert(it) +// }, +// errorHandler = { error -> +// assert(false) { "${error.toJsonObject()}" } +// } +// ) +// } +// } - subject.verifyCredentials( + func testVerifyNotaryIssuerSuccess() { + subject3.verifyCredentials( jwtCredentials: CredentialMocks.JwtCredentialsFromNotaryIssuer.toJwtList()!, finalizeOffersDescriptor: finalizeOffersDescriptorOfNotaryIssuer ) { @@ -97,14 +219,7 @@ class CredentialIssuerVerifierTest: XCTestCase { } func testVerifyNotaryIssuerMissingSubjectSuccess() { - subject = CredentialIssuerVerifierImpl( - CredentialTypesModelMock( - issuerCategory: CredentialTypesModelMock.IssuerCategoryNotaryIssuer - ), - NetworkServiceSuccess(validResponse: JsonLdMocks.Layer1v10Jsonld) - ) - - subject.verifyCredentials( + subject4.verifyCredentials( jwtCredentials: CredentialMocks.JwtCredentialsWithoutSubject.toJwtList()!, finalizeOffersDescriptor: finalizeOffersDescriptorOfNotaryIssuer ) { @@ -118,14 +233,7 @@ class CredentialIssuerVerifierTest: XCTestCase { } func testVerifyRegularIssuerSuccess() { - subject = CredentialIssuerVerifierImpl( - CredentialTypesModelMock( - issuerCategory: CredentialTypesModelMock.issuerCategoryRegularIssuer - ), - NetworkServiceSuccess(validResponse: JsonLdMocks.Layer1v10Jsonld) - ) - - subject.verifyCredentials( + subject5.verifyCredentials( jwtCredentials: CredentialMocks.JwtCredentialsFromRegularIssuer.toJwtList()!, finalizeOffersDescriptor: finalizeOffersDescriptorOfRegularIssuer ) { @@ -139,14 +247,7 @@ class CredentialIssuerVerifierTest: XCTestCase { } func testVerifyRegularIssuerWrongDidFailed() { - subject = CredentialIssuerVerifierImpl( - CredentialTypesModelMock( - issuerCategory: CredentialTypesModelMock.issuerCategoryRegularIssuer - ), - NetworkServiceSuccess(validResponse: JsonLdMocks.Layer1v10Jsonld) - ) - - subject.verifyCredentials( + subject6.verifyCredentials( jwtCredentials: CredentialMocks.JwtCredentialsFromNotaryIssuer.toJwtList()!, finalizeOffersDescriptor: finalizeOffersDescriptorOfRegularIssuer ) { @@ -160,14 +261,7 @@ class CredentialIssuerVerifierTest: XCTestCase { } func testVerifyIssuerWithoutServicesFailed() { - subject = CredentialIssuerVerifierImpl( - CredentialTypesModelMock( - issuerCategory: CredentialTypesModelMock.IssuerCategoryNotaryIssuer - ), - NetworkServiceSuccess(validResponse: JsonLdMocks.Layer1v10Jsonld) - ) - - subject.verifyCredentials( + subject7.verifyCredentials( jwtCredentials: CredentialMocks.JwtCredentialsFromNotaryIssuer.toJwtList()!, finalizeOffersDescriptor: finalizeOffersDescriptorWithoutPermittedServices ) { @@ -181,14 +275,7 @@ class CredentialIssuerVerifierTest: XCTestCase { } func testVerifyRegularIssuerMissingSubjectFailed() { - subject = CredentialIssuerVerifierImpl( - CredentialTypesModelMock( - issuerCategory: CredentialTypesModelMock.issuerCategoryRegularIssuer - ), - NetworkServiceSuccess(validResponse: JsonLdMocks.Layer1v10Jsonld) - ) - - subject.verifyCredentials( + subject8.verifyCredentials( jwtCredentials: CredentialMocks.JwtCredentialsWithoutSubject.toJwtList()!, finalizeOffersDescriptor: finalizeOffersDescriptorOfRegularIssuer ) { @@ -202,14 +289,7 @@ class CredentialIssuerVerifierTest: XCTestCase { } func testVerifyIdentityIssuerSuccess() { - subject = CredentialIssuerVerifierImpl( - CredentialTypesModelMock( - issuerCategory: CredentialTypesModelMock.IssuerCategoryIdDocumentIssuer - ), - NetworkServiceSuccess(validResponse: JsonLdMocks.Layer1v10Jsonld) - ) - - subject.verifyCredentials( + subject9.verifyCredentials( jwtCredentials: CredentialMocks.JwtCredentialsFromRegularIssuer.toJwtList()!, finalizeOffersDescriptor: finalizeOffersDescriptorOfIdentityIssuer ) { @@ -223,14 +303,7 @@ class CredentialIssuerVerifierTest: XCTestCase { } func testVerifyEmptyCredentialsSuccess() { - subject = CredentialIssuerVerifierImpl( - CredentialTypesModelMock( - issuerCategory: CredentialTypesModelMock.IssuerCategoryNotaryContactIssuer - ), - NetworkServiceSuccess(validResponse: JsonLdMocks.Layer1v10Jsonld) - ) - - subject.verifyCredentials( + subject10.verifyCredentials( jwtCredentials: CredentialMocks.JwtEmptyCredentials.toJwtList()!, finalizeOffersDescriptor: finalizeOffersDescriptorOfIdentityIssuer ) { @@ -244,14 +317,7 @@ class CredentialIssuerVerifierTest: XCTestCase { } func testVerifyIdentityIssuerFailedWithoutIdentityService() { - subject = CredentialIssuerVerifierImpl( - CredentialTypesModelMock( - issuerCategory: CredentialTypesModelMock.issuerCategoryRegularIssuer - ), - NetworkServiceSuccess(validResponse: JsonLdMocks.Layer1v10Jsonld) - ) - - subject.verifyCredentials( + subject11.verifyCredentials( jwtCredentials: CredentialMocks.JwtCredentialsFromIdentityIssuer.toJwtList()!, finalizeOffersDescriptor: finalizeOffersDescriptorOfIdentityIssuer ) { @@ -265,14 +331,7 @@ class CredentialIssuerVerifierTest: XCTestCase { } func testVerifyIssuerWithoutServicesFailedCompleteContextNotFound() { - subject = CredentialIssuerVerifierImpl( - CredentialTypesModelMock( - issuerCategory: CredentialTypesModelMock.issuerCategoryRegularIssuer - ), - NetworkServiceSuccess(validResponse: "") - ) - - subject.verifyCredentials( + subject12.verifyCredentials( jwtCredentials: CredentialMocks.JwtCredentialsFromRegularIssuer.toJwtList()!, finalizeOffersDescriptor: finalizeOffersDescriptorOfRegularIssuer ) { @@ -286,14 +345,7 @@ class CredentialIssuerVerifierTest: XCTestCase { } func testVerifyIssuerPrimaryOrganizationNotFound() { - subject = CredentialIssuerVerifierImpl( - CredentialTypesModelMock( - issuerCategory: CredentialTypesModelMock.issuerCategoryRegularIssuer - ), - NetworkServiceSuccess(validResponse: JsonLdMocks.Layer1v10JsonldWithoutPrimaryOrganization) - ) - - subject.verifyCredentials( + subject13.verifyCredentials( jwtCredentials: CredentialMocks.JwtCredentialsFromRegularIssuer.toJwtList()!, finalizeOffersDescriptor: finalizeOffersDescriptorOfRegularIssuer ) { diff --git a/VCL/VCLTests/verifiers/ProfileServiceTypeVerifierTest.swift b/VCL/VCLTests/verifiers/ProfileServiceTypeVerifierTest.swift index 46022aa..3a15d20 100644 --- a/VCL/VCLTests/verifiers/ProfileServiceTypeVerifierTest.swift +++ b/VCL/VCLTests/verifiers/ProfileServiceTypeVerifierTest.swift @@ -13,10 +13,15 @@ import XCTest class ProfileServiceTypeVerifierTest: XCTestCase { - private var subject: ProfileServiceTypeVerifier! + private var subject1: ProfileServiceTypeVerifier! + private var subject2: ProfileServiceTypeVerifier! + private var subject3: ProfileServiceTypeVerifier! + private var subject4: ProfileServiceTypeVerifier! + private var subject5: ProfileServiceTypeVerifier! + private var subject6: ProfileServiceTypeVerifier! - func testVerificationSuccess1() { - subject = ProfileServiceTypeVerifier( + override func setUp() { + subject1 = ProfileServiceTypeVerifier( verifiedProfileUseCase: VerifiedProfileUseCaseImpl( VerifiedProfileRepositoryImpl( NetworkServiceSuccess(validResponse: VerifiedProfileMocks.VerifiedProfileIssuerInspectorJsonStr) @@ -24,78 +29,93 @@ class ProfileServiceTypeVerifierTest: XCTestCase { ExecutorImpl() ) ) - - subject.verifyServiceTypeOfVerifiedProfile( + subject2 = ProfileServiceTypeVerifier( + verifiedProfileUseCase: VerifiedProfileUseCaseImpl( + VerifiedProfileRepositoryImpl( + NetworkServiceSuccess(validResponse: VerifiedProfileMocks.VerifiedProfileInspectorJsonStr) + ), + ExecutorImpl() + ) + ) + subject3 = ProfileServiceTypeVerifier( + verifiedProfileUseCase: VerifiedProfileUseCaseImpl( + VerifiedProfileRepositoryImpl( + NetworkServiceSuccess(validResponse: VerifiedProfileMocks.VerifiedProfileNotaryIssuerJsonStr) + ), + ExecutorImpl() + ) + ) + subject4 = ProfileServiceTypeVerifier( + verifiedProfileUseCase: VerifiedProfileUseCaseImpl( + VerifiedProfileRepositoryImpl( + NetworkServiceSuccess(validResponse: VerifiedProfileMocks.VerifiedProfileNotaryIssuerJsonStr) + ), + ExecutorImpl() + ) + ) + subject5 = ProfileServiceTypeVerifier( + verifiedProfileUseCase: VerifiedProfileUseCaseImpl( + VerifiedProfileRepositoryImpl( + NetworkServiceSuccess(validResponse: VerifiedProfileMocks.VerifiedProfileIssuerJsonStr1) + ), + ExecutorImpl() + ) + ) + subject6 = ProfileServiceTypeVerifier( + verifiedProfileUseCase: VerifiedProfileUseCaseImpl( + VerifiedProfileRepositoryImpl( + NetworkServiceSuccess(validResponse: VerifiedProfileMocks.VerifiedProfileIssuerInspectorJsonStr) + ), + ExecutorImpl() + ) + ) + } + + func testVerificationSuccess1() { + subject1.verifyServiceTypeOfVerifiedProfile( verifiedProfileDescriptor: VCLVerifiedProfileDescriptor(did: ""), expectedServiceTypes: VCLServiceTypes(issuingType: VCLIssuingType.Career), successHandler: {_ in assert(true) }, - errorHandler: {_ in - assert(false) + errorHandler: { error in + XCTFail("\(error)") } ) } func testVerificationSuccess2() { - subject = ProfileServiceTypeVerifier( - verifiedProfileUseCase: VerifiedProfileUseCaseImpl( - VerifiedProfileRepositoryImpl( - NetworkServiceSuccess(validResponse: VerifiedProfileMocks.VerifiedProfileInspectorJsonStr) - ), - ExecutorImpl() - ) - ) - - subject.verifyServiceTypeOfVerifiedProfile( + subject2.verifyServiceTypeOfVerifiedProfile( verifiedProfileDescriptor: VCLVerifiedProfileDescriptor(did: ""), expectedServiceTypes: VCLServiceTypes(serviceType: VCLServiceType.Inspector), successHandler: {_ in assert(true) }, - errorHandler: {_ in - assert(false) + errorHandler: { error in + XCTFail("\(error)") } ) } func testVerificationSuccess3() { - subject = ProfileServiceTypeVerifier( - verifiedProfileUseCase: VerifiedProfileUseCaseImpl( - VerifiedProfileRepositoryImpl( - NetworkServiceSuccess(validResponse: VerifiedProfileMocks.VerifiedProfileNotaryIssuerJsonStr) - ), - ExecutorImpl() - ) - ) - - subject.verifyServiceTypeOfVerifiedProfile( + subject3.verifyServiceTypeOfVerifiedProfile( verifiedProfileDescriptor: VCLVerifiedProfileDescriptor(did: ""), expectedServiceTypes: VCLServiceTypes(issuingType: VCLIssuingType.Career), successHandler: {_ in assert(true) }, - errorHandler: {_ in - assert(false) + errorHandler: { error in + XCTFail("\(error)") } ) } func testVerificationFailure1() { - subject = ProfileServiceTypeVerifier( - verifiedProfileUseCase: VerifiedProfileUseCaseImpl( - VerifiedProfileRepositoryImpl( - NetworkServiceSuccess(validResponse: VerifiedProfileMocks.VerifiedProfileNotaryIssuerJsonStr) - ), - ExecutorImpl() - ) - ) - - subject.verifyServiceTypeOfVerifiedProfile( + subject4.verifyServiceTypeOfVerifiedProfile( verifiedProfileDescriptor: VCLVerifiedProfileDescriptor(did: ""), expectedServiceTypes: VCLServiceTypes(issuingType: VCLIssuingType.Identity), successHandler: {_ in - assert(false) + XCTFail() }, errorHandler: { error in assert(error.statusCode == VCLStatusCode.VerificationError.rawValue) @@ -105,20 +125,11 @@ class ProfileServiceTypeVerifierTest: XCTestCase { } func testVerificationFailure2() { - subject = ProfileServiceTypeVerifier( - verifiedProfileUseCase: VerifiedProfileUseCaseImpl( - VerifiedProfileRepositoryImpl( - NetworkServiceSuccess(validResponse: VerifiedProfileMocks.VerifiedProfileIssuerJsonStr1) - ), - ExecutorImpl() - ) - ) - - subject.verifyServiceTypeOfVerifiedProfile( + subject5.verifyServiceTypeOfVerifiedProfile( verifiedProfileDescriptor: VCLVerifiedProfileDescriptor(did: ""), expectedServiceTypes: VCLServiceTypes(issuingType: VCLIssuingType.Identity), successHandler: {_ in - assert(false) + XCTFail() }, errorHandler: { error in assert(error.statusCode == VCLStatusCode.VerificationError.rawValue) @@ -128,20 +139,11 @@ class ProfileServiceTypeVerifierTest: XCTestCase { } func testVerificationFailure3() { - subject = ProfileServiceTypeVerifier( - verifiedProfileUseCase: VerifiedProfileUseCaseImpl( - VerifiedProfileRepositoryImpl( - NetworkServiceSuccess(validResponse: VerifiedProfileMocks.VerifiedProfileIssuerInspectorJsonStr) - ), - ExecutorImpl() - ) - ) - - subject.verifyServiceTypeOfVerifiedProfile( + subject6.verifyServiceTypeOfVerifiedProfile( verifiedProfileDescriptor: VCLVerifiedProfileDescriptor(did: ""), expectedServiceTypes: VCLServiceTypes(serviceType: VCLServiceType.Undefined), successHandler: {_ in - assert(false) + XCTFail() }, errorHandler: { error in assert(error.statusCode == VCLStatusCode.VerificationError.rawValue)