From c30cdeb50242c1e2b1462e0ca07309c473be3dec Mon Sep 17 00:00:00 2001 From: Santhosh Ramaraju Date: Thu, 16 Nov 2023 11:02:52 -0600 Subject: [PATCH] Fixing tests --- .../FactorStepHandlerTests.swift | 24 +++++++++---------- Tests/OktaOAuth2Tests/OAuth2ClientTests.swift | 3 ++- 2 files changed, 14 insertions(+), 13 deletions(-) diff --git a/Tests/OktaDirectAuthTests/FactorStepHandlerTests.swift b/Tests/OktaDirectAuthTests/FactorStepHandlerTests.swift index bcb596f30..c9bb3145a 100644 --- a/Tests/OktaDirectAuthTests/FactorStepHandlerTests.swift +++ b/Tests/OktaDirectAuthTests/FactorStepHandlerTests.swift @@ -261,7 +261,7 @@ final class FactorStepHandlerTests: XCTestCase { loginHint: "jane.doe@example.com", factor: factor) - let wait = expectation(description: "process") + let processExpectation = expectation(description: "process") handler.process { result in guard case .success(let status) = result, case .bindingUpdate(let context) = status else { @@ -282,9 +282,9 @@ final class FactorStepHandlerTests: XCTestCase { } } XCTAssertEqual(context.oobResponse.oobCode, "1c266114-a1be-4252-8ad1-04986c5b9ac1") - wait.fulfill() + processExpectation.fulfill() } - waitForExpectations(timeout: 5) + wait(for: [processExpectation], timeout: 5) } func testPrimaryOOBBindingTransferFail() throws { @@ -305,7 +305,7 @@ final class FactorStepHandlerTests: XCTestCase { loginHint: "jane.doe@example.com", factor: factor) - let wait = expectation(description: "process") + let processExpectation = expectation(description: "process") handler.process { result in switch result { case .success(_): @@ -313,9 +313,9 @@ final class FactorStepHandlerTests: XCTestCase { case .failure(let error): XCTAssertEqual(error, .bindingCodeMissing) } - wait.fulfill() + processExpectation.fulfill() } - waitForExpectations(timeout: 5) + wait(for: [processExpectation], timeout: 5) } func testPrimaryOOBMFARequired() throws { @@ -411,7 +411,7 @@ final class FactorStepHandlerTests: XCTestCase { mfaToken: "abcd1234")), factor: factor) - let wait = expectation(description: "process") + let processExpectation = expectation(description: "process") handler.process { result in guard case .success(let status) = result, case .bindingUpdate(let context) = status else { @@ -432,9 +432,9 @@ final class FactorStepHandlerTests: XCTestCase { } } XCTAssertEqual(context.oobResponse.oobCode, "1c266114-a1be-4252-8ad1-04986c5b9ac1") - wait.fulfill() + processExpectation.fulfill() } - waitForExpectations(timeout: 5) + wait(for: [processExpectation], timeout: 5) } func testSecondaryOOBBindingTransferFail() throws { @@ -456,7 +456,7 @@ final class FactorStepHandlerTests: XCTestCase { mfaToken: "abcd1234")), factor: factor) - let wait = expectation(description: "process") + let processExpectation = expectation(description: "process") handler.process { result in switch result { case .success(_): @@ -464,9 +464,9 @@ final class FactorStepHandlerTests: XCTestCase { case .failure(let error): XCTAssertEqual(error.errorDescription, DirectAuthenticationFlowError.bindingCodeMissing.errorDescription) } - wait.fulfill() + processExpectation.fulfill() } - waitForExpectations(timeout: 5) + wait(for: [processExpectation], timeout: 5) } private func assertGettingTokenAfterBindingTransfer(using handler: StepHandler) { diff --git a/Tests/OktaOAuth2Tests/OAuth2ClientTests.swift b/Tests/OktaOAuth2Tests/OAuth2ClientTests.swift index e66fb193c..a3a7af2ab 100644 --- a/Tests/OktaOAuth2Tests/OAuth2ClientTests.swift +++ b/Tests/OktaOAuth2Tests/OAuth2ClientTests.swift @@ -82,6 +82,7 @@ final class OAuth2ClientTests: XCTestCase { func testExchangeFailed() throws { let pkce = PKCE() + Token.idTokenValidator = MockIDTokenValidator(error: .invalidIssuer) let (openIdConfiguration, openIdData) = try openIdConfiguration(named: "openid-configuration-invalid-issuer") let clientConfiguration = try OAuth2Client.Configuration(domain: "example.com", clientId: "client_id", @@ -114,8 +115,8 @@ final class OAuth2ClientTests: XCTestCase { return } XCTAssertEqual(invalidIssuer as? JWTError, JWTError.invalidIssuer) + expect.fulfill() } - expect.fulfill() waitForExpectations(timeout: 1.0) { error in XCTAssertNil(error)