forked from aws-amplify/amplify-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(amplify-category-api): add global sandbox mode directive on sche…
…ma generation (aws-amplify#8074) * feat(amplify-category-api): add global sandbox mode directive on schema generation * test(amplify-e2e-tests): add e2e tests for sandbox mode * test(amplify-category-api): add unit test for generating sandbox mode directive; rm unused method
- Loading branch information
1 parent
3ec3fe3
commit 075a333
Showing
10 changed files
with
235 additions
and
87 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
21 changes: 21 additions & 0 deletions
21
...gory-api/src/__tests__/provider-utils/awscloudformation/utils/global-sandbox-mode.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,21 @@ | ||
import { defineGlobalSandboxMode } from '../../../../provider-utils/awscloudformation/utils/global-sandbox-mode'; | ||
import { $TSContext } from 'amplify-cli-core'; | ||
|
||
describe('global sandbox mode GraphQL directive', () => { | ||
it('returns AMPLIFY_DIRECTIVE type with code comment, directive, and env name', () => { | ||
const envName = 'envone'; | ||
const ctx = <$TSContext>{ | ||
amplify: { | ||
getEnvInfo() { | ||
return { envName }; | ||
}, | ||
}, | ||
}; | ||
|
||
expect(defineGlobalSandboxMode(ctx)) | ||
.toBe(`# This allows public create, read, update, and delete access for a limited time to all models via API Key. | ||
# To configure PRODUCTION-READY authorization rules, review: https://docs.amplify.aws/cli/graphql-transformer/auth | ||
type AMPLIFY_GLOBAL @allow_public_data_access_with_api_key(in: \"${envName}\") # FOR TESTING ONLY!\n | ||
`); | ||
}); | ||
}); |
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
8 changes: 8 additions & 0 deletions
8
...es/amplify-category-api/src/provider-utils/awscloudformation/utils/global-sandbox-mode.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,8 @@ | ||
export function defineGlobalSandboxMode(context: any): string { | ||
const envName = context.amplify.getEnvInfo().envName; | ||
|
||
return `# This allows public create, read, update, and delete access for a limited time to all models via API Key. | ||
# To configure PRODUCTION-READY authorization rules, review: https://docs.amplify.aws/cli/graphql-transformer/auth | ||
type AMPLIFY_GLOBAL @allow_public_data_access_with_api_key(in: \"${envName}\") # FOR TESTING ONLY!\n | ||
`; | ||
} |
6 changes: 6 additions & 0 deletions
6
packages/amplify-e2e-tests/schemas/model_with_sandbox_mode.graphql
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,6 @@ | ||
type AMPLIFY_GLOBAL @allow_public_data_access_with_api_key(in: "dev") | ||
|
||
type Todo @model { | ||
id: ID! | ||
content: String | ||
} |
45 changes: 45 additions & 0 deletions
45
packages/amplify-e2e-tests/src/__tests__/sandbox-mode.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,45 @@ | ||
import { | ||
initJSProjectWithProfile, | ||
deleteProject, | ||
createNewProjectDir, | ||
deleteProjectDir, | ||
addApiWithSchema, | ||
amplifyPush, | ||
getProjectMeta, | ||
} from 'amplify-e2e-core'; | ||
import { testSchema } from '../schema-api-directives'; | ||
|
||
describe('api directives @allow_public_data_access_with_api_key', () => { | ||
let projectDir: string; | ||
const envName = 'dev'; | ||
|
||
beforeEach(async () => { | ||
projectDir = await createNewProjectDir('model'); | ||
await initJSProjectWithProfile(projectDir, { envName }); | ||
}); | ||
|
||
afterEach(async () => { | ||
await deleteProject(projectDir); | ||
deleteProjectDir(projectDir); | ||
}); | ||
|
||
it('schema and files generate with sandbox mode', async () => { | ||
await addApiWithSchema(projectDir, 'model_with_sandbox_mode.graphql'); | ||
await amplifyPush(projectDir); | ||
|
||
const meta = getProjectMeta(projectDir); | ||
const { output } = meta.api.simplemodel; | ||
const { authConfig, globalSandboxModeConfig, GraphQLAPIIdOutput, GraphQLAPIEndpointOutput, GraphQLAPIKeyOutput } = output; | ||
|
||
expect(globalSandboxModeConfig[envName].enabled).toBe(true); | ||
expect(authConfig.defaultAuthentication.authenticationType).toBe('API_KEY'); | ||
expect(authConfig.defaultAuthentication.apiKeyConfig.apiKeyExpirationDate).toBeDefined(); | ||
|
||
expect(GraphQLAPIIdOutput).toBeDefined(); | ||
expect(GraphQLAPIEndpointOutput).toBeDefined(); | ||
expect(GraphQLAPIKeyOutput).toBeDefined(); | ||
|
||
const testresult = await testSchema(projectDir, 'model', 'generates'); | ||
expect(testresult).toBeTruthy(); | ||
}); | ||
}); |
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