|
@@ -43,6 +43,7 @@ import static org.hamcrest.Matchers.is;
|
|
|
public abstract class TransformRestTestCase extends ESRestTestCase {
|
|
|
|
|
|
protected static final String TEST_PASSWORD = "x-pack-test-password";
|
|
|
+ private static final String SECONDARY_AUTH_KEY = "es-secondary-authorization";
|
|
|
protected static final SecureString TEST_PASSWORD_SECURE_STRING = new SecureString(TEST_PASSWORD.toCharArray());
|
|
|
private static final String BASIC_AUTH_VALUE_SUPER_USER = basicAuthHeaderValue("x_pack_rest_user", TEST_PASSWORD_SECURE_STRING);
|
|
|
|
|
@@ -267,7 +268,7 @@ public abstract class TransformRestTestCase extends ESRestTestCase {
|
|
|
}
|
|
|
}""".formatted(transformIndex, REVIEWS_INDEX_NAME);
|
|
|
|
|
|
- createReviewsTransform(transformId, authHeader, config);
|
|
|
+ createReviewsTransform(transformId, authHeader, null, config);
|
|
|
}
|
|
|
|
|
|
protected void createPivotReviewsTransform(
|
|
@@ -277,6 +278,18 @@ public abstract class TransformRestTestCase extends ESRestTestCase {
|
|
|
String pipeline,
|
|
|
String authHeader,
|
|
|
String sourceIndex
|
|
|
+ ) throws IOException {
|
|
|
+ createPivotReviewsTransform(transformId, transformIndex, query, pipeline, authHeader, null, sourceIndex);
|
|
|
+ }
|
|
|
+
|
|
|
+ protected void createPivotReviewsTransform(
|
|
|
+ String transformId,
|
|
|
+ String transformIndex,
|
|
|
+ String query,
|
|
|
+ String pipeline,
|
|
|
+ String authHeader,
|
|
|
+ String secondaryAuthHeader,
|
|
|
+ String sourceIndex
|
|
|
) throws IOException {
|
|
|
String config = "{";
|
|
|
|
|
@@ -326,7 +339,7 @@ public abstract class TransformRestTestCase extends ESRestTestCase {
|
|
|
"frequency": "1s"
|
|
|
}""";
|
|
|
|
|
|
- createReviewsTransform(transformId, authHeader, config);
|
|
|
+ createReviewsTransform(transformId, authHeader, secondaryAuthHeader, config);
|
|
|
}
|
|
|
|
|
|
protected void createLatestReviewsTransform(String transformId, String transformIndex) throws IOException {
|
|
@@ -347,11 +360,17 @@ public abstract class TransformRestTestCase extends ESRestTestCase {
|
|
|
"frequency": "1s"
|
|
|
}""".formatted(transformIndex, REVIEWS_INDEX_NAME);
|
|
|
|
|
|
- createReviewsTransform(transformId, null, config);
|
|
|
+ createReviewsTransform(transformId, null, null, config);
|
|
|
}
|
|
|
|
|
|
- private void createReviewsTransform(String transformId, String authHeader, String config) throws IOException {
|
|
|
- final Request createTransformRequest = createRequestWithAuth("PUT", getTransformEndpoint() + transformId, authHeader);
|
|
|
+ private void createReviewsTransform(String transformId, String authHeader, String secondaryAuthHeader, String config)
|
|
|
+ throws IOException {
|
|
|
+ final Request createTransformRequest = createRequestWithSecondaryAuth(
|
|
|
+ "PUT",
|
|
|
+ getTransformEndpoint() + transformId,
|
|
|
+ authHeader,
|
|
|
+ secondaryAuthHeader
|
|
|
+ );
|
|
|
createTransformRequest.setJsonEntity(config);
|
|
|
|
|
|
Map<String, Object> createTransformResponse = entityAsMap(client().performRequest(createTransformRequest));
|
|
@@ -360,7 +379,7 @@ public abstract class TransformRestTestCase extends ESRestTestCase {
|
|
|
|
|
|
protected void createPivotReviewsTransform(String transformId, String transformIndex, String query, String pipeline, String authHeader)
|
|
|
throws IOException {
|
|
|
- createPivotReviewsTransform(transformId, transformIndex, query, pipeline, authHeader, REVIEWS_INDEX_NAME);
|
|
|
+ createPivotReviewsTransform(transformId, transformIndex, query, pipeline, authHeader, null, REVIEWS_INDEX_NAME);
|
|
|
}
|
|
|
|
|
|
protected void startTransform(String transformId) throws IOException {
|
|
@@ -369,7 +388,18 @@ public abstract class TransformRestTestCase extends ESRestTestCase {
|
|
|
|
|
|
protected void startTransform(String transformId, String authHeader, String... warnings) throws IOException {
|
|
|
// start the transform
|
|
|
- final Request startTransformRequest = createRequestWithAuth("POST", getTransformEndpoint() + transformId + "/_start", authHeader);
|
|
|
+ startTransform(transformId, authHeader, null, warnings);
|
|
|
+ }
|
|
|
+
|
|
|
+ protected void startTransform(String transformId, String authHeader, String secondaryAuthHeader, String... warnings)
|
|
|
+ throws IOException {
|
|
|
+ // start the transform
|
|
|
+ final Request startTransformRequest = createRequestWithSecondaryAuth(
|
|
|
+ "POST",
|
|
|
+ getTransformEndpoint() + transformId + "/_start",
|
|
|
+ authHeader,
|
|
|
+ secondaryAuthHeader
|
|
|
+ );
|
|
|
if (warnings.length > 0) {
|
|
|
startTransformRequest.setOptions(expectWarnings(warnings));
|
|
|
}
|
|
@@ -404,8 +434,18 @@ public abstract class TransformRestTestCase extends ESRestTestCase {
|
|
|
|
|
|
protected void startAndWaitForTransform(String transformId, String transformIndex, String authHeader, String... warnings)
|
|
|
throws Exception {
|
|
|
+ startAndWaitForTransform(transformId, transformIndex, authHeader, null, warnings);
|
|
|
+ }
|
|
|
+
|
|
|
+ protected void startAndWaitForTransform(
|
|
|
+ String transformId,
|
|
|
+ String transformIndex,
|
|
|
+ String authHeader,
|
|
|
+ String secondaryAuthHeader,
|
|
|
+ String... warnings
|
|
|
+ ) throws Exception {
|
|
|
// start the transform
|
|
|
- startTransform(transformId, authHeader, warnings);
|
|
|
+ startTransform(transformId, authHeader, secondaryAuthHeader, warnings);
|
|
|
assertTrue(indexExists(transformIndex));
|
|
|
// wait until the transform has been created and all data is available
|
|
|
waitForTransformCheckpoint(transformId);
|
|
@@ -435,18 +475,29 @@ public abstract class TransformRestTestCase extends ESRestTestCase {
|
|
|
assertThat(resetTransformResponse.get("acknowledged"), equalTo(Boolean.TRUE));
|
|
|
}
|
|
|
|
|
|
- protected Request createRequestWithAuth(final String method, final String endpoint, final String authHeader) {
|
|
|
+ protected Request createRequestWithSecondaryAuth(
|
|
|
+ final String method,
|
|
|
+ final String endpoint,
|
|
|
+ final String authHeader,
|
|
|
+ final String secondaryAuthHeader
|
|
|
+ ) {
|
|
|
final Request request = new Request(method, endpoint);
|
|
|
|
|
|
+ RequestOptions.Builder options = request.getOptions().toBuilder();
|
|
|
if (authHeader != null) {
|
|
|
- RequestOptions.Builder options = request.getOptions().toBuilder();
|
|
|
options.addHeader("Authorization", authHeader);
|
|
|
- request.setOptions(options);
|
|
|
}
|
|
|
-
|
|
|
+ if (secondaryAuthHeader != null) {
|
|
|
+ options.addHeader(SECONDARY_AUTH_KEY, secondaryAuthHeader);
|
|
|
+ }
|
|
|
+ request.setOptions(options);
|
|
|
return request;
|
|
|
}
|
|
|
|
|
|
+ protected Request createRequestWithAuth(final String method, final String endpoint, final String authHeader) {
|
|
|
+ return createRequestWithSecondaryAuth(method, endpoint, authHeader, null);
|
|
|
+ }
|
|
|
+
|
|
|
void waitForTransformStopped(String transformId) throws Exception {
|
|
|
assertBusy(() -> { assertEquals("stopped", getTransformState(transformId)); }, 15, TimeUnit.SECONDS);
|
|
|
}
|