diff --git a/Chronos/Services/Import/ImportService.swift b/Chronos/Services/Import/ImportService.swift index 0131c24..62ec40d 100644 --- a/Chronos/Services/Import/ImportService.swift +++ b/Chronos/Services/Import/ImportService.swift @@ -18,7 +18,7 @@ public class ImportService { case .CHRONOS: return importFromChronos(json: inputJson) case .TWOFAS: - return importFrom2FAS(json: inputJson) + return importFromTwoFAS(json: inputJson) case .AEGIS: return importFromAegis(json: inputJson) case .RAIVO: @@ -100,12 +100,11 @@ extension ImportService { } } - func importFrom2FAS(json: JSON) -> [Token]? { + func importFromTwoFAS(json: JSON) -> [Token]? { var tokens: [Token] = [] for (key, subJson) in json["services"] { guard - let issuer = subJson["otp"]["issuer"].string, let account = subJson["otp"]["account"].string, let secret = subJson["secret"].string, let digits = subJson["otp"]["digits"].int, @@ -121,7 +120,7 @@ extension ImportService { } let token = Token() - token.issuer = issuer + token.issuer = subJson["otp"]["issuer"].string ?? "" token.account = account token.secret = secret token.digits = digits diff --git a/ChronosTests/Import/2FAS.swift b/ChronosTests/Import/2FAS.swift index edf1221..d17e758 100644 --- a/ChronosTests/Import/2FAS.swift +++ b/ChronosTests/Import/2FAS.swift @@ -244,6 +244,34 @@ final class TwoFASTests: XCTestCase { "serviceTypeID": "3cb83fc3-8e25-4df5-bdde-1f35611c1d0a", "updatedAt": 1_721_919_046_000, ], + [ + "icon": [ + "iconCollection": [ + "id": "A5B3FB65-4EC5-43E6-8EC1-49E24CA9E7AD", + ], + "label": [ + "backgroundColor": "Green", + "text": "UN", + ], + "selected": "Label", + ], + "name": "Unknown", + "order": [ + "position": 7, + ], + "otp": [ + "account": "noIssuer@mail.com", + "algorithm": "SHA1", + "counter": 22, + "digits": 6, + "period": 0, + "source": "manual", + "tokenType": "HOTP", + ], + "secret": "KQOZTMLOJBSMYWIO4BG4UTXDSR", + "serviceTypeID": "3cb83fc3-8e25-4df5-bdde-1f35611c1d0a", + "updatedAt": 1_721_919_046_000, + ], ], ] @@ -315,6 +343,14 @@ final class TwoFASTests: XCTestCase { XCTAssertEqual(tokens[7].account, "") XCTAssertEqual(tokens[7].counter, 22) XCTAssertEqual(tokens[7].secret, "KQOZTMLOJBSMYWIO4BG4UTXDSR") + + XCTAssertEqual(tokens[8].digits, 6) + XCTAssertEqual(tokens[8].type, TokenTypeEnum.HOTP) + XCTAssertEqual(tokens[8].algorithm, TokenAlgorithmEnum.SHA1) + XCTAssertEqual(tokens[8].issuer, "") + XCTAssertEqual(tokens[8].account, "noIssuer@mail.com") + XCTAssertEqual(tokens[8].counter, 22) + XCTAssertEqual(tokens[8].secret, "BB6B7FAYHW2G42ZA4FJHLRWWHU") } func testValidImport_Period() throws {