Skip to content

Commit

Permalink
Merge pull request #139 from mikenachbaur-okta/feature/spm-support
Browse files Browse the repository at this point in the history
Feature/spm support
  • Loading branch information
mikenachbaur-okta authored Dec 1, 2020
2 parents a70e41b + 6b83bac commit 8ac7c07
Show file tree
Hide file tree
Showing 14 changed files with 86 additions and 41 deletions.
23 changes: 19 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -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
5 changes: 2 additions & 3 deletions OktaAuthNative.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@
A12F4FF82238311A00DB9147 /* OktaAuthSdk.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = OktaAuthSdk.swift; sourceTree = "<group>"; };
A151096B2281FD3F009AF8EB /* OktaAuthStatusPasswordWarningTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = OktaAuthStatusPasswordWarningTests.swift; sourceTree = "<group>"; };
A1671552227BA90700E7801D /* Unknown_State_And_FactorResult */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = Unknown_State_And_FactorResult; sourceTree = "<group>"; };
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 = "<group>"; };
A179276C2229BDB90001C889 /* OktaAuthSdk.podspec */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = OktaAuthSdk.podspec; sourceTree = "<group>"; };
A1920F77225E64D0007D50D2 /* OktaFactor.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = OktaFactor.swift; path = Factors/OktaFactor.swift; sourceTree = "<group>"; };
A1920F7B225E67A1007D50D2 /* OktaFactorPush.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = OktaFactorPush.swift; path = Factors/OktaFactorPush.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -403,8 +403,7 @@
children = (
A172512122E91B82007E460B /* E2ETests.swift */,
);
name = E2E;
path = "New Group";
path = E2E;
sourceTree = "<group>";
};
A1920F76225E6396007D50D2 /* Factors */ = {
Expand Down
18 changes: 18 additions & 0 deletions Package.swift
Original file line number Diff line number Diff line change
@@ -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"])
]
)
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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: <majorVersion>, minor: <minor>)
]
```

### CocoaPods
This SDK is available through [CocoaPods](http://cocoapods.org). To install it, simply add the following line to your Podfile:

Expand Down
6 changes: 1 addition & 5 deletions Tests/DomainObjects/OktaModelsTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
20 changes: 14 additions & 6 deletions Tests/E2E/E2ETests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions Tests/Factors/OktaFactorOtherTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
*/

import XCTest
@testable import OktaAuthNative

class OktaFactorOtherTests: OktaFactorTestCase {

Expand Down
33 changes: 16 additions & 17 deletions Tests/Mocks/OktaAPIMock.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down Expand Up @@ -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)
}

Expand Down
1 change: 1 addition & 0 deletions Tests/Mocks/OktaAuthHTTPClientMock.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
*/

import Foundation
@testable import OktaAuthNative

class OktaAuthHTTPClientMock: OktaHTTPRequestListenerProtocol {

Expand Down
1 change: 1 addition & 0 deletions Tests/Statuses/OktaAuthStatusRecoveryChallengeTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
*/

import XCTest
@testable import OktaAuthNative

class OktaAuthStatusRecoveryChallengeTests: XCTestCase {

Expand Down
1 change: 1 addition & 0 deletions Tests/Statuses/OktaAuthStatusRecoveryTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
*/

import XCTest
@testable import OktaAuthNative

class OktaAuthStatusRecoveryTests: XCTestCase {

Expand Down
1 change: 1 addition & 0 deletions Tests/Statuses/OktaAuthStatusSuccessTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
*/

import XCTest
@testable import OktaAuthNative

class OktaAuthStatusSuccessTests: XCTestCase {

Expand Down
1 change: 1 addition & 0 deletions Tests/Statuses/OktaAuthStatusUnauthenticatedTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
*/

import XCTest
@testable import OktaAuthNative

class OktaAuthStatusUnauthenticatedTests: XCTestCase {

Expand Down
7 changes: 1 addition & 6 deletions Tests/Utils/TestResponse.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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? {
Expand Down

0 comments on commit 8ac7c07

Please sign in to comment.