Skip to content

Commit

Permalink
try mocking discovery document to avoid flakey tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ahmednfwela committed Nov 26, 2024
1 parent 778fca3 commit 25c1f0a
Show file tree
Hide file tree
Showing 3 changed files with 158 additions and 2 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ jobs:
working-directory: ${{ matrix.working-directory }}
run: |
chromedriver --port=4444 --trace-buffer-size=100000 &
flutter drive --driver=./test_driver/integration_test.dart --target=./integration_test/app_test.dart -d chrome | tee output.log
flutter drive --driver=./test_driver/integration_test.dart --target=./integration_test/app_test.dart -d chrome --dart-define=CI=true | tee output.log
# We have to check the output for failed tests matching the string "[E]"
output=$(<output.log)
if [[ "$output" =~ \[E\] ]]; then
Expand Down
38 changes: 37 additions & 1 deletion packages/oidc/example/lib/app_state.dart
Original file line number Diff line number Diff line change
@@ -1,17 +1,53 @@
// ignore_for_file: avoid_redundant_argument_values

import 'dart:convert';
import 'dart:io';

import 'package:async/async.dart';
import 'package:bdaya_shared_value/bdaya_shared_value.dart';
import 'package:flutter/foundation.dart';
import 'package:http/http.dart' as http;
import 'package:http/testing.dart' as http;
import 'package:logging/logging.dart';
import 'package:oidc/oidc.dart';
import 'package:oidc_default_store/oidc_default_store.dart';

import 'mock.dart';

//This file represents a global state, which is bad
//in a production app (since you can't test it).

const kIsCI = bool.fromEnvironment('CI');
final http.Client client = kIsCI ? http.MockClient(ciHandler) : http.Client();
Future<http.Response> ciHandler(http.Request request) async {
// intercept requests to duende to avoid flaky tests.
switch (request) {
case http.Request(
method: 'GET',
url: Uri(
host: 'demo.duendesoftware.com',
pathSegments: [
'.well-known',
'openid-configuration',
]
)
):
return http.Response.bytes(
utf8.encode(duendeDiscoveryDocument),
HttpStatus.ok,
);
default:
exampleLogger
.warning('sending out ${request.method} request to ${request.url}');
final client = http.Client();
try {
return http.Response.fromStream(await client.send(request));
} finally {
client.close();
}
}
}

//usually you would use a dependency injection library
//and put these in a service.
final exampleLogger = Logger('oidc.example');
Expand All @@ -29,7 +65,7 @@ final duendeManager = OidcUserManager.lazy(
clientId: 'interactive.public.short',
),
store: OidcDefaultStore(),

httpClient: client,
// keyStore: JsonWebKeyStore(),
settings: OidcUserManagerSettings(
frontChannelLogoutUri: Uri(path: 'redirect.html'),
Expand Down
120 changes: 120 additions & 0 deletions packages/oidc/example/lib/mock.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
import 'dart:convert';

final duendeDiscoveryDocument = jsonEncode({
'issuer': 'https://demo.duendesoftware.com',
'jwks_uri':
'https://demo.duendesoftware.com/.well-known/openid-configuration/jwks',
'authorization_endpoint': 'https://demo.duendesoftware.com/connect/authorize',
'token_endpoint': 'https://demo.duendesoftware.com/connect/token',
'userinfo_endpoint': 'https://demo.duendesoftware.com/connect/userinfo',
'end_session_endpoint': 'https://demo.duendesoftware.com/connect/endsession',
'check_session_iframe':
'https://demo.duendesoftware.com/connect/checksession',
'revocation_endpoint': 'https://demo.duendesoftware.com/connect/revocation',
'introspection_endpoint':
'https://demo.duendesoftware.com/connect/introspect',
'device_authorization_endpoint':
'https://demo.duendesoftware.com/connect/deviceauthorization',
'backchannel_authentication_endpoint':
'https://demo.duendesoftware.com/connect/ciba',
'pushed_authorization_request_endpoint':
'https://demo.duendesoftware.com/connect/par',
'require_pushed_authorization_requests': false,
'frontchannel_logout_supported': true,
'frontchannel_logout_session_supported': true,
'backchannel_logout_supported': true,
'backchannel_logout_session_supported': true,
'scopes_supported': [
'openid',
'profile',
'email',
'api',
'resource1.scope1',
'resource1.scope2',
'resource2.scope1',
'resource2.scope2',
'resource3.scope1',
'resource3.scope2',
'scope3',
'scope4',
'shared.scope',
'transaction',
'offline_access',
],
'claims_supported': [
'sub',
'name',
'family_name',
'given_name',
'middle_name',
'nickname',
'preferred_username',
'profile',
'picture',
'website',
'gender',
'birthdate',
'zoneinfo',
'locale',
'updated_at',
'email',
'email_verified',
],
'grant_types_supported': [
'authorization_code',
'client_credentials',
'refresh_token',
'implicit',
'password',
'urn:ietf:params:oauth:grant-type:device_code',
'urn:openid:params:grant-type:ciba',
],
'response_types_supported': [
'code',
'token',
'id_token',
'id_token token',
'code id_token',
'code token',
'code id_token token',
],
'response_modes_supported': ['form_post', 'query', 'fragment'],
'token_endpoint_auth_methods_supported': [
'client_secret_basic',
'client_secret_post',
'private_key_jwt',
],
'id_token_signing_alg_values_supported': ['RS256'],
'subject_types_supported': ['public'],
'code_challenge_methods_supported': ['plain', 'S256'],
'request_parameter_supported': true,
'request_object_signing_alg_values_supported': [
'RS256',
'RS384',
'RS512',
'PS256',
'PS384',
'PS512',
'ES256',
'ES384',
'ES512',
'HS256',
'HS384',
'HS512',
],
'prompt_values_supported': ['none', 'login', 'consent', 'select_account'],
'authorization_response_iss_parameter_supported': true,
'backchannel_token_delivery_modes_supported': ['poll'],
'backchannel_user_code_parameter_supported': true,
'dpop_signing_alg_values_supported': [
'RS256',
'RS384',
'RS512',
'PS256',
'PS384',
'PS512',
'ES256',
'ES384',
'ES512',
],
});

0 comments on commit 25c1f0a

Please sign in to comment.