-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Vertex AI] Add integration tests for App Check failure (#14008)
- Loading branch information
1 parent
33a44a9
commit 5366717
Showing
5 changed files
with
133 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
FirebaseVertexAI/Tests/TestApp/Sources/TestAppCheckProviderFactory.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
// Copyright 2024 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 Foundation | ||
|
||
/// An `AppCheckProviderFactory` for the Test App. | ||
/// | ||
/// Defaults to the `AppCheckDebugProvider` unless the `FirebaseApp` `name` contains | ||
/// ``notConfiguredName``, in which case App Check is not configured; this facilitates integration | ||
/// testing of App Check failure cases. | ||
public class TestAppCheckProviderFactory: NSObject, AppCheckProviderFactory { | ||
/// The name, or a substring of the name, of Firebase apps where App Check is not configured. | ||
public static let notConfiguredName = "app-check-not-configured" | ||
|
||
/// Returns the `AppCheckDebugProvider` unless `app.name` contains ``notConfiguredName``. | ||
public func createProvider(with app: FirebaseApp) -> (any AppCheckProvider)? { | ||
if app.name.contains(TestAppCheckProviderFactory.notConfiguredName) { | ||
return nil | ||
} | ||
|
||
return AppCheckDebugProvider(app: app) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
FirebaseVertexAI/Tests/TestApp/Tests/Utilities/FirebaseAppTestUtils.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
// Copyright 2024 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 FirebaseCore | ||
|
||
extension FirebaseApp { | ||
/// Configures another `FirebaseApp` with the specified `name` and the same `FirebaseOptions`. | ||
func namedCopy(name: String) throws -> FirebaseApp { | ||
FirebaseApp.configure(name: name, options: options) | ||
guard let app = FirebaseApp.app(name: name) else { | ||
throw AppNotFound(name: name) | ||
} | ||
return app | ||
} | ||
|
||
/// Configures an app with the specified `name` and the same `FirebaseOptions` as the default app. | ||
static func defaultNamedCopy(name: String) throws -> FirebaseApp { | ||
guard FirebaseApp.isDefaultAppConfigured(), let defaultApp = FirebaseApp.app() else { | ||
throw DefaultAppNotConfigured() | ||
} | ||
return try defaultApp.namedCopy(name: name) | ||
} | ||
|
||
struct AppNotFound: Error { | ||
let name: String | ||
} | ||
|
||
struct DefaultAppNotConfigured: Error {} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters