Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
47261fb
Add support for R-GCIP tenant configuration
srushtisv Jun 13, 2025
5515e6f
Moving TenantConfig to (regionalized) auth extension
srushtisv Jun 23, 2025
391eebb
Adding tenantConfig in AuthRequestConfiguration instead of individual…
srushtisv Jun 23, 2025
f8753b1
updating static factory method
srushtisv Jun 23, 2025
bd95317
add missing availability to regional Auth extension
srushtisv Jun 23, 2025
603c971
Add request/response RPCs for regional OIDC token exchange
srushtisv Jun 14, 2025
aebb8bb
enforce expiresIn field in ExchangeTokenResponse
srushtisv Jun 23, 2025
2458702
Add OIDC token exchange methods for BYO-CIAM
srushtisv Jun 14, 2025
80b35a7
adding regionalized folder
srushtisv Jun 24, 2025
bc22ad2
replacing prod-global with global
srushtisv Jun 24, 2025
9536ca4
lint fixes
srushtisv Jun 24, 2025
4b068b0
Removing function using completion handler for the new API
srushtisv Jun 24, 2025
bc40336
Add OIDC token exchange methods for BYO-CIAM
srushtisv Jun 14, 2025
296526d
Add tests for ExchangeTokenRequest
srushtisv Jun 14, 2025
591e590
update comments in exchange token tests
srushtisv Jun 14, 2025
0d97ade
Update ExchangeTokenRequestTests.swift from review
srushtisv Jun 23, 2025
edbaaf3
Add OIDC token exchange methods for BYO-CIAM
srushtisv Jun 14, 2025
78181e2
lint fixes
srushtisv Jun 24, 2025
b7ab3aa
Removing function using completion handler for the new API
srushtisv Jun 24, 2025
0b78065
updating ExchangeTokenRequestTests
srushtisv Jun 24, 2025
4a8edc3
Merge branch 'exchangeToken-auth' into exchange-token-tests
srushtisv Jun 24, 2025
4303bda
lint fix
srushtisv Jun 24, 2025
90835dd
sample app implementation
srushtisv Jun 24, 2025
e0e7bdd
updating exchange token request and response file
srushtisv Jun 24, 2025
dcd2ddb
lint fix
srushtisv Jun 24, 2025
a17edfc
removing settings to resolve failing checks
srushtisv Jun 24, 2025
e2ad1b3
update AuthenticationExampleUITests
srushtisv Jun 24, 2025
b999c0b
interop changes for byociam
srushtisv Jun 24, 2025
bff237a
resolving reviews from older PR14986
srushtisv Jun 24, 2025
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
154 changes: 154 additions & 0 deletions ExchangeTokenRequestTests.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,154 @@
// 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 Foundation
import XCTest

@testable import FirebaseAuth
import FirebaseCore

/// Tests for `ExchangeTokenRequest`
@available(iOS 13, *)
class ExchangeTokenRequestTests: XCTestCase {
// MARK: - Constants for Testing

let kAPIKey = "test-api-key"
let kProjectID = "test-project-id"
let kLocation = "us-east1"
let kTenantID = "test-tenant-id-123"
let kIdToken = "a-very-long-and-secure-oidc-token-string"
let kIdpConfigId = "oidc.my-test-provider"

let kProductionHost = "identityplatform.googleapis.com"
let kStagingHost = "staging-identityplatform.sandbox.googleapis.com"

// MARK: - Test Cases

/// Tests that the production URL is correctly formed for a specific region.
func testProductionURLIsCorrectlyConstructed() {
let (auth, app) = createTestAuthInstance(
projectID: kProjectID,
location: kLocation,
tenantId: kTenantID
)

let request = ExchangeTokenRequest(
idToken: kIdToken,
idpConfigID: kIdpConfigId,
config: auth.requestConfiguration,
useStaging: false
)

let expectedHost = "\(kLocation)-\(kProductionHost)"
let expectedURL = "https://\(expectedHost)/v2beta/projects/\(kProjectID)" +
"/locations/\(kLocation)/tenants/\(kTenantID)/idpConfigs/\(kIdpConfigId):exchangeOidcToken?key=\(kAPIKey)"

XCTAssertEqual(request.requestURL().absoluteString, expectedURL)
}

/// Tests that the production URL is correctly formed for the "prod-global" location.
func testProductionURLIsCorrectlyConstructedForGlobalLocation() {
let (auth, app) = createTestAuthInstance(
projectID: kProjectID,
location: "prod-global",
tenantId: kTenantID
)
_ = app

let request = ExchangeTokenRequest(
idToken: kIdToken,
idpConfigID: kIdpConfigId,
config: auth.requestConfiguration,
useStaging: false
)

let expectedHost = kProductionHost
let expectedURL = "https://\(expectedHost)/v2beta/projects/\(kProjectID)" +
"/locations/global/tenants/\(kTenantID)/idpConfigs/\(kIdpConfigId):exchangeOidcToken?key=\(kAPIKey)"

XCTAssertEqual(request.requestURL().absoluteString, expectedURL)
}

/// Tests that the staging URL is correctly formed.
func testStagingURLIsCorrectlyConstructed() {
let (auth, app) = createTestAuthInstance(
projectID: kProjectID,
location: kLocation,
tenantId: kTenantID
)
_ = app

let request = ExchangeTokenRequest(
idToken: kIdToken,
idpConfigID: kIdpConfigId,
config: auth.requestConfiguration,
useStaging: true
)

let expectedHost = "\(kLocation)-\(kStagingHost)"
let expectedURL = "https://\(expectedHost)/v2beta/projects/\(kProjectID)" +
"/locations/\(kLocation)/tenants/\(kTenantID)/idpConfigs/\(kIdpConfigId):exchangeOidcToken?key=\(kAPIKey)"

XCTAssertEqual(request.requestURL().absoluteString, expectedURL)
}

/// Tests that the unencoded HTTP body contains the correct id_token.
func testUnencodedHTTPBodyIsCorrect() {
let (auth, app) = createTestAuthInstance(
projectID: kProjectID,
location: kLocation,
tenantId: kTenantID
)
_ = app

let request = ExchangeTokenRequest(
idToken: kIdToken,
idpConfigID: kIdpConfigId,
config: auth.requestConfiguration
)

let body = request.unencodedHTTPRequestBody
XCTAssertNotNil(body)
XCTAssertEqual(body?.count, 1)
XCTAssertEqual(body?["id_token"] as? String, kIdToken)
}

// MARK: - Helper Function

/// Creates a test FirebaseApp and Auth instance with specified configurations.
private func createTestAuthInstance(projectID: String?, location: String?,
tenantId: String?) -> (auth: Auth, app: FirebaseApp) {
let appName = "TestApp-\(UUID().uuidString)"
let options = FirebaseOptions(
googleAppID: "1:1234567890:ios:abcdef123456",
gcmSenderID: "1234567890"
)
options.apiKey = kAPIKey
if let projectID = projectID {
options.projectID = projectID
}

if FirebaseApp.app(name: appName) != nil {
FirebaseApp.app(name: appName)?.delete { _ in }
}
let app = FirebaseApp(instanceWithName: appName, options: options)

let auth = Auth(app: app)
auth.app = app
auth.requestConfiguration.location = location
auth.requestConfiguration.tenantId = tenantId

return (auth, app)
}
}
Loading
Loading