Skip to content

Commit

Permalink
Update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
kdubb committed Sep 12, 2021
1 parent 044874e commit 3e912a8
Show file tree
Hide file tree
Showing 10 changed files with 93 additions and 91 deletions.
26 changes: 1 addition & 25 deletions TestHosts/iOS/AppDelegate.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//
// AppDelegate.swift
// MessageSecurityTestHost
// ShieldTestHost
//
// Created by Kevin Wooten on 9/14/16.
// Copyright © 2016 Outfoxx, Inc. All rights reserved.
Expand All @@ -13,30 +13,6 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
// Override point for customization after application launch.
return true
}

func applicationWillResignActive(_ application: UIApplication) {
// Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
// Use this method to pause ongoing tasks, disable timers, and invalidate graphics rendering callbacks. Games should use this method to pause the game.
}

func applicationDidEnterBackground(_ application: UIApplication) {
// Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
// If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}

func applicationWillEnterForeground(_ application: UIApplication) {
// Called as part of the transition from the background to the active state; here you can undo many of the changes made on entering the background.
}

func applicationDidBecomeActive(_ application: UIApplication) {
// Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
}

func applicationWillTerminate(_ application: UIApplication) {
// Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}
}

12 changes: 1 addition & 11 deletions TestHosts/iOS/ViewController.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//
// ViewController.swift
// MessageSecurityTestHost
// ShieldTestHost
//
// Created by Kevin Wooten on 9/14/16.
// Copyright © 2016 Outfoxx, Inc. All rights reserved.
Expand All @@ -9,14 +9,4 @@
import UIKit

class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
}

override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}

14 changes: 14 additions & 0 deletions TestHosts/macOS/AppDelegate.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
//
// AppDelegate.swift
// ShieldTestHost
//
// Created by Kevin Wooten on 9/14/16.
// Copyright © 2016 Outfoxx, Inc. All rights reserved.
//

import AppKit

@NSApplicationMain
class AppDelegate: NSResponder, NSApplicationDelegate {
var window: NSWindow?
}
12 changes: 12 additions & 0 deletions TestHosts/macOS/ViewController.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
//
// ViewController.swift
// ShieldTestHost
//
// Created by Kevin Wooten on 9/14/16.
// Copyright © 2016 Outfoxx, Inc. All rights reserved.
//

import AppKit

class ViewController: NSViewController {
}
27 changes: 1 addition & 26 deletions TestHosts/tvOS/AppDelegate.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//
// AppDelegate.swift
// MessageSecurity-tvOSHost
// ShieldTestHost
//
// Created by Kevin Wooten on 6/7/18.
// Copyright © 2018 reTXT Labs LLC. All rights reserved.
Expand All @@ -12,32 +12,7 @@ import UIKit
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?


func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
// Override point for customization after application launch.
return true
}

func applicationWillResignActive(_ application: UIApplication) {
// Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
// Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
}

func applicationDidEnterBackground(_ application: UIApplication) {
// Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
// If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}

func applicationWillEnterForeground(_ application: UIApplication) {
// Called as part of the transition from the background to the active state; here you can undo many of the changes made on entering the background.
}

func applicationDidBecomeActive(_ application: UIApplication) {
// Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
}

func applicationWillTerminate(_ application: UIApplication) {
// Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}
}

7 changes: 1 addition & 6 deletions TestHosts/tvOS/ViewController.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//
// ViewController.swift
// MessageSecurity-tvOSHost
// ShieldTestHost
//
// Created by Kevin Wooten on 6/7/18.
// Copyright © 2018 reTXT Labs LLC. All rights reserved.
Expand All @@ -9,9 +9,4 @@
import UIKit

class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
}
}

10 changes: 5 additions & 5 deletions Tests/CertificationRequestBuilderTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import XCTest

class CertificationRequestBuilderTests: XCTestCase {

let outputEnabled = false
static let outputEnabled = false
static var keyPair: SecKeyPair!

override class func setUp() {
Expand All @@ -33,8 +33,8 @@ class CertificationRequestBuilderTests: XCTestCase {
let csr =
try CertificationRequest.Builder()
.subject(name: NameBuilder().add("Outfox Signing", forTypeName: "CN").name)
.alternativeNames(names: .dnsName("outfoxx.io"))
.publicKey(keyPair: Self.keyPair, usage: [.keyEncipherment])
.alternativeNames(names: .dnsName("outfoxx.io"))
.publicKey(keyPair: Self.keyPair, usage: [.keyCertSign, .cRLSign])
.extendedKeyUsage(keyPurposes: [kp.clientAuth.oid, kp.serverAuth.oid], isCritical: true)
.build(signingKey: Self.keyPair.privateKey, digestAlgorithm: .sha256)

Expand All @@ -44,12 +44,12 @@ class CertificationRequestBuilderTests: XCTestCase {
XCTAssertEqual(csr, csr2)

let csrAttrs = csr.certificationRequestInfo.attributes
XCTAssertEqual(try csrAttrs.first(Extensions.self)?.first(KeyUsage.self), [.keyEncipherment])
XCTAssertEqual(try csrAttrs.first(Extensions.self)?.first(KeyUsage.self), [.keyCertSign, .cRLSign])
XCTAssertEqual(try csrAttrs.first(Extensions.self)?.first(SubjectAltName.self), .init(names: [.dnsName("outfoxx.io")]))
}

func output(_ value: Encodable & SchemaSpecified) {
guard outputEnabled else { return }
guard Self.outputEnabled else { return }
guard let data = try? value.encoded().base64EncodedString() else { return }
print(data)
}
Expand Down
36 changes: 23 additions & 13 deletions Tests/SecCertificateTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import XCTest

class SecCertificateTests: XCTestCase {

static let outputEnabled = false
static var keyPair: SecKeyPair!

override class func setUp() {
Expand All @@ -26,21 +27,30 @@ class SecCertificateTests: XCTestCase {

func testCertificateProperties() throws {

let name = try NameBuilder().add("Unit Testing", forTypeName: "CN").name
let subjectName = try NameBuilder()
.add("Unit Testing", forTypeName: "CN")
.add("123456", forTypeName: "UID")
.name

let issuerName = try NameBuilder()
.add("Test Issuer", forTypeName: "CN")
.name

let certData =
try Certificate.Builder()
.subject(name: name)
.issuer(name: name)
.publicKey(keyPair: Self.keyPair, usage: [.keyEncipherment])
.subject(name: subjectName)
.issuer(name: issuerName)
.publicKey(keyPair: Self.keyPair, usage: [.keyCertSign, .cRLSign])
.valid(for: 86400 * 5)
.build(signingKey: Self.keyPair.privateKey, digestAlgorithm: .sha256)
.encoded()

output(certData)

let cert = SecCertificateCreateWithData(nil, certData as CFData)!

XCTAssertTrue(name == cert.issuerName!)
XCTAssertTrue(name == cert.subjectName!)
XCTAssertTrue(subjectName == cert.subjectName!)
XCTAssertTrue(issuerName == cert.issuerName!)
}

func testInvalidCertificate() throws {
Expand All @@ -58,12 +68,12 @@ class SecCertificateTests: XCTestCase {

let cert = SecCertificateCreateWithData(nil, certData as CFData)!

do {
_ = try cert.publicKeyValidated(trustedCertificates: [])
XCTFail("Should have thrown an error")
}
catch {
print(error)
}
XCTAssertThrowsError(try cert.publicKeyValidated(trustedCertificates: []))
}

func output(_ data: Data) {
guard Self.outputEnabled else { return }
print(data.base64EncodedString())
}

}
6 changes: 3 additions & 3 deletions Tests/SecKeyPairTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ class SecKeyPairTests: XCTestCase {

override func tearDownWithError() throws {

try rsaKeyPair?.delete()
try ecKeyPair?.delete()
try? rsaKeyPair?.delete()
try? ecKeyPair?.delete()

try super.tearDownWithError()
}

Expand Down
34 changes: 32 additions & 2 deletions project.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ options:
targets:
ShieldWrap:
type: framework.static
platform: [iOS, tvOS, watchOS]
platform: [macOS, iOS, tvOS, watchOS]
deploymentTarget:
macOS: 10.12
iOS: 10.0
Expand All @@ -24,9 +24,16 @@ targets:
- ShieldTests_${platform}
dependencies:
- package: Shield
settings:
PRODUCT_BUNDLE_IDENTIFIER: io.outfoxx.ShieldWrap
ShieldHost:
type: application
platform: [iOS, tvOS, watchOS]
platform: [macOS, iOS, tvOS, watchOS]
deploymentTarget:
macOS: 10.12
iOS: 10.0
tvOS: 10.0
watchOS: 3.0
sources:
- path: TestHosts/${platform}
createIntermediateGroups: true
Expand All @@ -36,14 +43,37 @@ targets:
path: Project/${platform}Host/Host.entitlements
properties:
keychain-access-groups: []
settings:
PRODUCT_BUNDLE_IDENTIFIER: io.outfoxx.ShieldHost


ShieldTests:
type: bundle.unit-test
platform: [iOS, tvOS, watchOS]
deploymentTarget:
iOS: 10.0
tvOS: 10.0
watchOS: 3.0
sources: [Tests]
dependencies:
- target: ShieldWrap_${platform}
link: true
- target: ShieldHost_${platform}
link: false
settings:
GENERATE_INFOPLIST_FILE: true
TEST_HOST: $(BUILT_PRODUCTS_DIR)/ShieldHost.app/ShieldHost

ShieldTests_macOS:
type: bundle.unit-test
platform: macOS
deploymentTarget: 10.12
sources: [Tests]
dependencies:
- target: ShieldWrap_macOS
link: true
- target: ShieldHost_macOS
link: false
settings:
GENERATE_INFOPLIST_FILE: true
TEST_HOST: $(BUILT_PRODUCTS_DIR)/ShieldHost.app/Contents/MacOS/ShieldHost

0 comments on commit 3e912a8

Please sign in to comment.