From a5318a13e1133a14f099640840f06140361d6e27 Mon Sep 17 00:00:00 2001 From: Andrew Heard Date: Tue, 31 Oct 2023 18:06:47 -0400 Subject: [PATCH] Remove FirebaseAppCheckIntegration SPM testTarget --- FirebaseAppCheck.podspec | 1 - .../Tests/Integration/AppCheckE2ETests.swift | 194 +++++++++--------- 2 files changed, 94 insertions(+), 101 deletions(-) diff --git a/FirebaseAppCheck.podspec b/FirebaseAppCheck.podspec index e9624916457..c61c74bac5e 100644 --- a/FirebaseAppCheck.podspec +++ b/FirebaseAppCheck.podspec @@ -96,7 +96,6 @@ Pod::Spec.new do |s| } swift_unit_tests.source_files = [ base_dir + 'Tests/Unit/Swift/**/*.swift', - base_dir + 'Tests/Unit/Swift/**/*.h', ] end diff --git a/FirebaseAppCheck/Tests/Integration/AppCheckE2ETests.swift b/FirebaseAppCheck/Tests/Integration/AppCheckE2ETests.swift index f1a30d7b3c3..fc8c025d6d0 100644 --- a/FirebaseAppCheck/Tests/Integration/AppCheckE2ETests.swift +++ b/FirebaseAppCheck/Tests/Integration/AppCheckE2ETests.swift @@ -16,139 +16,133 @@ import FirebaseAppCheck import FirebaseCore import XCTest -// Tests that use the Keychain require a host app and Swift Package Manager does not support adding -// a host app to test targets. -#if !SWIFT_PACKAGE - - final class AppCheckE2ETests: XCTestCase { - let appName = "test_app_name" - var app: FirebaseApp! - - override func setUp() { - AppCheck.setAppCheckProviderFactory(TestAppCheckProviderFactory()) - let options = FirebaseOptions( - googleAppID: "1:123456789:ios:abc123", - gcmSenderID: "123456789" - ) - options.projectID = "test_project_id" - options.apiKey = "test_api_key" - FirebaseApp.configure(name: appName, options: options) - - app = FirebaseApp.app(name: appName) - } +final class AppCheckE2ETests: XCTestCase { + let appName = "test_app_name" + var app: FirebaseApp! + + override func setUp() { + AppCheck.setAppCheckProviderFactory(TestAppCheckProviderFactory()) + let options = FirebaseOptions( + googleAppID: "1:123456789:ios:abc123", + gcmSenderID: "123456789" + ) + options.projectID = "test_project_id" + options.apiKey = "test_api_key" + FirebaseApp.configure(name: appName, options: options) + + app = FirebaseApp.app(name: appName) + } - override func tearDown() { - let semaphore = DispatchSemaphore(value: 0) - app.delete { _ in - semaphore.signal() - } - semaphore.wait() + override func tearDown() { + let semaphore = DispatchSemaphore(value: 0) + app.delete { _ in + semaphore.signal() } + semaphore.wait() + } - func testInitAppCheck() throws { - let appCheck = AppCheck.appCheck(app: app) - - XCTAssertNotNil(appCheck) - } + func testInitAppCheck() throws { + let appCheck = AppCheck.appCheck(app: app) - func testInitAppCheckDebugProvider() throws { - let debugProvider = AppCheckDebugProvider(app: app) + XCTAssertNotNil(appCheck) + } - XCTAssertNotNil(debugProvider) - } + func testInitAppCheckDebugProvider() throws { + let debugProvider = AppCheckDebugProvider(app: app) - func testInitAppCheckDebugProviderFactory() throws { - let debugProvider = AppCheckDebugProviderFactory().createProvider(with: app) + XCTAssertNotNil(debugProvider) + } - XCTAssertNotNil(debugProvider) - } + func testInitAppCheckDebugProviderFactory() throws { + let debugProvider = AppCheckDebugProviderFactory().createProvider(with: app) - @available(iOS 11.0, macOS 10.15, macCatalyst 13.0, tvOS 11.0, watchOS 9.0, *) - func testInitDeviceCheckProvider() throws { - let deviceCheckProvider = DeviceCheckProvider(app: app) + XCTAssertNotNil(debugProvider) + } - XCTAssertNotNil(deviceCheckProvider) - } + @available(iOS 11.0, macOS 10.15, macCatalyst 13.0, tvOS 11.0, watchOS 9.0, *) + func testInitDeviceCheckProvider() throws { + let deviceCheckProvider = DeviceCheckProvider(app: app) - @available(iOS 11.0, macOS 10.15, macCatalyst 13.0, tvOS 11.0, watchOS 9.0, *) - func testDeviceCheckProviderFactoryCreate() throws { - let deviceCheckProvider = DeviceCheckProviderFactory().createProvider(with: app) + XCTAssertNotNil(deviceCheckProvider) + } - XCTAssertNotNil(deviceCheckProvider) - } + @available(iOS 11.0, macOS 10.15, macCatalyst 13.0, tvOS 11.0, watchOS 9.0, *) + func testDeviceCheckProviderFactoryCreate() throws { + let deviceCheckProvider = DeviceCheckProviderFactory().createProvider(with: app) - @available(iOS 14.0, macOS 11.3, macCatalyst 14.5, tvOS 15.0, watchOS 9.0, *) - func testInitAppAttestProvider() throws { - let appAttestProvider = AppAttestProvider(app: app) + XCTAssertNotNil(deviceCheckProvider) + } - XCTAssertNotNil(appAttestProvider) - } + @available(iOS 14.0, macOS 11.3, macCatalyst 14.5, tvOS 15.0, watchOS 9.0, *) + func testInitAppAttestProvider() throws { + let appAttestProvider = AppAttestProvider(app: app) - // The following test is disabled on macOS since `token(forcingRefresh:handler:)` requires a - // provisioning profile to access the keychain to cache tokens. - // See go/firebase-macos-keychain-popups for more details. - #if !os(macOS) && !targetEnvironment(macCatalyst) - func testGetToken() throws { - guard let appCheck = AppCheck.appCheck(app: app) else { - XCTFail("AppCheck instance is nil.") - return - } - - let expectation = XCTestExpectation() - appCheck.token(forcingRefresh: true) { token, error in - XCTAssertNil(error) - XCTAssertNotNil(token) - XCTAssertEqual(token?.token, TestAppCheckProvider.tokenValue) - expectation.fulfill() - } - - wait(for: [expectation], timeout: 0.5) - } - #endif // !os(macOS) && !targetEnvironment(macCatalyst) + XCTAssertNotNil(appAttestProvider) + } - func testGetLimitedUseToken() throws { + // The following test is disabled on macOS since `token(forcingRefresh:handler:)` requires a + // provisioning profile to access the keychain to cache tokens. + // See go/firebase-macos-keychain-popups for more details. + #if !os(macOS) && !targetEnvironment(macCatalyst) + func testGetToken() throws { guard let appCheck = AppCheck.appCheck(app: app) else { XCTFail("AppCheck instance is nil.") return } let expectation = XCTestExpectation() - appCheck.limitedUseToken { token, error in + appCheck.token(forcingRefresh: true) { token, error in XCTAssertNil(error) XCTAssertNotNil(token) - XCTAssertEqual(token!.token, TestAppCheckProvider.limitedUseTokenValue) + XCTAssertEqual(token?.token, TestAppCheckProvider.tokenValue) expectation.fulfill() } wait(for: [expectation], timeout: 0.5) } - } - - class TestAppCheckProvider: NSObject, AppCheckProvider { - static let tokenValue = "TestToken" - static let limitedUseTokenValue = "TestLimitedUseToken" + #endif // !os(macOS) && !targetEnvironment(macCatalyst) - func getToken(completion handler: @escaping (AppCheckToken?, Error?) -> Void) { - let token = AppCheckToken( - token: TestAppCheckProvider.tokenValue, - expirationDate: Date.distantFuture - ) - handler(token, nil) + func testGetLimitedUseToken() throws { + guard let appCheck = AppCheck.appCheck(app: app) else { + XCTFail("AppCheck instance is nil.") + return } - func getLimitedUseToken(completion handler: @escaping (AppCheckToken?, Error?) -> Void) { - let token = AppCheckToken( - token: TestAppCheckProvider.limitedUseTokenValue, - expirationDate: Date.distantFuture - ) - handler(token, nil) + let expectation = XCTestExpectation() + appCheck.limitedUseToken { token, error in + XCTAssertNil(error) + XCTAssertNotNil(token) + XCTAssertEqual(token!.token, TestAppCheckProvider.limitedUseTokenValue) + expectation.fulfill() } + + wait(for: [expectation], timeout: 0.5) + } +} + +class TestAppCheckProvider: NSObject, AppCheckProvider { + static let tokenValue = "TestToken" + static let limitedUseTokenValue = "TestLimitedUseToken" + + func getToken(completion handler: @escaping (AppCheckToken?, Error?) -> Void) { + let token = AppCheckToken( + token: TestAppCheckProvider.tokenValue, + expirationDate: Date.distantFuture + ) + handler(token, nil) } - class TestAppCheckProviderFactory: NSObject, AppCheckProviderFactory { - func createProvider(with app: FirebaseApp) -> AppCheckProvider? { - return TestAppCheckProvider() - } + func getLimitedUseToken(completion handler: @escaping (AppCheckToken?, Error?) -> Void) { + let token = AppCheckToken( + token: TestAppCheckProvider.limitedUseTokenValue, + expirationDate: Date.distantFuture + ) + handler(token, nil) } +} -#endif // !SWIFT_PACKAGE +class TestAppCheckProviderFactory: NSObject, AppCheckProviderFactory { + func createProvider(with app: FirebaseApp) -> AppCheckProvider? { + return TestAppCheckProvider() + } +}