Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
// BSD-style license that can be found in the LICENSE file.

import 'dart:async';
import 'dart:convert';

import 'package:firebase_auth/firebase_auth.dart';
import 'package:flutter/foundation.dart';
Expand Down Expand Up @@ -113,34 +114,71 @@ void main() {
);

group('getIdTokenResult()', () {
test(
'should return a valid IdTokenResult Object',
() async {
// Setup
final userCredential = await FirebaseAuth.instance
.createUserWithEmailAndPassword(
email: email,
password: testPassword,
);
final user = userCredential.user!;
test('should return a valid IdTokenResult Object', () async {
// Setup
final userCredential = await FirebaseAuth.instance
.createUserWithEmailAndPassword(
email: email,
password: testPassword,
);
final user = userCredential.user!;

// Test
final idTokenResult = await user.getIdTokenResult();
// Test
final idTokenResult = await user.getIdTokenResult();

// Assertions
expect(idTokenResult.token.runtimeType, equals(String));
expect(idTokenResult.authTime.runtimeType, equals(DateTime));
expect(idTokenResult.issuedAtTime.runtimeType, equals(DateTime));
expect(idTokenResult.expirationTime.runtimeType, equals(DateTime));
expect(idTokenResult.token!.length, greaterThan(24));
expect(idTokenResult.signInProvider, equals('password'));
},
skip:
!kIsWeb &&
(defaultTargetPlatform == TargetPlatform.windows ||
defaultTargetPlatform == TargetPlatform.macOS),
);
// TODO add custom claims and tenant id tests for id token result
// Assertions
expect(idTokenResult.token.runtimeType, equals(String));
expect(idTokenResult.authTime.runtimeType, equals(DateTime));
expect(idTokenResult.issuedAtTime.runtimeType, equals(DateTime));
expect(idTokenResult.expirationTime.runtimeType, equals(DateTime));
expect(idTokenResult.token!.length, greaterThan(24));
expect(idTokenResult.signInProvider, equals('password'));
}, skip: !kIsWeb && defaultTargetPlatform == TargetPlatform.macOS);

test('should return custom claims and token metadata', () async {
const customClaims = <String, Object>{
'orgId': 'test-org',
'admin': true,
'roles': ['reader', 'editor'],
'profile': {'name': 'München 😀', 'quota': 2.5},
};
final credential = await FirebaseAuth.instance.signInWithCustomToken(
emulatorCreateCustomToken(
'token-claims-user',
claims: customClaims,
),
);
final result = await credential.user!.getIdTokenResult(true);
final payload =
jsonDecode(
utf8.decode(
base64Url.decode(
base64Url.normalize(result.token!.split('.')[1]),
),
),
)
as Map<String, dynamic>;

expect(result.claims, equals(payload));
for (final claim in customClaims.entries) {
expect(result.claims![claim.key], equals(claim.value));
}
expect(
result.authTime!.millisecondsSinceEpoch,
payload['auth_time'] * 1000,
);
expect(
result.issuedAtTime!.millisecondsSinceEpoch,
payload['iat'] * 1000,
);
expect(
result.expirationTime!.millisecondsSinceEpoch,
payload['exp'] * 1000,
);
expect(result.signInProvider, 'custom');
expect(result.signInSecondFactor, isNull);
});
// TODO add tenant id tests for id token result
});

group(
Expand Down
8 changes: 3 additions & 5 deletions packages/firebase_auth/firebase_auth/windows/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -101,16 +101,14 @@ set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
set(INSTALL_GTEST OFF CACHE BOOL "Disable installation of googletest" FORCE)
FetchContent_MakeAvailable(googletest)

# The plugin's C API is not very useful for unit testing, so build the sources
# directly into the test binary rather than using the DLL.
# Link the static plugin library to exercise the same parser as the app.
add_executable(${TEST_RUNNER}
test/firebase_auth_plugin_test.cpp
${PLUGIN_SOURCES}
)
apply_standard_settings(${TEST_RUNNER})
target_include_directories(${TEST_RUNNER} PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}")
target_link_libraries(${TEST_RUNNER} PRIVATE flutter_wrapper_plugin)
target_link_libraries(${TEST_RUNNER} PRIVATE gtest_main gmock)
target_link_libraries(${TEST_RUNNER} PRIVATE
${PLUGIN_NAME} firebase_core_plugin flutter_wrapper_plugin gtest_main)
Comment on lines +110 to +111

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

low

Explicitly link the crypt32 library in CMake to ensure that Windows Cryptography APIs (CryptStringToBinaryA and CryptBinaryToStringA) are always available, making the target self-contained and robust against changes in dependencies.

target_link_libraries(${TEST_RUNNER} PRIVATE
  ${PLUGIN_NAME} firebase_core_plugin flutter_wrapper_plugin gtest_main crypt32)

# flutter_wrapper_plugin has link dependencies on the Flutter DLL.
add_custom_command(TARGET ${TEST_RUNNER} POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_if_different
Expand Down
Loading
Loading