Skip to content

Commit

Permalink
added test for deleting account
Browse files Browse the repository at this point in the history
  • Loading branch information
tgymnich committed Jul 1, 2020
1 parent 7715a4c commit 073cc2f
Showing 1 changed file with 22 additions and 4 deletions.
26 changes: 22 additions & 4 deletions Tests/OTPKitTests/AccountTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -88,20 +88,37 @@ final class AccountTests: XCTestCase {

func testKeychainStore() {
let keychain = Keychain(service: "ch.gymni.test.otpauth")
defer { try! keychain.removeAll() }
let totp = TOTP(algorithm: .sha256, secret: "wew3k6ztd7kuh5ucg4pejqi4swwrrneh72ad2sdovikfatzbc5huto2j".base32DecodedData! , digits: 6, period: 30)
let account = Account(label: "foo", otp: totp)

XCTAssertNoThrow(try account.save(to: keychain))
defer {
try! keychain.removeAll()
}


let accounts = try? Account<TOTP>.loadAll(from: keychain)
XCTAssertNotNil(accounts)

XCTAssertEqual(accounts?.first, account)
}

func testKeychainRemove() {
let keychain = Keychain(service: "ch.gymni.test.otpauth")
defer { try! keychain.removeAll() }
let totp = TOTP(algorithm: .sha256, secret: "wew3k6ztd7kuh5ucg4pejqi4swwrrneh72ad2sdovikfatzbc5huto2j".base32DecodedData! , digits: 6, period: 30)
let account = Account(label: "foo", otp: totp)

XCTAssertNoThrow(try account.save(to: keychain))

var accounts = try? Account<TOTP>.loadAll(from: keychain)
XCTAssertNotNil(accounts)
XCTAssertEqual(accounts?.first, account)

XCTAssertNoThrow(try account.remove(from: keychain))

accounts = try? Account<TOTP>.loadAll(from: keychain)
XCTAssertNotNil(accounts)
XCTAssert(accounts!.isEmpty)
}

func testKeychainStoreMultiple() {
defer { try! keychain.removeAll() }
let keychain = Keychain(service: "ch.gymni.test.otpauth")
Expand All @@ -128,6 +145,7 @@ final class AccountTests: XCTestCase {
("testURLGenerationBasic1", testURLGenerationBasic1),
("testURLGenerationBasic2", testURLGenerationBasic2),
("testKeychainStore", testKeychainStore),
("testKeychainRemove", testKeychainRemove),
("testKeychainStoreMultiple", testKeychainStoreMultiple)
]

Expand Down

0 comments on commit 073cc2f

Please sign in to comment.