fix typoes, uncaught exceptions, started unit tests for ProcessManager
This commit is contained in:
parent
7d90f1c87f
commit
9754f23fd8
4 changed files with 178 additions and 98 deletions
|
|
@ -49,7 +49,7 @@ import org.mockito.ArgumentMatchers;
|
|||
public class JobServerAuthenticationTest {
|
||||
|
||||
private final String projectRoot = "";
|
||||
|
||||
|
||||
// Authorized client key/cert/ca
|
||||
private final String clientCa = projectRoot + "resources/client/ca.crt";
|
||||
private final String clientKey = projectRoot + "resources/client/private.pem";
|
||||
|
|
@ -73,65 +73,65 @@ public class JobServerAuthenticationTest {
|
|||
// was setUp able to use SSL Certs
|
||||
private Boolean serverSslInitialized = true;
|
||||
private Boolean clientSslInitialized = true;
|
||||
|
||||
|
||||
/*
|
||||
* test constructor
|
||||
* generates both clients and the server
|
||||
*/
|
||||
public JobServerAuthenticationTest() throws Exception {
|
||||
|
||||
try {
|
||||
// generate SSL contexts
|
||||
SslContextBuilder serverContextBuilder = SslContextBuilder.forServer(new File(serverCert),
|
||||
new File(serverKey));
|
||||
serverContextBuilder.trustManager(new File(clientCa));
|
||||
serverContextBuilder.clientAuth(ClientAuth.REQUIRE);
|
||||
|
||||
this.server = new JobServServer(GrpcSslContexts.configure(serverContextBuilder).build(), 8448);
|
||||
this.serverSslInitialized = true;
|
||||
|
||||
} catch (SSLException e) {
|
||||
this.serverSslInitialized = false;
|
||||
System.err.println(e.getMessage());
|
||||
|
||||
} catch (IOException e) {
|
||||
this.serverSslInitialized = false;
|
||||
System.err.println(e.getMessage());
|
||||
}
|
||||
try {
|
||||
// generate SSL contexts
|
||||
SslContextBuilder serverContextBuilder = SslContextBuilder.forServer(new File(serverCert),
|
||||
new File(serverKey));
|
||||
serverContextBuilder.trustManager(new File(clientCa));
|
||||
serverContextBuilder.clientAuth(ClientAuth.REQUIRE);
|
||||
|
||||
// generate ssl for clients
|
||||
this.server = new JobServServer(GrpcSslContexts.configure(serverContextBuilder).build(), 8448);
|
||||
this.serverSslInitialized = true;
|
||||
|
||||
} catch (SSLException e) {
|
||||
this.serverSslInitialized = false;
|
||||
System.err.println(e.getMessage());
|
||||
|
||||
} catch (IOException e) {
|
||||
this.serverSslInitialized = false;
|
||||
System.err.println(e.getMessage());
|
||||
}
|
||||
|
||||
// generate ssl for clients
|
||||
if (this.serverSslInitialized) {
|
||||
try {
|
||||
SslContextBuilder goodClientBuilder = GrpcSslContexts.forClient();
|
||||
goodClientBuilder.trustManager(new File(serverCa));
|
||||
goodClientBuilder.keyManager(new File(clientCert), new File(clientKey));
|
||||
try {
|
||||
SslContextBuilder goodClientBuilder = GrpcSslContexts.forClient();
|
||||
goodClientBuilder.trustManager(new File(serverCa));
|
||||
goodClientBuilder.keyManager(new File(clientCert), new File(clientKey));
|
||||
|
||||
SslContextBuilder badClientBuilder = GrpcSslContexts.forClient();
|
||||
badClientBuilder.trustManager(new File(serverCa));
|
||||
badClientBuilder.keyManager(new File(badCert), new File(badKey));
|
||||
|
||||
ManagedChannel goodChannel = NettyChannelBuilder.forAddress("localhost", 8448)
|
||||
.sslContext(goodClientBuilder.build())
|
||||
.directExecutor()
|
||||
.build();
|
||||
|
||||
SslContextBuilder badClientBuilder = GrpcSslContexts.forClient();
|
||||
badClientBuilder.trustManager(new File(serverCa));
|
||||
badClientBuilder.keyManager(new File(badCert), new File(badKey));
|
||||
|
||||
ManagedChannel goodChannel = NettyChannelBuilder.forAddress("localhost", 8448)
|
||||
.sslContext(goodClientBuilder.build())
|
||||
.directExecutor()
|
||||
.build();
|
||||
|
||||
ManagedChannel badChannel = NettyChannelBuilder.forAddress("localhost", 8448)
|
||||
.sslContext(badClientBuilder.build())
|
||||
.directExecutor()
|
||||
.build();
|
||||
|
||||
goodClient = new JobServClient(goodChannel);
|
||||
badClient = new JobServClient(badChannel);
|
||||
this.clientSslInitialized = true;
|
||||
|
||||
} catch (SSLException e) {
|
||||
this.clientSslInitialized = false;
|
||||
System.err.println(e.getMessage());
|
||||
}
|
||||
ManagedChannel badChannel = NettyChannelBuilder.forAddress("localhost", 8448)
|
||||
.sslContext(badClientBuilder.build())
|
||||
.directExecutor()
|
||||
.build();
|
||||
|
||||
goodClient = new JobServClient(goodChannel);
|
||||
badClient = new JobServClient(badChannel);
|
||||
this.clientSslInitialized = true;
|
||||
|
||||
} catch (SSLException e) {
|
||||
this.clientSslInitialized = false;
|
||||
System.err.println(e.getMessage());
|
||||
}
|
||||
|
||||
} else {
|
||||
this.clientSslInitialized = false;
|
||||
}
|
||||
} else {
|
||||
this.clientSslInitialized = false;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
@ -141,14 +141,14 @@ public class JobServerAuthenticationTest {
|
|||
*/
|
||||
@Test
|
||||
public void certificateAuthenticationTest() {
|
||||
assertEquals(true, serverSslInitialized);
|
||||
assertEquals(true, clientSslInitialized);
|
||||
assertEquals(true, serverSslInitialized);
|
||||
assertEquals(true, clientSslInitialized);
|
||||
|
||||
int result = badClient.sendNewJobMessage("test command");
|
||||
assertEquals(-2, result);
|
||||
int result = badClient.sendNewJobMessage("test command");
|
||||
assertEquals(-2, result);
|
||||
|
||||
result = goodClient.sendNewJobMessage("test command");
|
||||
Boolean assertCondition = result == -2;
|
||||
assertEquals(assertCondition, false);
|
||||
result = goodClient.sendNewJobMessage("test command");
|
||||
Boolean assertCondition = result == -2;
|
||||
assertEquals(assertCondition, false);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
49
src/test/java/JobServ/ProcessManagerTest.java
Normal file
49
src/test/java/JobServ/ProcessManagerTest.java
Normal file
|
|
@ -0,0 +1,49 @@
|
|||
/*
|
||||
* ProcessManagerTest
|
||||
*
|
||||
* v1.0
|
||||
*
|
||||
* May 22, 2019
|
||||
*/
|
||||
|
||||
package JobServ;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.JUnit4;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
|
||||
/*
|
||||
* ProcessManagerTest
|
||||
* Class that performs positive and negative unit tests
|
||||
* of every public method in ProcessManager. This not
|
||||
* only unit tests ProcessManager but also integration
|
||||
* tests it with ProcessController.
|
||||
*/
|
||||
public class ProcessManagerTest {
|
||||
ProcessManager manager;
|
||||
|
||||
/*
|
||||
* ProcessManagerTest constructor
|
||||
* initializes the process manager
|
||||
*/
|
||||
public ProcessManagerTest() {
|
||||
manager = new ProcessManager();
|
||||
}
|
||||
|
||||
/*
|
||||
* addProcessTest()
|
||||
* positive unit test for newProcess
|
||||
*/
|
||||
@Test
|
||||
public void addProcessesTest() {
|
||||
int pid1 = manager.newProcess("ping google");
|
||||
assertEquals(0, pid1);
|
||||
|
||||
int pid2 = manager.newProcess("ping google");
|
||||
assertEquals(1, pid2);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue