Skip to content

Commit

Permalink
Updates to get tests building on Linux
Browse files Browse the repository at this point in the history
  • Loading branch information
mikenachbaur-okta committed Oct 29, 2024
1 parent 26ed076 commit 6d8542b
Show file tree
Hide file tree
Showing 8 changed files with 51 additions and 41 deletions.
44 changes: 24 additions & 20 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ var package = Package(
.library(name: "AuthFoundation", targets: ["AuthFoundation"]),
.library(name: "OktaOAuth2", targets: ["OktaOAuth2"]),
.library(name: "OktaDirectAuth", targets: ["OktaDirectAuth"]),
.library(name: "WebAuthenticationUI", targets: ["WebAuthenticationUI"])
],
dependencies: [
.package(url: "https://github.com/apple/swift-docc-plugin", from: "1.0.0"),
Expand Down Expand Up @@ -234,25 +233,6 @@ var package = Package(
.target(name: "AuthFoundationTestCommon"),
],
resources: [ .process("MockResponses") ]),

// WebAuthenticationUI
.target(name: "WebAuthenticationUI",
dependencies: [
.target(name: "OktaOAuth2")
],
exclude: exclude(),
resources: include(.process("Resources"))),
.testTarget(name: "WebAuthenticationUITests",
dependencies: [
.target(name: "WebAuthenticationUI"),
.target(name: "OktaOAuth2"),
.target(name: "AuthFoundation"),
.target(name: "TestCommon"),
.target(name: "KeychainTestCommon"),
.target(name: "APIClientTestCommon"),
.target(name: "AuthFoundationTestCommon"),
],
resources: [ .process("MockResponses") ]),
],
swiftLanguageVersions: [.v5]
)
Expand All @@ -267,3 +247,27 @@ for target in package.targets where target.type != .system && target.type != .te
])
}
#endif

#if canImport(Darwin)
// WebAuthenticationUI
package.products.append(.library(name: "WebAuthenticationUI", targets: ["WebAuthenticationUI"]))
package.targets.append(contentsOf: [
.target(name: "WebAuthenticationUI",
dependencies: [
.target(name: "OktaOAuth2")
],
exclude: exclude(),
resources: include(.process("Resources"))),
.testTarget(name: "WebAuthenticationUITests",
dependencies: [
.target(name: "WebAuthenticationUI"),
.target(name: "OktaOAuth2"),
.target(name: "AuthFoundation"),
.target(name: "TestCommon"),
.target(name: "KeychainTestCommon"),
.target(name: "APIClientTestCommon"),
.target(name: "AuthFoundationTestCommon"),
],
resources: [ .process("MockResponses") ]),
])
#endif
2 changes: 1 addition & 1 deletion Sources/APIClient/APIClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
import Foundation

#if os(Linux)
import FoundationNetworking
@_exported import FoundationNetworking
#endif

import OktaUtilities
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@
import Foundation
import OktaUtilities

#if os(Linux)
import FoundationNetworking
#endif

extension DefaultTimeCoordinator: APIClientDelegate {
public func api(client: any APIClient, didSend request: URLRequest, received response: HTTPURLResponse) {
guard request.cachePolicy == .reloadIgnoringLocalAndRemoteCacheData,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,6 @@ extension Credential {
/// Defines a custom LocalAuthentication context for interactions with this credential, for systems that support it.
case context(_ obj: LAContext)
#endif
#else
public static var standard: [Security] = []
#endif
}
}
2 changes: 1 addition & 1 deletion Sources/JWT/Internal/DefaultTokenHashValidator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public struct DefaultTokenHashValidator: TokenHashValidator {
}

#if !canImport(CommonCrypto)
func validate(_ string: String, idToken: JWT) throws {
public func validate(_ string: String, idToken: JWT) throws {
throw JWTError.signatureVerificationUnavailable
}
#else
Expand Down
2 changes: 1 addition & 1 deletion Sources/OktaConcurrency/CoalescedResult.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
// See the License for the specific language governing permissions and limitations under the License.
//

import Foundation
@preconcurrency import Foundation

public final class CoalescedResult<T: Sendable>: Sendable {
private let lock = Lock()
Expand Down
34 changes: 19 additions & 15 deletions Tests/AuthFoundationTests/CredentialNotificationTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -56,22 +56,26 @@ final class CredentialNotificationTests: XCTestCase {
coordinator = nil
}

@MainActor
func testNotifications() throws {
let oldCredential = coordinator.default
let wait = expectation(description: "Main actor")

let recorder = NotificationRecorder(observing: [.defaultCredentialChanged])

let credential = try coordinator.store(token: token, security: [])
wait(for: .standard)
XCTAssertEqual(recorder.notifications.count, 1)
XCTAssertEqual(recorder.notifications.first?.object as? Credential, credential)
XCTAssertNotEqual(oldCredential, credential)

recorder.reset()
coordinator.default = nil
wait(for: .standard)
XCTAssertEqual(recorder.notifications.count, 1)
XCTAssertNil(recorder.notifications.first?.object)
Task { @MainActor in
let oldCredential = coordinator.default

let recorder = NotificationRecorder(observing: [.defaultCredentialChanged])

let credential = try coordinator.store(token: token, security: [])
self.wait(for: .standard)
XCTAssertEqual(recorder.notifications.count, 1)
XCTAssertEqual(recorder.notifications.first?.object as? Credential, credential)
XCTAssertNotEqual(oldCredential, credential)

recorder.reset()
coordinator.default = nil
self.wait(for: .standard)
XCTAssertEqual(recorder.notifications.count, 1)
XCTAssertNil(recorder.notifications.first?.object)
}
waitForExpectations(timeout: .long)
}
}
2 changes: 1 addition & 1 deletion Tests/OktaUtilitiesTests/SDKVersionMigrationTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ enum TestMigratorError: Error {
case generic
}

class TestMigrator: AnyObject, SDKVersionMigrator, @unchecked Sendable {
class TestMigrator: SDKVersionMigrator, @unchecked Sendable {
var error: Error?
private(set) var migrationCalled: Bool = false

Expand Down

0 comments on commit 6d8542b

Please sign in to comment.