Skip to content

Commit 88d1530

Browse files
authored
Replace FIRDeviceCheckAPIServiceE2ETests with AppCheckE2ETests (#12031)
1 parent 24be340 commit 88d1530

10 files changed

+128
-110
lines changed

FirebaseAppCheck.podspec

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -62,14 +62,13 @@ Pod::Spec.new do |s|
6262
}
6363
unit_tests.source_files = [
6464
base_dir + 'Tests/Unit/**/*.[mh]',
65-
base_dir + 'Tests/Utils/**/*.[mh]',
6665
'SharedTestUtilities/AppCheckFake/*',
6766
'SharedTestUtilities/AppCheckBackoffWrapperFake/*',
6867
'SharedTestUtilities/Date/*',
6968
'SharedTestUtilities/URLSession/*',
7069
]
7170

72-
unit_tests.resources = base_dir + 'Tests/Fixture/**/*'
71+
unit_tests.resources = base_dir + 'Tests/Unit/Fixture/**/*'
7372
unit_tests.dependency 'OCMock'
7473
unit_tests.requires_app_host = true
7574
end
@@ -81,10 +80,8 @@ Pod::Spec.new do |s|
8180
:tvos => tvos_deployment_target
8281
}
8382
integration_tests.source_files = [
84-
base_dir + 'Tests/Integration/**/*.[mh]',
85-
base_dir + 'Tests/Integration/**/*.[mh]',
83+
base_dir + 'Tests/Integration/**/*.swift',
8684
]
87-
integration_tests.resources = base_dir + 'Tests/Fixture/**/*'
8885
integration_tests.requires_app_host = true
8986
end
9087

Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
// Copyright 2023 Google LLC
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
import FirebaseAppCheck
16+
import FirebaseCore
17+
import XCTest
18+
19+
final class AppCheckE2ETests: XCTestCase {
20+
let appName = "test_app_name"
21+
var app: FirebaseApp!
22+
23+
override func setUp() {
24+
AppCheck.setAppCheckProviderFactory(TestAppCheckProviderFactory())
25+
let options = FirebaseOptions(
26+
googleAppID: "1:123456789:ios:abc123",
27+
gcmSenderID: "123456789"
28+
)
29+
options.projectID = "test_project_id"
30+
options.apiKey = "test_api_key"
31+
FirebaseApp.configure(name: appName, options: options)
32+
33+
app = FirebaseApp.app(name: appName)
34+
}
35+
36+
override func tearDown() {
37+
let semaphore = DispatchSemaphore(value: 0)
38+
app.delete { _ in
39+
semaphore.signal()
40+
}
41+
semaphore.wait()
42+
}
43+
44+
func testInitAppCheck() throws {
45+
let appCheck = AppCheck.appCheck(app: app)
46+
47+
XCTAssertNotNil(appCheck)
48+
}
49+
50+
func testInitAppCheckDebugProvider() throws {
51+
let debugProvider = AppCheckDebugProvider(app: app)
52+
53+
XCTAssertNotNil(debugProvider)
54+
}
55+
56+
func testInitAppCheckDebugProviderFactory() throws {
57+
let debugProvider = AppCheckDebugProviderFactory().createProvider(with: app)
58+
59+
XCTAssertNotNil(debugProvider)
60+
}
61+
62+
@available(iOS 11.0, macOS 10.15, macCatalyst 13.0, tvOS 11.0, watchOS 9.0, *)
63+
func testInitDeviceCheckProvider() throws {
64+
let deviceCheckProvider = DeviceCheckProvider(app: app)
65+
66+
XCTAssertNotNil(deviceCheckProvider)
67+
}
68+
69+
@available(iOS 11.0, macOS 10.15, macCatalyst 13.0, tvOS 11.0, watchOS 9.0, *)
70+
func testDeviceCheckProviderFactoryCreate() throws {
71+
let deviceCheckProvider = DeviceCheckProviderFactory().createProvider(with: app)
72+
73+
XCTAssertNotNil(deviceCheckProvider)
74+
}
75+
76+
@available(iOS 14.0, macOS 11.3, macCatalyst 14.5, tvOS 15.0, watchOS 9.0, *)
77+
func testInitAppAttestProvider() throws {
78+
let appAttestProvider = AppAttestProvider(app: app)
79+
80+
XCTAssertNotNil(appAttestProvider)
81+
}
82+
83+
// The following test is disabled on macOS since `token(forcingRefresh:handler:)` requires a
84+
// provisioning profile to access the keychain to cache tokens.
85+
// See go/firebase-macos-keychain-popups for more details.
86+
#if !os(macOS) && !targetEnvironment(macCatalyst)
87+
func testGetToken() throws {
88+
guard let appCheck = AppCheck.appCheck(app: app) else {
89+
XCTFail("AppCheck instance is nil.")
90+
return
91+
}
92+
93+
let expectation = XCTestExpectation()
94+
appCheck.token(forcingRefresh: true) { token, error in
95+
XCTAssertNil(error)
96+
XCTAssertNotNil(token)
97+
XCTAssertEqual(token?.token, TestAppCheckProvider.tokenValue)
98+
expectation.fulfill()
99+
}
100+
101+
wait(for: [expectation], timeout: 0.5)
102+
}
103+
#endif // !os(macOS) && !targetEnvironment(macCatalyst)
104+
}
105+
106+
class TestAppCheckProvider: NSObject, AppCheckProvider {
107+
static let tokenValue = "TestToken"
108+
109+
func getToken(completion handler: @escaping (AppCheckToken?, Error?) -> Void) {
110+
let token = AppCheckToken(
111+
token: TestAppCheckProvider.tokenValue,
112+
expirationDate: Date.distantFuture
113+
)
114+
handler(token, nil)
115+
}
116+
}
117+
118+
class TestAppCheckProviderFactory: NSObject, AppCheckProviderFactory {
119+
func createProvider(with app: FirebaseApp) -> AppCheckProvider? {
120+
return TestAppCheckProvider()
121+
}
122+
}

FirebaseAppCheck/Tests/Integration/FIRDeviceCheckAPIServiceE2ETests.m

Lines changed: 0 additions & 101 deletions
This file was deleted.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

Package.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1256,17 +1256,17 @@ let package = Package(
12561256
"SharedTestUtilities",
12571257
.product(name: "OCMock", package: "ocmock"),
12581258
],
1259-
path: "FirebaseAppCheck/Tests",
1259+
path: "FirebaseAppCheck/Tests/Unit",
12601260
exclude: [
12611261
// Swift tests are in the target `FirebaseAppCheckUnitSwift` since mixed language targets
1262-
// are not supported (as of Xcode 14.3).
1263-
"Unit/Swift",
1262+
// are not supported (as of Xcode 15.0).
1263+
"Swift",
12641264
],
12651265
resources: [
12661266
.process("Fixture"),
12671267
],
12681268
cSettings: [
1269-
.headerSearchPath("../.."),
1269+
.headerSearchPath("../../.."),
12701270
]
12711271
),
12721272
.testTarget(

0 commit comments

Comments
 (0)