Skip to content

Commit

Permalink
Fixed exceptions
Browse files Browse the repository at this point in the history
Signed-off-by: owaiskazi19 <[email protected]>
  • Loading branch information
owaiskazi19 committed Aug 16, 2024
1 parent aca3d00 commit a3026aa
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,12 @@ private void resolveUserAndExecute(
function.execute();
}
} catch (Exception e) {
listener.onFailure(e);
String errorMessage = "Failed to create or update workflow";
if (e instanceof FlowFrameworkException) {
listener.onFailure(e);
} else {
listener.onFailure(new FlowFrameworkException(errorMessage, ExceptionsHelper.status(e)));
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ public static void resolveUserAndExecute(
try {
if (requestedUser == null || !filterByEnabled) {
// requestedUser == null means security is disabled or user is superadmin. In this case we don't need to
// check if request user have access to the detector or not.
// check if request user have access to the workflow or not.
// !filterByEnabled means security is enabled and filterByEnabled is disabled
function.execute();
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,6 @@ public class FlowFrameworkSecureRestApiIT extends FlowFrameworkRestTestCase {
RestClient elkClient;
String fishUser = "fish";
RestClient fishClient;
String goatUser = "goat";
RestClient goatClient;
String lionUser = "lion";
RestClient lionClient;
private String indexAllAccessRole = "index_all_access";
Expand All @@ -63,8 +61,6 @@ public class FlowFrameworkSecureRestApiIT extends FlowFrameworkRestTestCase {
@Before
public void setupSecureTests() throws IOException {
if (!isHttps()) throw new IllegalArgumentException("Secure Tests are running but HTTPS is not set");
createIndexRole(indexAllAccessRole, "*");
createSearchRole(indexSearchAccessRole, "*");
String alicePassword = generatePassword(aliceUser);
createUser(aliceUser, alicePassword, List.of("odfe"));
aliceClient = new SecureRestClientBuilder(getClusterHosts().toArray(new HttpHost[0]), isHttps(), aliceUser, alicePassword)
Expand Down Expand Up @@ -101,23 +97,15 @@ public void setupSecureTests() throws IOException {
.setSocketTimeout(60000)
.build();

String goatPassword = generatePassword(goatUser);
createUser(goatUser, goatPassword, List.of("opensearch"));
goatClient = new SecureRestClientBuilder(getClusterHosts().toArray(new HttpHost[0]), isHttps(), goatUser, goatPassword)
.setSocketTimeout(60000)
.build();

String lionPassword = generatePassword(lionUser);
createUser(lionUser, lionPassword, List.of("opensearch"));
lionClient = new SecureRestClientBuilder(getClusterHosts().toArray(new HttpHost[0]), isHttps(), lionUser, lionPassword)
.setSocketTimeout(60000)
.build();

createRoleMapping(FLOW_FRAMEWORK_READ_ACCESS_ROLE, List.of(bobUser));
createRoleMapping(ML_COMMONS_FULL_ACCESS_ROLE, List.of(aliceUser, catUser, dogUser, elkUser, fishUser, goatUser));
createRoleMapping(FLOW_FRAMEWORK_FULL_ACCESS_ROLE, List.of(aliceUser, catUser, dogUser, elkUser, fishUser, goatUser));
createRoleMapping(indexAllAccessRole, List.of(aliceUser, bobUser, catUser, dogUser, fishUser, lionUser));
createRoleMapping(indexSearchAccessRole, List.of(goatUser));
createRoleMapping(ML_COMMONS_FULL_ACCESS_ROLE, List.of(aliceUser, catUser, dogUser, elkUser, fishUser));
createRoleMapping(FLOW_FRAMEWORK_FULL_ACCESS_ROLE, List.of(aliceUser, catUser, dogUser, elkUser, fishUser));
}

@After
Expand All @@ -128,15 +116,13 @@ public void tearDownSecureTests() throws IOException {
dogClient.close();
elkClient.close();
fishClient.close();
goatClient.close();
lionClient.close();
deleteUser(aliceUser);
deleteUser(bobUser);
deleteUser(catUser);
deleteUser(dogUser);
deleteUser(elkUser);
deleteUser(fishUser);
deleteUser(goatUser);
deleteUser(lionUser);
}

Expand Down Expand Up @@ -486,7 +472,7 @@ public void testUpdateWorkflowWithNoFFAccess() throws Exception {

enableFilterBy();

// User elk has FF full access, but has no read permission of index
// User lion has no FF access and should not be able to update the workflow created by alice
ResponseException exception1 = expectThrows(ResponseException.class, () -> { updateWorkflow(lionClient, workflowId, template); });
assertEquals(RestStatus.FORBIDDEN.getStatus(), exception1.getResponse().getStatusLine().getStatusCode());
}
Expand Down

0 comments on commit a3026aa

Please sign in to comment.