Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 16 additions & 3 deletions packages/amplify-data-construct/.jsii
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
]
},
"bundled": {
"@aws-amplify/ai-constructs": "^1.2.4",
"@aws-amplify/ai-constructs": "1.3.0",
"@aws-amplify/backend-output-schemas": "^1.0.0",
"@aws-amplify/backend-output-storage": "^1.0.0",
"@aws-amplify/graphql-auth-transformer": "4.2.3",
Expand All @@ -27,7 +27,7 @@
"@aws-amplify/graphql-transformer-core": "3.4.3",
"@aws-amplify/graphql-transformer-interfaces": "4.2.6",
"@aws-amplify/graphql-validate-transformer": "1.1.3",
"@aws-amplify/platform-core": "^1.0.0",
"@aws-amplify/platform-core": "1.6.5",
"@aws-amplify/plugin-types": "^1.0.0",
"@aws-crypto/crc32": "5.2.0",
"@aws-crypto/sha256-browser": "5.2.0",
Expand Down Expand Up @@ -1375,6 +1375,19 @@
}
}
},
"aws-cdk-lib.aws_dsql": {
"targets": {
"dotnet": {
"package": "Amazon.CDK.AWS.DSQL"
},
"java": {
"package": "software.amazon.awscdk.services.dsql"
},
"python": {
"module": "aws_cdk.aws_dsql"
}
}
},
"aws-cdk-lib.aws_dynamodb": {
"targets": {
"dotnet": {
Expand Down Expand Up @@ -4109,5 +4122,5 @@
},
"types": {},
"version": "1.16.1",
"fingerprint": "RmejNooIcfMZHBiK6PXB+e2XH6v5bdARzogf0gvsW9Q="
"fingerprint": "mrjoxD+VARlqcB7yH3pjjXrOgFOAZ2iWFDSt9BEn+9I="
}
4 changes: 2 additions & 2 deletions packages/amplify-data-construct/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@
"zod"
],
"dependencies": {
"@aws-amplify/ai-constructs": "^1.2.4",
"@aws-amplify/ai-constructs": "1.3.0",
"@aws-amplify/backend-output-schemas": "^1.0.0",
"@aws-amplify/backend-output-storage": "^1.0.0",
"@aws-amplify/graphql-api-construct": "1.20.1",
Expand All @@ -183,7 +183,7 @@
"@aws-amplify/graphql-transformer-core": "3.4.3",
"@aws-amplify/graphql-transformer-interfaces": "4.2.6",
"@aws-amplify/graphql-validate-transformer": "1.1.3",
"@aws-amplify/platform-core": "^1.0.0",
"@aws-amplify/platform-core": "1.6.5",
"@aws-amplify/plugin-types": "^1.0.0",
"@aws-crypto/crc32": "5.2.0",
"@aws-crypto/sha256-browser": "5.2.0",
Expand Down
37 changes: 33 additions & 4 deletions packages/amplify-e2e-core/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,14 +72,29 @@ export function injectSessionToken(profileName: string) {
fs.writeFileSync(pathManager.getAWSCredentialsFilePath(), ini.stringify(credentialsContents));
}

/**
* Execute an `npm install` in the given directory in a child process.
*
* @param cwd
*/
export function npmInstall(cwd: string) {
spawnSync('npm', ['install'], { cwd });
}

/**
* Run tests in a child process.
*
* @param cwd
*/
export function npmTest(cwd: string) {
spawnSync('npm', ['test'], { cwd });
}

/**
* Install the global `amplify` command.
*
* @param version
*/
export async function installAmplifyCLI(version: string = 'latest') {
spawnSync('npm', ['install', '-g', `@aws-amplify/cli@${version}`], {
cwd: process.cwd(),
Expand All @@ -103,6 +118,19 @@ export async function installAmplifyCLI(version: string = 'latest') {
console.log('PATH SET:', process.env.AMPLIFY_PATH);
}

/**
* Creates a folder in a temp directory for into which app code can be written. Intended for e2e's
* to perform app build-out and deployment.
*
* By default, this also sleeps for a random interval between 0 and 3 minutes. Helps to prevent concurrent
* e2e tests from running `amplify init` and other `amplify` commands concurrently and hitting service limits.
*
* To disable this sleep, run with environment variable `SKIP_CREATE_PROJECT_DIR_INITIAL_DELAY=true`.
*
* @param projectName Any name, ideally one that identifies the test app. E.g., "conversation".
* @param prefix Prefix/Directory under which the project will be created. Defauls to OS temp directory.
* @returns The created directory path.
*/
export const createNewProjectDir = async (
projectName: string,
prefix = path.join(fs.realpathSync(os.tmpdir()), amplifyTestsDir),
Expand All @@ -117,10 +145,6 @@ export const createNewProjectDir = async (
fs.ensureDirSync(projectDir);

if (!process.env.SKIP_CREATE_PROJECT_DIR_INITIAL_DELAY) {
// createProjectDir(..) is something that nearly every test uses
// Commands like 'init' would collide with each other if they occurred too close to one another.
// Especially for nexpect output waiting
// This makes it a perfect candidate for staggering test start times
const initialDelay = Math.floor(Math.random() * 180 * 1000); // between 0 to 3 min
console.log(`Waiting for ${initialDelay} ms`);
await sleep(initialDelay);
Expand All @@ -130,6 +154,11 @@ export const createNewProjectDir = async (
return projectDir;
};

/**
* Creates a temp directory in the operating system's default temp location.
*
* @returns The directory path.
*/
export const createTempDir = () => {
const osTempDir = fs.realpathSync(os.tmpdir());
const tempProjectDir = path.join(osTempDir, amplifyTestsDir, uuid());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,35 +40,50 @@ describe('conversation', () => {
let realtimeEndpoint: string;

beforeAll(async () => {
console.log('checkpoint a');
projRoot = await createNewProjectDir(projFolderName);

console.log('checkpoint b');
const { apiEndpoint: graphqlEndpoint, userPoolClientId, userPoolId } = await deployCdk(projRoot);

console.log('checkpoint c');
apiEndpoint = graphqlEndpoint;
realtimeEndpoint = apiEndpoint.replace('appsync-api', 'appsync-realtime-api').replace('https://', 'wss://');

console.log('checkpoint d');

const { username: user1Username, password: user1Password } = await createCognitoUser({
region,
userPoolId,
});

console.log('checkpoint d');

const { accessToken: user1AccessToken } = await signInCognitoUser({
username: user1Username,
password: user1Password,
region,
userPoolClientId,
});

console.log('checkpoint e');

const { username: user2Username, password: user2Password } = await createCognitoUser({
region,
userPoolId,
});

console.log('checkpoint f');

const { accessToken: user2AccessToken } = await signInCognitoUser({
username: user2Username,
password: user2Password,
region,
userPoolClientId,
});

console.log('checkpoint g');

accessToken = user1AccessToken;
accessToken2 = user2AccessToken;
});
Expand Down Expand Up @@ -590,15 +605,31 @@ describe('conversation', () => {
});
});

/**
* Full build and CDK deployment of an app into the given `projRoot` path.
*
* 1. Initializes default CDK template from `../backends/configurable-stack` into `projRoot`. Includes:
* 1. `esbuild`
* 2. Creates a "test definition" containing `./graphql/schema-conversation.graphql`
* 3. Writes the definition to the app for ingestion + deployment.
* 4. CDK deploy.
*
* @param projRoot
* @returns
*/
const deployCdk = async (projRoot: string): Promise<{ apiEndpoint: string; userPoolClientId: string; userPoolId: string }> => {
const templatePath = path.resolve(path.join(__dirname, '..', 'backends', 'configurable-stack'));
const name = await initCDKProject(projRoot, templatePath, {
additionalDependencies: ['esbuild'],
});

console.log(`CDK project initialized at ${projRoot}`);

const conversationSchemaPath = path.resolve(path.join(__dirname, 'graphql', 'schema-conversation.graphql'));
const conversationSchema = fs.readFileSync(conversationSchemaPath).toString();

console.log(`Schema loaded from ${conversationSchemaPath}`);

const testDefinitions: Record<string, TestDefinition> = {
conversation: {
schema: [conversationSchema].join('\n'),
Expand All @@ -609,7 +640,13 @@ const deployCdk = async (projRoot: string): Promise<{ apiEndpoint: string; userP
writeStackConfig(projRoot, { prefix: 'Conversation' });
writeTestDefinitions(testDefinitions, projRoot);

const stashPath = `/var/tmp/e2e-stash-${path.basename(projRoot)}`;
await fs.copy(projRoot, stashPath);
console.log(`Project directory copied to ${stashPath}`);

const outputs = await cdkDeploy(projRoot, '--all');
console.log(`CDK deployed to ${projRoot}`);

const { awsAppsyncApiEndpoint, UserPoolClientId, UserPoolId } = outputs[name];
return { apiEndpoint: awsAppsyncApiEndpoint, userPoolClientId: UserPoolClientId, userPoolId: UserPoolId };
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ export const cdkDeploy = async (cwd: string, option: string, props?: CdkDeployPr
// npx cdk does not work on verdaccio
env: { npm_config_registry: 'https://registry.npmjs.org/' },
noOutputTimeout,
stdio: 'inherit',
};

await spawn(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ export interface StackConfig {
sqlLambdaLayerArn?: string;
}

/**
* Stringifies `stackConfig` and writes it to `${projRoot}/stack-config.json` ...
* @param projRoot
* @param stackConfig
*/
export const writeStackConfig = (projRoot: string, stackConfig: StackConfig): void => {
const filePath = path.join(projRoot, 'stack-config.json');
fs.writeFileSync(filePath, JSON.stringify(stackConfig));
Expand Down
19 changes: 16 additions & 3 deletions packages/amplify-graphql-api-construct/.jsii
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
]
},
"bundled": {
"@aws-amplify/ai-constructs": "^1.2.4",
"@aws-amplify/ai-constructs": "1.3.0",
"@aws-amplify/backend-output-schemas": "^1.0.0",
"@aws-amplify/backend-output-storage": "^1.0.0",
"@aws-amplify/graphql-auth-transformer": "4.2.3",
Expand All @@ -27,7 +27,7 @@
"@aws-amplify/graphql-transformer-core": "3.4.3",
"@aws-amplify/graphql-transformer-interfaces": "4.2.6",
"@aws-amplify/graphql-validate-transformer": "1.1.3",
"@aws-amplify/platform-core": "^1.0.0",
"@aws-amplify/platform-core": "1.6.5",
"@aws-amplify/plugin-types": "^1.0.0",
"@aws-crypto/crc32": "5.2.0",
"@aws-crypto/sha256-browser": "5.2.0",
Expand Down Expand Up @@ -1367,6 +1367,19 @@
}
}
},
"aws-cdk-lib.aws_dsql": {
"targets": {
"dotnet": {
"package": "Amazon.CDK.AWS.DSQL"
},
"java": {
"package": "software.amazon.awscdk.services.dsql"
},
"python": {
"module": "aws_cdk.aws_dsql"
}
}
},
"aws-cdk-lib.aws_dynamodb": {
"targets": {
"dotnet": {
Expand Down Expand Up @@ -9513,5 +9526,5 @@
}
},
"version": "1.20.1",
"fingerprint": "+StR3FqEAlc1IFZPMqvjS5CUe5YnkTLZS2rMNf1BHPA="
"fingerprint": "cjIOrGVQMbbVMZ2swsYNXbBb+JtmPtIgXzc4zjF4f58="
}
4 changes: 2 additions & 2 deletions packages/amplify-graphql-api-construct/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@
"zod"
],
"dependencies": {
"@aws-amplify/ai-constructs": "^1.2.4",
"@aws-amplify/ai-constructs": "1.3.0",
"@aws-amplify/backend-output-schemas": "^1.0.0",
"@aws-amplify/backend-output-storage": "^1.0.0",
"@aws-amplify/graphql-auth-transformer": "4.2.3",
Expand All @@ -183,7 +183,7 @@
"@aws-amplify/graphql-transformer-core": "3.4.3",
"@aws-amplify/graphql-transformer-interfaces": "4.2.6",
"@aws-amplify/graphql-validate-transformer": "1.1.3",
"@aws-amplify/platform-core": "^1.0.0",
"@aws-amplify/platform-core": "1.6.5",
"@aws-amplify/plugin-types": "^1.0.0",
"@aws-crypto/crc32": "5.2.0",
"@aws-crypto/sha256-browser": "5.2.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -514,6 +514,45 @@ describe('Custom operations have @aws_iam directives when enableIamAuthorization
expect(out.schema).toMatch(/type EventInvocationResponse.*@aws_iam/);
});

test('Does not add @aws_iam to interfaces', () => {
const strategy = makeStrategy(strategyType);
const schema = /* GraphQL */ `
interface FooInterface {
id: ID!
}
type Foo {
description: String
}
type EventInvocationResponse @aws_api_key {
success: Boolean!
}
type Query {
getFooCustom: Foo
}
type Mutation {
updateFooCustom: Foo
doSomethingAsync(body: String!): EventInvocationResponse
@function(name: "FnDoSomethingAsync", invocationType: Event)
@auth(rules: [{ allow: public, provider: apiKey }])
}
type Subscription {
onUpdateFooCustom: Foo @aws_subscribe(mutations: ["updateFooCustom"])
}
`;

const out = testTransform({
schema,
dataSourceStrategies: constructDataSourceStrategies(schema, strategy),
authConfig: makeAuthConfig(),
synthParameters: makeSynthParameters(),
transformers: makeTransformers(),
sqlDirectiveDataSourceStrategies: makeSqlDirectiveDataSourceStrategies(schema, strategy),
});

// Also expect the custom type referenced by the custom operation to be authorized
expect(out.schema).not.toMatch(/interface FooInterface.*@aws_iam/);
});

test('Does not add duplicate @aws_iam directive to custom type if already present', () => {
const strategy = makeStrategy(strategyType);
const schema = /* GraphQL */ `
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -394,10 +394,15 @@ export class AuthTransformer extends TransformerAuthBase implements TransformerA
return !type.directives?.some((dir) => dir.name.value === 'model');
};

const isNotInterface = (type: TypeDefinitionNode): boolean => {
return type.kind !== Kind.INTERFACE_TYPE_DEFINITION;
};

ctx.inputDocument.definitions
.filter(isObjectTypeDefinitionNode)
.filter(isNonModelType)
.filter(needsAwsIamDirective)
.filter(isNotInterface)
.forEach((def) => extendTypeWithDirectives(ctx, def.name.value, [makeDirective('aws_iam', [])]));
};

Expand Down
Loading
Loading