Skip to content

Commit

Permalink
[#1078] Remove test to not verify SSL certificates.
Browse files Browse the repository at this point in the history
Reason: Not possible to test uniformly for all protocols.
Kafka connections do not check certificate during connection test.
AMQP connections time out when tested against an HTTP server.

Signed-off-by: Yufei Cai <yufei.cai@bosch.io>
  • Loading branch information
yufei-cai committed Jun 9, 2021
1 parent 8e5754c commit fa59422
Showing 1 changed file with 0 additions and 70 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,11 @@
package org.eclipse.ditto.connectivity.service.messaging;

import static java.util.Collections.singletonList;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.mock;

import java.time.Duration;
import java.util.Collections;

import javax.net.ssl.SSLContext;

import org.eclipse.ditto.base.model.exceptions.DittoRuntimeException;
import org.eclipse.ditto.base.model.headers.DittoHeaders;
import org.eclipse.ditto.connectivity.model.ClientCertificateCredentials;
import org.eclipse.ditto.connectivity.model.Connection;
import org.eclipse.ditto.connectivity.model.ConnectionBuilder;
import org.eclipse.ditto.connectivity.model.ConnectionId;
Expand All @@ -37,26 +31,17 @@
import org.eclipse.ditto.connectivity.model.signals.commands.modify.EnableConnectionLogs;
import org.eclipse.ditto.connectivity.model.signals.commands.modify.ResetConnectionLogs;
import org.eclipse.ditto.connectivity.model.signals.commands.modify.ResetConnectionMetrics;
import org.eclipse.ditto.connectivity.model.signals.commands.modify.TestConnection;
import org.eclipse.ditto.connectivity.model.signals.commands.query.RetrieveConnectionLogs;
import org.eclipse.ditto.connectivity.model.signals.commands.query.RetrieveConnectionLogsResponse;
import org.eclipse.ditto.connectivity.model.signals.commands.query.RetrieveConnectionMetrics;
import org.eclipse.ditto.connectivity.model.signals.commands.query.RetrieveConnectionMetricsResponse;
import org.eclipse.ditto.connectivity.model.signals.commands.query.RetrieveConnectionStatus;
import org.eclipse.ditto.connectivity.service.messaging.internal.ssl.SSLContextCreator;
import org.eclipse.ditto.connectivity.service.messaging.monitoring.logs.ConnectionLogger;
import org.junit.Test;

import akka.actor.ActorRef;
import akka.actor.ActorSystem;
import akka.actor.Props;
import akka.actor.Status;
import akka.http.javadsl.Http;
import akka.http.javadsl.ServerBinding;
import akka.http.javadsl.model.Uri;
import akka.stream.javadsl.Flow;
import akka.stream.javadsl.Sink;
import akka.stream.javadsl.Source;
import akka.testkit.javadsl.TestKit;

/**
Expand Down Expand Up @@ -150,61 +135,6 @@ public void resetConnectionLogs() {
}};
}

@Test
public void testTLSConnectionWithoutCertificateCheck() {
// GIVEN: server has a self-signed certificate (bind port number is random; connection port number is ignored)
final Connection serverConnection = getHttpConnectionBuilderToLocalBinding(true, 443).build();
final ClientCertificateCredentials credentials = ClientCertificateCredentials.newBuilder()
.clientKey(TestConstants.Certificates.CLIENT_SELF_SIGNED_KEY)
.clientCertificate(TestConstants.Certificates.CLIENT_SELF_SIGNED_CRT)
.build();
final ConnectionLogger connectionLogger = mock(ConnectionLogger.class);
final SSLContext sslContext =
SSLContextCreator.fromConnection(serverConnection, DittoHeaders.empty(), connectionLogger)
.clientCertificate(credentials);
// TODO the above code is not used??? what does this test do?
// check with YC

final ActorSystem actorSystem = getActorSystem();
final ServerBinding binding = Http.get(actorSystem)
.newServerAt("127.0.0.1", 0)
// TODO YC: use sslContext for server binding
.bindFlow(Flow.fromSinkAndSource(Sink.ignore(), Source.empty()))
.toCompletableFuture()
.join();

new TestKit(actorSystem) {{
// WHEN: the connection is tested against a client actor that really tries to connect to the local port
final Connection secureConnection = getConnection(true);
final Connection insecureConnection = secureConnection.toBuilder()
.uri(Uri.create(secureConnection.getUri()).port(binding.localAddress().getPort()).toString())
.validateCertificate(false)
.failoverEnabled(false)
.build();
final ActorRef underTest = watch(actorSystem.actorOf(
DefaultClientActorPropsFactory.getInstance()
.getActorPropsForType(insecureConnection, getRef(), getRef(), actorSystem)
));
underTest.tell(TestConnection.of(insecureConnection, DittoHeaders.empty()), getRef());

// THEN: the test should succeed, or it should fail with a different reason than SSL validation
final Object response = expectMsgClass(Duration.ofSeconds(5), Object.class);
if (response instanceof Status.Failure) {
final DittoRuntimeException error =
(DittoRuntimeException) getEventualCause(((Status.Failure) response).cause());
assertThat(error.getMessage())
.describedAs("error message")
.doesNotContain("unable to find valid certification path");
assertThat(error.getDescription().orElse(""))
.describedAs("error description")
.doesNotContain("unable to find valid certification path");
} else {
assertThat(response).isInstanceOf(Status.Success.class);
}
expectTerminated(underTest);
}};
}

protected ConnectionId getConnectionId() {
return getConnection(false).getId();
}
Expand Down

0 comments on commit fa59422

Please sign in to comment.