|
6 | 6 | */ |
7 | 7 | package org.elasticsearch.xpack.core.ml.datafeed; |
8 | 8 |
|
| 9 | +import org.elasticsearch.ElasticsearchStatusException; |
9 | 10 | import org.elasticsearch.action.search.SearchRequest; |
10 | 11 | import org.elasticsearch.action.support.IndicesOptions; |
11 | 12 | import org.elasticsearch.common.io.stream.NamedWriteableRegistry; |
12 | 13 | import org.elasticsearch.common.io.stream.Writeable; |
13 | 14 | import org.elasticsearch.common.settings.Settings; |
14 | 15 | import org.elasticsearch.core.TimeValue; |
| 16 | +import org.elasticsearch.rest.RestStatus; |
15 | 17 | import org.elasticsearch.search.SearchModule; |
16 | 18 | import org.elasticsearch.search.aggregations.AggregationBuilder; |
17 | 19 | import org.elasticsearch.search.aggregations.AggregationBuilders; |
|
30 | 32 |
|
31 | 33 | import static org.elasticsearch.xpack.core.ml.datafeed.DatafeedConfigTests.randomStringList; |
32 | 34 | import static org.elasticsearch.xpack.core.ml.utils.QueryProviderTests.createTestQueryProvider; |
| 35 | +import static org.hamcrest.Matchers.equalTo; |
33 | 36 |
|
34 | 37 | public class DatafeedConfigBuilderTests extends AbstractWireSerializingTestCase<DatafeedConfig.Builder> { |
35 | 38 |
|
@@ -147,4 +150,17 @@ protected Writeable.Reader<DatafeedConfig.Builder> instanceReader() { |
147 | 150 | return DatafeedConfig.Builder::new; |
148 | 151 | } |
149 | 152 |
|
| 153 | + public void testResolveCrossProjectIsDisabled() { |
| 154 | + var datafeedBuilder = createRandomizedDatafeedConfigBuilder("jobId", "datafeed-id", 3600000); |
| 155 | + datafeedBuilder = datafeedBuilder.setIndicesOptions( |
| 156 | + IndicesOptions.builder(datafeedBuilder.getIndicesOptions()) |
| 157 | + .crossProjectModeOptions(new IndicesOptions.CrossProjectModeOptions(true)) |
| 158 | + .build() |
| 159 | + ); |
| 160 | + |
| 161 | + var actualException = assertThrows(ElasticsearchStatusException.class, datafeedBuilder::build); |
| 162 | + assertThat(actualException.getMessage(), equalTo("Cross-project search is not enabled for Datafeeds")); |
| 163 | + assertThat(actualException.status(), equalTo(RestStatus.FORBIDDEN)); |
| 164 | + } |
| 165 | + |
150 | 166 | } |
0 commit comments