-
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.
[Backport 2.18] Setting validation for transform APIs (#1195)
* Setting validation for transform APIs (#1191) * Enabling validation for transform APIs Signed-off-by: Kshitij Tandon <[email protected]> * Updating snap files Signed-off-by: Kshitij Tandon <[email protected]> * Reverting some of the updated snap files from previous commit Signed-off-by: Kshitij Tandon <[email protected]> * Reverting some changes to test workflows Signed-off-by: Kshitij Tandon <[email protected]> * Change workflows java version to 21 from 11 Signed-off-by: Kshitij Tandon <[email protected]> * Reverting some changes done just to test the workflows Signed-off-by: Kshitij Tandon <[email protected]> * Updating vaidation rules and tests Signed-off-by: Kshitij Tandon <[email protected]> * Fixing an issue with API validation Signed-off-by: Kshitij Tandon <[email protected]> --------- Signed-off-by: Kshitij Tandon <[email protected]> (cherry picked from commit fd0e765) Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com> * feat: use fixed version Signed-off-by: SuZhou-Joe <[email protected]> * feat: update Signed-off-by: SuZhou-Joe <[email protected]> * feat: update Signed-off-by: SuZhou-Joe <[email protected]> --------- Signed-off-by: Kshitij Tandon <[email protected]> Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com> Signed-off-by: SuZhou-Joe <[email protected]> Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com> Co-authored-by: SuZhou-Joe <[email protected]>
- Loading branch information
1 parent
a9c12e8
commit fe11b13
Showing
4 changed files
with
118 additions
and
7 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