From 19e3136bfb787782845637b76ac247e5dab247f8 Mon Sep 17 00:00:00 2001 From: Antoine Gamond Date: Tue, 3 Nov 2020 13:35:44 +0100 Subject: [PATCH 1/4] Add support for SPM --- Package.swift | 18 ++++++++++++++++++ Tests/Factors/OktaFactorOtherTests.swift | 1 + Tests/Mocks/OktaAuthHTTPClientMock.swift | 1 + .../OktaAuthStatusRecoveryChallengeTests.swift | 1 + .../Statuses/OktaAuthStatusRecoveryTests.swift | 1 + .../Statuses/OktaAuthStatusSuccessTests.swift | 1 + .../OktaAuthStatusUnauthenticatedTests.swift | 1 + 7 files changed, 24 insertions(+) create mode 100644 Package.swift diff --git a/Package.swift b/Package.swift new file mode 100644 index 0000000..6a875c5 --- /dev/null +++ b/Package.swift @@ -0,0 +1,18 @@ +// swift-tools-version:5.1 +// The swift-tools-version declares the minimum version of Swift required to build this package. + +import PackageDescription + +let package = Package( + name: "OktaAuthNative", + platforms: [ + .macOS(.v10_14), .iOS(.v10) + ], + products: [ + .library(name: "OktaAuthNative", targets: ["OktaAuthNative"]) + ], + targets: [ + .target(name: "OktaAuthNative", dependencies: [], path: "Source", exclude: ["Source/Info.plist"]), + .testTarget(name: "OktaAuthNative_Tests", dependencies: ["OktaAuthNative"], path: "Tests", exclude: ["AuthenticationClientTests.swift"]) + ] +) diff --git a/Tests/Factors/OktaFactorOtherTests.swift b/Tests/Factors/OktaFactorOtherTests.swift index abc8af5..1c88755 100644 --- a/Tests/Factors/OktaFactorOtherTests.swift +++ b/Tests/Factors/OktaFactorOtherTests.swift @@ -11,6 +11,7 @@ */ import XCTest +@testable import OktaAuthNative class OktaFactorOtherTests: OktaFactorTestCase { diff --git a/Tests/Mocks/OktaAuthHTTPClientMock.swift b/Tests/Mocks/OktaAuthHTTPClientMock.swift index 05d853b..909b7c4 100644 --- a/Tests/Mocks/OktaAuthHTTPClientMock.swift +++ b/Tests/Mocks/OktaAuthHTTPClientMock.swift @@ -11,6 +11,7 @@ */ import Foundation +@testable import OktaAuthNative class OktaAuthHTTPClientMock: OktaHTTPRequestListenerProtocol { diff --git a/Tests/Statuses/OktaAuthStatusRecoveryChallengeTests.swift b/Tests/Statuses/OktaAuthStatusRecoveryChallengeTests.swift index 8ee542c..8171360 100644 --- a/Tests/Statuses/OktaAuthStatusRecoveryChallengeTests.swift +++ b/Tests/Statuses/OktaAuthStatusRecoveryChallengeTests.swift @@ -11,6 +11,7 @@ */ import XCTest +@testable import OktaAuthNative class OktaAuthStatusRecoveryChallengeTests: XCTestCase { diff --git a/Tests/Statuses/OktaAuthStatusRecoveryTests.swift b/Tests/Statuses/OktaAuthStatusRecoveryTests.swift index c82bb41..1eac64e 100644 --- a/Tests/Statuses/OktaAuthStatusRecoveryTests.swift +++ b/Tests/Statuses/OktaAuthStatusRecoveryTests.swift @@ -11,6 +11,7 @@ */ import XCTest +@testable import OktaAuthNative class OktaAuthStatusRecoveryTests: XCTestCase { diff --git a/Tests/Statuses/OktaAuthStatusSuccessTests.swift b/Tests/Statuses/OktaAuthStatusSuccessTests.swift index 6e5ae34..5b9796d 100644 --- a/Tests/Statuses/OktaAuthStatusSuccessTests.swift +++ b/Tests/Statuses/OktaAuthStatusSuccessTests.swift @@ -11,6 +11,7 @@ */ import XCTest +@testable import OktaAuthNative class OktaAuthStatusSuccessTests: XCTestCase { diff --git a/Tests/Statuses/OktaAuthStatusUnauthenticatedTests.swift b/Tests/Statuses/OktaAuthStatusUnauthenticatedTests.swift index 66e568c..0470cf1 100644 --- a/Tests/Statuses/OktaAuthStatusUnauthenticatedTests.swift +++ b/Tests/Statuses/OktaAuthStatusUnauthenticatedTests.swift @@ -11,6 +11,7 @@ */ import XCTest +@testable import OktaAuthNative class OktaAuthStatusUnauthenticatedTests: XCTestCase { From 77bee857693090dd6706c28e552b790b15682866 Mon Sep 17 00:00:00 2001 From: Mike Nachbaur Date: Wed, 25 Nov 2020 16:49:57 -0800 Subject: [PATCH 2/4] Resolve SPM test errors in accessing test resources --- OktaAuthNative.xcodeproj/project.pbxproj | 5 ++-- Tests/DomainObjects/OktaModelsTests.swift | 6 +---- Tests/E2E/E2ETests.swift | 20 +++++++++----- Tests/Mocks/OktaAPIMock.swift | 33 +++++++++++------------ Tests/Utils/TestResponse.swift | 7 +---- 5 files changed, 34 insertions(+), 37 deletions(-) diff --git a/OktaAuthNative.xcodeproj/project.pbxproj b/OktaAuthNative.xcodeproj/project.pbxproj index 3de25d7..2b6b0b6 100644 --- a/OktaAuthNative.xcodeproj/project.pbxproj +++ b/OktaAuthNative.xcodeproj/project.pbxproj @@ -191,7 +191,7 @@ A12F4FF82238311A00DB9147 /* OktaAuthSdk.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = OktaAuthSdk.swift; sourceTree = ""; }; A151096B2281FD3F009AF8EB /* OktaAuthStatusPasswordWarningTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = OktaAuthStatusPasswordWarningTests.swift; sourceTree = ""; }; A1671552227BA90700E7801D /* Unknown_State_And_FactorResult */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = Unknown_State_And_FactorResult; sourceTree = ""; }; - A172512122E91B82007E460B /* E2ETests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = E2ETests.swift; path = Tests/E2E/E2ETests.swift; sourceTree = SOURCE_ROOT; }; + A172512122E91B82007E460B /* E2ETests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = E2ETests.swift; sourceTree = ""; }; A179276C2229BDB90001C889 /* OktaAuthSdk.podspec */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = OktaAuthSdk.podspec; sourceTree = ""; }; A1920F77225E64D0007D50D2 /* OktaFactor.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = OktaFactor.swift; path = Factors/OktaFactor.swift; sourceTree = ""; }; A1920F7B225E67A1007D50D2 /* OktaFactorPush.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = OktaFactorPush.swift; path = Factors/OktaFactorPush.swift; sourceTree = ""; }; @@ -403,8 +403,7 @@ children = ( A172512122E91B82007E460B /* E2ETests.swift */, ); - name = E2E; - path = "New Group"; + path = E2E; sourceTree = ""; }; A1920F76225E6396007D50D2 /* Factors */ = { diff --git a/Tests/DomainObjects/OktaModelsTests.swift b/Tests/DomainObjects/OktaModelsTests.swift index 0671742..efafe56 100644 --- a/Tests/DomainObjects/OktaModelsTests.swift +++ b/Tests/DomainObjects/OktaModelsTests.swift @@ -339,10 +339,6 @@ class OktaModelsTests: XCTestCase { // MARK: - Utils private func readResponse(named name: String) -> Data? { - guard let url = Bundle.init(for: self.classForCoder).url(forResource: name, withExtension: nil) else { - return nil - } - - return try? Data(contentsOf: url) + return OktaAPIMock.dataFor(resource: name) } } diff --git a/Tests/E2E/E2ETests.swift b/Tests/E2E/E2ETests.swift index 008ecdd..dd75042 100644 --- a/Tests/E2E/E2ETests.swift +++ b/Tests/E2E/E2ETests.swift @@ -15,18 +15,26 @@ import XCTest class E2ETests: XCTestCase { - let username = ProcessInfo.processInfo.environment["USERNAME"]! - let password = ProcessInfo.processInfo.environment["PASSWORD"]! - let urlString = ProcessInfo.processInfo.environment["DOMAIN_URL"]! - let phoneNumber = ProcessInfo.processInfo.environment["PHONE"]! - let answer = ProcessInfo.processInfo.environment["ANSWER"]! + let username = ProcessInfo.processInfo.environment["USERNAME"] ?? "" + let password = ProcessInfo.processInfo.environment["PASSWORD"] ?? "" + let urlString = ProcessInfo.processInfo.environment["DOMAIN_URL"] ?? "" + let phoneNumber = ProcessInfo.processInfo.environment["PHONE"] ?? "" + let answer = ProcessInfo.processInfo.environment["ANSWER"] ?? "" var primaryAuthUser: (username: String, password: String)? var factorRequiredUser: (username: String, password: String)? var factorEnrollmentUser: (username: String, password: String)? - override func setUp() { + override func setUpWithError() throws { + try super.setUpWithError() + try XCTSkipIf(username.count == 0 || + password.count == 0 || + urlString.count == 0 || + phoneNumber.count == 0 || + answer.count == 0, + file: "Environment settings not configured") + if let _ = primaryAuthUser, let _ = factorRequiredUser { return diff --git a/Tests/Mocks/OktaAPIMock.swift b/Tests/Mocks/OktaAPIMock.swift index 2ac7054..97c7d14 100644 --- a/Tests/Mocks/OktaAPIMock.swift +++ b/Tests/Mocks/OktaAPIMock.swift @@ -14,22 +14,28 @@ import Foundation import OktaAuthNative class OktaAPIMock: OktaAPI { + static let resourcesDirectory = URL(fileURLWithPath: #file).appendingPathComponent("../../Resources").standardized + static func dataFor(resource name: String) -> Data? { + #if SWIFT_PACKAGE + let url = OktaAPIMock.resourcesDirectory.appendingPathComponent(name) + #else + let url = Bundle.init(for: OktaAPIMock.self).url(forResource: name, withExtension: nil)! + #endif + do { + return try Data(contentsOf: url) + } catch { + return nil + } + } public init?(successCase: Bool, json: String?, resourceName: String?) { var jsonData: Data? if let resourceName = resourceName { - - let url = Bundle.init(for: OktaAPIMock.self).url(forResource: resourceName, withExtension: nil) - do { - jsonData = try Data(contentsOf: url!) - } catch { - return nil - } + jsonData = OktaAPIMock.dataFor(resource: resourceName) } if let json = json { - jsonData = json.data(using: .utf8) } @@ -402,20 +408,13 @@ class OktaAPIMock: OktaAPI { func getPayloadData(json: String?, resourceName: String?) -> Data? { var jsonData: Data? - if let resourceName = resourceName, - let url = Bundle.init(for: OktaAPIMock.self).url(forResource: resourceName, withExtension: nil) { - - do { - jsonData = try Data(contentsOf: url) - } catch { - return nil - } + if let resourceName = resourceName { + jsonData = OktaAPIMock.dataFor(resource: resourceName) } else { return nil } if let json = json { - jsonData = json.data(using: .utf8) } diff --git a/Tests/Utils/TestResponse.swift b/Tests/Utils/TestResponse.swift index 5651af7..7049842 100644 --- a/Tests/Utils/TestResponse.swift +++ b/Tests/Utils/TestResponse.swift @@ -37,12 +37,7 @@ enum TestResponse: String { case Unknown_State_And_FactorResult = "Unknown_State_And_FactorResult" func data() -> Data? { - guard let file = Bundle(for: OktaAPIMock.self).url(forResource: self.rawValue, withExtension: nil), - let data = try? Data(contentsOf: file) else { - return nil - } - - return data + return OktaAPIMock.dataFor(resource: self.rawValue) } func parse() -> OktaAPISuccessResponse? { From b4654b812c289885dc68173d17be711225537e56 Mon Sep 17 00:00:00 2001 From: Mike Nachbaur Date: Wed, 25 Nov 2020 16:53:02 -0800 Subject: [PATCH 3/4] Update the README to include instructions for installing using SPM --- README.md | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/README.md b/README.md index 19dc6cf..64adf50 100644 --- a/README.md +++ b/README.md @@ -86,6 +86,15 @@ If you do not already have a **Developer Edition Account**, you can create one a ## Getting started +### Swift Package Manager + +Add the following to the `dependencies` attribute defined in your `Package.swift` file. You can select the version using the `majorVersion` and `minor` parameters. For example: +``` + dependencies: [ + .Package(url: "https://github.com/okta/okta-auth-swift.git", majorVersion: , minor: ) + ] +``` + ### CocoaPods This SDK is available through [CocoaPods](http://cocoapods.org). To install it, simply add the following line to your Podfile: From 6b83bacef37ee94a516a3289f5187972564c9afa Mon Sep 17 00:00:00 2001 From: Mike Nachbaur Date: Tue, 1 Dec 2020 11:16:09 -0800 Subject: [PATCH 4/4] Update Travis CI build to include SPM, Cocoapods, and Carthage verification steps --- .travis.yml | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/.travis.yml b/.travis.yml index 4d92b3e..4df32f5 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,5 +1,20 @@ language: objective-c -osx_image: xcode10.1 -xcode_workspace: OktaAuthSdk.xcworkspace -xcode_scheme: OktaAuthNative iOS -xcode_destination: platform=iOS Simulator,OS=latest,name=iPhone 8 +osx_image: xcode11.5 +jobs: + include: + - stage: Unit tests iOS + name: iOS + script: + - xcodebuild -workspace OktaAuthSdk.xcworkspace -scheme "OktaAuthNative iOS" -destination "platform=iOS Simulator,OS=latest,name=iPhone 11" clean test + - stage: Swift Package Manager validation + name: MacOS + script: + - swift test + - stage: Cocoapods validation + name: iOS + script: + - pod lib lint --allow-warnings + - stage: Carthage validation + name: iOS + script: + - carthage build --no-skip-current