@Override public PemTrustOptions clone() { return new PemTrustOptions(this); }
@Override public PemTrustOptions trustOptions() { return new PemTrustOptions().addCertPath(certificatePath()); }
case "pemTrustOptions": if (member.getValue() instanceof JsonObject) { obj.setPemTrustOptions(new io.vertx.core.net.PemTrustOptions((JsonObject)member.getValue()));
case "pemTrustOptions": if (member.getValue() instanceof JsonObject) { obj.setPemTrustOptions(new io.vertx.core.net.PemTrustOptions((JsonObject)member.getValue()));
@Test public void testCaInvalidPem() throws IOException { String[] contents = { "", "-----BEGIN CERTIFICATE-----", "-----BEGIN CERTIFICATE-----\n-----END CERTIFICATE-----", "-----BEGIN CERTIFICATE-----\n*\n-----END CERTIFICATE-----" }; String[] messages = { "Missing -----BEGIN CERTIFICATE----- delimiter", "Missing -----END CERTIFICATE----- delimiter", "Empty pem file", "Input byte[] should at least have 2 bytes for base64 bytes" }; for (int i = 0;i < contents.length;i++) { Path file = testFolder.newFile("vertx" + UUID.randomUUID().toString() + ".pem").toPath(); Files.write(file, Collections.singleton(contents[i])); String expectedMessage = messages[i]; testInvalidTrustStore(new PemTrustOptions().addCertPath(file.toString()), expectedMessage, null); } }
@Test public void testTrustOptionsJson() throws Exception { PemTrustOptions options = new PemTrustOptions(new JsonObject()); assertEquals(Collections.emptyList(), options.getCertPaths()); assertEquals(Collections.emptyList(), options.getCertValues()); String certPath = TestUtils.randomAlphaString(100); String certValue = TestUtils.randomAlphaString(100); JsonObject json = new JsonObject(). put("certPaths", new JsonArray().add(certPath)). put("certValues", new JsonArray().add(certValue.getBytes())); options = new PemTrustOptions(json); assertEquals(Collections.singletonList(certPath), options.getCertPaths()); assertEquals(Collections.singletonList(Buffer.buffer(certValue)), options.getCertValues()); }
@Test public void testDefaultTrustOptionsJson() { PemTrustOptions def = new PemTrustOptions(); PemTrustOptions json = new PemTrustOptions(new JsonObject()); assertEquals(def.getCertPaths(), json.getCertPaths()); assertEquals(def.getCertValues(), json.getCertValues()); }
@Test public void testCopyTrustOptions() throws Exception { PemTrustOptions options = new PemTrustOptions(new JsonObject()); String certPath = TestUtils.randomAlphaString(100); Buffer certValue = Buffer.buffer(TestUtils.randomAlphaString(100)); options.addCertPath(certPath); options.addCertValue(certValue); options = new PemTrustOptions(options); assertEquals(Collections.singletonList(certPath), options.getCertPaths()); assertEquals(Collections.singletonList(certValue), options.getCertValues()); options = new PemTrustOptions(options.toJson()); assertEquals(Collections.singletonList(certPath), options.getCertPaths()); assertEquals(Collections.singletonList(certValue), options.getCertValues()); }
@Test public void testCaInvalidPath() { testInvalidTrustStore(new PemTrustOptions().addCertPath("/invalid.pem"), "java.nio.file.NoSuchFileException: ", "invalid.pem"); }
@Test public void testTrustOptions() throws Exception { PemTrustOptions options = new PemTrustOptions(); assertEquals(Collections.emptyList(), options.getCertPaths()); assertNullPointerException(() -> options.addCertPath(null)); assertIllegalArgumentException(() -> options.addCertPath("")); String randString = TestUtils.randomAlphaString(100); options.addCertPath(randString); assertEquals(Collections.singletonList(randString), options.getCertPaths()); assertEquals(Collections.emptyList(), options.getCertValues()); assertNullPointerException(() -> options.addCertValue(null)); randString = TestUtils.randomAlphaString(100); options.addCertValue(Buffer.buffer(randString)); assertEquals(Collections.singletonList(Buffer.buffer(randString)), options.getCertValues()); }
@Override public PemTrustOptions clone() { return new PemTrustOptions(this); }
@Test public void testTrustOptionsEquality() { String certPath1 = TestUtils.randomAlphaString(100); String certPath2 = TestUtils.randomAlphaString(100); Buffer certValue1 = Buffer.buffer(TestUtils.randomAlphaString(100)); Buffer certValue2 = Buffer.buffer(TestUtils.randomAlphaString(100)); PemTrustOptions options = new PemTrustOptions(); PemTrustOptions otherOptions = new PemTrustOptions(); assertEquals(options, otherOptions); assertEquals(options.hashCode(), otherOptions.hashCode()); options.addCertPath(certPath1); options.addCertPath(certPath2); options.addCertValue(certValue1); options.addCertValue(certValue2); otherOptions.addCertPath(certPath1); otherOptions.addCertPath(certPath2); otherOptions.addCertValue(certValue1); otherOptions.addCertValue(certValue2); assertEquals(options, otherOptions); assertEquals(options.hashCode(), otherOptions.hashCode()); otherOptions.addCertPath(TestUtils.randomAlphaString(100)); assertNotEquals(options, otherOptions); PemTrustOptions reverseOrderOptions = new PemTrustOptions(); reverseOrderOptions.addCertPath(certPath2); reverseOrderOptions.addCertPath(certPath1); reverseOrderOptions.addCertValue(certValue2); reverseOrderOptions.addCertValue(certValue1); assertNotEquals(options, reverseOrderOptions); }
public static TrustOptions randomTrustOptions() { TrustOptions trustOptions; switch (TestUtils.randomPositiveInt() % 3) { case 0: trustOptions = new JksOptions(); String tsPassword = TestUtils.randomAlphaString(100); ((JksOptions) trustOptions).setPassword(tsPassword); break; case 1: trustOptions = new PemTrustOptions(); Buffer keyValue = TestUtils.randomBuffer(100); ((PemTrustOptions) trustOptions).addCertValue(keyValue); break; default: trustOptions = new PfxOptions(); String pfxPassword = TestUtils.randomAlphaString(100); ((PfxOptions) trustOptions).setPassword(pfxPassword); } return trustOptions; }
@Override public PemTrustOptions trustOptions() { return new PemTrustOptions().addCertPath(certificatePath()); }
@Test public void testTrustOptionsJson() throws Exception { PemTrustOptions options = new PemTrustOptions(new JsonObject()); assertEquals(Collections.emptyList(), options.getCertPaths()); assertEquals(Collections.emptyList(), options.getCertValues()); String certPath = TestUtils.randomAlphaString(100); String certValue = TestUtils.randomAlphaString(100); JsonObject json = new JsonObject(). put("certPaths", new JsonArray().add(certPath)). put("certValues", new JsonArray().add(certValue.getBytes())); options = new PemTrustOptions(json); assertEquals(Collections.singletonList(certPath), options.getCertPaths()); assertEquals(Collections.singletonList(Buffer.buffer(certValue)), options.getCertValues()); }
@Test public void testDefaultTrustOptionsJson() { PemTrustOptions def = new PemTrustOptions(); PemTrustOptions json = new PemTrustOptions(new JsonObject()); assertEquals(def.getCertPaths(), json.getCertPaths()); assertEquals(def.getCertValues(), json.getCertValues()); }
@Test public void testCaInvalidPath() { testInvalidTrustStore(new PemTrustOptions().addCertPath("/invalid.pem"), "java.nio.file.NoSuchFileException: ", "invalid.pem"); }
@Test public void testCopyTrustOptions() throws Exception { PemTrustOptions options = new PemTrustOptions(new JsonObject()); String certPath = TestUtils.randomAlphaString(100); Buffer certValue = Buffer.buffer(TestUtils.randomAlphaString(100)); options.addCertPath(certPath); options.addCertValue(certValue); options = new PemTrustOptions(options); assertEquals(Collections.singletonList(certPath), options.getCertPaths()); assertEquals(Collections.singletonList(certValue), options.getCertValues()); options = new PemTrustOptions(options.toJson()); assertEquals(Collections.singletonList(certPath), options.getCertPaths()); assertEquals(Collections.singletonList(certValue), options.getCertValues()); }
@Test public void testTrustOptions() throws Exception { PemTrustOptions options = new PemTrustOptions(); assertEquals(Collections.emptyList(), options.getCertPaths()); assertNullPointerException(() -> options.addCertPath(null)); assertIllegalArgumentException(() -> options.addCertPath("")); String randString = TestUtils.randomAlphaString(100); options.addCertPath(randString); assertEquals(Collections.singletonList(randString), options.getCertPaths()); assertEquals(Collections.emptyList(), options.getCertValues()); assertNullPointerException(() -> options.addCertValue(null)); randString = TestUtils.randomAlphaString(100); options.addCertValue(Buffer.buffer(randString)); assertEquals(Collections.singletonList(Buffer.buffer(randString)), options.getCertValues()); }
public static TrustOptions randomTrustOptions() { TrustOptions trustOptions; switch (TestUtils.randomPositiveInt() % 3) { case 0: trustOptions = new JksOptions(); String tsPassword = TestUtils.randomAlphaString(100); ((JksOptions) trustOptions).setPassword(tsPassword); break; case 1: trustOptions = new PemTrustOptions(); Buffer keyValue = TestUtils.randomBuffer(100); ((PemTrustOptions) trustOptions).addCertValue(keyValue); break; default: trustOptions = new PfxOptions(); String pfxPassword = TestUtils.randomAlphaString(100); ((PfxOptions) trustOptions).setPassword(pfxPassword); } return trustOptions; }