use of org.opensearch.ad.model.AnomalyDetector in project anomaly-detection by opensearch-project.
the class SecureADRestIT method testStopApiFilterByEnabled.
public void testStopApiFilterByEnabled() throws IOException {
// User Alice has AD full access, should be able to create a detector
AnomalyDetector aliceDetector = createRandomAnomalyDetector(false, false, aliceClient);
enableFilterBy();
// User Cat has AD full access, but is part of different backend role so Cat should not be able to access
// Alice detector
Exception exception = expectThrows(IOException.class, () -> {
stopAnomalyDetector(aliceDetector.getDetectorId(), catClient, true);
});
Assert.assertTrue(exception.getMessage().contains("User does not have permissions to access detector: " + aliceDetector.getDetectorId()));
}
use of org.opensearch.ad.model.AnomalyDetector in project anomaly-detection by opensearch-project.
the class SecureADRestIT method testPreviewAnomalyDetectorWithFilterEnabled.
public void testPreviewAnomalyDetectorWithFilterEnabled() throws IOException {
// User Alice has AD full access, should be able to create a detector
AnomalyDetector aliceDetector = createRandomAnomalyDetector(false, false, aliceClient);
AnomalyDetectorExecutionInput input = new AnomalyDetectorExecutionInput(aliceDetector.getDetectorId(), Instant.now().minusSeconds(60 * 10), Instant.now(), null);
enableFilterBy();
// User Cat has AD full access, but is part of different backend role so Cat should not be able to access
// Alice detector
Exception exception = expectThrows(IOException.class, () -> {
previewAnomalyDetector(aliceDetector.getDetectorId(), catClient, input);
});
Assert.assertTrue(exception.getMessage().contains("User does not have permissions to access detector: " + aliceDetector.getDetectorId()));
}
use of org.opensearch.ad.model.AnomalyDetector in project anomaly-detection by opensearch-project.
the class SecureADRestIT method testPreviewAnomalyDetectorWithReadAccess.
public void testPreviewAnomalyDetectorWithReadAccess() throws IOException {
// User Alice has AD full access, should be able to create a detector
AnomalyDetector aliceDetector = createRandomAnomalyDetector(false, false, aliceClient);
AnomalyDetectorExecutionInput input = new AnomalyDetectorExecutionInput(randomAlphaOfLength(5), Instant.now().minusSeconds(60 * 10), Instant.now(), null);
// User bob has AD read access, should not be able to preview a detector
Exception exception = expectThrows(IOException.class, () -> {
previewAnomalyDetector(aliceDetector.getDetectorId(), bobClient, input);
});
Assert.assertTrue(exception.getMessage().contains("no permissions for [cluster:admin/opendistro/ad/detector/preview]"));
}
use of org.opensearch.ad.model.AnomalyDetector in project anomaly-detection by opensearch-project.
the class SecureADRestIT method testValidateAnomalyDetectorWithNoADAccess.
public void testValidateAnomalyDetectorWithNoADAccess() throws IOException {
// User Lion has no AD access at all, should not be able to validate a detector
AnomalyDetector detector = TestHelpers.randomAnomalyDetector(null, Instant.now());
Exception exception = expectThrows(IOException.class, () -> {
validateAnomalyDetector(detector, lionClient);
});
Assert.assertTrue(exception.getMessage().contains("no permissions for [cluster:admin/opendistro/ad/detector/validate]"));
}
use of org.opensearch.ad.model.AnomalyDetector in project anomaly-detection by opensearch-project.
the class AnomalyDetectorJobTransportActionTests method testRaceConditionByStartingMultipleTasks.
public void testRaceConditionByStartingMultipleTasks() throws IOException, InterruptedException {
AnomalyDetector detector = TestHelpers.randomDetector(ImmutableList.of(maxValueFeature()), testIndex, detectionIntervalInMinutes, timeField);
String detectorId = createDetector(detector);
AnomalyDetectorJobRequest request = new AnomalyDetectorJobRequest(detectorId, dateRange, true, UNASSIGNED_SEQ_NO, UNASSIGNED_PRIMARY_TERM, START_JOB);
client().execute(AnomalyDetectorJobAction.INSTANCE, request);
client().execute(AnomalyDetectorJobAction.INSTANCE, request);
Thread.sleep(5000);
List<ADTask> adTasks = searchADTasks(detectorId, null, 100);
assertEquals(1, adTasks.size());
assertTrue(adTasks.get(0).getLatest());
assertNotEquals(ADTaskState.FAILED.name(), adTasks.get(0).getState());
}
Aggregations