Skip to content

Commit

Permalink
Move test fixture JSON responses to subdir
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewheard committed Oct 31, 2023
1 parent 930823c commit ace85bb
Show file tree
Hide file tree
Showing 9 changed files with 87 additions and 94 deletions.
3 changes: 1 addition & 2 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 Down
170 changes: 82 additions & 88 deletions FirebaseAppCheck/Tests/Integration/AppCheckE2ETests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,113 +16,107 @@ 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)
func testInitAppCheck() throws {
let appCheck = AppCheck.appCheck(app: app)

XCTAssertNotNil(appCheck)
}
XCTAssertNotNil(appCheck)
}

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

XCTAssertNotNil(debugProvider)
}
XCTAssertNotNil(debugProvider)
}

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

XCTAssertNotNil(debugProvider)
}
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)
@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)
}
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 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 14.0, macOS 11.3, macCatalyst 14.5, tvOS 15.0, watchOS 9.0, *)
func testInitAppAttestProvider() throws {
let appAttestProvider = AppAttestProvider(app: 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(appAttestProvider)
}
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)
// 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
}
#endif // !os(macOS) && !targetEnvironment(macCatalyst)
}

class TestAppCheckProvider: NSObject, AppCheckProvider {
static let tokenValue = "TestToken"
let expectation = XCTestExpectation()
appCheck.token(forcingRefresh: true) { token, error in
XCTAssertNil(error)
XCTAssertNotNil(token)
XCTAssertEqual(token?.token, TestAppCheckProvider.tokenValue)
expectation.fulfill()
}

func getToken(completion handler: @escaping (AppCheckToken?, Error?) -> Void) {
let token = AppCheckToken(
token: TestAppCheckProvider.tokenValue,
expirationDate: Date.distantFuture
)
handler(token, nil)
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()
}
class TestAppCheckProviderFactory: NSObject, AppCheckProviderFactory {
func createProvider(with app: FirebaseApp) -> AppCheckProvider? {
return TestAppCheckProvider()
}

#endif // !SWIFT_PACKAGE
}
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

0 comments on commit ace85bb

Please sign in to comment.