Skip to content

Commit

Permalink
Improve claim integration test
Browse files Browse the repository at this point in the history
  • Loading branch information
Hopsaheysa committed Dec 7, 2023
1 parent cb0e438 commit 356c588
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 10 deletions.
14 changes: 11 additions & 3 deletions WultraMobileTokenSDKTests/IntegrationProxy.swift
Original file line number Diff line number Diff line change
Expand Up @@ -89,14 +89,15 @@ class IntegrationProxy {
}
}

func createNonPersonalisedOperation(_ factors: Factors = .F_2FA, completion: @escaping (NonPersonalisedOperationObject?) -> Void) {
func createNonPersonalisedPACOperation(_ factors: Factors = .F_2FA, completion: @escaping (NonPersonalisedTOTPOperationObject?) -> Void) {
DispatchQueue.global().async {
let opBody: String
switch factors {
case .F_2FA:
opBody = """
{
"template": "login",
"template": "login_preApproval",
"proximityCheckEnabled": true,
"parameters": {
"party.id": "666",
"party.name": "Datová schránka",
Expand All @@ -111,6 +112,12 @@ class IntegrationProxy {
}
}

func getOperation(operation: NonPersonalisedTOTPOperationObject, completion: @escaping (NonPersonalisedTOTPOperationObject?) -> Void) {
DispatchQueue.global().async {
completion(self.makeRequest(url: URL(string: "\(self.config.cloudServerUrl)/v2/operations/\(operation.operationId)")!, body: "", httpMethod: "GET"))
}
}

func getQROperation(operation: OperationObject, completion: @escaping (QROperationData?) -> Void) {
DispatchQueue.global().async {
completion(self.makeRequest(url: URL(string: "\(self.config.cloudServerUrl)/v2/operations/\(operation.operationId)/offline/qr?registrationId=\(self.registrationId)")!, body: "", httpMethod: "GET"))
Expand Down Expand Up @@ -266,14 +273,15 @@ struct OperationObject: Codable {
let timestampExpires: Int
}

struct NonPersonalisedOperationObject: Codable {
struct NonPersonalisedTOTPOperationObject: Codable {
let operationId: String
let status: String
let operationType: String
let failureCount: Int
let maxFailureCount: Int
let timestampCreated: Int
let timestampExpires: Int
let proximityOtp: String?
}

private struct IntegrationConfig: Codable {
Expand Down
42 changes: 35 additions & 7 deletions WultraMobileTokenSDKTests/IntegrationTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ class IntegrationTests: XCTestCase {
func testDetail() {
let exp = expectation(description: "Operation detail")

proxy.createNonPersonalisedOperation { op in
proxy.createNonPersonalisedPACOperation { op in
if let op {
DispatchQueue.main.async {
_ = self.ops.getDetail(operationId: op.operationId) { result in
Expand All @@ -121,19 +121,47 @@ class IntegrationTests: XCTestCase {
func testClaim() {
let exp = expectation(description: "Operation Claim should return UserOperation with operation.id")

proxy.createNonPersonalisedOperation { op in
proxy.createNonPersonalisedPACOperation { op in
if let op {
DispatchQueue.main.async {
_ = self.ops.claim(operationId: op.operationId) { result in
switch result {
case .success(let operation):
XCTAssertEqual(op.operationId, operation.id)
case .failure(let err):
XCTFail(err.description)
if operation.ui?.preApprovalScreen?.type == .qr {
self.proxy.getOperation(operation: op) { totpOP in
XCTAssertNotNil(totpOP?.proximityOtp, "Even with proximityCheckEnabled: true, in proximityOtp nil")
if let totpOP = totpOP, let proximityOtp = totpOP.proximityOtp {
operation.proximityCheck = WMTProximityCheck(totp: proximityOtp, type: .qrCode)
// wrong password on purpose
let auth = PowerAuthAuthentication.possessionWithPassword(password: "xxxx")
self.ops.authorize(operation: operation, with: auth) { result in
switch result {
case .failure:
let auth = PowerAuthAuthentication.possessionWithPassword(password: self.pin)
self.ops.authorize(operation: operation, with: auth) { result in
if case .failure(let error) = result {
XCTFail("Failed to authorize op: \(error.description)")
}
exp.fulfill()
}
case .success:
XCTFail("Operation approved with wrong password")
exp.fulfill()
}
}
} else {
XCTFail("Operation or TOTP is NIL")
exp.fulfill()
}
}
}

case .failure(let err):
XCTFail(err.description)
exp.fulfill()
}
}
exp.fulfill()
}
}
} else {
XCTFail("Failed to get operation detail")
exp.fulfill()
Expand Down

0 comments on commit 356c588

Please sign in to comment.