use of software.amazon.awssdk.crt.CrtRuntimeException in project aws-crt-java by awslabs.
the class ServerListenerTest method testBindErrorPropagates.
@Test
public void testBindErrorPropagates() throws ExecutionException, InterruptedException, TimeoutException {
SocketOptions socketOptions = new SocketOptions();
socketOptions.connectTimeoutMs = 3000;
socketOptions.domain = SocketOptions.SocketDomain.IPv4;
socketOptions.type = SocketOptions.SocketType.STREAM;
EventLoopGroup elGroup = new EventLoopGroup(1);
ServerBootstrap bootstrap = new ServerBootstrap(elGroup);
ServerListener listener1 = new ServerListener("127.0.0.1", (short) 8039, socketOptions, null, bootstrap, new ServerListenerHandler() {
public ServerConnectionHandler onNewConnection(ServerConnection serverConnection, int errorCode) {
return null;
}
public void onConnectionShutdown(ServerConnection serverConnection, int errorCode) {
}
});
assertNotNull(listener1);
boolean exceptionThrown = false;
try {
ServerListener listener2 = new ServerListener("127.0.0.1", (short) 8039, socketOptions, null, bootstrap, new ServerListenerHandler() {
public ServerConnectionHandler onNewConnection(ServerConnection serverConnection, int errorCode) {
return null;
}
public void onConnectionShutdown(ServerConnection serverConnection, int errorCode) {
}
});
} catch (CrtRuntimeException ex) {
assertTrue(ex.getMessage().contains("AWS_IO_SOCKET_ADDRESS_IN_USE(1054), Socket address already in use."));
exceptionThrown = true;
}
assertTrue(exceptionThrown);
listener1.close();
listener1.getShutdownCompleteFuture().get(1, TimeUnit.SECONDS);
bootstrap.close();
elGroup.close();
elGroup.getShutdownCompleteFuture().get(1, TimeUnit.SECONDS);
socketOptions.close();
}
use of software.amazon.awssdk.crt.CrtRuntimeException in project aws-crt-java by awslabs.
the class Pkcs11LibTest method testPkcs11LibInitializeFinalizeBehavior.
@Test
public void testPkcs11LibInitializeFinalizeBehavior() {
assumeEnvironmentSetUpForPkcs11Tests();
// check that the behavior enum is passed to native.
// we expect OMIT behavior to cause failure here because no one else
// has called C_Initialize.
CrtRuntimeException crtException = null;
try (Pkcs11Lib pkcs11Lib = new Pkcs11Lib(TEST_PKCS11_LIB, Pkcs11Lib.InitializeFinalizeBehavior.OMIT)) {
} catch (Exception ex) {
crtException = (CrtRuntimeException) ex;
}
assertNotNull(crtException);
assertTrue(crtException.errorName.contains("CKR_CRYPTOKI_NOT_INITIALIZED"));
}
use of software.amazon.awssdk.crt.CrtRuntimeException in project aws-crt-java by awslabs.
the class ProxyTest method doCredentialsProviderProxyTest.
private void doCredentialsProviderProxyTest(CredentialsProvider provider) {
try {
Credentials credentials = provider.getCredentials().get();
Assert.assertNotNull(credentials);
} catch (Exception e) {
throw new CrtRuntimeException(e.toString());
}
}
use of software.amazon.awssdk.crt.CrtRuntimeException in project aws-crt-java by awslabs.
the class ProxyTest method doHttpConnectionManagerProxyTest.
private void doHttpConnectionManagerProxyTest(HttpClientConnectionManager manager) {
HttpRequest request = new HttpRequest("GET", "/");
CompletableFuture requestCompleteFuture = new CompletableFuture();
manager.acquireConnection().whenComplete((conn, throwable) -> {
if (throwable != null) {
requestCompleteFuture.completeExceptionally(throwable);
}
HttpStream stream = conn.makeRequest(request, new HttpStreamResponseHandler() {
@Override
public void onResponseHeaders(HttpStream stream, int responseStatusCode, int blockType, HttpHeader[] nextHeaders) {
;
}
@Override
public void onResponseComplete(HttpStream stream, int errorCode) {
// When this Request is complete, release the conn back to the pool
manager.releaseConnection(conn);
stream.close();
if (errorCode != CRT.AWS_CRT_SUCCESS) {
requestCompleteFuture.completeExceptionally(new CrtRuntimeException(errorCode));
} else {
requestCompleteFuture.complete(null);
}
}
});
if (stream != null) {
stream.activate();
}
});
requestCompleteFuture.join();
}
use of software.amazon.awssdk.crt.CrtRuntimeException in project aws-crt-java by awslabs.
the class TlsContextOptionsTest method testMtlsPkcs11.
@Test
public void testMtlsPkcs11() {
Assume.assumeTrue(System.getProperty("NETWORK_TESTS_DISABLED") == null);
Pkcs11LibTest.assumeEnvironmentSetUpForPkcs11Tests();
try (Pkcs11Lib pkcs11Lib = new Pkcs11Lib(Pkcs11LibTest.TEST_PKCS11_LIB);
TlsContextPkcs11Options pkcs11Options = new TlsContextPkcs11Options(pkcs11Lib).withUserPin(Pkcs11LibTest.TEST_PKCS11_PIN).withTokenLabel(Pkcs11LibTest.TEST_PKCS11_TOKEN_LABEL).withPrivateKeyObjectLabel(Pkcs11LibTest.TEST_PKCS11_PKEY_LABEL).withCertificateFilePath(Pkcs11LibTest.TEST_PKCS11_CERT_FILE);
TlsContextOptions tlsOptions = TlsContextOptions.createWithMtlsPkcs11(pkcs11Options);
TlsContext tls = new TlsContext(tlsOptions)) {
} catch (CrtRuntimeException ex) {
// This is expected to fail on platforms where we don't yet support mTLS with PKCS#11
assertEquals("AWS_ERROR_UNIMPLEMENTED", ex.errorName);
}
}
Aggregations