Skip to content

Commit

Permalink
update ssl test
Browse files Browse the repository at this point in the history
  • Loading branch information
Nicole00 committed Nov 4, 2021
1 parent 0bae30b commit 2df8fa3
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 94 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -555,9 +555,6 @@ public void testSelfSignedSsl() {
Session sslSession = null;
NebulaPool sslPool = new NebulaPool();
try {
Runtime runtime = Runtime.getRuntime();
runtime.exec("docker-compose -f src/test/resources/docker-compose"
+ "-selfsigned.yaml up -d");

NebulaPoolConfig nebulaSslPoolConfig = new NebulaPoolConfig();
nebulaSslPoolConfig.setMaxConnSize(100);
Expand All @@ -566,8 +563,7 @@ public void testSelfSignedSsl() {
"src/test/resources/ssl/selfsigned.pem",
"src/test/resources/ssl/selfsigned.key",
"vesoft"));
TimeUnit.SECONDS.sleep(45);
Assert.assertTrue(sslPool.init(Arrays.asList(new HostAddress("127.0.0.1", 8669)),
Assert.assertTrue(sslPool.init(Arrays.asList(new HostAddress("127.0.0.1", 7669)),
nebulaSslPoolConfig));
sslSession = sslPool.getSession("root", "nebula", true);

Expand All @@ -577,9 +573,6 @@ public void testSelfSignedSsl() {
.getJSONObject(0).getJSONArray("row").toJSONString();
String exp = "[1]";
Assert.assertEquals(rowData, exp);

runtime.exec("docker-compose -f src/test/resources/docker-compose"
+ "-selfsigned.yaml down").waitFor(60, TimeUnit.SECONDS);
} catch (Exception e) {
e.printStackTrace();
assert false;
Expand All @@ -596,18 +589,13 @@ public void testCASignedSsl() {
Session sslSession = null;
NebulaPool sslPool = new NebulaPool();
try {
Runtime runtime = Runtime.getRuntime();
runtime.exec("docker-compose -f src/test/resources/docker-compose"
+ "-casigned.yaml up -d");

NebulaPoolConfig nebulaSslPoolConfig = new NebulaPoolConfig();
nebulaSslPoolConfig.setMaxConnSize(100);
nebulaSslPoolConfig.setEnableSsl(true);
nebulaSslPoolConfig.setSslParam(new CASignedSSLParam(
"src/test/resources/ssl/casigned.pem",
"src/test/resources/ssl/casigned.crt",
"src/test/resources/ssl/casigned.key"));
TimeUnit.SECONDS.sleep(45);
Assert.assertTrue(sslPool.init(Arrays.asList(new HostAddress("127.0.0.1", 8669)),
nebulaSslPoolConfig));
sslSession = sslPool.getSession("root", "nebula", true);
Expand All @@ -619,8 +607,6 @@ public void testCASignedSsl() {
String exp = "[1]";
Assert.assertEquals(rowData, exp);

runtime.exec("docker-compose -f src/test/resources/docker-compose"
+ "-casigned.yaml down").waitFor(60, TimeUnit.SECONDS);
} catch (Exception e) {
e.printStackTrace();
assert false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,24 @@ public static String createSpace() {
return exec;
}

public static String createSpaceCA() {
String exec = "CREATE SPACE IF NOT EXISTS testMetaCA(partition_num=10, "
+ "vid_type=fixed_string(8));"
+ "USE testMetaCA;"
+ "CREATE TAG IF NOT EXISTS person(name string, age int);"
+ "CREATE EDGE IF NOT EXISTS friend(likeness double);";
return exec;
}

public static String createSpaceSelf() {
String exec = "CREATE SPACE IF NOT EXISTS testMetaSelf(partition_num=10, "
+ "vid_type=fixed_string(8));"
+ "USE testMetaSelf;"
+ "CREATE TAG IF NOT EXISTS person(name string, age int);"
+ "CREATE EDGE IF NOT EXISTS friend(likeness double);";
return exec;
}

public static void createMultiVersionTagAndEdge() {
NebulaPoolConfig nebulaPoolConfig = new NebulaPoolConfig();
nebulaPoolConfig.setMaxConnSize(100);
Expand Down Expand Up @@ -117,7 +135,7 @@ public static void createSpaceWithCASSL() {
pool.init(addresses, nebulaPoolConfig);
session = pool.getSession("root", "nebula", true);

ResultSet resp = session.execute(createSpace());
ResultSet resp = session.execute(createSpaceCA());
if (!resp.isSucceeded()) {
LOGGER.error("create space failed, {}", resp.getErrorMessage());
assert (false);
Expand All @@ -143,13 +161,13 @@ public static void createSpaceWithSelfSSL() {
"src/test/resources/ssl/selfsigned.pem",
"src/test/resources/ssl/selfsigned.key",
"vesoft"));
List<HostAddress> addresses = Arrays.asList(new HostAddress("127.0.0.1", 8669));
List<HostAddress> addresses = Arrays.asList(new HostAddress("127.0.0.1", 7669));
NebulaPool pool = new NebulaPool();
Session session = null;
try {
pool.init(addresses, nebulaPoolConfig);
session = pool.getSession("root", "nebula", true);
ResultSet resp = session.execute(createSpace());
ResultSet resp = session.execute(createSpaceSelf());
if (!resp.isSucceeded()) {
LOGGER.error("create space failed, {}", resp.getErrorMessage());
assert (false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,12 +142,8 @@ public void testListOnlineHosts() {
}

public void testCASignedSSLMetaClient() {
String startCmd = "docker-compose -f src/test/resources/docker-compose-casigned.yaml up -d";
String stopCmd = "docker-compose -f src/test/resources/docker-compose-casigned.yaml down";
Runtime runtime = Runtime.getRuntime();
MetaClient metaClient = null;
try {
runtime.exec(startCmd).waitFor(60, TimeUnit.SECONDS);

// mock data with CA ssl
MockNebulaGraph.createSpaceWithCASSL();
Expand All @@ -161,33 +157,22 @@ public void testCASignedSSLMetaClient() {
3000, 1, 1, true, sslParam);
metaClient.connect();

List<TagItem> tags = metaClient.getTags("testMeta");
List<TagItem> tags = metaClient.getTags("testMetaCA");
Assert.assertTrue(tags.size() >= 1);
assert (metaClient.getTag("testMeta", "person") != null);
assert (metaClient.getTag("testMetaCA", "person") != null);
} catch (Exception e) {
LOGGER.error("test CA signed ssl meta client failed, ", e);
assert (false);
} finally {
if (metaClient != null) {
metaClient.close();
}
try {
runtime.exec(stopCmd).waitFor(60, TimeUnit.SECONDS);
} catch (InterruptedException | IOException e) {
e.printStackTrace();
}
}
}

public void testSelfSignedSSLMetaClient() {
String startCmd =
"docker-compose -f src/test/resources/docker-compose-selfsigned.yaml up -d";
String stopCmd = "docker-compose -f src/test/resources/docker-compose-selfsigned.yaml down";

MetaClient metaClient = null;
Runtime runtime = Runtime.getRuntime();
try {
runtime.exec(startCmd).waitFor(60, TimeUnit.SECONDS);

// mock data with Self ssl
MockNebulaGraph.createSpaceWithSelfSSL();
Expand All @@ -196,25 +181,20 @@ public void testSelfSignedSSLMetaClient() {
"src/test/resources/ssl/selfsigned.pem",
"src/test/resources/ssl/selfsigned.key",
"vesoft");
metaClient = new MetaClient(Arrays.asList(new HostAddress(address, 8559)),
metaClient = new MetaClient(Arrays.asList(new HostAddress(address, 7559)),
3000, 1, 1, true, sslParam);
metaClient.connect();

List<TagItem> tags = metaClient.getTags("testMeta");
List<TagItem> tags = metaClient.getTags("testMetaSelf");
Assert.assertTrue(tags.size() >= 1);
assert (metaClient.getTag("testMeta", "person") != null);
assert (metaClient.getTag("testMetaSelf", "person") != null);
} catch (Exception e) {
LOGGER.error("test Self signed ssl meta client failed, ", e);
assert (false);
} finally {
if (metaClient != null) {
metaClient.close();
}
try {
runtime.exec(stopCmd).waitFor(60, TimeUnit.SECONDS);
} catch (Exception e) {
e.printStackTrace();
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import com.vesoft.nebula.client.graph.data.SSLParam;
import com.vesoft.nebula.client.graph.data.SelfSignedSSLParam;
import com.vesoft.nebula.client.graph.exception.ClientServerIncompatibleException;
import com.vesoft.nebula.client.util.ProcessUtil;
import com.vesoft.nebula.meta.EdgeItem;
import com.vesoft.nebula.meta.SpaceItem;
import com.vesoft.nebula.meta.TagItem;
Expand Down Expand Up @@ -120,12 +121,8 @@ public void testMultiVersionSchema() throws ClientServerIncompatibleException {


public void testCASignedSSLMetaManager() {
Runtime runtime = Runtime.getRuntime();
MetaManager metaManager = null;
try {
runtime.exec(
"docker-compose -f src/test/resources/docker-compose-casigned.yaml up -d")
.waitFor(45, TimeUnit.SECONDS);

// mock data with CA ssl
MockNebulaGraph.createSpaceWithCASSL();
Expand All @@ -139,9 +136,9 @@ public void testCASignedSSLMetaManager() {
8559)), 3000, 1, 1, true, sslParam);


assert (metaManager.getSpaceId("testMeta") > 0);
SpaceItem spaceItem = metaManager.getSpace("testMeta");
assert Objects.equals("testMeta", new String(spaceItem.properties.getSpace_name()));
assert (metaManager.getSpaceId("testMetaCA") > 0);
SpaceItem spaceItem = metaManager.getSpace("testMetaCA");
assert Objects.equals("testMetaCA", new String(spaceItem.properties.getSpace_name()));
Assert.assertEquals(8, spaceItem.properties.getVid_type().getType_length());
Assert.assertEquals(10, spaceItem.properties.getPartition_num());

Expand All @@ -158,23 +155,12 @@ public void testCASignedSSLMetaManager() {
if (metaManager != null) {
metaManager.close();
}
try {
runtime.exec("docker-compose -f src/test/resources/docker-compose"
+ "-casigned.yaml down").waitFor(60, TimeUnit.SECONDS);
} catch (InterruptedException | IOException e) {
e.printStackTrace();
}
}
}

public void testSelfSignedSSLMetaClient() {
String startCmd =
"docker-compose -f src/test/resources/docker-compose-selfsigned.yaml up -d";
String stopCmd = "docker-compose -f src/test/resources/docker-compose-selfsigned.yaml down";
Runtime runtime = Runtime.getRuntime();
MetaManager metaManager = null;
try {
runtime.exec(startCmd).waitFor(45, TimeUnit.SECONDS);

// mock data with Self ssl
MockNebulaGraph.createSpaceWithSelfSSL();
Expand All @@ -183,12 +169,12 @@ public void testSelfSignedSSLMetaClient() {
"src/test/resources/ssl/selfsigned.pem",
"src/test/resources/ssl/selfsigned.key",
"vesoft");
metaManager = new MetaManager(Arrays.asList(new HostAddress("127.0.0.1", 8559)),
metaManager = new MetaManager(Arrays.asList(new HostAddress("127.0.0.1", 7559)),
3000, 1, 1, true, sslParam);

assert (metaManager.getSpaceId("testMeta") > 0);
SpaceItem spaceItem = metaManager.getSpace("testMeta");
assert Objects.equals("testMeta", new String(spaceItem.properties.getSpace_name()));
assert (metaManager.getSpaceId("testMetaSelf") > 0);
SpaceItem spaceItem = metaManager.getSpace("testMetaSelf");
assert Objects.equals("testMetaSelf", new String(spaceItem.properties.getSpace_name()));
Assert.assertEquals(8, spaceItem.properties.getVid_type().getType_length());
Assert.assertEquals(10, spaceItem.properties.getPartition_num());

Expand All @@ -206,11 +192,6 @@ public void testSelfSignedSSLMetaClient() {
if (metaManager != null) {
metaManager.close();
}
try {
runtime.exec(stopCmd).waitFor(60, TimeUnit.SECONDS);
} catch (InterruptedException | IOException e) {
e.printStackTrace();
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,24 @@ public static String createSpace() {
return exec;
}

public static String createSpaceCa() {
String exec = "CREATE SPACE IF NOT EXISTS testStorageCA(partition_num=10,"
+ "vid_type=fixed_string(8));"
+ "USE testStorageCA;"
+ "CREATE TAG IF NOT EXISTS person(name string, age int);"
+ "CREATE EDGE IF NOT EXISTS friend(likeness double);";
return exec;
}

public static String createSpaceSelf() {
String exec = "CREATE SPACE IF NOT EXISTS testStorageSelf(partition_num=10,"
+ "vid_type=fixed_string(8));"
+ "USE testStorageSelf;"
+ "CREATE TAG IF NOT EXISTS person(name string, age int);"
+ "CREATE EDGE IF NOT EXISTS friend(likeness double);";
return exec;
}

public static String insertData() {
String exec = "INSERT VERTEX person(name, age) VALUES "
+ "\"1\":(\"Tom\", 18), "
Expand Down Expand Up @@ -100,7 +118,7 @@ public static void mockCASslData() {
pool.init(addresses, nebulaPoolConfig);
session = pool.getSession("root", "nebula", true);

ResultSet resp = session.execute(createSpace());
ResultSet resp = session.execute(createSpaceCa());
try {
Thread.sleep(6000);
} catch (InterruptedException e) {
Expand Down Expand Up @@ -140,7 +158,7 @@ public static void mockSelfSslData() {
pool.init(addresses, nebulaPoolConfig);
session = pool.getSession("root", "nebula", true);

ResultSet resp = session.execute(createSpace());
ResultSet resp = session.execute(createSpaceSelf());

try {
Thread.sleep(5000);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import com.vesoft.nebula.client.storage.scan.ScanEdgeResultIterator;
import com.vesoft.nebula.client.storage.scan.ScanVertexResult;
import com.vesoft.nebula.client.storage.scan.ScanVertexResultIterator;
import com.vesoft.nebula.client.util.ProcessUtil;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.util.Arrays;
Expand Down Expand Up @@ -368,14 +369,10 @@ public void testScanEdgeWithAllCols() {

@Test
public void testCASignedSSL() {
String startCmd = "docker-compose -f src/test/resources/docker-compose-casigned.yaml up -d";
String stopCmd = "docker-compose -f src/test/resources/docker-compose-casigned.yaml down";
// start nebula service with ssl enable
List<HostAddress> address = null;
StorageClient sslClient = null;
Runtime runtime = Runtime.getRuntime();
try {
runtime.exec(startCmd).waitFor(60, TimeUnit.SECONDS);
address = Arrays.asList(new HostAddress(ip, 8559));

// mock graph data
Expand All @@ -389,7 +386,7 @@ public void testCASignedSSL() {
sslClient.connect();

ScanVertexResultIterator resultIterator = sslClient.scanVertex(
"testStorage",
"testStorageCA",
"person");
while (resultIterator.hasNext()) {
ScanVertexResult result = null;
Expand Down Expand Up @@ -443,26 +440,17 @@ public void testCASignedSSL() {
}
}
}
// stop nebula service
try {
runtime.exec(stopCmd).waitFor(60, TimeUnit.SECONDS);
} catch (InterruptedException | IOException e) {
e.printStackTrace();
}
}


@Test
public void testSelfSignedSSL() {
String startCmd =
"docker-compose -f src/test/resources/docker-compose-selfsigned.yaml up -d";
String stopCmd = "docker-compose -f src/test/resources/docker-compose-selfsigned.yaml down";
// start nebula service with ssl enable
List<HostAddress> address = null;
StorageClient sslClient = null;
Runtime runtime = Runtime.getRuntime();
try {
runtime.exec(startCmd).waitFor(60, TimeUnit.SECONDS);

address = Arrays.asList(new HostAddress(ip, 8559));

// mock graph data
Expand All @@ -476,7 +464,7 @@ public void testSelfSignedSSL() {
sslClient.connect();

ScanVertexResultIterator resultIterator = sslClient.scanVertex(
"testStorage",
"testStorageSelf",
"person");
assertIterator(resultIterator);
} catch (Exception e) {
Expand All @@ -489,12 +477,6 @@ public void testSelfSignedSSL() {
} catch (Exception e) {
e.printStackTrace();
}
try {
// stop nebula service
runtime.exec(stopCmd).waitFor(60, TimeUnit.SECONDS);
} catch (Exception e) {
e.printStackTrace();
}
}
}
}
Expand Down

0 comments on commit 2df8fa3

Please sign in to comment.