Skip to content

Commit

Permalink
Watcher: Ensure secrets integration tests also run triggered watch (#…
Browse files Browse the repository at this point in the history
…30478)

When the encrpytion of sensitive date is enabled, test that a
scheduled watch is executed as expected and produces the correct value
from a secret in the basic auth header.
  • Loading branch information
spinscale committed May 16, 2018
1 parent 4720778 commit b1eda60
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
*/
package org.elasticsearch.xpack.core.watcher.support.xcontent;

import org.apache.lucene.util.BytesRef;
import org.elasticsearch.ElasticsearchException;
import org.elasticsearch.ElasticsearchParseException;
import org.elasticsearch.common.Nullable;
import org.elasticsearch.common.xcontent.DeprecationHandler;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public class HttpSecretsIntegrationTests extends AbstractWatcherIntegrationTestC

private MockWebServer webServer = new MockWebServer();
private static Boolean encryptSensitiveData = null;
private static byte[] encryptionKey = CryptoServiceTests.generateKey();
private static final byte[] encryptionKey = CryptoServiceTests.generateKey();

@Before
public void init() throws Exception {
Expand Down Expand Up @@ -155,6 +155,14 @@ public void testHttpInput() throws Exception {
assertThat(webServer.requests(), hasSize(1));
assertThat(webServer.requests().get(0).getHeader("Authorization"),
is(ApplicableBasicAuth.headerValue(USERNAME, PASSWORD.toCharArray())));

// now trigger the by the scheduler and make sure that the password is also correctly transmitted
webServer.enqueue(new MockResponse().setResponseCode(200).setBody(
BytesReference.bytes(jsonBuilder().startObject().field("key", "value").endObject()).utf8ToString()));
timeWarp().trigger("_id");
assertThat(webServer.requests(), hasSize(2));
assertThat(webServer.requests().get(1).getHeader("Authorization"),
is(ApplicableBasicAuth.headerValue(USERNAME, PASSWORD.toCharArray())));
}

public void testWebhookAction() throws Exception {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ public ScheduleTriggerEvent parseTriggerEvent(TriggerService service, String wat

@Override
public void start(Collection<Watch> jobs) {
jobs.forEach(this::add);
}

@Override
Expand Down

0 comments on commit b1eda60

Please sign in to comment.