Skip to content

Commit 574dd8d

Browse files
author
Bas de Vaan
committed
modify tests to apply for id token
1 parent 7057f3e commit 574dd8d

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
lines changed

test/oauth_chopper_test.dart

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ void main() {
1313
{
1414
"accessToken": "accesToken",
1515
"refreshToken": "refreshToken",
16-
"idToken": null,
16+
"idToken": "idToken",
1717
"tokenEndpoint": "https://test.test/oauth/token",
1818
"scopes": [],
1919
"expiration": 1664359530234
@@ -63,6 +63,7 @@ void main() {
6363
// assert
6464
expect(token?.accessToken, 'accesToken');
6565
expect(token?.refreshToken, 'refreshToken');
66+
expect(token?.idToken, 'idToken');
6667
});
6768

6869
test('Returns no token if not in storage', () async {
@@ -98,6 +99,7 @@ void main() {
9899
verify(grantMock.handle(any, 'identifier', 'secret')).called(1);
99100
verify(storageMock.saveCredentials(testJson)).called(1);
100101
expect(token.accessToken, 'accesToken');
102+
expect(token?.idToken, 'idToken');
101103
expect(token.refreshToken, 'refreshToken');
102104
});
103105
}

test/oauth_interceptor_test.dart

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,16 @@ void main() {
2020
),
2121
);
2222

23+
final testIDtoken = OAuthToken.fromCredentials(
24+
Credentials(
25+
'token',
26+
refreshToken: 'refresh',
27+
idToken: 'idToken',
28+
expiration: DateTime(2022, 9, 1),
29+
),
30+
);
31+
32+
2333
final testRequest = Request('GET', Uri(host: 'test'), Uri(host: 'test'));
2434

2535
test('HeaderInterceptor adds available token to headers', () async {
@@ -34,6 +44,20 @@ void main() {
3444
// assert
3545
expect(result.headers, expected);
3646
});
47+
48+
test('HeaderInterceptor adds IDToken when available to headers', () async {
49+
// arrange
50+
when(mockOAuthChopper.token).thenAnswer((_) async => testIDtoken);
51+
final interceptor = OAuthInterceptor(mockOAuthChopper);
52+
final expected = {'Authorization': 'Bearer idToken'};
53+
54+
// act
55+
final result = await interceptor.onRequest(testRequest);
56+
57+
// assert
58+
expect(result.headers, expected);
59+
});
60+
3761
test('HeaderInterceptor adds no token to headers', () async {
3862
// arrange
3963
when(mockOAuthChopper.token).thenAnswer((_) async => null);

0 commit comments

Comments
 (0)