|
12 | 12 | // See the License for the specific language governing permissions and
|
13 | 13 | // limitations under the License.
|
14 | 14 |
|
15 |
| -@testable import FirebaseAuth |
16 |
| -import Foundation |
17 |
| -import XCTest |
| 15 | +#if os(iOS) || os(tvOS) || os(macOS) |
18 | 16 |
|
19 |
| -@available(iOS 15.0, macOS 12.0, tvOS 16.0, *) |
20 |
| -class FinalizePasskeyEnrollmentRequestTests: XCTestCase { |
21 |
| - private var request: FinalizePasskeyEnrollmentRequest! |
22 |
| - private var fakeConfig: AuthRequestConfiguration! |
| 17 | + @testable import FirebaseAuth |
| 18 | + import FirebaseCore |
| 19 | + import Foundation |
| 20 | + import XCTest |
23 | 21 |
|
24 |
| - override func setUp() { |
25 |
| - super.setUp() |
26 |
| - fakeConfig = AuthRequestConfiguration( |
27 |
| - apiKey: "FAKE_API_KEY", |
28 |
| - appID: "FAKE_APP_ID" |
29 |
| - ) |
30 |
| - } |
| 22 | + @available(iOS 15.0, macOS 12.0, tvOS 16.0, *) |
| 23 | + class FinalizePasskeyEnrollmentRequestTests: XCTestCase { |
| 24 | + private var request: FinalizePasskeyEnrollmentRequest! |
| 25 | + private var fakeConfig: AuthRequestConfiguration! |
31 | 26 |
|
32 |
| - override func tearDown() { |
33 |
| - request = nil |
34 |
| - fakeConfig = nil |
35 |
| - super.tearDown() |
36 |
| - } |
| 27 | + override func setUp() { |
| 28 | + super.setUp() |
| 29 | + fakeConfig = AuthRequestConfiguration( |
| 30 | + apiKey: "FAKE_API_KEY", |
| 31 | + appID: "FAKE_APP_ID" |
| 32 | + ) |
| 33 | + } |
37 | 34 |
|
38 |
| - func testInitWithValidParameters() { |
39 |
| - request = FinalizePasskeyEnrollmentRequest( |
40 |
| - idToken: "ID_TOKEN", |
41 |
| - name: "MyPasskey", |
42 |
| - credentialID: "CRED_ID", |
43 |
| - clientDataJSON: "CLIENT_JSON", |
44 |
| - attestationObject: "ATTEST_OBJ", |
45 |
| - requestConfiguration: fakeConfig |
46 |
| - ) |
| 35 | + override func tearDown() { |
| 36 | + request = nil |
| 37 | + fakeConfig = nil |
| 38 | + super.tearDown() |
| 39 | + } |
47 | 40 |
|
48 |
| - XCTAssertEqual(request.idToken, "ID_TOKEN") |
49 |
| - XCTAssertEqual(request.name, "MyPasskey") |
50 |
| - XCTAssertEqual(request.credentialID, "CRED_ID") |
51 |
| - XCTAssertEqual(request.clientDataJSON, "CLIENT_JSON") |
52 |
| - XCTAssertEqual(request.attestationObject, "ATTEST_OBJ") |
53 |
| - XCTAssertEqual(request.endpoint, "accounts/passkeyEnrollment:finalize") |
54 |
| - XCTAssertTrue(request.useIdentityPlatform) |
55 |
| - } |
| 41 | + func testInitWithValidParameters() { |
| 42 | + request = FinalizePasskeyEnrollmentRequest( |
| 43 | + idToken: "ID_TOKEN", |
| 44 | + name: "MyPasskey", |
| 45 | + credentialID: "CRED_ID", |
| 46 | + clientDataJSON: "CLIENT_JSON", |
| 47 | + attestationObject: "ATTEST_OBJ", |
| 48 | + requestConfiguration: fakeConfig |
| 49 | + ) |
56 | 50 |
|
57 |
| - func testUnencodedHTTPRequestBodyWithoutTenantId() { |
58 |
| - request = FinalizePasskeyEnrollmentRequest( |
59 |
| - idToken: "ID_TOKEN", |
60 |
| - name: "MyPasskey", |
61 |
| - credentialID: "CRED_ID", |
62 |
| - clientDataJSON: "CLIENT_JSON", |
63 |
| - attestationObject: "ATTEST_OBJ", |
64 |
| - requestConfiguration: fakeConfig |
65 |
| - ) |
| 51 | + XCTAssertEqual(request.idToken, "ID_TOKEN") |
| 52 | + XCTAssertEqual(request.name, "MyPasskey") |
| 53 | + XCTAssertEqual(request.credentialID, "CRED_ID") |
| 54 | + XCTAssertEqual(request.clientDataJSON, "CLIENT_JSON") |
| 55 | + XCTAssertEqual(request.attestationObject, "ATTEST_OBJ") |
| 56 | + XCTAssertEqual(request.endpoint, "accounts/passkeyEnrollment:finalize") |
| 57 | + XCTAssertTrue(request.useIdentityPlatform) |
| 58 | + } |
66 | 59 |
|
67 |
| - let body = request.unencodedHTTPRequestBody |
68 |
| - XCTAssertNotNil(body) |
69 |
| - XCTAssertEqual(body?["idToken"] as? String, "ID_TOKEN") |
70 |
| - XCTAssertEqual(body?["name"] as? String, "MyPasskey") |
| 60 | + func testUnencodedHTTPRequestBodyWithoutTenantId() { |
| 61 | + request = FinalizePasskeyEnrollmentRequest( |
| 62 | + idToken: "ID_TOKEN", |
| 63 | + name: "MyPasskey", |
| 64 | + credentialID: "CRED_ID", |
| 65 | + clientDataJSON: "CLIENT_JSON", |
| 66 | + attestationObject: "ATTEST_OBJ", |
| 67 | + requestConfiguration: fakeConfig |
| 68 | + ) |
71 | 69 |
|
72 |
| - let authReg = body?["authenticatorRegistrationResponse"] as? [String: AnyHashable] |
73 |
| - XCTAssertNotNil(authReg) |
74 |
| - XCTAssertEqual(authReg?["id"] as? String, "CRED_ID") |
| 70 | + let body = request.unencodedHTTPRequestBody |
| 71 | + XCTAssertNotNil(body) |
| 72 | + XCTAssertEqual(body?["idToken"] as? String, "ID_TOKEN") |
| 73 | + XCTAssertEqual(body?["name"] as? String, "MyPasskey") |
75 | 74 |
|
76 |
| - let authResp = authReg?["response"] as? [String: AnyHashable] |
77 |
| - XCTAssertEqual(authResp?["clientDataJSON"] as? String, "CLIENT_JSON") |
78 |
| - XCTAssertEqual(authResp?["attestationObject"] as? String, "ATTEST_OBJ") |
| 75 | + let authReg = body?["authenticatorRegistrationResponse"] as? [String: AnyHashable] |
| 76 | + XCTAssertNotNil(authReg) |
| 77 | + XCTAssertEqual(authReg?["id"] as? String, "CRED_ID") |
79 | 78 |
|
80 |
| - XCTAssertNil(body?["tenantId"]) |
81 |
| - } |
| 79 | + let authResp = authReg?["response"] as? [String: AnyHashable] |
| 80 | + XCTAssertEqual(authResp?["clientDataJSON"] as? String, "CLIENT_JSON") |
| 81 | + XCTAssertEqual(authResp?["attestationObject"] as? String, "ATTEST_OBJ") |
82 | 82 |
|
83 |
| - func testUnencodedHTTPRequestBodyWithTenantId() { |
84 |
| - request = FinalizePasskeyEnrollmentRequest( |
85 |
| - idToken: "ID_TOKEN", |
86 |
| - name: "MyPasskey", |
87 |
| - credentialID: "CRED_ID", |
88 |
| - clientDataJSON: "CLIENT_JSON", |
89 |
| - attestationObject: "ATTEST_OBJ", |
90 |
| - requestConfiguration: fakeConfig |
91 |
| - ) |
92 |
| - request.tenantID = "TENANT_ID" |
| 83 | + XCTAssertNil(body?["tenantId"]) |
| 84 | + } |
93 | 85 |
|
94 |
| - let body = request.unencodedHTTPRequestBody |
95 |
| - XCTAssertEqual(body?["tenantId"] as? String, "TENANT_ID") |
| 86 | + func testUnencodedHTTPRequestBodyWithTenantId() { |
| 87 | + // setting up fake auth to set tenantId |
| 88 | + let options = FirebaseOptions(googleAppID: "0:0000000000000:ios:0000000000000000", |
| 89 | + gcmSenderID: "00000000000000000-00000000000-000000000") |
| 90 | + options.apiKey = AuthTests.kFakeAPIKey |
| 91 | + options.projectID = "myProjectID" |
| 92 | + let name = "test-AuthTests\(AuthTests.testNum)" |
| 93 | + AuthTests.testNum = AuthTests.testNum + 1 |
| 94 | + let fakeAuth = Auth(app: FirebaseApp(instanceWithName: name, options: options)) |
| 95 | + fakeAuth.tenantID = "TEST_TENANT" |
| 96 | + let configWithTenant = AuthRequestConfiguration( |
| 97 | + apiKey: "FAKE_API_KEY", |
| 98 | + appID: "FAKE_APP_ID", |
| 99 | + auth: fakeAuth |
| 100 | + ) |
| 101 | + request = FinalizePasskeyEnrollmentRequest( |
| 102 | + idToken: "ID_TOKEN", |
| 103 | + name: "MyPasskey", |
| 104 | + credentialID: "CRED_ID", |
| 105 | + clientDataJSON: "CLIENT_JSON", |
| 106 | + attestationObject: "ATTEST_OBJ", |
| 107 | + requestConfiguration: configWithTenant |
| 108 | + ) |
| 109 | + let body = request.unencodedHTTPRequestBody |
| 110 | + XCTAssertEqual(body?["tenantId"] as? String, "TENANT_ID") |
| 111 | + } |
96 | 112 | }
|
97 |
| -} |
| 113 | + |
| 114 | +#endif |
0 commit comments