Skip to content
Draft
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
18 changes: 9 additions & 9 deletions packages/adk-core/test/core.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,15 +77,18 @@ describe('@aws/codecatalyst-adk-core', () => {
it('test setOutput validation', () => {
const errorMessage = `Invalid output parameter name, it must match the following pattern ${outputVariableNamePattern}`;
const outputParamValue = 'outputParamValue';
const validInput30Chars = 'Stack_ID_12345678910111213145';
const validInput40Chars = 'Stack_ID-1234567891011121314512345678911';

const validInput = 'Stack_ID';
const emptyInput = '';
const invalidInput = 'Stack ID';
const tooLongInput = 'longer_than_255_chars_123456789101112131415161718487612357845768929562892576458234765287495628495682412345678910111213141516171848761235784576892956289257645823476528749562849568241234567891011121314151617184876123578457689295628925764582347652874956284959';
const startsWithInvalidChar = '-Stack_ID';
const endsWithInvalidChar = 'Stack_ID-';
const validInputSpecialChar = '-StackA_a-@_ID';
const invalidInputWithInvalidSpecialChar = 'Stack$#:ID';

expect(adkCore.setOutput(validInput30Chars, outputParamValue).code === undefined).toBeTruthy();
expect(adkCore.setOutput(validInput40Chars, outputParamValue).code === undefined).toBeTruthy();
expect(adkCore.setOutput(validInput, outputParamValue).code === undefined).toBeTruthy();
expect(adkCore.setOutput(validInputSpecialChar, outputParamValue).code === undefined).toBeTruthy();

expect(adkCore.setOutput(emptyInput, outputParamValue).code === 1).toBeTruthy();
expect(adkCore.setOutput(emptyInput, outputParamValue).stdout === errorMessage).toBeTruthy();
Expand All @@ -96,11 +99,8 @@ describe('@aws/codecatalyst-adk-core', () => {
expect(adkCore.setOutput(tooLongInput, outputParamValue).code === 1).toBeTruthy();
expect(adkCore.setOutput(tooLongInput, outputParamValue).stdout === errorMessage).toBeTruthy();

expect(adkCore.setOutput(startsWithInvalidChar, outputParamValue).code === 1).toBeTruthy();
expect(adkCore.setOutput(startsWithInvalidChar, outputParamValue).stdout === errorMessage).toBeTruthy();

expect(adkCore.setOutput(endsWithInvalidChar, outputParamValue).code === 1).toBeTruthy();
expect(adkCore.setOutput(endsWithInvalidChar, outputParamValue).stdout === errorMessage).toBeTruthy();
expect(adkCore.setOutput(invalidInputWithInvalidSpecialChar, outputParamValue).code === 1).toBeTruthy();
expect(adkCore.setOutput(invalidInputWithInvalidSpecialChar, outputParamValue).stdout === errorMessage).toBeTruthy();
});

});
2 changes: 1 addition & 1 deletion packages/adk-utils/lib/util/util.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import fs from 'fs';

export const outputVariableNamePattern = new RegExp(/^[A-Za-z0-9@\\-_]+$/);
export const outputVariableNamePattern = new RegExp(/^[A-Za-z0-9@\-_]+$/);

/**
* Sanitizes (escapes) special characters in the command and its arguments.
Expand Down
12 changes: 6 additions & 6 deletions packages/adk-utils/test/util.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,19 +129,19 @@ describe('ADK-Util test', () => {

it('test validateOutputVariableName', async () => {
const validInput = 'Stack_ID';
const validInput30Chars = 'Stack_ID_12345678910111213145';
const validInput40Chars = 'Stack_ID-1234567891011121314512345678911';
const emptyInput = '';
const invalidInput = 'Stack ID';
const tooLongInput = 'longer_than_255_chars_123456789101112131415161718487612357845768929562892576458234765287495628495682412345678910111213141516171848761235784576892956289257645823476528749562849568241234567891011121314151617184876123578457689295628925764582347652874956284959';
const startsWithInvalidChar = '-Stack_ID';
const endsWithInvalidChar = 'Stack_ID-';
const validInputSpecialChar = '-StackA_a-@_ID';
const invalidInputWithInvalidSpecialChar = 'Stack/$#:ID';

expect(isValidOutputVariableName(validInput)).toBeTruthy();
expect(isValidOutputVariableName(validInput30Chars)).toBeTruthy();
expect(isValidOutputVariableName(validInput40Chars)).toBeTruthy();
expect(isValidOutputVariableName(emptyInput)).toBeFalsy();
expect(isValidOutputVariableName(invalidInput)).toBeFalsy();
expect(isValidOutputVariableName(tooLongInput)).toBeFalsy();
expect(isValidOutputVariableName(startsWithInvalidChar)).toBeFalsy();
expect(isValidOutputVariableName(endsWithInvalidChar)).toBeFalsy();
expect(isValidOutputVariableName(validInputSpecialChar)).toBeTruthy();
expect(isValidOutputVariableName(invalidInputWithInvalidSpecialChar)).toBeFalsy();
});
});
2 changes: 1 addition & 1 deletion packages/adk/templates/codecatalyst_model_schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@
"description": "Action output variables",
"type": "object",
"propertyNames": {
"pattern": "^[A-Za-z0-9][A-Za-z0-9\\-_]{1,30}[A-Za-z0-9]$"
"pattern": "^[A-Za-z0-9@\\-_]+$"
Copy link
Contributor Author

@aj-aws aj-aws Jan 10, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the string version of the Regex, so does contain two "\"

},
"minProperties": 1,
"maxProperties": 10,
Expand Down