From 7a058ddedaea5d6e7b8c635e703c5f31ce065b92 Mon Sep 17 00:00:00 2001 From: Nika Hassani Date: Thu, 25 Jul 2024 13:52:10 -0700 Subject: [PATCH] chore(test): update to use Amplify Gen2 config in unit tests --- .../amplify_api_dart/test/graphql_test.dart | 2 +- .../test/plugin_configuration_test.dart | 13 +- .../test/rest_methods_test.dart | 7 +- .../test_data/fake_amplify_configuration.dart | 119 ++++------- ...mplify_configuration_iam_with_api_key.dart | 117 ++++------- .../lib/common/mock_config.dart | 190 ++++++++++-------- .../hostedui/hosted_ui_platform_io_test.dart | 9 +- .../hostedui/hosted_ui_platform_test.dart | 8 +- ..._device_password_verifier_worker_test.dart | 4 +- .../srp_password_verifier_worker_test.dart | 4 +- .../test/plugin/sign_out_test.dart | 4 +- .../configuration_state_machine_test.dart | 2 + ...fetch_auth_session_state_machine_test.dart | 2 +- .../state/hosted_ui_state_machine_test.dart | 12 +- .../state/sign_in_state_machine_test.dart | 6 +- .../amplify_push_notifications_impl_test.dart | 16 +- .../test_data/fake_amplify_configuration.dart | 110 ++++------ .../fake_defective_configuration.dart | 101 +++------- 18 files changed, 300 insertions(+), 426 deletions(-) diff --git a/packages/api/amplify_api_dart/test/graphql_test.dart b/packages/api/amplify_api_dart/test/graphql_test.dart index bf1e9d0ed9..c1399a0025 100644 --- a/packages/api/amplify_api_dart/test/graphql_test.dart +++ b/packages/api/amplify_api_dart/test/graphql_test.dart @@ -97,7 +97,7 @@ void main() { ); await Amplify.addPlugin(api); - await Amplify.configure(amplifyconfig); + await Amplify.configure(amplifyConfig); hubEventsController = StreamController.broadcast(); hubEvents = hubEventsController.stream; diff --git a/packages/api/amplify_api_dart/test/plugin_configuration_test.dart b/packages/api/amplify_api_dart/test/plugin_configuration_test.dart index dae096aabe..b51db0109b 100644 --- a/packages/api/amplify_api_dart/test/plugin_configuration_test.dart +++ b/packages/api/amplify_api_dart/test/plugin_configuration_test.dart @@ -61,17 +61,12 @@ void main() { APIAuthorizationType.iam.authProviderToken, TestIamAuthProvider(), ); - // TODO(nikahsn): update to use AmplifyOutputs config - final config = AmplifyConfig.fromJson( - jsonDecode(amplifyconfig) as Map, + final amplifyOutputs = AmplifyOutputs.fromJson( + jsonDecode(amplifyConfig) as Map, ); - // ignore: invalid_use_of_internal_member - final amplifyOutputs = config.toAmplifyOutputs(); - final configIamWithApiKey = AmplifyConfig.fromJson( - jsonDecode(amplifyconfigwithapikey) as Map, + final amplifyOutputsIamWithApiKey = AmplifyOutputs.fromJson( + jsonDecode(amplifyConfigIamWithApiKey) as Map, ); - // ignore: invalid_use_of_internal_member - final amplifyOutputsIamWithApiKey = configIamWithApiKey.toAmplifyOutputs(); group('AmplifyAPI plugin configuration', () { test( diff --git a/packages/api/amplify_api_dart/test/rest_methods_test.dart b/packages/api/amplify_api_dart/test/rest_methods_test.dart index 3d3bad58fd..57b014ee02 100644 --- a/packages/api/amplify_api_dart/test/rest_methods_test.dart +++ b/packages/api/amplify_api_dart/test/rest_methods_test.dart @@ -40,12 +40,9 @@ void main() { APIAuthorizationType.iam.authProviderToken, TestIamAuthProvider(), ); - // TODO(nikahsn): update to use AmplifyOutputs config - final config = AmplifyConfig.fromJson( - jsonDecode(amplifyconfig) as Map, + final amplifyOutputs = AmplifyOutputs.fromJson( + jsonDecode(amplifyConfig) as Map, ); - // ignore: invalid_use_of_internal_member - final amplifyOutputs = config.toAmplifyOutputs(); await apiPlugin.configure( config: amplifyOutputs, authProviderRepo: authProviderRepo, diff --git a/packages/api/amplify_api_dart/test/test_data/fake_amplify_configuration.dart b/packages/api/amplify_api_dart/test/test_data/fake_amplify_configuration.dart index db25b7c982..bcb832319c 100644 --- a/packages/api/amplify_api_dart/test/test_data/fake_amplify_configuration.dart +++ b/packages/api/amplify_api_dart/test/test_data/fake_amplify_configuration.dart @@ -1,82 +1,45 @@ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. // SPDX-License-Identifier: Apache-2.0 -const amplifyconfig = '''{ - "UserAgent": "aws-amplify-cli/2.0", - "Version": "1.0", - "api": { - "plugins": { - "awsAPIPlugin": { - "apiIntegrationTestGraphQL": { - "endpointType": "GraphQL", - "endpoint": "https://abc123.appsync-api.us-east-1.amazonaws.com/graphql", - "region": "us-east-1", - "authorizationType": "API_KEY", - "apiKey": "abc123" - }, - "api123": { - "endpointType": "REST", - "endpoint": "https://abc123.execute-api.us-east-1.amazonaws.com/test", - "region": "us-east-1", - "authorizationType": "AWS_IAM" - } - } - } - }, - "auth": { - "plugins": { - "awsCognitoAuthPlugin": { - "UserAgent": "aws-amplify-cli/0.1.0", - "Version": "0.1.0", - "IdentityManager": { - "Default": {} - }, - "AppSync": { - "Default": { - "ApiUrl": "https://abc123.appsync-api.us-east-1.amazonaws.com/graphql", - "Region": "us-east-1", - "AuthMode": "API_KEY", - "ApiKey": "abc123", - "ClientDatabasePrefix": "apiIntegrationTestGraphQL_API_KEY" - } - }, - "CredentialsProvider": { - "CognitoIdentity": { - "Default": { - "PoolId": "us-east-1:abc123", - "Region": "us-east-1" - } - } - }, - "CognitoUserPool": { - "Default": { - "PoolId": "us-east-1_abc123", - "AppClientId": "abc123", - "Region": "us-east-1" - } - }, - "Auth": { - "Default": { - "authenticationFlowType": "USER_SRP_AUTH", - "socialProviders": [], - "usernameAttributes": [], - "signupAttributes": [ - "EMAIL" - ], - "passwordProtectionSettings": { - "passwordPolicyMinLength": 8, - "passwordPolicyCharacters": [] - }, - "mfaConfiguration": "OFF", - "mfaTypes": [ - "SMS" - ], - "verificationMechanisms": [ - "EMAIL" - ] - } - } - } - } - } +const amplifyConfig = '''{ + "version": "1", + "auth": { + "aws_region": "us-east-1", + "user_pool_id": "us-east-1_abc123", + "user_pool_client_id": "abc123", + "identity_pool_id": "us-east-1:abc123", + "password_policy": { + "min_length": 8, + "require_numbers": false, + "require_lowercase": false, + "require_uppercase": false, + "require_symbols": false + }, + "standard_required_attributes":[ + "email" + ], + "username_attributes":[], + "user_verification_types":[ + "email" + ], + "unauthenticated_identities_enabled": true, + "mfa_configuration": "NONE", + "mfa_methods":[ + "SMS" + ] + }, + "data": { + "aws_region": "us-east-1", + "url": "https://abc123.appsync-api.us-east-1.amazonaws.com/graphql", + "api_key": "abc123", + "default_authorization_type": "API_KEY", + "authorization_types":[] + }, + "rest_api": { + "api123": { + "aws_region": "us-east-1", + "url": "https://abc123.execute-api.us-east-1.amazonaws.com/test", + "authorization_type": "AWS_IAM" + } + } }'''; diff --git a/packages/api/amplify_api_dart/test/test_data/fake_amplify_configuration_iam_with_api_key.dart b/packages/api/amplify_api_dart/test/test_data/fake_amplify_configuration_iam_with_api_key.dart index 9f93e1138e..7e71cc6074 100644 --- a/packages/api/amplify_api_dart/test/test_data/fake_amplify_configuration_iam_with_api_key.dart +++ b/packages/api/amplify_api_dart/test/test_data/fake_amplify_configuration_iam_with_api_key.dart @@ -1,81 +1,46 @@ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. // SPDX-License-Identifier: Apache-2.0 -const amplifyconfigwithapikey = '''{ - "UserAgent": "aws-amplify-cli/2.0", - "Version": "1.0", - "api": { - "plugins": { - "awsAPIPlugin": { - "apiIntegrationTestGraphQL": { - "endpointType": "GraphQL", - "endpoint": "https://abc123.appsync-api.us-east-1.amazonaws.com/graphql", - "region": "us-east-1", - "authorizationType": "AWS_IAM", - "apiKey": "abc123" - }, - "api123": { - "endpointType": "REST", - "endpoint": "https://abc123.execute-api.us-east-1.amazonaws.com/test", - "region": "us-east-1", - "authorizationType": "AWS_IAM" - } - } - } - }, +const amplifyConfigIamWithApiKey = ''' { + "version": "1", "auth": { - "plugins": { - "awsCognitoAuthPlugin": { - "UserAgent": "aws-amplify-cli/0.1.0", - "Version": "0.1.0", - "IdentityManager": { - "Default": {} - }, - "AppSync": { - "Default": { - "ApiUrl": "https://abc123.appsync-api.us-east-1.amazonaws.com/graphql", - "Region": "us-east-1", - "AuthMode": "AWS_IAM", - "ClientDatabasePrefix": "apiIntegrationTestGraphQL_API_KEY" - } - }, - "CredentialsProvider": { - "CognitoIdentity": { - "Default": { - "PoolId": "us-east-1:abc123", - "Region": "us-east-1" - } - } - }, - "CognitoUserPool": { - "Default": { - "PoolId": "us-east-1_abc123", - "AppClientId": "abc123", - "Region": "us-east-1" - } - }, - "Auth": { - "Default": { - "authenticationFlowType": "USER_SRP_AUTH", - "socialProviders": [], - "usernameAttributes": [], - "signupAttributes": [ - "EMAIL" - ], - "passwordProtectionSettings": { - "passwordPolicyMinLength": 8, - "passwordPolicyCharacters": [] - }, - "mfaConfiguration": "OFF", - "mfaTypes": [ - "SMS" - ], - "verificationMechanisms": [ - "EMAIL" - ] - } - } - } - } + "aws_region": "us-east-1", + "user_pool_id": "us-east-1_abc123", + "user_pool_client_id": "abc123", + "identity_pool_id": "us-east-1:abc123", + "password_policy": { + "min_length": 8, + "require_numbers": false, + "require_lowercase": false, + "require_uppercase": false, + "require_symbols": false + }, + "standard_required_attributes":[ + "email" + ], + "username_attributes":[], + "user_verification_types":[ + "email" + ], + "unauthenticated_identities_enabled": true, + "mfa_configuration": "NONE", + "mfa_methods":[ + "SMS" + ] + }, + "data": { + "aws_region": "us-east-1", + "url": "https://abc123.appsync-api.us-east-1.amazonaws.com/graphql", + "api_key": "abc123", + "default_authorization_type": "AWS_IAM", + "authorization_types":[] + }, + "rest_api": { + "api123": { + "aws_region": "us-east-1", + "url": "https://abc123.execute-api.us-east-1.amazonaws.com/test", + "authorization_type": "AWS_IAM" + } } -}'''; +} +'''; diff --git a/packages/auth/amplify_auth_cognito_test/lib/common/mock_config.dart b/packages/auth/amplify_auth_cognito_test/lib/common/mock_config.dart index e0ebba2771..2e1a7c29b4 100644 --- a/packages/auth/amplify_auth_cognito_test/lib/common/mock_config.dart +++ b/packages/auth/amplify_auth_cognito_test/lib/common/mock_config.dart @@ -1,5 +1,7 @@ -// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. -// SPDX-License-Identifier: Apache-2.0 +// // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. +// // SPDX-License-Identifier: Apache-2.0 + +import 'dart:convert'; import 'package:amplify_auth_cognito_dart/amplify_auth_cognito_dart.dart'; import 'package:amplify_auth_cognito_dart/src/credentials/cognito_keys.dart'; @@ -7,69 +9,106 @@ import 'package:amplify_auth_cognito_dart/src/jwt/jwt.dart'; import 'package:amplify_auth_cognito_dart/src/model/auth_configuration.dart'; import 'package:amplify_core/amplify_core.dart'; -const testUserPoolId = 'us-east-1_userPoolId'; -const testAppClientId = 'appClientId'; -const testIdentityPoolId = 'identityPoolId'; -const testRegion = 'region'; -const scopes = ['profile']; -const testUrlScheme = 'authtest'; -const redirectUri = '$testUrlScheme:/,http://localhost:9999/'; -const webDomain = 'example.com'; - -const testPinpointAppId = 'pinpointAppId'; +const amplifyConfig = '''{ + "version": "1", + "auth": { + "aws_region": "region", + "user_pool_id": "us-east-1_userPoolId", + "user_pool_client_id": "appClientId", + "identity_pool_id": "identityPoolId", + "password_policy": { + "require_numbers": false, + "require_lowercase": false, + "require_uppercase": false, + "require_symbols": false + }, + "oauth":{ + "identity_providers": [], + "domain": "example.com", + "scopes":[ + "profile" + ], + "redirect_sign_in_uri":[ + "authtest:/", + "http://localhost:9999/" + ], + "redirect_sign_out_uri":[ + "authtest:/", + "http://localhost:9999/" + ], + "response_type": "code" + }, + "standard_required_attributes": [], + "username_attributes": [], + "unauthenticated_identities_enabled": true + } +}'''; -const hostedUiConfig = CognitoOAuthConfig( - appClientId: testAppClientId, - scopes: scopes, - signInRedirectUri: redirectUri, - signOutRedirectUri: redirectUri, - webDomain: webDomain, -); -// TODO(nikahsn): update to use AmplifyOutputs config -final userPoolOnlyConfig = AmplifyConfig( - auth: AuthConfig.cognito( - userPoolConfig: const CognitoUserPoolConfig( - poolId: testUserPoolId, - appClientId: testAppClientId, - region: testRegion, - ), - ), -).toAmplifyOutputs(); +const amplifyConfigUserPoolOnly = '''{ + "version": "1", + "auth": { + "aws_region": "region", + "user_pool_id": "us-east-1_userPoolId", + "user_pool_client_id": "appClientId", + "password_policy": { + "require_numbers": false, + "require_lowercase": false, + "require_uppercase": false, + "require_symbols": false + }, + "standard_required_attributes":[], + "username_attributes":[], + "unauthenticated_identities_enabled":true + } +} +'''; -final mockConfig = AmplifyConfig( - auth: AuthConfig.cognito( - userPoolConfig: const CognitoUserPoolConfig( - poolId: testUserPoolId, - appClientId: testAppClientId, - region: testRegion, - ), - identityPoolConfig: const CognitoIdentityPoolConfig( - poolId: testIdentityPoolId, - region: testRegion, - ), - hostedUiConfig: hostedUiConfig, - ), -).toAmplifyOutputs(); +const amplifyConfigWithAnalytics = '''{ + "version": "1", + "analytics": { + "amazon_pinpoint": { + "aws_region": "region", + "app_id": "pinpointAppId" + } + }, + "auth": { + "aws_region": "region", + "user_pool_id": "us-east-1_userPoolId", + "user_pool_client_id": "appClientId", + "password_policy": { + "require_numbers": false, + "require_lowercase": false, + "require_uppercase": false, + "require_symbols": false + }, + "standard_required_attributes":[], + "username_attributes":[], + "unauthenticated_identities_enabled":true + } +}'''; -final mockConfigWithPinpoint = AmplifyConfig( - auth: AuthConfig.cognito( - userPoolConfig: const CognitoUserPoolConfig( - poolId: testUserPoolId, - appClientId: testAppClientId, - region: testRegion, - ), - ), - analytics: const AnalyticsConfig( - plugins: { - 'awsPinpointAnalyticsPlugin': PinpointPluginConfig( - pinpointAnalytics: - PinpointAnalytics(appId: testPinpointAppId, region: testRegion), - pinpointTargeting: PinpointTargeting(region: testRegion), - ), +const username = 'username'; +const password = 'password'; +const userSub = 'userSub'; +const accessKeyId = 'accessKeyId'; +const secretAccessKey = 'secretAccessKey'; +const sessionToken = 'sessionToken'; +final expiration = DateTime.utc(2100, 1, 1); +const identityId = 'identityId'; +const deviceKey = 'deviceKey'; +const deviceGroupKey = 'deviceGroupKey'; +const devicePassword = 'devicePassword'; +const refreshToken = 'refreshToken'; +const idToken = JsonWebToken( + header: JsonWebHeader(algorithm: Algorithm.hmacSha256), + claims: JsonWebClaims( + subject: userSub, + customClaims: { + 'cognito:username': username, }, ), -).toAmplifyOutputs(); - + signature: [], +); final accessToken = JsonWebToken( header: const JsonWebHeader(algorithm: Algorithm.hmacSha256), claims: JsonWebClaims( @@ -81,29 +120,18 @@ final accessToken = JsonWebToken( ), signature: const [], ); -const refreshToken = 'refreshToken'; -const idToken = JsonWebToken( - header: JsonWebHeader(algorithm: Algorithm.hmacSha256), - claims: JsonWebClaims( - subject: userSub, - customClaims: { - 'cognito:username': username, - }, - ), - signature: [], + +final mockConfig = AmplifyOutputs.fromJson( + jsonDecode(amplifyConfig) as Map, +); +final mockConfigUserPoolOnly = AmplifyOutputs.fromJson( + jsonDecode(amplifyConfigUserPoolOnly) as Map, +); +final mockConfigWithPinpoint = AmplifyOutputs.fromJson( + jsonDecode(amplifyConfigWithAnalytics) as Map, ); -const username = 'username'; -const password = 'password'; -const userSub = 'userSub'; -const accessKeyId = 'accessKeyId'; -const secretAccessKey = 'secretAccessKey'; -const sessionToken = 'sessionToken'; -final expiration = DateTime.utc(2100, 1, 1); -const identityId = 'identityId'; -const deviceKey = 'deviceKey'; -const deviceGroupKey = 'deviceGroupKey'; -const devicePassword = 'devicePassword'; +final hostedUiConfig = CognitoOAuthConfig.fromAuthOutputs(mockConfig.auth!); final authConfig = AuthConfiguration.fromAmplifyOutputs(mockConfig); final userPoolConfig = authConfig.userPoolConfig!; final identityPoolConfig = authConfig.identityPoolConfig!; diff --git a/packages/auth/amplify_auth_cognito_test/test/flows/hostedui/hosted_ui_platform_io_test.dart b/packages/auth/amplify_auth_cognito_test/test/flows/hostedui/hosted_ui_platform_io_test.dart index 6673d1cf6a..2e07e4e636 100644 --- a/packages/auth/amplify_auth_cognito_test/test/flows/hostedui/hosted_ui_platform_io_test.dart +++ b/packages/auth/amplify_auth_cognito_test/test/flows/hostedui/hosted_ui_platform_io_test.dart @@ -9,10 +9,7 @@ import 'dart:io'; import 'package:amplify_auth_cognito_dart/amplify_auth_cognito_dart.dart'; import 'package:amplify_auth_cognito_dart/src/flows/hosted_ui/hosted_ui_platform_io.dart'; import 'package:amplify_auth_cognito_dart/src/state/state.dart'; -import 'package:amplify_auth_cognito_test/common/mock_config.dart'; -import 'package:amplify_auth_cognito_test/common/mock_dispatcher.dart'; -import 'package:amplify_auth_cognito_test/common/mock_hosted_ui.dart'; -import 'package:amplify_auth_cognito_test/common/mock_secure_storage.dart'; +import 'package:amplify_auth_cognito_test/amplify_auth_cognito_test.dart'; import 'package:amplify_core/amplify_core.dart'; import 'package:amplify_secure_storage_dart/amplify_secure_storage_dart.dart'; import 'package:http/http.dart' as http; @@ -144,7 +141,9 @@ void main() { final hostedUiPlatform = MockHostedUiPlatform(dependencyManager); final redirect = Uri.parse( - redirectUri.split(',').firstWhere((uri) => uri.contains('localhost')), + hostedUiConfig.signInRedirectUri + .split(',') + .firstWhere((uri) => uri.contains('localhost')), ); expect(hostedUiPlatform.signInRedirectUri, redirect); expect(hostedUiPlatform.signOutRedirectUri, redirect); diff --git a/packages/auth/amplify_auth_cognito_test/test/flows/hostedui/hosted_ui_platform_test.dart b/packages/auth/amplify_auth_cognito_test/test/flows/hostedui/hosted_ui_platform_test.dart index c9a600d928..ff36a8f83f 100644 --- a/packages/auth/amplify_auth_cognito_test/test/flows/hostedui/hosted_ui_platform_test.dart +++ b/packages/auth/amplify_auth_cognito_test/test/flows/hostedui/hosted_ui_platform_test.dart @@ -26,7 +26,7 @@ void main() { late SecureStorageInterface secureStorage; late HostedUiPlatform platform; late DependencyManager dependencyManager; - const keys = HostedUiKeys(hostedUiConfig); + final keys = HostedUiKeys(hostedUiConfig); AWSLogger().logLevel = LogLevel.verbose; @@ -69,7 +69,7 @@ void main() { test('missing state throws', () async { final parameters = await server.authorize( await platform.getSignInUri( - redirectUri: Uri.parse(redirectUri), + redirectUri: Uri.parse(hostedUiConfig.signInRedirectUri), ), ); @@ -86,7 +86,7 @@ void main() { test('mismatched state throws', () async { final parameters = await server.authorize( await platform.getSignInUri( - redirectUri: Uri.parse(redirectUri), + redirectUri: Uri.parse(hostedUiConfig.signInRedirectUri), ), ); @@ -105,7 +105,7 @@ void main() { test('succeeds', () async { final parameters = await server.authorize( await platform.getSignInUri( - redirectUri: Uri.parse(redirectUri), + redirectUri: Uri.parse(hostedUiConfig.signInRedirectUri), ), ); diff --git a/packages/auth/amplify_auth_cognito_test/test/flows/srp/srp_device_password_verifier_worker_test.dart b/packages/auth/amplify_auth_cognito_test/test/flows/srp/srp_device_password_verifier_worker_test.dart index 0e9748ec3c..cc45f6fa2a 100644 --- a/packages/auth/amplify_auth_cognito_test/test/flows/srp/srp_device_password_verifier_worker_test.dart +++ b/packages/auth/amplify_auth_cognito_test/test/flows/srp/srp_device_password_verifier_worker_test.dart @@ -30,7 +30,7 @@ void main() { final message = SrpDevicePasswordVerifierMessage( (b) => b ..initResult = initResult - ..clientId = testAppClientId + ..clientId = mockConfig.auth!.userPoolClientId ..deviceSecrets = CognitoDeviceSecrets( (b) => b ..deviceKey = deviceKey @@ -69,7 +69,7 @@ void main() { final message = SrpDevicePasswordVerifierMessage( (b) => b ..initResult = initResult - ..clientId = testAppClientId + ..clientId = mockConfig.auth!.userPoolClientId ..deviceSecrets = CognitoDeviceSecrets( (b) => b ..deviceKey = deviceKey diff --git a/packages/auth/amplify_auth_cognito_test/test/flows/srp/srp_password_verifier_worker_test.dart b/packages/auth/amplify_auth_cognito_test/test/flows/srp/srp_password_verifier_worker_test.dart index 595b2cb246..1db796e6f4 100644 --- a/packages/auth/amplify_auth_cognito_test/test/flows/srp/srp_password_verifier_worker_test.dart +++ b/packages/auth/amplify_auth_cognito_test/test/flows/srp/srp_password_verifier_worker_test.dart @@ -29,7 +29,7 @@ void main() { final message = SrpPasswordVerifierMessage( (b) => b ..initResult = initResult - ..clientId = testAppClientId + ..clientId = mockConfig.auth!.userPoolClientId ..poolId = 'us-east-1_$poolName' ..parameters = SignInParameters( (p) => p @@ -70,7 +70,7 @@ void main() { final message = SrpPasswordVerifierMessage( (b) => b ..initResult = initResult - ..clientId = testAppClientId + ..clientId = mockConfig.auth!.userPoolClientId ..poolId = 'us-east-1_$poolName' ..parameters = SignInParameters( (p) => p diff --git a/packages/auth/amplify_auth_cognito_test/test/plugin/sign_out_test.dart b/packages/auth/amplify_auth_cognito_test/test/plugin/sign_out_test.dart index a1d8d7dd73..1fcef4af24 100644 --- a/packages/auth/amplify_auth_cognito_test/test/plugin/sign_out_test.dart +++ b/packages/auth/amplify_auth_cognito_test/test/plugin/sign_out_test.dart @@ -25,7 +25,7 @@ final throwsSignedOutException = throwsA(isA()); void main() { final userPoolKeys = CognitoUserPoolKeys(userPoolConfig); final identityPoolKeys = CognitoIdentityPoolKeys(identityPoolConfig); - const hostedUiKeys = HostedUiKeys(hostedUiConfig); + final hostedUiKeys = HostedUiKeys(hostedUiConfig); late AmplifyAuthCognitoDart plugin; late CognitoAuthStateMachine stateMachine; @@ -250,7 +250,7 @@ void main() { test('can sign out in user pool-only mode', () async { seedStorage(secureStorage, userPoolKeys: userPoolKeys); await plugin.configure( - config: userPoolOnlyConfig, + config: mockConfigUserPoolOnly, authProviderRepo: testAuthRepo, ); diff --git a/packages/auth/amplify_auth_cognito_test/test/state/configuration_state_machine_test.dart b/packages/auth/amplify_auth_cognito_test/test/state/configuration_state_machine_test.dart index 83725d0003..32bea41250 100644 --- a/packages/auth/amplify_auth_cognito_test/test/state/configuration_state_machine_test.dart +++ b/packages/auth/amplify_auth_cognito_test/test/state/configuration_state_machine_test.dart @@ -89,6 +89,8 @@ void main() { test('reads existing analytics metadata if analytics is configured', () async { const testEndpointId = 'testEndpointId'; + final testPinpointAppId = + mockConfigWithPinpoint.analytics!.amazonPinpoint!.appId; // Add state machine dependencies. stateMachine.addInstance( diff --git a/packages/auth/amplify_auth_cognito_test/test/state/fetch_auth_session_state_machine_test.dart b/packages/auth/amplify_auth_cognito_test/test/state/fetch_auth_session_state_machine_test.dart index 93acde47d4..ce7f2747bc 100644 --- a/packages/auth/amplify_auth_cognito_test/test/state/fetch_auth_session_state_machine_test.dart +++ b/packages/auth/amplify_auth_cognito_test/test/state/fetch_auth_session_state_machine_test.dart @@ -1253,7 +1253,7 @@ void main() { }); group('User Pool Only Config', () { setUp(() { - config = userPoolOnlyConfig; + config = mockConfigUserPoolOnly; }); group('tokens valid', () { setUp(() { diff --git a/packages/auth/amplify_auth_cognito_test/test/state/hosted_ui_state_machine_test.dart b/packages/auth/amplify_auth_cognito_test/test/state/hosted_ui_state_machine_test.dart index 81d8696bc0..eecd4c4628 100644 --- a/packages/auth/amplify_auth_cognito_test/test/state/hosted_ui_state_machine_test.dart +++ b/packages/auth/amplify_auth_cognito_test/test/state/hosted_ui_state_machine_test.dart @@ -70,7 +70,7 @@ class FailingHostedUiPlatform extends HostedUiPlatform { void main() { AWSLogger().logLevel = LogLevel.verbose; - const keys = HostedUiKeys(hostedUiConfig); + final keys = HostedUiKeys(hostedUiConfig); group('HostedUiStateMachine', () { late MockOAuthServer server; @@ -107,10 +107,16 @@ void main() { expect(authorizationUri.queryParameters['redirect_uri'], isNotEmpty); expect(authorizationUri.queryParameters['scope'], isNotNull); - expect(authorizationUri.queryParameters['scope'], scopes.join(' ')); + expect( + authorizationUri.queryParameters['scope'], + hostedUiConfig.scopes.join(' '), + ); expect(authorizationUri.queryParameters['response_type'], 'code'); - expect(authorizationUri.queryParameters['client_id'], testAppClientId); + expect( + authorizationUri.queryParameters['client_id'], + hostedUiConfig.appClientId, + ); expect(authorizationUri.queryParameters['code_challenge'], isNotNull); expect(authorizationUri.queryParameters['code_challenge'], isNotEmpty); diff --git a/packages/auth/amplify_auth_cognito_test/test/state/sign_in_state_machine_test.dart b/packages/auth/amplify_auth_cognito_test/test/state/sign_in_state_machine_test.dart index c5bfbb87cc..40e0f7b715 100644 --- a/packages/auth/amplify_auth_cognito_test/test/state/sign_in_state_machine_test.dart +++ b/packages/auth/amplify_auth_cognito_test/test/state/sign_in_state_machine_test.dart @@ -36,7 +36,7 @@ void main() { test('smoke test', () async { stateMachine .dispatch( - ConfigurationEvent.configure(userPoolOnlyConfig), + ConfigurationEvent.configure(mockConfigUserPoolOnly), ) .ignore(); await expectLater( @@ -97,7 +97,7 @@ void main() { test('customAuthWithSrp requires password', () async { stateMachine .dispatch( - ConfigurationEvent.configure(userPoolOnlyConfig), + ConfigurationEvent.configure(mockConfigUserPoolOnly), ) .ignore(); await expectLater( @@ -134,7 +134,7 @@ void main() { test('customAuthWithoutSrp forbids password', () async { stateMachine .dispatch( - ConfigurationEvent.configure(userPoolOnlyConfig), + ConfigurationEvent.configure(mockConfigUserPoolOnly), ) .ignore(); await expectLater( diff --git a/packages/notifications/push/amplify_push_notifications/test/amplify_push_notifications_impl_test.dart b/packages/notifications/push/amplify_push_notifications/test/amplify_push_notifications_impl_test.dart index a170e8e03f..327911ee43 100644 --- a/packages/notifications/push/amplify_push_notifications/test/amplify_push_notifications_impl_test.dart +++ b/packages/notifications/push/amplify_push_notifications/test/amplify_push_notifications_impl_test.dart @@ -54,11 +54,9 @@ void main() { ..addInstance(mockPushNotificationsHostApi) ..addInstance(mockAmplifySecureStorage); - // TODO(nikahsn): update to use AmplifyOutputs config - final config = AmplifyConfig.fromJson( - jsonDecode(amplifyconfig) as Map, - // ignore: invalid_use_of_internal_member - ).toAmplifyOutputs(); + final config = AmplifyOutputs.fromJson( + jsonDecode(amplifyConfig) as Map, + ); setUp(() { plugin = TestAmplifyPushNotifications( @@ -204,11 +202,9 @@ void main() { group('Config failure cases', () { test('should throw exception when configuring if there is no appId present', () async { - // TODO(nikahsn): update to use AmplifyOutputs config - final config = AmplifyConfig.fromJson( - jsonDecode(noPushAppIdAmplifyConfig) as Map, - // ignore: invalid_use_of_internal_member - ).toAmplifyOutputs(); + final config = AmplifyOutputs.fromJson( + jsonDecode(amplifyConfigNoPushNotification) as Map, + ); expect( () async => plugin.configure( authProviderRepo: authProviderRepo, diff --git a/packages/notifications/push/amplify_push_notifications/test/test_data/fake_amplify_configuration.dart b/packages/notifications/push/amplify_push_notifications/test/test_data/fake_amplify_configuration.dart index b9e01dde08..5935cd49d9 100644 --- a/packages/notifications/push/amplify_push_notifications/test/test_data/fake_amplify_configuration.dart +++ b/packages/notifications/push/amplify_push_notifications/test/test_data/fake_amplify_configuration.dart @@ -1,79 +1,41 @@ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. // SPDX-License-Identifier: Apache-2.0 -const amplifyconfig = '''{ - "UserAgent": "aws-amplify-cli/2.0", - "Version": "1.0", - "analytics": { - "plugins": { - "awsPinpointAnalyticsPlugin": { - "pinpointAnalytics": { - "appId": "APP_ID", - "region": "us-west-2" - }, - "pinpointTargeting": { - "region": "us-west-2" - } - } - } - }, - "notifications": { - "plugins": { - "awsPinpointPushNotificationsPlugin": { - "appId": "APP_ID", - "region": "us-west-2" - } - } - }, +const amplifyConfig = '''{ + "version": "1", + "analytics": { + "amazon_pinpoint":{ + "aws_region": "us-west-2", + "app_id": "APP_ID" + } + }, "auth": { - "plugins": { - "awsCognitoAuthPlugin": { - "UserAgent": "aws-amplify-cli/0.1.0", - "Version": "0.1.0", - "IdentityManager": { - "Default": {} - }, - "CredentialsProvider": { - "CognitoIdentity": { - "Default": { - "PoolId": "us-east-1:abc123", - "Region": "us-east-1" - } - } - }, - "Auth": { - "Default": { - "authenticationFlowType": "USER_SRP_AUTH", - "socialProviders": [], - "usernameAttributes": [], - "signupAttributes": [ - "EMAIL" - ], - "passwordProtectionSettings": { - "passwordPolicyMinLength": 8, - "passwordPolicyCharacters": [] - }, - "mfaConfiguration": "OFF", - "mfaTypes": [ - "SMS" - ], - "verificationMechanisms": [ - "EMAIL" - ] - } - }, - "PinpointAnalytics": { - "Default": { - "AppId": "APP_ID", - "Region": "us-west-2" - } - }, - "PinpointTargeting": { - "Default": { - "Region": "us-west-2" - } - } - } - } + "aws_region": "us-east-1", + "identity_pool_id": "us-east-1:abc123", + "password_policy": { + "min_length": 8, + "require_numbers": false, + "require_lowercase": false, + "require_uppercase": false, + "require_symbols": false + }, + "standard_required_attributes":[ + "email" + ], + "username_attributes":[], + "user_verification_types":[ + "email" + ], + "unauthenticated_identities_enabled": true, + "mfa_configuration": "NONE", + "mfa_methods":[ + "SMS" + ] + }, + "notifications": { + "aws_region": "us-west-2", + "amazon_pinpoint_app_id": "APP_ID", + "channels":[] } -}'''; +} +'''; diff --git a/packages/notifications/push/amplify_push_notifications/test/test_data/fake_defective_configuration.dart b/packages/notifications/push/amplify_push_notifications/test/test_data/fake_defective_configuration.dart index 1e59cfe369..8bee4fec99 100644 --- a/packages/notifications/push/amplify_push_notifications/test/test_data/fake_defective_configuration.dart +++ b/packages/notifications/push/amplify_push_notifications/test/test_data/fake_defective_configuration.dart @@ -1,75 +1,36 @@ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. // SPDX-License-Identifier: Apache-2.0 -const noPushAppIdAmplifyConfig = '''{ - "UserAgent": "aws-amplify-cli/2.0", - "Version": "1.0", +const amplifyConfigNoPushNotification = '''{ + "version": "1", "analytics": { - "plugins": { - "awsPinpointAnalyticsPlugin": { - "pinpointAnalytics": { - "appId": "APP_ID", - "region": "us-west-2" - }, - "pinpointTargeting": { - "region": "us-west-2" - } - } - } - }, - "notifications": { - "plugins": { - } - }, - "auth": { - "plugins": { - "awsCognitoAuthPlugin": { - "UserAgent": "aws-amplify-cli/0.1.0", - "Version": "0.1.0", - "IdentityManager": { - "Default": {} - }, - "CredentialsProvider": { - "CognitoIdentity": { - "Default": { - "PoolId": "us-east-1:abc123", - "Region": "us-east-1" - } - } - }, - "Auth": { - "Default": { - "authenticationFlowType": "USER_SRP_AUTH", - "socialProviders": [], - "usernameAttributes": [], - "signupAttributes": [ - "EMAIL" - ], - "passwordProtectionSettings": { - "passwordPolicyMinLength": 8, - "passwordPolicyCharacters": [] - }, - "mfaConfiguration": "OFF", - "mfaTypes": [ - "SMS" - ], - "verificationMechanisms": [ - "EMAIL" - ] - } - }, - "PinpointAnalytics": { - "Default": { - "AppId": "APP_ID", - "Region": "us-west-2" - } - }, - "PinpointTargeting": { - "Default": { - "Region": "us-west-2" - } - } - } + "amazon_pinpoint": { + "aws_region": "us-west-2", + "app_id":"APP_ID" } - } -}'''; + }, + "auth": { + "aws_region": "us-east-1", + "identity_pool_id": "us-east-1:abc123", + "password_policy": { + "min_length": 8, + "require_numbers": false, + "require_lowercase": false, + "require_uppercase": false, + "require_symbols": false + }, + "standard_required_attributes":[ + "email" + ], + "username_attributes":[], + "user_verification_types":[ + "email" + ], + "unauthenticated_identities_enabled": true, + "mfa_configuration": "NONE", + "mfa_methods":[ + "SMS" + ] + } +} +''';