Skip to content

Commit 4a4fc49

Browse files
authored
test: add more tests (#102)
* test: add more tests * clean * more * fix typo * clean * clean * clean ci * more
1 parent 17730c1 commit 4a4fc49

File tree

12 files changed

+705
-47
lines changed

12 files changed

+705
-47
lines changed

.github/workflows/build.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,11 +200,12 @@ jobs:
200200
201201
- name: Upload coverage to codecov
202202
if: matrix.dart-version == 'stable'
203+
continue-on-error: true
203204
uses: codecov/codecov-action@v3
204205
with:
205206
files: packages/dart_firebase_admin/coverage.lcov
206207
flags: unittests
207-
fail_ci_if_error: true
208+
fail_ci_if_error: false
208209

209210
build:
210211
name: Build verification (Dart ${{ matrix.dart-version }})

packages/dart_firebase_admin/lib/src/app_check/app_check.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import '../app.dart';
22
import '../utils/crypto_signer.dart';
3-
import 'ap_check_api_internal.dart';
43
import 'app_check_api.dart';
4+
import 'app_check_api_internal.dart';
55
import 'token_generator.dart';
66
import 'token_verifier.dart';
77

packages/dart_firebase_admin/lib/src/app_check/app_check_api.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import 'package:freezed_annotation/freezed_annotation.dart';
22

3-
import 'ap_check_api_internal.dart';
43
import 'app_check.dart';
4+
import 'app_check_api_internal.dart';
55

66
class AppCheckToken {
77
@internal

packages/dart_firebase_admin/lib/src/app_check/ap_check_api_internal.dart renamed to packages/dart_firebase_admin/lib/src/app_check/app_check_api_internal.dart

File renamed without changes.

packages/dart_firebase_admin/lib/src/app_check/token_generator.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ import 'dart:convert';
33
import 'package:meta/meta.dart';
44

55
import '../utils/crypto_signer.dart';
6-
import 'ap_check_api_internal.dart';
76
import 'app_check_api.dart';
7+
import 'app_check_api_internal.dart';
88

99
// Audience to use for Firebase App Check Custom tokens
1010
const firebaseAppCheckAudience =

packages/dart_firebase_admin/lib/src/app_check/token_verifier.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ import 'package:meta/meta.dart';
22

33
import '../app.dart';
44
import '../utils/jwt.dart';
5-
import 'ap_check_api_internal.dart';
65
import 'app_check_api.dart';
6+
import 'app_check_api_internal.dart';
77

88
const appCheckIssuer = 'https://firebaseappcheck.googleapis.com/';
99
const jwksUrl = 'https://firebaseappcheck.googleapis.com/v1/jwks';

packages/dart_firebase_admin/pubspec.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,4 +33,5 @@ dev_dependencies:
3333

3434
false_secrets:
3535
- /test/auth/jwt_test.dart
36-
- /test/client/get_id_token.js
36+
- /test/client/get_id_token.js
37+
- /test/mock_service_account.dart
Lines changed: 165 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,165 @@
1+
import 'package:dart_firebase_admin/src/app_check/app_check_api_internal.dart';
2+
import 'package:dart_firebase_admin/src/utils/jwt.dart';
3+
import 'package:test/test.dart';
4+
5+
void main() {
6+
group('AppCheckErrorCode', () {
7+
test('should have correct error code values', () {
8+
expect(AppCheckErrorCode.aborted.code, equals('aborted'));
9+
expect(
10+
AppCheckErrorCode.invalidArgument.code,
11+
equals('invalid-argument'),
12+
);
13+
expect(
14+
AppCheckErrorCode.invalidCredential.code,
15+
equals('invalid-credential'),
16+
);
17+
expect(AppCheckErrorCode.internalError.code, equals('internal-error'));
18+
expect(
19+
AppCheckErrorCode.permissionDenied.code,
20+
equals('permission-denied'),
21+
);
22+
expect(
23+
AppCheckErrorCode.unauthenticated.code,
24+
equals('unauthenticated'),
25+
);
26+
expect(AppCheckErrorCode.notFound.code, equals('not-found'));
27+
expect(
28+
AppCheckErrorCode.appCheckTokenExpired.code,
29+
equals('app-check-token-expired'),
30+
);
31+
expect(AppCheckErrorCode.unknownError.code, equals('unknown-error'));
32+
});
33+
34+
test('from should map crypto signer error codes', () {
35+
expect(
36+
AppCheckErrorCode.from('invalid-credential'),
37+
equals(AppCheckErrorCode.invalidCredential),
38+
);
39+
expect(
40+
AppCheckErrorCode.from('invalid-argument'),
41+
equals(AppCheckErrorCode.invalidArgument),
42+
);
43+
expect(
44+
AppCheckErrorCode.from('unknown-code'),
45+
equals(AppCheckErrorCode.internalError),
46+
);
47+
});
48+
});
49+
50+
group('FirebaseAppCheckException', () {
51+
test('should create exception with code and message', () {
52+
final exception = FirebaseAppCheckException(
53+
AppCheckErrorCode.invalidArgument,
54+
'Test error message',
55+
);
56+
57+
expect(exception.code, equals('app-check/invalid-argument'));
58+
expect(exception.message, equals('Test error message'));
59+
});
60+
61+
test('should create exception without message', () {
62+
final exception = FirebaseAppCheckException(
63+
AppCheckErrorCode.permissionDenied,
64+
);
65+
66+
expect(exception.code, equals('app-check/permission-denied'));
67+
// Base class provides a default message when none is specified
68+
expect(exception.message, isNotEmpty);
69+
});
70+
71+
test('fromJwtException should handle tokenExpired error', () {
72+
final jwtError = JwtException(
73+
JwtErrorCode.tokenExpired,
74+
'Token expired',
75+
);
76+
77+
final exception = FirebaseAppCheckException.fromJwtException(jwtError);
78+
79+
expect(exception.code, equals('app-check/app-check-token-expired'));
80+
expect(
81+
exception.message,
82+
contains('The provided App Check token has expired'),
83+
);
84+
});
85+
86+
test('fromJwtException should handle invalidSignature error', () {
87+
final jwtError = JwtException(
88+
JwtErrorCode.invalidSignature,
89+
'Invalid signature',
90+
);
91+
92+
final exception = FirebaseAppCheckException.fromJwtException(jwtError);
93+
94+
expect(exception.code, equals('app-check/invalid-argument'));
95+
expect(
96+
exception.message,
97+
contains('The provided App Check token has invalid signature'),
98+
);
99+
});
100+
101+
test('fromJwtException should handle noMatchingKid error', () {
102+
final jwtError = JwtException(
103+
JwtErrorCode.noMatchingKid,
104+
'No matching kid',
105+
);
106+
107+
final exception = FirebaseAppCheckException.fromJwtException(jwtError);
108+
109+
expect(exception.code, equals('app-check/invalid-argument'));
110+
expect(
111+
exception.message,
112+
contains('The provided App Check token has "kid" claim which does not'),
113+
);
114+
});
115+
116+
test('fromJwtException should handle other errors', () {
117+
final jwtError = JwtException(
118+
JwtErrorCode.unknown,
119+
'Unknown error',
120+
);
121+
122+
final exception = FirebaseAppCheckException.fromJwtException(jwtError);
123+
124+
expect(exception.code, equals('app-check/invalid-argument'));
125+
expect(exception.message, equals('Unknown error'));
126+
});
127+
});
128+
129+
group('appCheckErrorCodeMapping', () {
130+
test('should have correct mappings', () {
131+
expect(
132+
appCheckErrorCodeMapping['ABORTED'],
133+
equals(AppCheckErrorCode.aborted),
134+
);
135+
expect(
136+
appCheckErrorCodeMapping['INVALID_ARGUMENT'],
137+
equals(AppCheckErrorCode.invalidArgument),
138+
);
139+
expect(
140+
appCheckErrorCodeMapping['INVALID_CREDENTIAL'],
141+
equals(AppCheckErrorCode.invalidCredential),
142+
);
143+
expect(
144+
appCheckErrorCodeMapping['INTERNAL'],
145+
equals(AppCheckErrorCode.internalError),
146+
);
147+
expect(
148+
appCheckErrorCodeMapping['PERMISSION_DENIED'],
149+
equals(AppCheckErrorCode.permissionDenied),
150+
);
151+
expect(
152+
appCheckErrorCodeMapping['UNAUTHENTICATED'],
153+
equals(AppCheckErrorCode.unauthenticated),
154+
);
155+
expect(
156+
appCheckErrorCodeMapping['NOT_FOUND'],
157+
equals(AppCheckErrorCode.notFound),
158+
);
159+
expect(
160+
appCheckErrorCodeMapping['UNKNOWN'],
161+
equals(AppCheckErrorCode.unknownError),
162+
);
163+
});
164+
});
165+
}

0 commit comments

Comments
 (0)