This repository was archived by the owner on Jan 10, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 339
Expand file tree
/
Copy pathKeychainWrapperTests.swift
More file actions
57 lines (44 loc) · 2.44 KB
/
Copy pathKeychainWrapperTests.swift
File metadata and controls
57 lines (44 loc) · 2.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
//
// KeychainWrapperTests.swift
// SwiftKeychainWrapper
//
// Created by Jason Rendel on 4/25/16.
// Copyright © 2016 Jason Rendel. All rights reserved.
//
import XCTest
import SwiftKeychainWrapper
class KeychainWrapperTests: XCTestCase {
override func setUp() {
super.setUp()
// Put setup code here. This method is called before the invocation of each test method in the class.
}
override func tearDown() {
// Put teardown code here. This method is called after the invocation of each test method in the class.
super.tearDown()
}
func testCustomInstance() {
let uniqueServiceName = UUID().uuidString
let uniqueAccessGroup = UUID().uuidString
let customKeychainWrapperInstance = KeychainWrapper(serviceName: uniqueServiceName, accessGroup: uniqueAccessGroup)
XCTAssertNotEqual(customKeychainWrapperInstance.serviceName, KeychainWrapper.standard.serviceName, "Custom instance initialized with unique service name, should not match standard Service Name")
XCTAssertNotEqual(customKeychainWrapperInstance.accessGroup, KeychainWrapper.standard.accessGroup, "Custom instance initialized with unique access group, should not match standard Access Group")
}
func testAccessibility() {
let accessibilityOptions: [KeychainItemAccessibility] = [
.afterFirstUnlock,
.afterFirstUnlockThisDeviceOnly,
.whenPasscodeSetThisDeviceOnly,
.whenUnlocked,
.whenUnlockedThisDeviceOnly
]
let key = "testKey"
for accessibilityOption in accessibilityOptions {
KeychainWrapper.standard.set("Test123", forKey: key, withAccessibility: accessibilityOption)
let accessibilityForKey = KeychainWrapper.standard.accessibilityOfKey(key)
let accessibilityDescription = String(describing: accessibilityForKey)
XCTAssertEqual(accessibilityForKey, accessibilityOption, "Accessibility does not match. Expected: \(accessibilityOption) Found: \(accessibilityDescription)")
// INFO: If re-using a key but with a different accessibility, first remove the previous key value using removeObjectForKey(:withAccessibility) using the same accessibilty it was saved with
KeychainWrapper.standard.removeObject(forKey: key, withAccessibility: accessibilityOption)
}
}
}