Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace FIRDeviceCheckAPIServiceE2ETests with AppCheckE2ETests #12031

Merged
merged 2 commits into from
Nov 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 2 additions & 5 deletions FirebaseAppCheck.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -62,14 +62,13 @@ Pod::Spec.new do |s|
}
unit_tests.source_files = [
base_dir + 'Tests/Unit/**/*.[mh]',
base_dir + 'Tests/Utils/**/*.[mh]',
'SharedTestUtilities/AppCheckFake/*',
'SharedTestUtilities/AppCheckBackoffWrapperFake/*',
'SharedTestUtilities/Date/*',
'SharedTestUtilities/URLSession/*',
]

unit_tests.resources = base_dir + 'Tests/Fixture/**/*'
unit_tests.resources = base_dir + 'Tests/Unit/Fixture/**/*'
unit_tests.dependency 'OCMock'
unit_tests.requires_app_host = true
end
Expand All @@ -81,10 +80,8 @@ Pod::Spec.new do |s|
:tvos => tvos_deployment_target
}
integration_tests.source_files = [
base_dir + 'Tests/Integration/**/*.[mh]',
base_dir + 'Tests/Integration/**/*.[mh]',
base_dir + 'Tests/Integration/**/*.swift',
]
integration_tests.resources = base_dir + 'Tests/Fixture/**/*'
integration_tests.requires_app_host = true
end

Expand Down
122 changes: 122 additions & 0 deletions FirebaseAppCheck/Tests/Integration/AppCheckE2ETests.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
// Copyright 2023 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

import FirebaseAppCheck
import FirebaseCore
import XCTest

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()
}

func testInitAppCheck() throws {
let appCheck = AppCheck.appCheck(app: app)

XCTAssertNotNil(appCheck)
}

func testInitAppCheckDebugProvider() throws {
let debugProvider = AppCheckDebugProvider(app: app)

XCTAssertNotNil(debugProvider)
}

func testInitAppCheckDebugProviderFactory() throws {
let debugProvider = AppCheckDebugProviderFactory().createProvider(with: app)

XCTAssertNotNil(debugProvider)
}

@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(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)

XCTAssertNotNil(deviceCheckProvider)
}

@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(appAttestProvider)
}

// 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)
}

class TestAppCheckProvider: NSObject, AppCheckProvider {
static let tokenValue = "TestToken"

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()
}
}
101 changes: 0 additions & 101 deletions FirebaseAppCheck/Tests/Integration/FIRDeviceCheckAPIServiceE2ETests.m

This file was deleted.

8 changes: 4 additions & 4 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1256,17 +1256,17 @@ let package = Package(
"SharedTestUtilities",
.product(name: "OCMock", package: "ocmock"),
],
path: "FirebaseAppCheck/Tests",
path: "FirebaseAppCheck/Tests/Unit",
exclude: [
// Swift tests are in the target `FirebaseAppCheckUnitSwift` since mixed language targets
// are not supported (as of Xcode 14.3).
"Unit/Swift",
// are not supported (as of Xcode 15.0).
"Swift",
],
resources: [
.process("Fixture"),
],
cSettings: [
.headerSearchPath("../.."),
.headerSearchPath("../../.."),
]
),
.testTarget(
Expand Down
Loading