From 495c464623143c03b386115741915cf5b98bb695 Mon Sep 17 00:00:00 2001 From: Joel-David Date: Wed, 7 Aug 2024 16:29:09 +0800 Subject: [PATCH] Added period test --- ChronosTests/Import/2FAS.swift | 166 +++++++++++++++++++++++++++++++++ 1 file changed, 166 insertions(+) diff --git a/ChronosTests/Import/2FAS.swift b/ChronosTests/Import/2FAS.swift index 272d4b5..48acb41 100644 --- a/ChronosTests/Import/2FAS.swift +++ b/ChronosTests/Import/2FAS.swift @@ -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": "user1+totp@test.com", + "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": "user2+totp@test.com", + "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": "user3+totp@test.com", + "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, "user1+totp@test.com") + 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, "user2+totp@test.com") + 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, "user3+totp@test.com") + 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 =