Fixed rest runners that check watcher+shield and an expired license.

* The watcher+shield test failed, but the error was ignored due to a buggy if statement that existed for the hijack rest test.
* Blacklisted the hijack test.
* Also ade sure that we run the watcher+rest test with an user that doesn't have credentials.

Original commit: elastic/x-pack-elasticsearch@61b1bf0142
This commit is contained in:
Martijn van Groningen 2015-08-07 14:26:22 +02:00
parent 1b72f13458
commit f726a8a017
3 changed files with 26 additions and 26 deletions

View File

@ -24,6 +24,7 @@
<elasticsearch.integ.antfile>dev-tools/integration-tests.xml</elasticsearch.integ.antfile> <elasticsearch.integ.antfile>dev-tools/integration-tests.xml</elasticsearch.integ.antfile>
<tests.rest.load_packaged>false</tests.rest.load_packaged> <tests.rest.load_packaged>false</tests.rest.load_packaged>
<tests.timewarp>true</tests.timewarp> <tests.timewarp>true</tests.timewarp>
<tests.rest.blacklist>hijack/10_basic/*</tests.rest.blacklist>
</properties> </properties>
<dependencies> <dependencies>

View File

@ -31,16 +31,14 @@ public class WatcherDisabledLicenseRestTests extends WatcherRestTests {
@Test @Test
public void test() throws IOException { public void test() throws IOException {
disableLicensing();
try { try {
disableLicensing();
super.test(); super.test();
fail(); fail();
} catch(AssertionError ae) { } catch(AssertionError e) {
if (ae.getMessage() == null || ae.getMessage().contains("not supported")){ assertThat(e.getMessage(), containsString("license expired for feature [watcher]"));
//This was a test testing the "hijacked" methods } finally {
return; enableLicensing();
}
assertThat(ae.getMessage(), containsString("license expired for feature [watcher]"));
} }
} }
@ -49,4 +47,15 @@ public class WatcherDisabledLicenseRestTests extends WatcherRestTests {
service.disable(); service.disable();
} }
} }
public static void enableLicensing() {
for (MockLicenseService service : internalCluster().getInstances(MockLicenseService.class)) {
service.enable();
}
}
@Override
protected boolean enableShield() {
return false;
}
} }

View File

@ -6,27 +6,13 @@
package org.elasticsearch.watcher.test.rest; package org.elasticsearch.watcher.test.rest;
import com.carrotsearch.randomizedtesting.annotations.Name; import com.carrotsearch.randomizedtesting.annotations.Name;
import org.elasticsearch.ElasticsearchException;
import org.elasticsearch.client.support.Headers; import org.elasticsearch.client.support.Headers;
import org.elasticsearch.common.io.FileSystemUtils;
import org.elasticsearch.common.io.Streams;
import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.license.plugin.LicensePlugin;
import org.elasticsearch.node.Node;
import org.elasticsearch.plugins.PluginsService;
import org.elasticsearch.shield.ShieldPlugin;
import org.elasticsearch.shield.authc.esusers.ESUsersRealm;
import org.elasticsearch.shield.authc.support.Hasher;
import org.elasticsearch.shield.authc.support.SecuredString; import org.elasticsearch.shield.authc.support.SecuredString;
import org.elasticsearch.test.rest.RestTestCandidate; import org.elasticsearch.test.rest.RestTestCandidate;
import org.elasticsearch.watcher.WatcherPlugin;
import org.elasticsearch.watcher.test.AbstractWatcherIntegrationTests;
import org.junit.Test; import org.junit.Test;
import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import static org.elasticsearch.shield.authc.support.UsernamePasswordToken.basicAuthHeaderValue; import static org.elasticsearch.shield.authc.support.UsernamePasswordToken.basicAuthHeaderValue;
import static org.hamcrest.Matchers.containsString; import static org.hamcrest.Matchers.containsString;
@ -50,12 +36,16 @@ public class WatcherShieldAuthorizationFailedRestTests extends WatcherRestTests
super.test(); super.test();
fail(); fail();
} catch(AssertionError ae) { } catch(AssertionError ae) {
if (ae.getMessage() == null || ae.getMessage().contains("not supported")){
//This was a test testing the "hijacked" methods
return;
}
assertThat(ae.getMessage(), containsString("returned [403 Forbidden]")); assertThat(ae.getMessage(), containsString("returned [403 Forbidden]"));
assertThat(ae.getMessage(), containsString("is unauthorized for user [admin]")); assertThat(ae.getMessage(), containsString("is unauthorized for user [test]"));
} }
} }
@Override
protected Settings restClientSettings() {
String token = basicAuthHeaderValue("test", new SecuredString("changeme".toCharArray()));
return Settings.builder()
.put(Headers.PREFIX + ".Authorization", token)
.build();
}
} }