diff --git a/.github/workflows/test_security.yml b/.github/workflows/test_security.yml index a1c77f39e..23640d922 100644 --- a/.github/workflows/test_security.yml +++ b/.github/workflows/test_security.yml @@ -7,6 +7,9 @@ on: pull_request: types: [opened, synchronize, reopened] +env: + ACTIONS_ALLOW_USE_UNSECURE_NODE_VERSION: true + jobs: Get-CI-Image-Tag: uses: opensearch-project/opensearch-build/.github/workflows/get-ci-image-tag.yml@main diff --git a/src/test/java/org/opensearch/flowframework/FlowFrameworkRestTestCase.java b/src/test/java/org/opensearch/flowframework/FlowFrameworkRestTestCase.java index 922c26b0f..c793e27e9 100644 --- a/src/test/java/org/opensearch/flowframework/FlowFrameworkRestTestCase.java +++ b/src/test/java/org/opensearch/flowframework/FlowFrameworkRestTestCase.java @@ -434,6 +434,25 @@ protected Response updateWorkflow(RestClient client, String workflowId, Template ); } + /** + * Helper method to invoke the Update Workflow API + * @param client the rest client + * @param workflowId the document id + * @param templateFields the JSON containing some template fields + * @throws Exception if the request fails + * @return a rest response + */ + protected Response updateWorkflowWithFields(RestClient client, String workflowId, String templateFields) throws Exception { + return TestHelpers.makeRequest( + client, + "PUT", + String.format(Locale.ROOT, "%s/%s?update_fields=true", WORKFLOW_URI, workflowId), + Collections.emptyMap(), + templateFields, + null + ); + } + /** * Helper method to invoke the Provision Workflow Rest Action * @param client the rest client diff --git a/src/test/java/org/opensearch/flowframework/rest/FlowFrameworkRestApiIT.java b/src/test/java/org/opensearch/flowframework/rest/FlowFrameworkRestApiIT.java index b12137070..7cea10ff8 100644 --- a/src/test/java/org/opensearch/flowframework/rest/FlowFrameworkRestApiIT.java +++ b/src/test/java/org/opensearch/flowframework/rest/FlowFrameworkRestApiIT.java @@ -116,7 +116,45 @@ public void testFailedUpdateWorkflow() throws Exception { assertTrue( exceptionProvisioned.getMessage().contains("The template can not be updated unless its provisioning state is NOT_STARTED") ); + } + + public void testUpdateWorkflowUsingFields() throws Exception { + Template template = TestHelpers.createTemplateFromFile("createconnector-registerremotemodel-deploymodel.json"); + Response response = createWorkflow(client(), template); + assertEquals(RestStatus.CREATED, TestHelpers.restStatus(response)); + + Map responseMap = entityAsMap(response); + String workflowId = (String) responseMap.get(WORKFLOW_ID); + + // Ensure Ml config index is initialized as creating a connector requires this, then hit Provision API and assert status + Response provisionResponse; + if (!indexExistsWithAdminClient(".plugins-ml-config")) { + assertBusy(() -> assertTrue(indexExistsWithAdminClient(".plugins-ml-config")), 40, TimeUnit.SECONDS); + provisionResponse = provisionWorkflow(client(), workflowId); + } else { + provisionResponse = provisionWorkflow(client(), workflowId); + } + assertEquals(RestStatus.OK, TestHelpers.restStatus(provisionResponse)); + getAndAssertWorkflowStatus(client(), workflowId, State.PROVISIONING, ProvisioningProgress.IN_PROGRESS); + // Attempt to update with update_fields with illegal field + // Fails because contains workflow field + ResponseException exceptionProvisioned = expectThrows( + ResponseException.class, + () -> updateWorkflowWithFields(client(), workflowId, "{\"workflows\":{}}") + ); + assertTrue( + exceptionProvisioned.getMessage().contains("You can not update the field [workflows] without updating the whole template.") + ); + // Change just the name and description + response = updateWorkflowWithFields(client(), workflowId, "{\"name\":\"foo\",\"description\":\"bar\"}"); + assertEquals(RestStatus.CREATED, TestHelpers.restStatus(response)); + // Get the updated template + response = getWorkflow(client(), workflowId); + assertEquals(RestStatus.OK.getStatus(), response.getStatusLine().getStatusCode()); + Template t = Template.parse(EntityUtils.toString(response.getEntity(), StandardCharsets.UTF_8)); + assertEquals("foo", t.name()); + assertEquals("bar", t.description()); } public void testCreateAndProvisionLocalModelWorkflow() throws Exception {