Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions STSecurity.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
2C55A1781617C70700C54B8C /* STSecurityRSAEncryption.m in Sources */ = {isa = PBXBuildFile; fileRef = 2C55A1771617C70700C54B8C /* STSecurityRSAEncryption.m */; };
2C55A17E161832D400C54B8C /* STSecurityRSAEncryptionTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 2C55A17D161832D400C54B8C /* STSecurityRSAEncryptionTests.m */; };
2C5F7EED161B03D200001538 /* STSecurityKeychainAccessPasswordTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 2C5F7EEC161B03D200001538 /* STSecurityKeychainAccessPasswordTests.m */; };
2C9D7FB919583C4C00E662D6 /* STSecurityRandomizationTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2C9D7FB819583C4C00E662D6 /* STSecurityRandomizationTests.swift */; };
2C9D7FBB19583C5B00E662D6 /* STSecurityKeychainAccessPasswordTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2C9D7FBA19583C5B00E662D6 /* STSecurityKeychainAccessPasswordTests.swift */; };
2CBC57E61615D8C000FF15E9 /* STSecurityRandomization.h in CopyFiles */ = {isa = PBXBuildFile; fileRef = 2CBC57E51615D8C000FF15E9 /* STSecurityRandomization.h */; };
2CBC57E81615D8C000FF15E9 /* STSecurityRandomization.m in Sources */ = {isa = PBXBuildFile; fileRef = 2CBC57E71615D8C000FF15E9 /* STSecurityRandomization.m */; };
2CBC57F31615D8C000FF15E9 /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 2CBC57E01615D8C000FF15E9 /* Foundation.framework */; };
Expand All @@ -26,6 +28,13 @@
/* End PBXBuildFile section */

/* Begin PBXContainerItemProxy section */
2C9D7FB619583BAA00E662D6 /* PBXContainerItemProxy */ = {
isa = PBXContainerItemProxy;
containerPortal = 2CBC57D41615D8C000FF15E9 /* Project object */;
proxyType = 1;
remoteGlobalIDString = 2CBC57DC1615D8C000FF15E9;
remoteInfo = STSecurity;
};
2CBC57F41615D8C000FF15E9 /* PBXContainerItemProxy */ = {
isa = PBXContainerItemProxy;
containerPortal = 2CBC57D41615D8C000FF15E9 /* Project object */;
Expand Down Expand Up @@ -67,11 +76,14 @@
2C55A1771617C70700C54B8C /* STSecurityRSAEncryption.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = STSecurityRSAEncryption.m; sourceTree = "<group>"; };
2C55A17D161832D400C54B8C /* STSecurityRSAEncryptionTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = STSecurityRSAEncryptionTests.m; sourceTree = "<group>"; };
2C5F7EEC161B03D200001538 /* STSecurityKeychainAccessPasswordTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = STSecurityKeychainAccessPasswordTests.m; sourceTree = "<group>"; };
2C6FF2F2194094DE0070CA3A /* STSecurityTests-Bridging-Header.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "STSecurityTests-Bridging-Header.h"; sourceTree = "<group>"; };
2C9C1E571711A2AA003E19B9 /* Target.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = Target.xcconfig; sourceTree = "<group>"; };
2C9C1E581711A2CC003E19B9 /* Project-Debug.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = "Project-Debug.xcconfig"; sourceTree = "<group>"; };
2C9C1E591711A2E6003E19B9 /* Project-Coverage.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = "Project-Coverage.xcconfig"; sourceTree = "<group>"; };
2C9C1E5A1711A2F0003E19B9 /* Project-Release.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = "Project-Release.xcconfig"; sourceTree = "<group>"; };
2C9C1E5E1711A3CA003E19B9 /* Project.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = Project.xcconfig; sourceTree = "<group>"; };
2C9D7FB819583C4C00E662D6 /* STSecurityRandomizationTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = STSecurityRandomizationTests.swift; sourceTree = "<group>"; };
2C9D7FBA19583C5B00E662D6 /* STSecurityKeychainAccessPasswordTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = STSecurityKeychainAccessPasswordTests.swift; sourceTree = "<group>"; };
2CBC57DD1615D8C000FF15E9 /* libSTSecurity.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = libSTSecurity.a; sourceTree = BUILT_PRODUCTS_DIR; };
2CBC57E01615D8C000FF15E9 /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = System/Library/Frameworks/Foundation.framework; sourceTree = SDKROOT; };
2CBC57E51615D8C000FF15E9 /* STSecurityRandomization.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = STSecurityRandomization.h; sourceTree = "<group>"; };
Expand Down Expand Up @@ -128,6 +140,7 @@
2CBC57DE1615D8C000FF15E9 /* Products */,
);
sourceTree = "<group>";
usesTabs = 1;
};
2CBC57DE1615D8C000FF15E9 /* Products */ = {
isa = PBXGroup;
Expand Down Expand Up @@ -168,10 +181,13 @@
isa = PBXGroup;
children = (
2CBC57F91615D8C000FF15E9 /* Info.plist */,
2C6FF2F2194094DE0070CA3A /* STSecurityTests-Bridging-Header.h */,
2CBC57FE1615D8C000FF15E9 /* STSecurityRandomizationTests.m */,
2C9D7FB819583C4C00E662D6 /* STSecurityRandomizationTests.swift */,
2C1D8D03161931CB009EB62A /* STSecurityRSAKeyTests.m */,
2C55A17416171D3000C54B8C /* STSecurityKeychainAccessRSATests.m */,
2C5F7EEC161B03D200001538 /* STSecurityKeychainAccessPasswordTests.m */,
2C9D7FBA19583C5B00E662D6 /* STSecurityKeychainAccessPasswordTests.swift */,
2C55A17D161832D400C54B8C /* STSecurityRSAEncryptionTests.m */,
);
path = STSecurityTests;
Expand Down Expand Up @@ -210,6 +226,7 @@
);
dependencies = (
2CBC57F51615D8C000FF15E9 /* PBXTargetDependency */,
2C9D7FB719583BAA00E662D6 /* PBXTargetDependency */,
);
name = STSecurityTests;
productName = STSecurityTests;
Expand All @@ -224,6 +241,11 @@
attributes = {
LastUpgradeCheck = 0610;
ORGANIZATIONNAME = "Scott Talbot";
TargetAttributes = {
2CBC57ED1615D8C000FF15E9 = {
TestTargetID = 2CBC57DC1615D8C000FF15E9;
};
};
};
buildConfigurationList = 2CBC57D71615D8C000FF15E9 /* Build configuration list for PBXProject "STSecurity" */;
compatibilityVersion = "Xcode 3.2";
Expand Down Expand Up @@ -269,7 +291,9 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
2C9D7FB919583C4C00E662D6 /* STSecurityRandomizationTests.swift in Sources */,
2CBC57FF1615D8C000FF15E9 /* STSecurityRandomizationTests.m in Sources */,
2C9D7FBB19583C5B00E662D6 /* STSecurityKeychainAccessPasswordTests.swift in Sources */,
2C55A17516171D3000C54B8C /* STSecurityKeychainAccessRSATests.m in Sources */,
2C55A17E161832D400C54B8C /* STSecurityRSAEncryptionTests.m in Sources */,
2C1D8D04161931CB009EB62A /* STSecurityRSAKeyTests.m in Sources */,
Expand All @@ -280,6 +304,11 @@
/* End PBXSourcesBuildPhase section */

/* Begin PBXTargetDependency section */
2C9D7FB719583BAA00E662D6 /* PBXTargetDependency */ = {
isa = PBXTargetDependency;
target = 2CBC57DC1615D8C000FF15E9 /* STSecurity */;
targetProxy = 2C9D7FB619583BAA00E662D6 /* PBXContainerItemProxy */;
};
2CBC57F51615D8C000FF15E9 /* PBXTargetDependency */ = {
isa = PBXTargetDependency;
target = 2CBC57DC1615D8C000FF15E9 /* STSecurity */;
Expand Down Expand Up @@ -312,7 +341,9 @@
"$(inherited)",
);
INFOPLIST_FILE = STSecurityTests/Info.plist;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
PRODUCT_NAME = STSecurityTests;
SWIFT_OBJC_BRIDGING_HEADER = "STSecurityTests/STSecurityTests-Bridging-Header.h";
};
name = Coverage;
};
Expand Down Expand Up @@ -354,7 +385,9 @@
"$(inherited)",
);
INFOPLIST_FILE = STSecurityTests/Info.plist;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
PRODUCT_NAME = STSecurityTests;
SWIFT_OBJC_BRIDGING_HEADER = "STSecurityTests/STSecurityTests-Bridging-Header.h";
};
name = Debug;
};
Expand All @@ -368,7 +401,9 @@
"$(inherited)",
);
INFOPLIST_FILE = STSecurityTests/Info.plist;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
PRODUCT_NAME = STSecurityTests;
SWIFT_OBJC_BRIDGING_HEADER = "STSecurityTests/STSecurityTests-Bridging-Header.h";
};
name = Release;
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
</BuildActionEntry>
<BuildActionEntry
buildForTesting = "YES"
buildForRunning = "YES"
buildForRunning = "NO"
buildForProfiling = "NO"
buildForArchiving = "NO"
buildForAnalyzing = "NO">
Expand All @@ -40,7 +40,7 @@
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
shouldUseLaunchSchemeArgsEnv = "YES"
buildConfiguration = "Debug">
buildConfiguration = "Coverage">
<Testables>
<TestableReference
skipped = "NO">
Expand All @@ -55,13 +55,14 @@
</Testables>
</TestAction>
<LaunchAction
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
selectedDebuggerIdentifier = ""
selectedLauncherIdentifier = "Xcode.IDEFoundation.Launcher.PosixSpawn"
launchStyle = "0"
useCustomWorkingDirectory = "NO"
buildConfiguration = "Debug"
ignoresPersistentStateOnLaunch = "NO"
debugDocumentVersioning = "YES"
debugXPCServices = "NO"
allowLocationSimulation = "YES">
<AdditionalOptions>
</AdditionalOptions>
Expand Down
74 changes: 74 additions & 0 deletions STSecurityTests/STSecurityKeychainAccessPasswordTests.swift
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)
}

}
33 changes: 33 additions & 0 deletions STSecurityTests/STSecurityRandomizationTests.swift
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")
}

}
6 changes: 6 additions & 0 deletions STSecurityTests/STSecurityTests-Bridging-Header.h
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>