use of org.apache.knox.gateway.config.impl.GatewayConfigImpl in project knox by apache.
the class KnoxCLITest method testRemoteConfigurationRegistryUploadDescriptorWithDestinationOverride.
@Test
public void testRemoteConfigurationRegistryUploadDescriptorWithDestinationOverride() throws Exception {
outContent.reset();
final String descriptorName = "my-topology.json";
final String entryName = "different-topology.json";
final String descriptorContent = testDescriptorContentJSON;
final File testRoot = TestUtils.createTempDir(this.getClass().getName());
try {
final File testRegistry = new File(testRoot, "registryRoot");
final File testDescriptor = new File(testRoot, descriptorName);
final String[] args = { "upload-descriptor", testDescriptor.getAbsolutePath(), "--entry-name", entryName, "--registry-client", "test_client", "--master", "master" };
FileUtils.writeStringToFile(testDescriptor, descriptorContent);
KnoxCLI cli = new KnoxCLI();
Configuration config = new GatewayConfigImpl();
// Configure a client for the test local filesystem registry implementation
config.set("gateway.remote.config.registry.test_client", "type=LocalFileSystem;address=" + testRegistry);
cli.setConf(config);
// Run the test command
int rc = cli.run(args);
// Validate the result
assertEquals(0, rc);
assertFalse((new File(testRegistry, "knox/config/descriptors/" + descriptorName)).exists());
File registryFile = new File(testRegistry, "knox/config/descriptors/" + entryName);
assertTrue(registryFile.exists());
assertEquals(FileUtils.readFileToString(registryFile), descriptorContent);
} finally {
FileUtils.forceDelete(testRoot);
}
}
use of org.apache.knox.gateway.config.impl.GatewayConfigImpl in project knox by apache.
the class KnoxCLITest method testListAndDeleteOfAliasForInvalidClusterName.
@Test
public void testListAndDeleteOfAliasForInvalidClusterName() throws Exception {
outContent.reset();
String[] args1 = { "create-alias", "alias1", "--cluster", "cluster1", "--value", "testvalue1", "--master", "master" };
int rc = 0;
KnoxCLI cli = new KnoxCLI();
cli.setConf(new GatewayConfigImpl());
rc = cli.run(args1);
assertEquals(0, rc);
assertTrue(outContent.toString(), outContent.toString().contains("alias1 has been successfully " + "created."));
outContent.reset();
String[] args2 = { "list-alias", "--cluster", "Invalidcluster1", "--master", "master" };
rc = cli.run(args2);
assertEquals(0, rc);
System.out.println(outContent.toString());
assertTrue(outContent.toString(), outContent.toString().contains("Invalid cluster name provided: Invalidcluster1"));
outContent.reset();
String[] args4 = { "delete-alias", "alias1", "--cluster", "Invalidcluster1", "--master", "master" };
rc = cli.run(args4);
assertEquals(0, rc);
assertTrue(outContent.toString(), outContent.toString().contains("Invalid cluster name provided: Invalidcluster1"));
}
use of org.apache.knox.gateway.config.impl.GatewayConfigImpl in project knox by apache.
the class KnoxCLITest method testCreateMasterForce.
@Test
public void testCreateMasterForce() throws Exception {
GatewayConfigImpl config = new GatewayConfigImpl();
File masterFile = new File(config.getGatewaySecurityDir(), "master");
// Need to delete the master file so that the change isn't ignored.
if (masterFile.exists()) {
assertThat("Failed to delete existing master file.", masterFile.delete(), is(true));
}
KnoxCLI cli = new KnoxCLI();
cli.setConf(config);
MasterService ms;
int rc = 0;
outContent.reset();
String[] args = { "create-master", "--master", "test-master-1" };
rc = cli.run(args);
assertThat(rc, is(0));
ms = cli.getGatewayServices().getService("MasterService");
String master = String.copyValueOf(ms.getMasterSecret());
assertThat(master, is("test-master-1"));
assertThat(outContent.toString(), containsString("Master secret has been persisted to disk."));
outContent.reset();
rc = cli.run(args);
assertThat(rc, is(0));
assertThat(outContent.toString(), containsString("Master secret is already present on disk."));
outContent.reset();
args = new String[] { "create-master", "--master", "test-master-2", "--force" };
rc = cli.run(args);
assertThat(rc, is(0));
ms = cli.getGatewayServices().getService("MasterService");
master = String.copyValueOf(ms.getMasterSecret());
assertThat(master, is("test-master-2"));
assertThat(outContent.toString(), containsString("Master secret has been persisted to disk."));
}
use of org.apache.knox.gateway.config.impl.GatewayConfigImpl in project knox by apache.
the class KnoxCLITest method testExportCert.
@Test
public void testExportCert() throws Exception {
GatewayConfigImpl config = new GatewayConfigImpl();
FileUtils.deleteQuietly(new File(config.getGatewaySecurityDir()));
createTestMaster();
outContent.reset();
KnoxCLI cli = new KnoxCLI();
cli.setConf(config);
String[] gwCreateArgs = { "create-cert", "--hostname", "hostname1", "--master", "master" };
int rc = 0;
rc = cli.run(gwCreateArgs);
assertEquals(0, rc);
assertTrue(outContent.toString(), outContent.toString().contains("gateway-identity has been successfully " + "created."));
outContent.reset();
String[] gwCreateArgs2 = { "export-cert", "--type", "PEM" };
rc = 0;
rc = cli.run(gwCreateArgs2);
assertEquals(0, rc);
assertTrue(outContent.toString(), outContent.toString().contains("Certificate gateway-identity has been successfully exported to"));
assertTrue(outContent.toString(), outContent.toString().contains("gateway-identity.pem"));
outContent.reset();
String[] gwCreateArgs2_5 = { "export-cert" };
rc = 0;
rc = cli.run(gwCreateArgs2_5);
assertEquals(0, rc);
assertTrue(outContent.toString(), outContent.toString().contains("Certificate gateway-identity has been successfully exported to"));
assertTrue(outContent.toString(), outContent.toString().contains("gateway-identity.pem"));
outContent.reset();
String[] gwCreateArgs3 = { "export-cert", "--type", "JKS" };
rc = 0;
rc = cli.run(gwCreateArgs3);
assertEquals(0, rc);
assertTrue(outContent.toString(), outContent.toString().contains("Certificate gateway-identity has been successfully exported to"));
assertTrue(outContent.toString(), outContent.toString().contains("gateway-client-trust.jks"));
outContent.reset();
String[] gwCreateArgs4 = { "export-cert", "--type", "invalid" };
rc = 0;
rc = cli.run(gwCreateArgs4);
assertEquals(0, rc);
assertTrue(outContent.toString(), outContent.toString().contains("Invalid type for export file provided."));
}
use of org.apache.knox.gateway.config.impl.GatewayConfigImpl in project knox by apache.
the class KnoxCLITest method testCreateMasterGenerate.
@Test
public void testCreateMasterGenerate() throws Exception {
String[] args = { "create-master", "--generate" };
int rc = 0;
GatewayConfigImpl config = new GatewayConfigImpl();
File masterFile = new File(config.getGatewaySecurityDir(), "master");
// Need to delete the master file so that the change isn't ignored.
if (masterFile.exists()) {
assertThat("Failed to delete existing master file.", masterFile.delete(), is(true));
}
outContent.reset();
KnoxCLI cli = new KnoxCLI();
cli.setConf(config);
rc = cli.run(args);
assertThat(rc, is(0));
MasterService ms = cli.getGatewayServices().getService("MasterService");
String master = String.copyValueOf(ms.getMasterSecret());
assertThat(master.length(), is(36));
assertThat(master.indexOf('-'), is(8));
assertThat(master.indexOf('-', 9), is(13));
assertThat(master.indexOf('-', 14), is(18));
assertThat(master.indexOf('-', 19), is(23));
assertThat(UUID.fromString(master), notNullValue());
assertThat(outContent.toString(), containsString("Master secret has been persisted to disk."));
// Need to delete the master file so that the change isn't ignored.
if (masterFile.exists()) {
assertThat("Failed to delete existing master file.", masterFile.delete(), is(true));
}
outContent.reset();
cli = new KnoxCLI();
rc = cli.run(args);
ms = cli.getGatewayServices().getService("MasterService");
String master2 = String.copyValueOf(ms.getMasterSecret());
assertThat(master2.length(), is(36));
assertThat(UUID.fromString(master2), notNullValue());
assertThat(master2, not(is(master)));
assertThat(rc, is(0));
assertThat(outContent.toString(), containsString("Master secret has been persisted to disk."));
}
Aggregations