Skip to content

Commit 4a8ea12

Browse files
committed
Add limited use tests
1 parent b5940dc commit 4a8ea12

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed

FirebaseAI/Tests/Unit/Fakes/AppCheckInteropFake.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,10 @@ class AppCheckInteropFake: NSObject, AppCheckInterop {
4040
return AppCheckTokenResultInteropFake(token: token, error: error)
4141
}
4242

43+
func getLimitedUseToken() async -> any FIRAppCheckTokenResultInterop {
44+
return AppCheckTokenResultInteropFake(token: "limited_use_\(token)", error: error)
45+
}
46+
4347
func tokenDidChangeNotificationName() -> String {
4448
fatalError("\(#function) not implemented.")
4549
}

FirebaseAI/Tests/Unit/GenerativeModelVertexAITests.swift

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -501,6 +501,31 @@ final class GenerativeModelVertexAITests: XCTestCase {
501501
_ = try await model.generateContent(testPrompt)
502502
}
503503

504+
func testGenerateContent_appCheck_validToken_limitedUse() async throws {
505+
let appCheckToken = "test-valid-token"
506+
model = GenerativeModel(
507+
modelName: testModelName,
508+
modelResourceName: testModelResourceName,
509+
firebaseInfo: GenerativeModelTestUtil.testFirebaseInfo(
510+
appCheck: AppCheckInteropFake(token: appCheckToken)
511+
),
512+
apiConfig: apiConfig,
513+
tools: nil,
514+
requestOptions: RequestOptions(),
515+
urlSession: urlSession,
516+
useLimitedUseAppCheckTokens: true
517+
)
518+
MockURLProtocol
519+
.requestHandler = try GenerativeModelTestUtil.httpRequestHandler(
520+
forResource: "unary-success-basic-reply-short",
521+
withExtension: "json",
522+
subdirectory: vertexSubdirectory,
523+
appCheckToken: "limited_use_\(appCheckToken)"
524+
)
525+
526+
_ = try await model.generateContent(testPrompt)
527+
}
528+
504529
func testGenerateContent_dataCollectionOff() async throws {
505530
let appCheckToken = "test-valid-token"
506531
model = GenerativeModel(

0 commit comments

Comments
 (0)