Skip to content

Commit

Permalink
test: test
Browse files Browse the repository at this point in the history
  • Loading branch information
AmmarKarachi committed Oct 30, 2020
1 parent 86581c5 commit 66f5ea1
Show file tree
Hide file tree
Showing 21 changed files with 569 additions and 47 deletions.
34 changes: 34 additions & 0 deletions .circleci/config.base.yml
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,30 @@ jobs:
path: ~/repo/packages/amplify-migration-tests/amplify-migration-reports
working_directory: ~/repo

amplify_migration_tests_v4_30_0:
<<: *defaults
steps:
- attach_workspace:
at: ./
- restore_cache:
key: amplify-cli-yarn-deps-{{ .Branch }}-{{ checksum "yarn.lock" }}
- run:
name: Update OS Packages
command: sudo apt-get update
- run:
name: Run tests migrating from CLI v4.30.0
command: |
source .circleci/local_publish_helpers.sh
changeNpmGlobalPath
cd packages/amplify-migration-tests
yarn run migration_v4.30.0_auth --maxWorkers=3 $TEST_SUITE
no_output_timeout: 5m
- store_test_results:
path: packages/amplify-migration-tests/
- store_artifacts:
path: ~/repo/packages/amplify-migration-tests/amplify-migration-reports
working_directory: ~/repo

amplify_migration_tests_latest:
<<: *defaults
steps:
Expand Down Expand Up @@ -748,6 +772,16 @@ workflows:
- feat-import
requires:
- build
- amplify_migration_tests_v4_30_0:
filters:
branches:
only:
- master
- graphqlschemae2e
- /fix\/team-provider/
- feat-import
requires:
- build
- amplify_console_integration_tests:
filters:
branches:
Expand Down
34 changes: 34 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,30 @@ jobs:
path: packages/amplify-migration-tests/
- store_artifacts:
path: ~/repo/packages/amplify-migration-tests/amplify-migration-reports
amplify_migration_tests_v4_30_0:
working_directory: ~/repo
docker: *ref_0
resource_class: large
steps:
- attach_workspace:
at: ./
- restore_cache:
key: 'amplify-cli-yarn-deps-{{ .Branch }}-{{ checksum "yarn.lock" }}'
- run:
name: Update OS Packages
command: sudo apt-get update
- run:
name: Run tests migrating from CLI v4.30.0
command: |
source .circleci/local_publish_helpers.sh
changeNpmGlobalPath
cd packages/amplify-migration-tests
yarn run migration_v4.30.0_auth --maxWorkers=3 $TEST_SUITE
no_output_timeout: 5m
- store_test_results:
path: packages/amplify-migration-tests/
- store_artifacts:
path: ~/repo/packages/amplify-migration-tests/amplify-migration-reports
amplify_migration_tests_latest:
working_directory: ~/repo
docker: *ref_0
Expand Down Expand Up @@ -1304,6 +1328,16 @@ workflows:
- feat-import
requires:
- build
- amplify_migration_tests_v4_30_0:
filters:
branches:
only:
- master
- graphqlschemae2e
- /fix\/team-provider/
- feat-import
requires:
- build
- amplify_console_integration_tests:
filters:
branches:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ Parameters:

Conditions:
ShouldNotCreateEnvResources: !Equals [ !Ref env, NONE ]
HasHostedUIProviderCreds: !Not [ !Equals [ !Ref hostedUIProviderCreds, NONE ]]

Resources:
<%if (props.verificationBucketName) { %>
Expand Down Expand Up @@ -305,6 +306,7 @@ Resources:
<% } %>
RefreshTokenValidity: !Ref userpoolClientRefreshTokenValidity
UserPoolId: !Ref UserPool
PreventUserExistenceErrors: ENABLED
DependsOn: UserPool
UserPoolClient:
# Created provide application access to user pool
Expand All @@ -319,6 +321,7 @@ Resources:
GenerateSecret: !Ref userpoolClientGenerateSecret
RefreshTokenValidity: !Ref userpoolClientRefreshTokenValidity
UserPoolId: !Ref UserPool
PreventUserExistenceErrors: ENABLED
DependsOn: UserPool
# BEGIN USER POOL LAMBDA RESOURCES
UserPoolClientRole:
Expand Down Expand Up @@ -367,7 +370,7 @@ Resources:
- ' }'
- '};'
Handler: index.handler
Runtime: nodejs10.x
Runtime: nodejs12.x
Timeout: '300'
Role: !GetAtt
- UserPoolClientRole
Expand Down Expand Up @@ -493,7 +496,7 @@ Resources:
Handler: index.handler
Runtime: nodejs10.x
Runtime: nodejs12.x
Timeout: '300'
Role: !GetAtt
- UserPoolClientRole
Expand Down Expand Up @@ -562,6 +565,9 @@ Resources:
- ' const userPoolId = event.ResourceProperties.userPoolId;'
- ' let hostedUIProviderMeta = JSON.parse(event.ResourceProperties.hostedUIProviderMeta);'
- ' let hostedUIProviderCreds = JSON.parse(event.ResourceProperties.hostedUIProviderCreds);'
- ' if(Object.keys(hostedUIProviderCreds).length === 0) {'
- ' response.send(event, context, response.SUCCESS, {});'
- ' }'
- ' if (event.RequestType == ''Delete'') {'
- ' response.send(event, context, response.SUCCESS, {});'
- ' }'
Expand Down Expand Up @@ -622,7 +628,7 @@ Resources:
- '} '
Handler: index.handler
Runtime: nodejs10.x
Runtime: nodejs12.x
Timeout: '300'
Role: !GetAtt
- UserPoolClientRole
Expand Down Expand Up @@ -672,7 +678,7 @@ Resources:
ServiceToken: !GetAtt HostedUIProvidersCustomResource.Arn
userPoolId: !Ref UserPool
hostedUIProviderMeta: !Ref hostedUIProviderMeta
hostedUIProviderCreds: !Ref hostedUIProviderCreds
hostedUIProviderCreds: !If [HasHostedUIProviderCreds, !Ref hostedUIProviderCreds, "{}" ]
DependsOn: HostedUIProvidersCustomResourceLogPolicy
<% } %>
<%if (props.oAuthMetadata) { %>
Expand Down Expand Up @@ -721,7 +727,7 @@ Resources:
- '}'
Handler: index.handler
Runtime: nodejs10.x
Runtime: nodejs12.x
Timeout: '300'
Role: !GetAtt
- UserPoolClientRole
Expand Down Expand Up @@ -842,7 +848,7 @@ Resources:
- ' }'
- '};'
Handler: index.handler
Runtime: nodejs10.x
Runtime: nodejs12.x
Timeout: '300'
Role: !GetAtt
- MFALambdaRole
Expand Down Expand Up @@ -1002,7 +1008,7 @@ Resources:
- ' }'
- '};'
Handler: index.handler
Runtime: nodejs10.x
Runtime: nodejs12.x
Timeout: '300'
Role: !GetAtt
- OpenIdLambdaRole
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
import { StateManager } from '../../lib';

const teamProviderInfoSecrets = {
dev: {
awscloudformation: {
AuthRoleName: 'amplify-teamprovider-dev-134909-authRole',
UnauthRoleArn: 'arn:aws:iam::1234567891011:role/amplify-teamprovider-dev-134909-unauthRole',
AuthRoleArn: 'arn:aws:iam::1234567891011:role/amplify-teamprovider-dev-134909-authRole',
Region: 'us-east-1',
DeploymentBucketName: 'amplify-teamprovider-dev-134909-deployment',
UnauthRoleName: 'amplify-teamprovider-dev-134909-unauthRole',
StackName: 'amplify-teamprovider-dev-134909',
StackId: 'arn:aws:cloudformation:us-east-1:1234567891011:stack/amplify-teamprovider-dev-134909/df33f4d0-1895-11eb-a8b4-0e706f74ed45',
AmplifyAppId: 'd1gmlw7l76gj9',
},
categories: {
auth: {
teamprovider1819bdce: {
hostedUIProviderCreds: '[{"ProviderName":"Facebook","client_id":"asdasdasdasd","client_secret":"asdasdasd"}]',
},
},
},
},
prod: {
awscloudformation: {
AuthRoleName: 'amplify-teamprovider-prod-164239-authRole',
UnauthRoleArn: 'arn:aws:iam::1234567891011:role/amplify-teamprovider-prod-164239-unauthRole',
AuthRoleArn: 'arn:aws:iam::1234567891011:role/amplify-teamprovider-prod-164239-authRole',
Region: 'us-east-1',
DeploymentBucketName: 'amplify-teamprovider-prod-164239-deployment',
UnauthRoleName: 'amplify-teamprovider-prod-164239-unauthRole',
StackName: 'amplify-teamprovider-prod-164239',
StackId: 'arn:aws:cloudformation:us-east-1:1234567891011:stack/amplify-teamprovider-prod-164239/1b625f60-18ae-11eb-9e65-0ab042f700a7',
AmplifyAppId: 'd1gmlw7l76gj9',
},
categories: {
auth: {
teamprovider1819bdce: {
hostedUIProviderCreds: '[{"ProviderName":"Facebook","client_id":"abc","client_secret":"adb"}]',
},
},
},
},
};

const teamProviderInfoWithoutSecrets = {
dev: {
awscloudformation: {
AuthRoleName: 'amplify-teamprovider-dev-134909-authRole',
UnauthRoleArn: 'arn:aws:iam::1234567891011:role/amplify-teamprovider-dev-134909-unauthRole',
AuthRoleArn: 'arn:aws:iam::1234567891011:role/amplify-teamprovider-dev-134909-authRole',
Region: 'us-east-1',
DeploymentBucketName: 'amplify-teamprovider-dev-134909-deployment',
UnauthRoleName: 'amplify-teamprovider-dev-134909-unauthRole',
StackName: 'amplify-teamprovider-dev-134909',
StackId: 'arn:aws:cloudformation:us-east-1:1234567891011:stack/amplify-teamprovider-dev-134909/df33f4d0-1895-11eb-a8b4-0e706f74ed45',
AmplifyAppId: 'd1gmlw7l76gj9',
},
categories: {
auth: {
teamprovider1819bdce: {},
},
},
},
prod: {
awscloudformation: {
AuthRoleName: 'amplify-teamprovider-prod-164239-authRole',
UnauthRoleArn: 'arn:aws:iam::1234567891011:role/amplify-teamprovider-prod-164239-unauthRole',
AuthRoleArn: 'arn:aws:iam::1234567891011:role/amplify-teamprovider-prod-164239-authRole',
Region: 'us-east-1',
DeploymentBucketName: 'amplify-teamprovider-prod-164239-deployment',
UnauthRoleName: 'amplify-teamprovider-prod-164239-unauthRole',
StackName: 'amplify-teamprovider-prod-164239',
StackId: 'arn:aws:cloudformation:us-east-1:1234567891011:stack/amplify-teamprovider-prod-164239/1b625f60-18ae-11eb-9e65-0ab042f700a7',
AmplifyAppId: 'd1gmlw7l76gj9',
},
categories: {
auth: {
teamprovider1819bdce: {
hostedUIProviderCreds: '[{"ProviderName":"Facebook","client_id":"abc","client_secret":"adb"}]',
},
},
},
},
};
const secrets = {
d1gmlw7l76gj9: {
dev: {
auth: {
teamprovider1819bdce: {
hostedUIProviderCreds: '[{"ProviderName":"Facebook","client_id":"asdasdasdasd","client_secret":"asdasdasd"}]',
},
},
},
},
};

describe('test move secrests to deployment', () => {
const stateManager = new StateManager();
const mockGetLocalEnvInfo = jest.spyOn(stateManager, 'getLocalEnvInfo').mockReturnValue({ envName: 'dev' });
const mockGetTeamProviderInfo = jest.spyOn(stateManager, 'getTeamProviderInfo').mockReturnValue(teamProviderInfoSecrets);
const setTeamProviderInfo = jest.spyOn(stateManager, 'setTeamProviderInfo').mockImplementation();
const setDeploymentSecrets = jest.spyOn(stateManager, 'setDeploymentSecrets').mockImplementation();
it('test with migrate', () => {
stateManager.moveSecretsFromDeploymentToTeamProvider();
expect(setTeamProviderInfo).toBeCalledWith(undefined, teamProviderInfoWithoutSecrets);
expect(setDeploymentSecrets).toBeCalledWith(secrets);
expect(mockGetLocalEnvInfo).toBeCalled();
expect(mockGetLocalEnvInfo).toBeCalled();
});
});
1 change: 1 addition & 0 deletions packages/amplify-cli-core/src/errors/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ export class NonEmptyDirectoryError extends Error {}
export class InvalidEnvironmentNameError extends Error {}
export class InvalidSubCommandError extends Error {}
export class FrontendBuildError extends Error {}
export class MigrateError extends Error {}
6 changes: 5 additions & 1 deletion packages/amplify-cli-core/src/jsonUtilities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ export class JSONUtilities {
options?: {
minify?: boolean;
keepComments?: boolean;
mode?: number;
},
): void => {
if (!fileName) {
Expand All @@ -68,7 +69,10 @@ export class JSONUtilities {
const dirPath = path.dirname(fileName);
fs.ensureDirSync(dirPath);

fs.writeFileSync(fileName, jsonString, 'utf8');
fs.writeFileSync(fileName, jsonString, {
encoding: 'utf8',
mode: options?.mode,
});
};

public static parse = <T>(
Expand Down
5 changes: 5 additions & 0 deletions packages/amplify-cli-core/src/state-manager/pathManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export const PathConstants = {
DotAWSDir: '.aws',
AWSCredentials: 'credentials',
AWSConfig: 'config',
DeploymentSecrets: 'deployment-secrets.json',

// in project root
AmplifyDirName: 'amplify',
Expand Down Expand Up @@ -130,6 +131,10 @@ export class PathManager {
return this.constructPath(projectPath, [PathConstants.AmplifyDirName, fileName]);
};

getDotAWSAmplifyDirPath = (): string => path.normalize(path.join(homedir(), PathConstants.DotAWSDir, PathConstants.AmplifyDirName));

getDeploymentSecrets = (): string => path.normalize(path.join(this.getDotAWSAmplifyDirPath(), PathConstants.DeploymentSecrets));

private constructPath = (projectPath?: string, segments: string[] = []): string => {
if (!projectPath) {
projectPath = this.findProjectRoot();
Expand Down
Loading

0 comments on commit 66f5ea1

Please sign in to comment.