Skip to content

Commit bed34dd

Browse files
authored
Fixing bug in transform API validation to support index patterns (opensearch-project#1237)
* Fixing bug in transform API validation Signed-off-by: Kshitij Tandon <[email protected]> * Adding test for creating transform job using wildcard Signed-off-by: Kshitij Tandon <[email protected]> * Retracting a change which was for testing only Signed-off-by: Kshitij Tandon <[email protected]> * Fixing an issue with the delete test of transform Signed-off-by: Kshitij Tandon <[email protected]> * Modifying transform test Signed-off-by: Kshitij Tandon <[email protected]> --------- Signed-off-by: Kshitij Tandon <[email protected]>
1 parent a32b669 commit bed34dd

File tree

2 files changed

+97
-17
lines changed

2 files changed

+97
-17
lines changed

cypress/integration/plugins/index-management-dashboards-plugin/transforms_spec.js

+95-15
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { BASE_PATH, IM_PLUGIN_NAME } from "../../../utils/constants";
77
import sampleTransform from "../../../fixtures/plugins/index-management-dashboards-plugin/sample_transform";
88

99
const TRANSFORM_ID = "test_transform_id";
10-
10+
const TRANSFORM_ID_WILDCARD = "test_transform_wildard";
1111
describe("Transforms", () => {
1212
before(() => {
1313
// Delete all indices
@@ -50,7 +50,7 @@ describe("Transforms", () => {
5050
cy.contains("Create transform", { timeout: 60000 });
5151
});
5252

53-
describe("can be created", () => {
53+
describe("can be created with source index", () => {
5454
it("successfully", () => {
5555
// Confirm we loaded empty state
5656
cy.contains("Transform jobs help you create a materialized view on top of existing data.");
@@ -128,6 +128,96 @@ describe("Transforms", () => {
128128
});
129129
});
130130

131+
describe("can be created with source index wildcard", () => {
132+
it("successfully", () => {
133+
// Confirm we loaded empty state
134+
// cy.contains("Transform jobs help you create a materialized view on top of existing data.");
135+
136+
// Route to create transform page
137+
cy.contains("Create transform").click({ force: true });
138+
139+
// Type in transform ID
140+
cy.get(`input[placeholder="my-transformjob1"]`).type(TRANSFORM_ID_WILDCARD, {
141+
force: true,
142+
});
143+
144+
// Get description input box
145+
cy.get(`textarea[data-test-subj="description"]`).focus().type("some description");
146+
147+
// Enter source index
148+
cy.get(`div[data-test-subj="sourceIndexCombobox"]`)
149+
.find(`input[data-test-subj="comboBoxSearchInput"]`)
150+
.focus()
151+
.type("opensearch_dashboards_sample_data_ecommerce*{enter}");
152+
153+
cy.wait(5000);
154+
155+
// Enter target index
156+
cy.get(`div[data-test-subj="targetIndexCombobox"]`)
157+
.find(`input[data-test-subj="comboBoxSearchInput"]`)
158+
.focus()
159+
.type("test_transform{enter}");
160+
161+
cy.wait(2000);
162+
163+
// Click the next button
164+
cy.get("button").contains("Next").click({ force: true });
165+
166+
// Confirm that we got to step 2 of creation page
167+
cy.contains("Select fields to transform");
168+
169+
cy.get(`button[data-test-subj="category.keywordOptionsPopover"]`).click({
170+
force: true,
171+
});
172+
173+
cy.contains("Group by terms").click({ force: true });
174+
175+
// Confirm group was added
176+
cy.contains("category.keyword_terms");
177+
178+
// Add aggregable field
179+
cy.contains("50 columns hidden").click({ force: true });
180+
cy.contains("taxless_total_price").click({ force: true });
181+
// Click out of the window
182+
cy.contains("Select fields to transform").click({ force: true });
183+
184+
cy.get(`button[data-test-subj="taxless_total_priceOptionsPopover"]`).click({ force: true });
185+
186+
cy.contains("Aggregate by avg").click({ force: true });
187+
188+
// Confirm agg was added
189+
cy.contains("avg_taxless_total_price");
190+
191+
// Click the next button
192+
cy.get("button").contains("Next").click({ force: true });
193+
194+
// Confirm that we got to step 3 of creation page
195+
cy.contains("Job enabled by default");
196+
197+
// Click the next button
198+
cy.get("button").contains("Next").click({ force: true });
199+
200+
// Confirm that we got to step 4 of creation page
201+
cy.contains("Review and create");
202+
203+
// Click the create button
204+
cy.get("button").contains("Create").click({ force: true });
205+
206+
cy.wait(2000);
207+
208+
// Verify that sample data is add by checking toast notification
209+
cy.contains(`Transform job "${TRANSFORM_ID_WILDCARD}" successfully created.`);
210+
cy.location("hash").should("contain", "transforms");
211+
cy.get(`button[data-test-subj="transformLink_${TRANSFORM_ID_WILDCARD}"]`);
212+
213+
cy.request({
214+
method: "DELETE",
215+
url: `${Cypress.env("openSearchUrl")}/_plugins/_transform/${TRANSFORM_ID_WILDCARD} `,
216+
failOnStatusCode: false,
217+
});
218+
});
219+
});
220+
131221
describe("can be edited", () => {
132222
beforeEach(() => {
133223
cy.createTransform(TRANSFORM_ID, sampleTransform);
@@ -208,9 +298,6 @@ describe("Transforms", () => {
208298

209299
// Confirm we got deleted toaster
210300
cy.contains(`"${TRANSFORM_ID}" successfully deleted`);
211-
212-
// Confirm showing empty loading state
213-
cy.contains("Transform jobs help you create a materialized view on top of existing data.");
214301
});
215302
});
216303

@@ -226,10 +313,7 @@ describe("Transforms", () => {
226313

227314
// Intercept different transform requests endpoints to wait before clicking disable and enable buttons
228315
cy.intercept(`/api/ism/transforms/${TRANSFORM_ID}`).as("getTransform");
229-
cy.intercept(`/api/ism/transforms/${TRANSFORM_ID}/_stop`).as(
230-
"stopTransform"
231-
);
232-
316+
cy.intercept(`/api/ism/transforms/${TRANSFORM_ID}/_stop`).as("stopTransform");
233317

234318
// Click into transform job details page
235319
cy.get(`[data-test-subj="transformLink_${TRANSFORM_ID}"]`).click({
@@ -248,9 +332,7 @@ describe("Transforms", () => {
248332
cy.get(`[data-test-subj="actionButton"]`).click({ force: true });
249333

250334
// Click Disable button
251-
cy.get(`[data-test-subj="disableButton"]`)
252-
.should("not.be.disabled")
253-
.click();
335+
cy.get(`[data-test-subj="disableButton"]`).should("not.be.disabled").click();
254336

255337
cy.wait("@stopTransform");
256338
cy.wait("@getTransform");
@@ -265,9 +347,7 @@ describe("Transforms", () => {
265347
cy.get(`[data-test-subj="actionButton"]`).click({ force: true });
266348

267349
// Click Enable button
268-
cy.get(`[data-test-subj="enableButton"]`)
269-
.should("not.be.disabled")
270-
.click({ force: true });
350+
cy.get(`[data-test-subj="enableButton"]`).should("not.be.disabled").click({ force: true });
271351

272352
// Confirm we get toaster saying transform job is enabled
273353
cy.contains(`"${TRANSFORM_ID}" is enabled`);

server/routes/transforms.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ export default function (services: NodeServices, router: IRouter, dataSourceEnab
113113
params: schema.object({
114114
index: schema.string({
115115
validate: (value) => {
116-
const invalidCharactersPattern = /[\s,:\"*+\/\\|?#><]/;
116+
const invalidCharactersPattern = /[\s,:\"+\/\\|?#><]/;
117117
if (value !== value.toLowerCase() || value.startsWith("_") || value.startsWith("-") || invalidCharactersPattern.test(value)) {
118118
return "Invalid index name.";
119119
}
@@ -148,7 +148,7 @@ export default function (services: NodeServices, router: IRouter, dataSourceEnab
148148
{
149149
source_index: schema.string({
150150
validate: (value) => {
151-
const invalidCharactersPattern = /[\s,:\"*+\/\\|?#><]/;
151+
const invalidCharactersPattern = /[\s,:\"+\/\\|?#><]/;
152152
if (
153153
value !== value.toLowerCase() ||
154154
value.startsWith("_") ||

0 commit comments

Comments
 (0)