-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2513b04
commit 495c464
Showing
1 changed file
with
166 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -316,6 +316,172 @@ final class TwoFASTests: XCTestCase { | |
XCTAssertEqual(tokens[7].counter, 22) | ||
XCTAssertEqual(tokens[7].secret, "KQOZTMLOJBSMYWIO4BG4UTXDSR") | ||
} | ||
|
||
func testValidImport_Period() throws { | ||
let json: JSON = | ||
[ | ||
"appOrigin": "ios", | ||
"appVersionCode": 50308, | ||
"appVersionName": "5.3.8", | ||
"groups": [], | ||
"schemaVersion": 4, | ||
"services": [ | ||
[ | ||
"icon": [ | ||
"iconCollection": [ | ||
"id": "90CAF674-4269-4193-9749-4849F97CFB53", | ||
], | ||
"label": [ | ||
"backgroundColor": "Orange", | ||
"text": "AP", | ||
], | ||
"selected": "IconCollection", | ||
], | ||
"name": "Apple", | ||
"order": [ | ||
"position": 0, | ||
], | ||
"otp": [ | ||
"account": "[email protected]", | ||
"algorithm": "SHA1", | ||
"counter": 0, | ||
"digits": 6, | ||
"issuer": "Apple", | ||
"period": 10, | ||
"source": "link", | ||
"tokenType": "TOTP", | ||
], | ||
"secret": "AB6B7FAYHW2G42ZA4FJHLRWWHU", | ||
"serviceTypeID": "ea250427-4465-48d7-bbcd-4616be85626a", | ||
"updatedAt": 1_721_919_046_000, | ||
], | ||
[ | ||
"icon": [ | ||
"iconCollection": [ | ||
"id": "A5B3FB65-4EC5-43E6-8EC1-49E24CA9E7AD", | ||
], | ||
"label": [ | ||
"backgroundColor": "Brown", | ||
"text": "AW", | ||
], | ||
"selected": "Label", | ||
], | ||
"name": "AWS", | ||
"order": [ | ||
"position": 1, | ||
], | ||
"otp": [ | ||
"account": "[email protected]", | ||
"algorithm": "SHA256", | ||
"counter": 0, | ||
"digits": 7, | ||
"issuer": "AWS", | ||
"period": 30, | ||
"source": "link", | ||
"tokenType": "TOTP", | ||
], | ||
"secret": "U7WXBPTLK62EC6Y2X4ALCMWWHS", | ||
"serviceTypeID": "71789cdc-d0be-42ad-98ab-ea146c5ea5d6", | ||
"updatedAt": 1_721_919_046_000, | ||
], | ||
[ | ||
"icon": [ | ||
"iconCollection": [ | ||
"id": "A5B3FB65-4EC5-43E6-8EC1-49E24CA9E7AD", | ||
], | ||
"label": [ | ||
"backgroundColor": "Indigo", | ||
"text": "PG", | ||
], | ||
"selected": "Label", | ||
], | ||
"name": "PG", | ||
"order": [ | ||
"position": 2, | ||
], | ||
"otp": [ | ||
"account": "[email protected]", | ||
"algorithm": "SHA512", | ||
"counter": 0, | ||
"digits": 8, | ||
"issuer": "PG", | ||
"period": 60, | ||
"source": "link", | ||
"tokenType": "TOTP", | ||
], | ||
"secret": "V27AJDJS4HZM3CTQNZXLVCHJYE", | ||
"serviceTypeID": "f98fdeef-03ef-4491-b408-2ecfa4f20ad4", | ||
"updatedAt": 1_721_919_046_000, | ||
], | ||
[ | ||
"icon": [ | ||
"iconCollection": [ | ||
"id": "A5B3FB65-4EC5-43E6-8EC1-49E24CA9E7AD", | ||
], | ||
"label": [ | ||
"backgroundColor": "Gray", | ||
"text": "UN", | ||
], | ||
"selected": "Label", | ||
], | ||
"name": "Unknown", | ||
"order": [ | ||
"position": 3, | ||
], | ||
"otp": [ | ||
"account": "", | ||
"algorithm": "SHA1", | ||
"counter": 0, | ||
"digits": 6, | ||
"issuer": "", | ||
"period": 90, | ||
"source": "manual", | ||
"tokenType": "TOTP", | ||
], | ||
"secret": "MGTMWSHCBRMOBRI2AXNJD4M332", | ||
"serviceTypeID": "2b2ba134-870d-4100-91f6-1193ad569841", | ||
"updatedAt": 1_721_919_046_000, | ||
], | ||
], | ||
] | ||
|
||
let importService = ImportService() | ||
let tokens = importService.importFrom2FAS(json: json)! | ||
|
||
XCTAssertEqual(tokens.count, 4) | ||
|
||
XCTAssertEqual(tokens[0].digits, 6) | ||
XCTAssertEqual(tokens[0].type, TokenTypeEnum.TOTP) | ||
XCTAssertEqual(tokens[0].algorithm, TokenAlgorithmEnum.SHA1) | ||
XCTAssertEqual(tokens[0].issuer, "Apple") | ||
XCTAssertEqual(tokens[0].account, "[email protected]") | ||
XCTAssertEqual(tokens[0].period, 10) | ||
XCTAssertEqual(tokens[0].secret, "AB6B7FAYHW2G42ZA4FJHLRWWHU") | ||
|
||
XCTAssertEqual(tokens[1].digits, 7) | ||
XCTAssertEqual(tokens[1].type, TokenTypeEnum.TOTP) | ||
XCTAssertEqual(tokens[1].algorithm, TokenAlgorithmEnum.SHA256) | ||
XCTAssertEqual(tokens[1].issuer, "AWS") | ||
XCTAssertEqual(tokens[1].account, "[email protected]") | ||
XCTAssertEqual(tokens[1].period, 30) | ||
XCTAssertEqual(tokens[1].secret, "U7WXBPTLK62EC6Y2X4ALCMWWHS") | ||
|
||
XCTAssertEqual(tokens[2].digits, 8) | ||
XCTAssertEqual(tokens[2].type, TokenTypeEnum.TOTP) | ||
XCTAssertEqual(tokens[2].algorithm, TokenAlgorithmEnum.SHA512) | ||
XCTAssertEqual(tokens[2].issuer, "PG") | ||
XCTAssertEqual(tokens[2].account, "[email protected]") | ||
XCTAssertEqual(tokens[2].period, 60) | ||
XCTAssertEqual(tokens[2].secret, "V27AJDJS4HZM3CTQNZXLVCHJYE") | ||
|
||
XCTAssertEqual(tokens[3].digits, 6) | ||
XCTAssertEqual(tokens[3].type, TokenTypeEnum.TOTP) | ||
XCTAssertEqual(tokens[3].algorithm, TokenAlgorithmEnum.SHA1) | ||
XCTAssertEqual(tokens[3].issuer, "") | ||
XCTAssertEqual(tokens[3].account, "") | ||
XCTAssertEqual(tokens[3].period, 90) | ||
XCTAssertEqual(tokens[3].secret, "MGTMWSHCBRMOBRI2AXNJD4M332") | ||
} | ||
|
||
func testInvalidImport_Algorithm() throws { | ||
let json: JSON = | ||
|