| Index: pkg/oauth2/test/authorization_code_grant_test.dart
|
| diff --git a/pkg/oauth2/test/authorization_code_grant_test.dart b/pkg/oauth2/test/authorization_code_grant_test.dart
|
| index 2b80cf4544fe52442db2417c3c23817ddb1fb08e..e896dca25a2be039cdfdf74cd3c28240a0e64f01 100644
|
| --- a/pkg/oauth2/test/authorization_code_grant_test.dart
|
| +++ b/pkg/oauth2/test/authorization_code_grant_test.dart
|
| @@ -30,6 +30,12 @@ void createGrant() {
|
| httpClient: client);
|
| }
|
|
|
| +void expectFutureThrows(future, predicate) {
|
| + future.catchError(expectAsync1((AsyncError e) {
|
| + expect(predicate(e.error), isTrue);
|
| + }));
|
| +}
|
| +
|
| void main() {
|
| group('.getAuthorizationUrl', () {
|
| setUp(createGrant);
|
| @@ -83,7 +89,8 @@ void main() {
|
|
|
| test("can't be called twice", () {
|
| grant.getAuthorizationUrl(redirectUrl);
|
| - expect(() => grant.getAuthorizationUrl(redirectUrl), throwsStateError);
|
| + expectFutureThrows(grant.getAuthorizationUrl(redirectUrl),
|
| + (e) => e is StateError);
|
| });
|
| });
|
|
|
| @@ -91,39 +98,44 @@ void main() {
|
| setUp(createGrant);
|
|
|
| test("can't be called before .getAuthorizationUrl", () {
|
| - expect(grant.handleAuthorizationResponse({}), throwsStateError);
|
| + expectFutureThrows(grant.handleAuthorizationResponse({}),
|
| + (e) => e is StateError);
|
| });
|
|
|
| test("can't be called twice", () {
|
| grant.getAuthorizationUrl(redirectUrl);
|
| grant.handleAuthorizationResponse({'code': 'auth code'});
|
| - expect(grant.handleAuthorizationResponse({'code': 'auth code'}),
|
| - throwsStateError);
|
| + expectFutureThrows(
|
| + grant.handleAuthorizationResponse({'code': 'auth code'}),
|
| + (e) => e is StateError);
|
| });
|
|
|
| test('must have a state parameter if the authorization URL did', () {
|
| grant.getAuthorizationUrl(redirectUrl, state: 'state');
|
| - expect(grant.handleAuthorizationResponse({'code': 'auth code'}),
|
| - throwsFormatException);
|
| + expectFutureThrows(
|
| + grant.handleAuthorizationResponse({'code': 'auth code'}),
|
| + (e) => e is FormatException);
|
| });
|
|
|
| test('must have the same state parameter the authorization URL did', () {
|
| grant.getAuthorizationUrl(redirectUrl, state: 'state');
|
| - expect(grant.handleAuthorizationResponse({
|
| + expectFutureThrows(grant.handleAuthorizationResponse({
|
| 'code': 'auth code',
|
| 'state': 'other state'
|
| - }), throwsFormatException);
|
| + }), (e) => e is FormatException);
|
| });
|
|
|
| test('must have a code parameter', () {
|
| grant.getAuthorizationUrl(redirectUrl);
|
| - expect(grant.handleAuthorizationResponse({}), throwsFormatException);
|
| + expectFutureThrows(grant.handleAuthorizationResponse({}),
|
| + (e) => e is FormatException);
|
| });
|
|
|
| test('with an error parameter throws an AuthorizationException', () {
|
| grant.getAuthorizationUrl(redirectUrl);
|
| - expect(grant.handleAuthorizationResponse({'error': 'invalid_request'}),
|
| - throwsAuthorizationException);
|
| + expectFutureThrows(
|
| + grant.handleAuthorizationResponse({'error': 'invalid_request'}),
|
| + (e) => e is AuthorizationException);
|
| });
|
|
|
| test('sends an authorization code request', () {
|
| @@ -163,8 +175,8 @@ void main() {
|
| test("can't be called twice", () {
|
| grant.getAuthorizationUrl(redirectUrl);
|
| grant.handleAuthorizationCode('auth code');
|
| - expect(grant.handleAuthorizationCode('auth code'),
|
| - throwsStateError);
|
| + expectFutureThrows(grant.handleAuthorizationCode('auth code'),
|
| + (e) => e is StateError);
|
| });
|
|
|
| test('sends an authorization code request', () {
|
|
|