-
Notifications
You must be signed in to change notification settings - Fork 3
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
Showing
5 changed files
with
153 additions
and
4 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
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
74 changes: 74 additions & 0 deletions
74
STSecurityTests/STSecurityKeychainAccessPasswordTests.swift
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 |
---|---|---|
@@ -0,0 +1,74 @@ | ||
// Copyright (c) 2014 Scott Talbot. All rights reserved. | ||
|
||
import XCTest | ||
|
||
|
||
let service = "STSecurityTest" | ||
|
||
|
||
class STSecurityKeychainAccessPasswordTests: XCTestCase { | ||
|
||
override func setUp() { | ||
STSecurityKeychainAccess.deletePasswordsForService(service) | ||
} | ||
|
||
func testFetchNonexistent() { | ||
let username = "username" | ||
|
||
var error: NSError? | ||
let password: String? = STSecurityKeychainAccess.passwordForUsername(username, service: service, error: &error) | ||
XCTAssertNil(password) | ||
XCTAssertNotNil(error) | ||
} | ||
|
||
func testRoundtrip() { | ||
let username = "username" | ||
let password = "password" | ||
|
||
let status = STSecurityKeychainAccess.setPassword(password, forUsername: username, service: service) | ||
XCTAssertTrue(status) | ||
|
||
var error: NSError? | ||
let fetchedPassword: String? = STSecurityKeychainAccess.passwordForUsername(username, service: service, error: &error) | ||
XCTAssertNotNil(fetchedPassword) | ||
XCTAssertNil(error) | ||
XCTAssertEqual(password, fetchedPassword!) | ||
} | ||
|
||
func testMultipleInsertion() { | ||
let username = "username" | ||
let password = "password"; | ||
|
||
var error: NSError? | ||
|
||
let status1 = STSecurityKeychainAccess.setPassword(password, forUsername: username, service: service, error: &error) | ||
XCTAssertTrue(status1) | ||
XCTAssertNil(error) | ||
|
||
let status2 = STSecurityKeychainAccess.setPassword(password, forUsername: username, service: service, error: &error) | ||
XCTAssertFalse(status2) | ||
XCTAssertNotNil(error) | ||
|
||
let status3 = STSecurityKeychainAccess.setPassword(password, forUsername: username, service: service, withAccessibility: .AccessibleAlways, overwriteExisting: true, error: &error) | ||
XCTAssertTrue(status3) | ||
XCTAssertNil(error) | ||
|
||
let status4 = STSecurityKeychainAccess.setPassword(password, forUsername: username, service: service, error: &error) | ||
XCTAssertFalse(status4) | ||
XCTAssertNotNil(error) | ||
|
||
let status5 = STSecurityKeychainAccess.setPassword(password, forUsername: username, service: service, withAccessibility: .AccessibleAlwaysThisDeviceOnly, overwriteExisting: true, error: &error) | ||
XCTAssertTrue(status5) | ||
XCTAssertNil(error) | ||
|
||
let fetchedPassword: String? = STSecurityKeychainAccess.passwordForUsername(username, service: service, error: &error) | ||
XCTAssertNotNil(fetchedPassword); | ||
XCTAssertEqual(password, fetchedPassword!); | ||
XCTAssertNil(error) | ||
|
||
let status6 = STSecurityKeychainAccess.deletePasswordForUsername(username, service: service, error: &error) | ||
XCTAssertTrue(status6) | ||
XCTAssertNil(error) | ||
} | ||
|
||
} |
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 |
---|---|---|
@@ -0,0 +1,33 @@ | ||
// Copyright (c) 2014 Scott Talbot. All rights reserved. | ||
|
||
import XCTest | ||
|
||
|
||
class STSecurityTests: XCTestCase { | ||
|
||
func testRandom0() { | ||
let count: UInt = 0 | ||
var error: NSError? | ||
let randomData = STSecurityRandomization.dataWithRandomBytesOfLength(count, error: &error) | ||
|
||
XCTAssertNotNil(randomData, "STSecurityRandomization returned nil, error: \(error)") | ||
XCTAssertEqual(UInt(randomData.length), count, "STSecurityRandomization returned incorrect length of random data") | ||
} | ||
|
||
func testRandom1() { | ||
let count: UInt = 0 | ||
var error: NSError? | ||
let randomData = STSecurityRandomization.dataWithRandomBytesOfLength(count, error: &error) | ||
XCTAssertNotNil(randomData, "STSecurityRandomization returned nil, error: \(error)") | ||
XCTAssertEqual(UInt(randomData.length), count, "STSecurityRandomization returned incorrect length of random data") | ||
} | ||
|
||
func testRandom16() { | ||
let count: UInt = 16 | ||
var error: NSError? | ||
let randomData = STSecurityRandomization.dataWithRandomBytesOfLength(count, error: &error) | ||
XCTAssertNotNil(randomData, "STSecurityRandomization returned nil, error: \(error)") | ||
XCTAssertEqual(UInt(randomData.length), count, "STSecurityRandomization returned incorrect length of random data") | ||
} | ||
|
||
} |
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 |
---|---|---|
@@ -0,0 +1,6 @@ | ||
// Copyright (c) 2014 Scott Talbot. All rights reserved. | ||
|
||
#import <STSecurity/STSecurityRandomization.h> | ||
#import <STSecurity/STSecurityRSAKey.h> | ||
#import <STSecurity/STSecurityKeychainAccess.h> | ||
#import <STSecurity/STSecurityRSAEncryption.h> |