Skip to content

Commit 18e6ded

Browse files
committed
test: add unit tests for convering all RequestState cases in authorize and endSession methods
1 parent 461a49e commit 18e6ded

1 file changed

Lines changed: 174 additions & 1 deletion

File tree

flutter_appauth_platform_interface/test/method_channel_flutter_appauth_test.dart

Lines changed: 174 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,66 @@ void main() {
4848
);
4949
});
5050

51+
test('authorize with CustomState', () async {
52+
await flutterAppAuth.authorize(AuthorizationRequest(
53+
'someClientId', 'someRedirectUrl',
54+
discoveryUrl: 'someDiscoveryUrl',
55+
loginHint: 'someLoginHint',
56+
state: const CustomState('someState')));
57+
expect(
58+
log,
59+
<Matcher>[
60+
isMethodCall('authorize', arguments: <String, Object?>{
61+
'clientId': 'someClientId',
62+
'issuer': null,
63+
'redirectUrl': 'someRedirectUrl',
64+
'discoveryUrl': 'someDiscoveryUrl',
65+
'loginHint': 'someLoginHint',
66+
'scopes': null,
67+
'serviceConfiguration': null,
68+
'additionalParameters': null,
69+
'allowInsecureConnections': false,
70+
'externalUserAgent':
71+
ExternalUserAgent.asWebAuthenticationSession.index,
72+
'promptValues': null,
73+
'responseMode': null,
74+
'nonce': null,
75+
'state': 'someState',
76+
})
77+
],
78+
);
79+
});
80+
81+
test('authorize with SuppressedState sends null state', () async {
82+
await flutterAppAuth.authorize(AuthorizationRequest(
83+
'someClientId', 'someRedirectUrl',
84+
discoveryUrl: 'someDiscoveryUrl',
85+
loginHint: 'someLoginHint',
86+
state: const SuppressedState()));
87+
expect(
88+
log,
89+
<Matcher>[
90+
isMethodCall('authorize', arguments: <String, Object?>{
91+
'clientId': 'someClientId',
92+
'issuer': null,
93+
'redirectUrl': 'someRedirectUrl',
94+
'discoveryUrl': 'someDiscoveryUrl',
95+
'loginHint': 'someLoginHint',
96+
'scopes': null,
97+
'serviceConfiguration': null,
98+
'additionalParameters': null,
99+
'allowInsecureConnections': false,
100+
'externalUserAgent':
101+
ExternalUserAgent.asWebAuthenticationSession.index,
102+
'promptValues': null,
103+
'responseMode': null,
104+
'nonce': null,
105+
'state': null,
106+
})
107+
],
108+
);
109+
});
110+
51111
test('authorizeAndExchangeCode', () async {
52112
await flutterAppAuth.authorizeAndExchangeCode(AuthorizationTokenRequest(
53113
'someClientId', 'someRedirectUrl',
@@ -82,6 +142,79 @@ void main() {
82142
);
83143
});
84144

145+
test('authorizeAndExchangeCode with CustomState', () async {
146+
await flutterAppAuth.authorizeAndExchangeCode(AuthorizationTokenRequest(
147+
'someClientId', 'someRedirectUrl',
148+
discoveryUrl: 'someDiscoveryUrl',
149+
loginHint: 'someLoginHint',
150+
responseMode: 'fragment',
151+
state: const CustomState('someState')));
152+
expect(
153+
log,
154+
<Matcher>[
155+
isMethodCall('authorizeAndExchangeCode', arguments: <String, Object?>{
156+
'clientId': 'someClientId',
157+
'issuer': null,
158+
'redirectUrl': 'someRedirectUrl',
159+
'discoveryUrl': 'someDiscoveryUrl',
160+
'loginHint': 'someLoginHint',
161+
'scopes': null,
162+
'serviceConfiguration': null,
163+
'additionalParameters': null,
164+
'allowInsecureConnections': false,
165+
'externalUserAgent':
166+
ExternalUserAgent.asWebAuthenticationSession.index,
167+
'promptValues': null,
168+
'clientSecret': null,
169+
'refreshToken': null,
170+
'authorizationCode': null,
171+
'grantType': 'authorization_code',
172+
'codeVerifier': null,
173+
'responseMode': 'fragment',
174+
'nonce': null,
175+
'state': 'someState',
176+
})
177+
],
178+
);
179+
});
180+
181+
test('authorizeAndExchangeCode with SuppressedState sends null state',
182+
() async {
183+
await flutterAppAuth.authorizeAndExchangeCode(AuthorizationTokenRequest(
184+
'someClientId', 'someRedirectUrl',
185+
discoveryUrl: 'someDiscoveryUrl',
186+
loginHint: 'someLoginHint',
187+
responseMode: 'fragment',
188+
state: const SuppressedState()));
189+
expect(
190+
log,
191+
<Matcher>[
192+
isMethodCall('authorizeAndExchangeCode', arguments: <String, Object?>{
193+
'clientId': 'someClientId',
194+
'issuer': null,
195+
'redirectUrl': 'someRedirectUrl',
196+
'discoveryUrl': 'someDiscoveryUrl',
197+
'loginHint': 'someLoginHint',
198+
'scopes': null,
199+
'serviceConfiguration': null,
200+
'additionalParameters': null,
201+
'allowInsecureConnections': false,
202+
'externalUserAgent':
203+
ExternalUserAgent.asWebAuthenticationSession.index,
204+
'promptValues': null,
205+
'clientSecret': null,
206+
'refreshToken': null,
207+
'authorizationCode': null,
208+
'grantType': 'authorization_code',
209+
'codeVerifier': null,
210+
'responseMode': 'fragment',
211+
'nonce': null,
212+
'state': null,
213+
})
214+
],
215+
);
216+
});
217+
85218
group('token', () {
86219
test('cannot infer grant type', () async {
87220
expect(
@@ -170,7 +303,26 @@ void main() {
170303
});
171304
});
172305

173-
test('endSession', () async {
306+
test('endSession with default AutoGeneratedState omits state key', () async {
307+
await flutterAppAuth.endSession(EndSessionRequest(
308+
idTokenHint: 'someIdToken',
309+
postLogoutRedirectUrl: 'somePostLogoutRedirectUrl',
310+
discoveryUrl: 'someDiscoveryUrl'));
311+
expect(log, <Matcher>[
312+
isMethodCall('endSession', arguments: <String, Object?>{
313+
'idTokenHint': 'someIdToken',
314+
'postLogoutRedirectUrl': 'somePostLogoutRedirectUrl',
315+
'allowInsecureConnections': false,
316+
'additionalParameters': null,
317+
'issuer': null,
318+
'discoveryUrl': 'someDiscoveryUrl',
319+
'serviceConfiguration': null,
320+
'externalUserAgent': ExternalUserAgent.asWebAuthenticationSession.index,
321+
})
322+
]);
323+
});
324+
325+
test('endSession with CustomState', () async {
174326
await flutterAppAuth.endSession(EndSessionRequest(
175327
idTokenHint: 'someIdToken',
176328
postLogoutRedirectUrl: 'somePostLogoutRedirectUrl',
@@ -190,4 +342,25 @@ void main() {
190342
})
191343
]);
192344
});
345+
346+
test('endSession with SuppressedState sends null state', () async {
347+
await flutterAppAuth.endSession(EndSessionRequest(
348+
idTokenHint: 'someIdToken',
349+
postLogoutRedirectUrl: 'somePostLogoutRedirectUrl',
350+
state: const SuppressedState(),
351+
discoveryUrl: 'someDiscoveryUrl'));
352+
expect(log, <Matcher>[
353+
isMethodCall('endSession', arguments: <String, Object?>{
354+
'idTokenHint': 'someIdToken',
355+
'postLogoutRedirectUrl': 'somePostLogoutRedirectUrl',
356+
'state': null,
357+
'allowInsecureConnections': false,
358+
'additionalParameters': null,
359+
'issuer': null,
360+
'discoveryUrl': 'someDiscoveryUrl',
361+
'serviceConfiguration': null,
362+
'externalUserAgent': ExternalUserAgent.asWebAuthenticationSession.index,
363+
})
364+
]);
365+
});
193366
}

0 commit comments

Comments
 (0)