-
Notifications
You must be signed in to change notification settings - Fork 86
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Setting validation for transform APIs (#1191)
* Enabling validation for transform APIs Signed-off-by: Kshitij Tandon <tandonks@amazon.com> * Updating snap files Signed-off-by: Kshitij Tandon <tandonks@amazon.com> * Reverting some of the updated snap files from previous commit Signed-off-by: Kshitij Tandon <tandonks@amazon.com> * Reverting some changes to test workflows Signed-off-by: Kshitij Tandon <tandonks@amazon.com> * Change workflows java version to 21 from 11 Signed-off-by: Kshitij Tandon <tandonks@amazon.com> * Reverting some changes done just to test the workflows Signed-off-by: Kshitij Tandon <tandonks@amazon.com> * Updating vaidation rules and tests Signed-off-by: Kshitij Tandon <tandonks@amazon.com> * Fixing an issue with API validation Signed-off-by: Kshitij Tandon <tandonks@amazon.com> --------- Signed-off-by: Kshitij Tandon <tandonks@amazon.com>
- Loading branch information
Showing
4 changed files
with
117 additions
and
6 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import { schema } from "@osd/config-schema"; | ||
|
||
describe("Index Name Validation", () => { | ||
const validateSchema = schema.object({ | ||
indexName: schema.string({ | ||
validate: (value) => { | ||
const invalidCharactersPattern = /[\s,:\"*+\/\\|?#><]/; | ||
if (value !== value.toLowerCase() || value.startsWith("_") || value.startsWith("-") || invalidCharactersPattern.test(value)) { | ||
return "Invalid index name."; | ||
} | ||
|
||
return undefined; | ||
}, | ||
}), | ||
dataSourceId: schema.maybe(schema.string()), | ||
}); | ||
|
||
const validateQuery = (indexName: string) => { | ||
try { | ||
validateSchema.validate({ indexName }); | ||
return undefined; | ||
} catch (e) { | ||
return e.message; | ||
} | ||
}; | ||
|
||
it("should fail validation for index names with uppercase letters", () => { | ||
const errorMessage = validateQuery("IndexNameWithUppercase"); | ||
expect(errorMessage).toBe("[indexName]: Invalid index name."); | ||
}); | ||
|
||
it("should fail validation for index names starting with an underscore", () => { | ||
const errorMessage = validateQuery("_indexname"); | ||
expect(errorMessage).toBe("[indexName]: Invalid index name."); | ||
}); | ||
|
||
it("should fail validation for index names starting with a hyphen", () => { | ||
const errorMessage = validateQuery("-indexname"); | ||
expect(errorMessage).toBe("[indexName]: Invalid index name."); | ||
}); | ||
|
||
it("should fail validation for index names containing invalid characters", () => { | ||
const errorMessage = validateQuery("********************************"); | ||
expect(errorMessage).toBe("[indexName]: Invalid index name."); | ||
}); | ||
|
||
it("should pass validation for valid index names", () => { | ||
const errorMessage = validateQuery("valid_index-name123"); | ||
expect(errorMessage).toBeUndefined(); | ||
}); | ||
|
||
it("should fail validation for index names containing spaces", () => { | ||
const errorMessage = validateQuery("invalid index"); | ||
expect(errorMessage).toBe("[indexName]: Invalid index name."); | ||
}); | ||
}); |
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