Skip to content

Commit

Permalink
Attempt to fix pending task issues on integ tests
Browse files Browse the repository at this point in the history
Signed-off-by: Daniel Widdis <[email protected]>
  • Loading branch information
dbwiddis committed Jan 17, 2024
1 parent 764881e commit 1d0b7cf
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 6 deletions.
12 changes: 6 additions & 6 deletions .github/workflows/test_security.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
name: Security test workflow for Flow Framework
on:
push:
branches:
- "*"
branches-ignore:
- 'whitesource-remediate/**'
- 'backport/**'
pull_request:
branches:
- "*"
types: [opened, synchronize, reopened]

jobs:
Get-CI-Image-Tag:
Expand All @@ -30,9 +30,9 @@ jobs:

steps:
- name: Checkout Flow Framework
uses: actions/checkout@v1
uses: actions/checkout@v3
- name: Setup Java ${{ matrix.java }}
uses: actions/setup-java@v1
uses: actions/setup-java@v3
with:
distribution: 'temurin'
java-version: ${{ matrix.java }}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,21 +34,25 @@ public void tearDownSecureTests() throws IOException {

public void testCreateWorkflowWithReadAccess() throws Exception {
Template template = TestHelpers.createTemplateFromFile("register-deploylocalsparseencodingmodel.json");
waitForPendingTasks(readAccessClient());
ResponseException exception = expectThrows(ResponseException.class, () -> createWorkflow(readAccessClient(), template));
assertTrue(exception.getMessage().contains("no permissions for [cluster:admin/opensearch/flow_framework/workflow/create]"));
}

public void testProvisionWorkflowWithReadAccess() throws Exception {
waitForPendingTasks(readAccessClient());
ResponseException exception = expectThrows(ResponseException.class, () -> provisionWorkflow(readAccessClient(), "test"));
assertTrue(exception.getMessage().contains("no permissions for [cluster:admin/opensearch/flow_framework/workflow/provision]"));
}

public void testDeleteWorkflowWithReadAccess() throws Exception {
waitForPendingTasks(readAccessClient());
ResponseException exception = expectThrows(ResponseException.class, () -> deleteWorkflow(readAccessClient(), "test"));
assertTrue(exception.getMessage().contains("no permissions for [cluster:admin/opensearch/flow_framework/workflow/delete]"));
}

public void testDeprovisionWorkflowWithReadAcess() throws Exception {
waitForPendingTasks(readAccessClient());
ResponseException exception = expectThrows(ResponseException.class, () -> deprovisionWorkflow(readAccessClient(), "test"));
assertTrue(exception.getMessage().contains("no permissions for [cluster:admin/opensearch/flow_framework/workflow/deprovision]"));
}
Expand All @@ -60,28 +64,33 @@ public void testGetWorkflowStepsWithReadAccess() throws Exception {

public void testGetWorkflowWithReadAccess() throws Exception {
// No permissions to create, so we assert only that the response status isnt forbidden
waitForPendingTasks(readAccessClient());
ResponseException exception = expectThrows(ResponseException.class, () -> getWorkflow(readAccessClient(), "test"));
assertEquals(RestStatus.NOT_FOUND, TestHelpers.restStatus(exception.getResponse()));
}

public void testSearchWorkflowWithReadAccess() throws Exception {
// Use full access client to invoke create workflow to ensure the template/state indices are created
Template template = TestHelpers.createTemplateFromFile("createconnector-registerremotemodel-deploymodel.json");
waitForPendingTasks(fullAccessClient());
Response response = createWorkflow(fullAccessClient(), template);
assertEquals(RestStatus.CREATED, TestHelpers.restStatus(response));

// No permissions to create, so we assert only that the response status isnt forbidden
String termIdQuery = "{\"query\":{\"ids\":{\"values\":[\"test\"]}}}";
waitForPendingTasks(readAccessClient());
SearchResponse seachResponse = searchWorkflows(readAccessClient(), termIdQuery);
assertEquals(RestStatus.OK, seachResponse.status());
}

public void testGetWorkflowStateWithReadAccess() throws Exception {
// Use the full access client to invoke create workflow to ensure the template/state indices are created
Template template = TestHelpers.createTemplateFromFile("createconnector-registerremotemodel-deploymodel.json");
waitForPendingTasks(fullAccessClient());
Response response = createWorkflow(fullAccessClient(), template);
assertEquals(RestStatus.CREATED, TestHelpers.restStatus(response));

waitForPendingTasks(readAccessClient());
// No permissions to create or provision, so we assert only that the response status isnt forbidden
ResponseException exception = expectThrows(ResponseException.class, () -> getWorkflowStatus(readAccessClient(), "test", false));
assertTrue(exception.getMessage().contains("Fail to find workflow"));
Expand All @@ -91,18 +100,21 @@ public void testGetWorkflowStateWithReadAccess() throws Exception {
public void testSearchWorkflowStateWithReadAccess() throws Exception {
// Use the full access client to invoke create workflow to ensure the template/state indices are created
Template template = TestHelpers.createTemplateFromFile("createconnector-registerremotemodel-deploymodel.json");
waitForPendingTasks(fullAccessClient());
Response response = createWorkflow(fullAccessClient(), template);
assertEquals(RestStatus.CREATED, TestHelpers.restStatus(response));

// No permissions to create, so we assert only that the response status isnt forbidden
String termIdQuery = "{\"query\":{\"ids\":{\"values\":[\"test\"]}}}";
waitForPendingTasks(readAccessClient());
SearchResponse searchResponse = searchWorkflowState(readAccessClient(), termIdQuery);
assertEquals(RestStatus.OK, searchResponse.status());
}

public void testCreateProvisionDeprovisionWorkflowWithFullAccess() throws Exception {
// Invoke create workflow API
Template template = TestHelpers.createTemplateFromFile("createconnector-registerremotemodel-deploymodel.json");
waitForPendingTasks(fullAccessClient());
Response response = createWorkflow(fullAccessClient(), template);
assertEquals(RestStatus.CREATED, TestHelpers.restStatus(response));

Expand All @@ -112,27 +124,33 @@ public void testCreateProvisionDeprovisionWorkflowWithFullAccess() throws Except

// Invoke search workflows API
String termIdQuery = "{\"query\":{\"ids\":{\"values\":[\"" + workflowId + "\"]}}}";
waitForPendingTasks(fullAccessClient());
SearchResponse searchResponse = searchWorkflows(fullAccessClient(), termIdQuery);
assertEquals(RestStatus.OK, searchResponse.status());

// Invoke provision API
waitForPendingTasks(fullAccessClient());
response = provisionWorkflow(fullAccessClient(), workflowId);
assertEquals(RestStatus.OK, TestHelpers.restStatus(response));

// Invoke status API
waitForPendingTasks(fullAccessClient());
response = getWorkflowStatus(fullAccessClient(), workflowId, false);
assertEquals(RestStatus.OK, TestHelpers.restStatus(response));

// Invoke deprovision API
waitForPendingTasks(fullAccessClient());
response = deprovisionWorkflow(fullAccessClient(), workflowId);
assertEquals(RestStatus.OK, TestHelpers.restStatus(response));

// Invoke delete API
waitForPendingTasks(fullAccessClient());
response = deleteWorkflow(fullAccessClient(), workflowId);
assertEquals(RestStatus.OK, TestHelpers.restStatus(response));
}

public void testGetWorkflowStepWithFullAccess() throws Exception {
waitForPendingTasks(fullAccessClient());
Response response = getWorkflowStep(fullAccessClient());
assertEquals(RestStatus.OK, TestHelpers.restStatus(response));
}
Expand Down

0 comments on commit 1d0b7cf

Please sign in to comment.