-
Notifications
You must be signed in to change notification settings - Fork 825
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(cli): add sandbox mode warning to amplify status
- Loading branch information
1 parent
acaff15
commit 2c0f74a
Showing
19 changed files
with
448 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
78 changes: 78 additions & 0 deletions
78
packages/amplify-cli/src/__tests__/extensions/amplify-helpers/api-key.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
import fs from 'fs'; | ||
import { getAppSyncApiConfig, getApiKeyConfig, apiKeyIsActive, hasApiKey } from '../../../extensions/amplify-helpers/api-key'; | ||
import { stateManager } from 'amplify-cli-core'; | ||
|
||
jest.mock('amplify-cli-core', () => { | ||
const original = jest.requireActual('amplify-cli-core'); | ||
const amplifyMeta = fs.readFileSync(`${__dirname}/testData/mockLocalCloud/amplify-meta.json`); | ||
return { | ||
...original, | ||
stateManager: { | ||
metaFileExists: jest.fn(), | ||
getMeta: jest.fn().mockImplementation(() => JSON.parse(amplifyMeta.toString())), | ||
}, | ||
}; | ||
}); | ||
|
||
const stateManager_mock = stateManager as jest.Mocked<typeof stateManager>; | ||
|
||
describe('getAppSyncApiConfig', () => { | ||
it('returns the api object', async () => { | ||
const result = getAppSyncApiConfig(); | ||
|
||
expect(result).toStrictEqual({ | ||
service: 'AppSync', | ||
providerPlugin: 'awscloudformation', | ||
output: { | ||
authConfig: { | ||
defaultAuthentication: { | ||
authenticationType: 'AWS_IAM', | ||
}, | ||
additionalAuthenticationProviders: [ | ||
{ | ||
authenticationType: 'API_KEY', | ||
apiKeyConfig: { | ||
apiKeyExpirationDays: 2, | ||
apiKeyExpirationDate: '2021-08-20T20:38:07.585Z', | ||
description: '', | ||
}, | ||
}, | ||
], | ||
}, | ||
globalSandboxModeConfig: { | ||
dev: { | ||
enabled: true, | ||
}, | ||
}, | ||
}, | ||
}); | ||
}); | ||
}); | ||
|
||
describe('getApiKeyConfig', () => { | ||
it('returns the api key config', () => { | ||
const result = getApiKeyConfig(); | ||
|
||
expect(result).toStrictEqual({ | ||
apiKeyExpirationDays: 2, | ||
apiKeyExpirationDate: '2021-08-20T20:38:07.585Z', | ||
description: '', | ||
}); | ||
}); | ||
}); | ||
|
||
describe('apiKeyIsActive', () => { | ||
it('returns true if api key is active', () => { | ||
const result = apiKeyIsActive(); | ||
|
||
expect(result).toBe(false); | ||
}); | ||
}); | ||
|
||
describe('hasApiKey', () => { | ||
it('returns true if api key is present', () => { | ||
const result = hasApiKey(); | ||
|
||
expect(result).toBe(true); | ||
}); | ||
}); |
67 changes: 67 additions & 0 deletions
67
...ify-cli/src/__tests__/extensions/amplify-helpers/show-global-sandbox-mode-warning.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
import { | ||
globalSandboxModeEnabled, | ||
showGlobalSandboxModeWarning, | ||
} from '../../../extensions/amplify-helpers/show-global-sandbox-mode-warning'; | ||
import { $TSContext } from '../../../../../amplify-cli-core/lib'; | ||
import fs from 'fs'; | ||
import chalk from 'chalk'; | ||
|
||
let ctx, amplifyMeta; | ||
|
||
jest.mock('amplify-cli-core', () => ({ | ||
stateManager: { | ||
getMeta: jest.fn(() => JSON.parse(amplifyMeta.toString())), | ||
}, | ||
})); | ||
|
||
describe('global sandbox mode warning', () => { | ||
beforeEach(() => { | ||
const envName = 'dev'; | ||
ctx = { | ||
amplify: { | ||
getEnvInfo() { | ||
return { envName }; | ||
}, | ||
}, | ||
print: { | ||
info() { | ||
// noop | ||
}, | ||
}, | ||
} as unknown as $TSContext; | ||
}); | ||
|
||
describe('globalSandboxModeEnabled', () => { | ||
describe('enabled', () => { | ||
it('returns true', async () => { | ||
amplifyMeta = fs.readFileSync(`${__dirname}/testData/mockLocalCloud/amplify-meta.json`); | ||
expect(globalSandboxModeEnabled(ctx)).toBe(true); | ||
}); | ||
}); | ||
|
||
describe('not specified', () => { | ||
it('returns false', async () => { | ||
amplifyMeta = fs.readFileSync(`${__dirname}/testData/mockLocalCloud/amplify-meta-2.json`); | ||
expect(globalSandboxModeEnabled(ctx)).toBe(false); | ||
}); | ||
}); | ||
}); | ||
|
||
describe('showGlobalSandboxModeWarning', () => { | ||
it('prints warning message', async () => { | ||
amplifyMeta = fs.readFileSync(`${__dirname}/testData/mockLocalCloud/amplify-meta.json`); | ||
|
||
jest.spyOn(ctx.print, 'info'); | ||
|
||
await showGlobalSandboxModeWarning(ctx); | ||
|
||
expect(ctx.print.info).toBeCalledWith(` | ||
⚠️ WARNING: ${chalk.green('"type AMPLIFY_GLOBAL @allow_public_data_access_with_api_key"')} in your GraphQL schema | ||
allows public create, read, update, and delete access to all models via API Key. This | ||
should only be used for testing purposes. API Key expiration date is: 8/20/2021 | ||
To configure PRODUCTION-READY authorization rules, review: https://docs.amplify.aws/cli/graphql-transformer/auth | ||
`); | ||
}); | ||
}); | ||
}); |
25 changes: 25 additions & 0 deletions
25
...-cli/src/__tests__/extensions/amplify-helpers/testData/mockLocalCloud/amplify-meta-2.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
{ | ||
"api": { | ||
"ampapp": { | ||
"service": "AppSync", | ||
"providerPlugin": "awscloudformation", | ||
"output": { | ||
"authConfig": { | ||
"defaultAuthentication": { | ||
"authenticationType": "AWS_IAM" | ||
}, | ||
"additionalAuthenticationProviders": [ | ||
{ | ||
"authenticationType": "API_KEY", | ||
"apiKeyConfig": { | ||
"apiKeyExpirationDays": 2, | ||
"apiKeyExpirationDate": "2021-08-20T20:38:07.585Z", | ||
"description": "" | ||
} | ||
} | ||
] | ||
} | ||
} | ||
} | ||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
...fy-cli/src/__tests__/extensions/amplify-helpers/testData/mockLocalCloud/amplify-meta.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
{ | ||
"api": { | ||
"ampapp": { | ||
"service": "AppSync", | ||
"providerPlugin": "awscloudformation", | ||
"output": { | ||
"authConfig": { | ||
"defaultAuthentication": { | ||
"authenticationType": "AWS_IAM" | ||
}, | ||
"additionalAuthenticationProviders": [ | ||
{ | ||
"authenticationType": "API_KEY", | ||
"apiKeyConfig": { | ||
"apiKeyExpirationDays": 2, | ||
"apiKeyExpirationDate": "2021-08-20T20:38:07.585Z", | ||
"description": "" | ||
} | ||
} | ||
] | ||
}, | ||
"globalSandboxModeConfig": { | ||
"dev": { | ||
"enabled": true | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.