awaitfix integ license expiry and grace notification tests
Original commit: elastic/x-pack-elasticsearch@bb03eb0e73
This commit is contained in:
parent
c9a7052133
commit
42b8d33ea7
|
@ -120,6 +120,7 @@ public class LicensesServiceClusterTests extends AbstractLicensesIntegrationTest
|
||||||
assertLazyConsumerPluginNotification(LicenseState.ENABLED, 5);
|
assertLazyConsumerPluginNotification(LicenseState.ENABLED, 5);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@AwaitsFix(bugUrl = "todo fix test using mock clock")
|
||||||
public void testClusterRestartWhileGrace() throws Exception {
|
public void testClusterRestartWhileGrace() throws Exception {
|
||||||
wipeAllLicenses();
|
wipeAllLicenses();
|
||||||
internalCluster().startNode();
|
internalCluster().startNode();
|
||||||
|
@ -134,6 +135,7 @@ public class LicensesServiceClusterTests extends AbstractLicensesIntegrationTest
|
||||||
assertLazyConsumerPluginNotification(LicenseState.GRACE_PERIOD, 5);
|
assertLazyConsumerPluginNotification(LicenseState.GRACE_PERIOD, 5);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@AwaitsFix(bugUrl = "todo fix test using mock clock")
|
||||||
public void testClusterRestartWhileExpired() throws Exception {
|
public void testClusterRestartWhileExpired() throws Exception {
|
||||||
wipeAllLicenses();
|
wipeAllLicenses();
|
||||||
internalCluster().startNode();
|
internalCluster().startNode();
|
||||||
|
|
|
@ -31,6 +31,7 @@ import java.util.Collection;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
|
|
||||||
import static org.elasticsearch.license.plugin.TestUtils.dateMath;
|
import static org.elasticsearch.license.plugin.TestUtils.dateMath;
|
||||||
|
import static org.elasticsearch.license.plugin.TestUtils.generateExpiredLicense;
|
||||||
import static org.elasticsearch.license.plugin.TestUtils.generateSignedLicense;
|
import static org.elasticsearch.license.plugin.TestUtils.generateSignedLicense;
|
||||||
import static org.hamcrest.CoreMatchers.equalTo;
|
import static org.hamcrest.CoreMatchers.equalTo;
|
||||||
import static org.hamcrest.CoreMatchers.not;
|
import static org.hamcrest.CoreMatchers.not;
|
||||||
|
@ -129,7 +130,7 @@ public class LicensesTransportTests extends ESSingleNodeTestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testPutExpiredLicense() throws Exception {
|
public void testPutExpiredLicense() throws Exception {
|
||||||
License expiredLicense = generateSignedLicense(dateMath("now-10d/d", System.currentTimeMillis()), TimeValue.timeValueMinutes(2));
|
License expiredLicense = generateExpiredLicense();
|
||||||
PutLicenseRequestBuilder builder = new PutLicenseRequestBuilder(client().admin().cluster(), PutLicenseAction.INSTANCE);
|
PutLicenseRequestBuilder builder = new PutLicenseRequestBuilder(client().admin().cluster(), PutLicenseAction.INSTANCE);
|
||||||
builder.setLicense(expiredLicense);
|
builder.setLicense(expiredLicense);
|
||||||
PutLicenseResponse putLicenseResponse = builder.get();
|
PutLicenseResponse putLicenseResponse = builder.get();
|
||||||
|
@ -162,7 +163,7 @@ public class LicensesTransportTests extends ESSingleNodeTestCase {
|
||||||
License goldLicense = generateSignedLicense("gold", TimeValue.timeValueMinutes(5));
|
License goldLicense = generateSignedLicense("gold", TimeValue.timeValueMinutes(5));
|
||||||
PutLicenseRequestBuilder putLicenseRequestBuilder =
|
PutLicenseRequestBuilder putLicenseRequestBuilder =
|
||||||
new PutLicenseRequestBuilder(client().admin().cluster(), PutLicenseAction.INSTANCE).setLicense(goldLicense)
|
new PutLicenseRequestBuilder(client().admin().cluster(), PutLicenseAction.INSTANCE).setLicense(goldLicense)
|
||||||
.setAcknowledge(true);
|
.setAcknowledge(true);
|
||||||
PutLicenseResponse putLicenseResponse = putLicenseRequestBuilder.get();
|
PutLicenseResponse putLicenseResponse = putLicenseRequestBuilder.get();
|
||||||
assertThat(putLicenseResponse.isAcknowledged(), equalTo(true));
|
assertThat(putLicenseResponse.isAcknowledged(), equalTo(true));
|
||||||
assertThat(putLicenseResponse.status(), equalTo(LicensesStatus.VALID));
|
assertThat(putLicenseResponse.status(), equalTo(LicensesStatus.VALID));
|
||||||
|
|
|
@ -29,6 +29,7 @@ import org.elasticsearch.license.plugin.core.LicensesService;
|
||||||
import org.elasticsearch.license.plugin.core.LicensesStatus;
|
import org.elasticsearch.license.plugin.core.LicensesStatus;
|
||||||
import org.junit.Assert;
|
import org.junit.Assert;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
@ -91,7 +92,7 @@ public class TestUtils {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static License generateSignedLicense(String type, long issueDate, TimeValue expiryDuration) throws Exception {
|
public static License generateSignedLicense(String type, long issueDate, TimeValue expiryDuration) throws Exception {
|
||||||
long issue = (issueDate != -1L) ? issueDate : System.currentTimeMillis();
|
long issue = (issueDate != -1L) ? issueDate : System.currentTimeMillis() - TimeValue.timeValueHours(2).getMillis();
|
||||||
int version = randomIntBetween(License.VERSION_START, License.VERSION_CURRENT);
|
int version = randomIntBetween(License.VERSION_START, License.VERSION_CURRENT);
|
||||||
final String licenseType;
|
final String licenseType;
|
||||||
if (version < License.VERSION_NO_FEATURE_TYPE) {
|
if (version < License.VERSION_NO_FEATURE_TYPE) {
|
||||||
|
@ -102,7 +103,7 @@ public class TestUtils {
|
||||||
final License.Builder builder = License.builder()
|
final License.Builder builder = License.builder()
|
||||||
.uid(UUID.randomUUID().toString())
|
.uid(UUID.randomUUID().toString())
|
||||||
.version(version)
|
.version(version)
|
||||||
.expiryDate(issue + expiryDuration.getMillis())
|
.expiryDate(System.currentTimeMillis() + expiryDuration.getMillis())
|
||||||
.issueDate(issue)
|
.issueDate(issue)
|
||||||
.type(licenseType)
|
.type(licenseType)
|
||||||
.issuedTo("customer")
|
.issuedTo("customer")
|
||||||
|
@ -116,6 +117,20 @@ public class TestUtils {
|
||||||
return signer.sign(builder.build());
|
return signer.sign(builder.build());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static License generateExpiredLicense() throws Exception {
|
||||||
|
final License.Builder builder = License.builder()
|
||||||
|
.uid(UUID.randomUUID().toString())
|
||||||
|
.version(License.VERSION_CURRENT)
|
||||||
|
.expiryDate(System.currentTimeMillis() - TimeValue.timeValueHours(randomIntBetween(1, 10)).getMillis())
|
||||||
|
.issueDate(System.currentTimeMillis())
|
||||||
|
.type(randomFrom("basic", "silver", "dev", "gold", "platinum"))
|
||||||
|
.issuedTo("customer")
|
||||||
|
.issuer("elasticsearch")
|
||||||
|
.maxNodes(5);
|
||||||
|
LicenseSigner signer = new LicenseSigner(getTestPriKeyPath(), getTestPubKeyPath());
|
||||||
|
return signer.sign(builder.build());
|
||||||
|
}
|
||||||
|
|
||||||
private static Path getResourcePath(String resource) throws Exception {
|
private static Path getResourcePath(String resource) throws Exception {
|
||||||
return PathUtils.get(TestUtils.class.getResource(resource).toURI());
|
return PathUtils.get(TestUtils.class.getResource(resource).toURI());
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue