[TEST] generate sane random licens specs

Original commit: elastic/x-pack-elasticsearch@f83d9d80b6
This commit is contained in:
Areek Zillur 2014-11-06 15:48:46 -05:00
parent 8e9574a925
commit bb929c7470
2 changed files with 10 additions and 10 deletions

View File

@ -25,8 +25,8 @@ import java.util.Set;
import java.util.UUID;
import java.util.concurrent.TimeUnit;
import static com.carrotsearch.randomizedtesting.RandomizedTest.randomInt;
import static com.carrotsearch.randomizedtesting.RandomizedTest.randomIntBetween;
import static com.carrotsearch.randomizedtesting.RandomizedTest.randomRealisticUnicodeOfCodepointLengthBetween;
import static org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder;
import static org.elasticsearch.test.ElasticsearchTestCase.randomFrom;
import static org.hamcrest.MatcherAssert.assertThat;
@ -74,10 +74,10 @@ public class AbstractLicensingTestBase {
long now = System.currentTimeMillis();
String issueDate = dateMathString("now", now);
String expiryDate = dateMathString("now+10d/d", now);
String uid = randomRealisticUnicodeOfCodepointLengthBetween(2, 10);
String feature = randomRealisticUnicodeOfCodepointLengthBetween(5, 15);
String issuer = randomRealisticUnicodeOfCodepointLengthBetween(5, 15);
String issuedTo = randomRealisticUnicodeOfCodepointLengthBetween(5, 15);
String uid = UUID.randomUUID().toString();
String feature = "feature__" + randomInt();
String issuer = "issuer__" + randomInt();
String issuedTo = "issuedTo__" + randomInt();
String type = randomFrom("subscription", "internal", "development");
String subscriptionType = randomFrom("none", "gold", "silver", "platinum");
int maxNodes = randomIntBetween(5, 100);

View File

@ -52,7 +52,7 @@ public class LicenseVerificationToolTests extends CliToolTestCase {
@Test
public void testParsingSimple() throws Exception {
ESLicense inputLicense = generateSignedLicense(randomRealisticUnicodeOfCodepointLengthBetween(5, 15),
ESLicense inputLicense = generateSignedLicense("feature__1",
TimeValue.timeValueHours(1));
LicenseVerificationTool licenseVerificationTool = new LicenseVerificationTool();
Command command = licenseVerificationTool.parse(LicenseVerificationTool.NAME,
@ -66,7 +66,7 @@ public class LicenseVerificationToolTests extends CliToolTestCase {
@Test
public void testParsingLicenseFile() throws Exception {
ESLicense inputLicense = generateSignedLicense(randomRealisticUnicodeOfCodepointLengthBetween(5, 15),
ESLicense inputLicense = generateSignedLicense("feature__1",
TimeValue.timeValueHours(1));
LicenseVerificationTool licenseVerificationTool = new LicenseVerificationTool();
@ -85,7 +85,7 @@ public class LicenseVerificationToolTests extends CliToolTestCase {
int n = randomIntBetween(2, 5);
Map<String, ESLicense> inputLicenses = new HashMap<>();
for (int i = 0; i < n; i++) {
ESLicense esLicense = generateSignedLicense(randomRealisticUnicodeOfCodepointLengthBetween(5, 15),
ESLicense esLicense = generateSignedLicense("feature__" + i,
TimeValue.timeValueHours(1));
inputLicenses.put(esLicense.feature(), esLicense);
}
@ -114,7 +114,7 @@ public class LicenseVerificationToolTests extends CliToolTestCase {
int n = randomIntBetween(2, 5);
Map<String, ESLicense> inputLicenses = new HashMap<>();
for (int i = 0; i < n; i++) {
ESLicense esLicense = generateSignedLicense(randomRealisticUnicodeOfCodepointLengthBetween(5, 15),
ESLicense esLicense = generateSignedLicense("feature__" + i,
TimeValue.timeValueHours(1));
inputLicenses.put(esLicense.feature(), esLicense);
}
@ -132,7 +132,7 @@ public class LicenseVerificationToolTests extends CliToolTestCase {
@Test
public void testToolInvalidLicense() throws Exception {
ESLicense signedLicense = generateSignedLicense(randomRealisticUnicodeOfCodepointLengthBetween(5, 15)
ESLicense signedLicense = generateSignedLicense("feature__1"
, TimeValue.timeValueHours(1));
ESLicense tamperedLicense = ESLicense.builder()