-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(GiniBankSDK): Add unit tests and integration tests from `GiniBan…
…kAPILibraryPinningExample` project PP-194
- Loading branch information
1 parent
22807fe
commit 0f79f10
Showing
6 changed files
with
290 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
124 changes: 124 additions & 0 deletions
124
...inningExample/Tests/BankAPILibraryPinning/GiniBankAPILibraryPinningIntegrationTests.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,124 @@ | ||
// | ||
// GiniBankAPILibraryPinningIntegrationTests.swift | ||
// | ||
// Copyright © 2024 Gini GmbH. All rights reserved. | ||
// | ||
|
||
import XCTest | ||
@testable import GiniBankAPILibrary | ||
@testable import TrustKit | ||
|
||
class GiniBankAPILibraryPinningIntegrationTests: XCTestCase { | ||
|
||
// When running from Xcode: update these environment variables in the scheme. | ||
// Make sure not to commit the credentials if the scheme is shared! | ||
let clientId = ProcessInfo.processInfo.environment["CLIENT_ID"]! | ||
let clientSecret = ProcessInfo.processInfo.environment["CLIENT_SECRET"]! | ||
let paymentRequestID = "a6466506-acf1-4896-94c8-9b398d4e0ee1" | ||
var giniBankAPILib: GiniBankAPI! | ||
var documentService: DefaultDocumentService! | ||
|
||
override func setUp() { | ||
let yourPublicPinningConfig = [ | ||
kTSKPinnedDomains: [ | ||
"pay-api.gini.net": [ | ||
kTSKPublicKeyHashes: [ | ||
// old *.gini.net public key | ||
"cNzbGowA+LNeQ681yMm8ulHxXiGojHE8qAjI+M7bIxU=", | ||
// new *.gini.net public key, active from around June 2020 | ||
"zEVdOCzXU8euGVuMJYPr3DUU/d1CaKevtr0dW0XzZNo=", | ||
]], | ||
"user.gini.net": [ | ||
kTSKPublicKeyHashes: [ | ||
// old *.gini.net public key | ||
"cNzbGowA+LNeQ681yMm8ulHxXiGojHE8qAjI+M7bIxU=", | ||
// new *.gini.net public key, active from around June 2020 | ||
"zEVdOCzXU8euGVuMJYPr3DUU/d1CaKevtr0dW0XzZNo=", | ||
]], | ||
]] as [String: Any] | ||
let client = Client(id: clientId, secret: clientSecret, domain: "pay-api-lib-example") | ||
giniBankAPILib = GiniBankAPI.Builder(client: client, pinningConfig: yourPublicPinningConfig).build() | ||
documentService = giniBankAPILib.documentService() | ||
} | ||
|
||
func testErrorLogging() { | ||
let expect = expectation(description: "it logs the error event") | ||
|
||
let errorEvent = ErrorEvent(deviceModel: UIDevice.current.model, | ||
osName: UIDevice.current.systemName, | ||
osVersion: UIDevice.current.systemVersion, | ||
captureSdkVersion: "Not available", | ||
apiLibVersion: Bundle(for: GiniBankAPI.self).infoDictionary?["CFBundleShortVersionString"] as? String ?? "Unknown", | ||
description: "Error logging integration test", | ||
documentId: nil, | ||
originalRequestId: nil) | ||
|
||
documentService.log(errorEvent: errorEvent) { result in | ||
switch result { | ||
case .success: | ||
expect.fulfill() | ||
case .failure(let error): | ||
XCTFail(String(describing: error)) | ||
} | ||
} | ||
|
||
wait(for: [expect], timeout: 10) | ||
} | ||
|
||
func testBuildPaymentService() { | ||
let paymentService = giniBankAPILib.paymentService() | ||
XCTAssertEqual(paymentService.apiDomain.domainString, "pay-api.gini.net") | ||
} | ||
|
||
func testFetchPaymentRequest(){ | ||
let expect = expectation(description: "it fetches the payment request") | ||
|
||
let paymentService = giniBankAPILib.paymentService() | ||
paymentService.paymentRequest(id: paymentRequestID) { result in | ||
switch result { | ||
case .success(let request): | ||
XCTAssertEqual(request.iban, "DE13760700120500154000") | ||
expect.fulfill() | ||
case .failure(let error): | ||
XCTFail(String(describing: error)) | ||
} | ||
} | ||
wait(for: [expect], timeout: 10) | ||
} | ||
|
||
func testResolvePaymentRequest(){ | ||
let message = "You can't resolve the previously resolved payment request" | ||
let expect = expectation(description: message) | ||
|
||
let paymentService = giniBankAPILib.paymentService() | ||
paymentService.resolvePaymentRequest(id: paymentRequestID, | ||
recipient: "Dr. med. Hackler", | ||
iban: "DE13760700120500154000", | ||
bic: "", amount: "335.50:EUR", | ||
purpose: "ReNr AZ356789Z") { result in | ||
switch result { | ||
case .success(_): | ||
XCTFail(message) | ||
case .failure(_): | ||
expect.fulfill() | ||
} | ||
} | ||
wait(for: [expect], timeout: 10) | ||
} | ||
|
||
func testPayment(){ | ||
let expect = expectation(description: "it gets the payment") | ||
|
||
let paymentService = giniBankAPILib.paymentService() | ||
paymentService.payment(id: "a6466506-acf1-4896-94c8-9b398d4e0ee1") { result in | ||
switch result { | ||
case .success(let payment): | ||
XCTAssertEqual(payment.iban, "DE13760700120500154000") | ||
expect.fulfill() | ||
case .failure(let error): | ||
XCTFail(String(describing: error)) | ||
} | ||
} | ||
wait(for: [expect], timeout: 10) | ||
} | ||
} |
63 changes: 63 additions & 0 deletions
63
...ts/BankAPILibraryPinning/GiniBankAPILibraryPinningIntegrationWrongCertificatesTests.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
// | ||
// GiniBankAPILibraryPinningIntegrationTests.swift | ||
// | ||
// Copyright © 2024 Gini GmbH. All rights reserved. | ||
// | ||
|
||
import XCTest | ||
@testable import GiniBankAPILibrary | ||
@testable import TrustKit | ||
|
||
class PinningWrongCertificatesIntegrationTests: XCTestCase { | ||
|
||
// When running from Xcode: update these environment variables in the scheme. | ||
// Make sure not to commit the credentials if the scheme is shared! | ||
let clientId = ProcessInfo.processInfo.environment["CLIENT_ID"]! | ||
let clientSecret = ProcessInfo.processInfo.environment["CLIENT_SECRET"]! | ||
let paymentRequestID = "a6466506-acf1-4896-94c8-9b398d4e0ee1" | ||
var giniBankAPILib: GiniBankAPI! | ||
var documentService: DefaultDocumentService! | ||
|
||
override func setUp() { | ||
let yourPublicPinningConfig = [ | ||
kTSKPinnedDomains: [ | ||
"pay-api.gini.net": [ | ||
kTSKPublicKeyHashes: [ | ||
// Wrong hashes | ||
"TQEtdMbmwFgYUifM4LDF+xgEtd0z69mPGmkp014d6ZY=", | ||
"rFjc3wG7lTZe43zeYTvPq8k4xdDEutCmIhI5dn4oCeE=" | ||
]], | ||
"user.gini.net": [ | ||
kTSKPublicKeyHashes: [ | ||
// Wrong hashes | ||
"TQEtdMbmwFgYUifM4LDF+xgEtd0z69mPGmkp014d6ZY=", | ||
"rFjc3wG7lTZe43zeYTvPq8k4xdDEutCmIhI5dn4oCeE=" | ||
]], | ||
]] as [String: Any] | ||
let client = Client(id: clientId, secret: clientSecret, domain: "pay-api-lib-example") | ||
giniBankAPILib = GiniBankAPI.Builder(client: client, pinningConfig: yourPublicPinningConfig).build() | ||
documentService = giniBankAPILib.documentService() | ||
} | ||
|
||
|
||
func testResolvePaymentRequestFails() { | ||
let expect = expectation(description: "it fails to resolve the payment request due to wrong pinning certificates") | ||
|
||
let paymentService = giniBankAPILib.paymentService() | ||
paymentService.resolvePaymentRequest(id: paymentRequestID, | ||
recipient: "Dr. med. Hackler", | ||
iban: "DE13760700120500154000", | ||
bic: "", | ||
amount: "335.50:EUR", | ||
purpose: "ReNr AZ356789Z") { result in | ||
switch result { | ||
case .success(_): | ||
XCTFail("resolving the payment request should have failed due to wrong pinning certificates") | ||
case .failure(let error): | ||
XCTAssertEqual(error, GiniBankAPILibrary.GiniError.noResponse) | ||
expect.fulfill() | ||
} | ||
} | ||
wait(for: [expect], timeout: 10) | ||
} | ||
} |
82 changes: 82 additions & 0 deletions
82
...iniBankSDKPinningExample/Tests/BankAPILibraryPinning/GiniBankAPILibraryPinningTests.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
// | ||
// GiniBankAPILibraryPinningTests.swift | ||
// | ||
// Copyright © 2024 Gini GmbH. All rights reserved. | ||
// | ||
|
||
import XCTest | ||
@testable import GiniBankAPILibrary | ||
@testable import TrustKit | ||
|
||
final class GiniBankAPILibraryPinningTests: XCTestCase { | ||
let client = Client(id: "", secret: "", domain: "") | ||
let yourPublicPinningConfig = [ | ||
kTSKPinnedDomains: [ | ||
"pay-api.gini.net": [ | ||
kTSKPublicKeyHashes: [ | ||
// old *.gini.net public key | ||
"cNzbGowA+LNeQ681yMm8ulHxXiGojHE8qAjI+M7bIxU=", | ||
// new *.gini.net public key, active from around June 2020 | ||
"zEVdOCzXU8euGVuMJYPr3DUU/d1CaKevtr0dW0XzZNo=", | ||
]], | ||
"user.gini.net": [ | ||
kTSKPublicKeyHashes: [ | ||
// old *.gini.net public key | ||
"cNzbGowA+LNeQ681yMm8ulHxXiGojHE8qAjI+M7bIxU=", | ||
// new *.gini.net public key, active from around June 2020 | ||
"zEVdOCzXU8euGVuMJYPr3DUU/d1CaKevtr0dW0XzZNo=", | ||
]], | ||
]] as [String: Any] | ||
|
||
func testBuildWithCustomApiDomain() { | ||
let giniBankAPILib = GiniBankAPI.Builder(client: client, | ||
api: .custom(domain: "custom-api.domain.com", tokenSource: nil), | ||
pinningConfig: yourPublicPinningConfig, | ||
logLevel: .none).build() | ||
|
||
let documentService: DefaultDocumentService = giniBankAPILib.documentService() | ||
XCTAssertEqual(documentService.apiDomain.domainString, "custom-api.domain.com") | ||
} | ||
|
||
func testBuildWithCustomUserDomain() { | ||
let giniBankAPILib = GiniBankAPI.Builder(client: client, | ||
userApi: .custom(domain: "custom-user.domain.com"), | ||
pinningConfig: yourPublicPinningConfig, | ||
logLevel: .none).build() | ||
let documentService: DefaultDocumentService = giniBankAPILib.documentService() | ||
let sessionManager: SessionManager = documentService.sessionManager as! SessionManager | ||
XCTAssertEqual(sessionManager.userDomain.domainString, "custom-user.domain.com") | ||
} | ||
|
||
func testBuildWithCustomApiAndUserDomain() { | ||
let giniBankAPILib = GiniBankAPI.Builder(client: client, | ||
api: .custom(domain: "custom-api.domain.com", tokenSource: nil), | ||
userApi: .custom(domain: "custom-user.domain.com"), | ||
pinningConfig: yourPublicPinningConfig, | ||
logLevel: .none).build() | ||
let documentService: DefaultDocumentService = giniBankAPILib.documentService() | ||
XCTAssertEqual(documentService.apiDomain.domainString, "custom-api.domain.com") | ||
|
||
let sessionManager: SessionManager = documentService.sessionManager as! SessionManager | ||
XCTAssertEqual(sessionManager.userDomain.domainString, "custom-user.domain.com") | ||
} | ||
|
||
func testWithCustomApiDomainAndAlternativeTokenSource() { | ||
let tokenSource = TokenSource() | ||
let giniBankAPILib = GiniBankAPI.Builder(customApiDomain: "custom-api.domain.com", | ||
alternativeTokenSource: tokenSource, | ||
pinningConfig: yourPublicPinningConfig, | ||
logLevel: .none).build() | ||
|
||
let documentService: DefaultDocumentService = giniBankAPILib.documentService() | ||
XCTAssertEqual(documentService.apiDomain.domainString, "custom-api.domain.com") | ||
|
||
let sessionManager: SessionManager = documentService.sessionManager as! SessionManager | ||
XCTAssertNotNil(sessionManager.alternativeTokenSource) | ||
} | ||
|
||
private class TokenSource: AlternativeTokenSource { | ||
func fetchToken(completion: @escaping (Result<Token, GiniError>) -> Void) { | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 1 addition & 2 deletions
3
BankSDK/GiniBankSDKPinningExample/Tests/TransferSummaryIntegrationTest.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters