use of org.opensearch.ad.model.AnomalyDetector in project anomaly-detection by opensearch-project.
the class SecureADRestIT method testPreviewAnomalyDetectorWithNoReadPermissionOfIndex.
public void testPreviewAnomalyDetectorWithNoReadPermissionOfIndex() 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(), aliceDetector);
enableFilterBy();
// User elk has no read permission of index
Exception exception = expectThrows(Exception.class, () -> {
previewAnomalyDetector(aliceDetector.getDetectorId(), elkClient, input);
});
Assert.assertTrue(exception.getMessage().contains("no permissions for [indices:data/read/search]"));
}
use of org.opensearch.ad.model.AnomalyDetector in project anomaly-detection by opensearch-project.
the class SecureADRestIT method testCreateAnomalyDetectorWithCustomResultIndex.
public void testCreateAnomalyDetectorWithCustomResultIndex() throws IOException {
// User alice has AD full access and index permission, so can create detector
AnomalyDetector anomalyDetector = createRandomAnomalyDetector(false, false, aliceClient);
// User elk has AD full access, but has no read permission of index
String resultIndex = CommonName.CUSTOM_RESULT_INDEX_PREFIX + "test";
AnomalyDetector detector = cloneDetector(anomalyDetector, resultIndex);
// User goat has no permission to create index
Exception exception = expectThrows(IOException.class, () -> {
createAnomalyDetector(detector, true, goatClient);
});
Assert.assertTrue(exception.getMessage().contains("no permissions for [indices:admin/create]"));
// User cat has permission to create index
resultIndex = CommonName.CUSTOM_RESULT_INDEX_PREFIX + "test2";
TestHelpers.createIndexWithTimeField(client(), anomalyDetector.getIndices().get(0), anomalyDetector.getTimeField());
AnomalyDetector detectorOfCat = createAnomalyDetector(cloneDetector(anomalyDetector, resultIndex), true, catClient);
assertEquals(resultIndex, detectorOfCat.getResultIndex());
}
use of org.opensearch.ad.model.AnomalyDetector in project anomaly-detection by opensearch-project.
the class SecureADRestIT method testFilterByDisabled.
public void testFilterByDisabled() throws IOException {
// User Alice has AD full access, should be able to create a detector
AnomalyDetector aliceDetector = createRandomAnomalyDetector(false, false, aliceClient);
// User Cat has AD full access, should be able to get a detector
AnomalyDetector detector = getAnomalyDetector(aliceDetector.getDetectorId(), catClient);
Assert.assertEquals(aliceDetector.getDetectorId(), detector.getDetectorId());
}
use of org.opensearch.ad.model.AnomalyDetector in project anomaly-detection by opensearch-project.
the class SecureADRestIT method testCreateAnomalyDetectorWithNoReadPermissionOfIndex.
public void testCreateAnomalyDetectorWithNoReadPermissionOfIndex() throws IOException {
enableFilterBy();
// User alice has AD full access and index permission, so can create detector
AnomalyDetector anomalyDetector = createRandomAnomalyDetector(false, false, aliceClient);
// User elk has AD full access, but has no read permission of index
String indexName = anomalyDetector.getIndices().get(0);
Exception exception = expectThrows(IOException.class, () -> {
createRandomAnomalyDetector(false, false, indexName, elkClient);
});
Assert.assertTrue(exception.getMessage().contains("no permissions for [indices:data/read/search]"));
}
use of org.opensearch.ad.model.AnomalyDetector in project anomaly-detection by opensearch-project.
the class SecureADRestIT method testValidateAnomalyDetectorWithNoReadPermissionOfIndex.
public void testValidateAnomalyDetectorWithNoReadPermissionOfIndex() throws IOException {
AnomalyDetector detector = TestHelpers.randomAnomalyDetector(null, Instant.now());
enableFilterBy();
// User elk has no read permission of index, can't validate detector
Exception exception = expectThrows(Exception.class, () -> {
validateAnomalyDetector(detector, elkClient);
});
Assert.assertTrue(exception.getMessage().contains("no permissions for [indices:data/read/search]"));
}
Aggregations