martinzink commented on a change in pull request #978:
URL: https://github.com/apache/nifi-minifi-cpp/pull/978#discussion_r564498125



##########
File path: 
extensions/standard-processors/tests/integration/TLSClientSocketSupportedProtocolsTest.cpp
##########
@@ -0,0 +1,221 @@
+/**
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#include <signal.h>
+#include <sys/stat.h>
+#include <chrono>
+#include <thread>
+#undef NDEBUG
+#include <cassert>
+#include <utility>
+#include <memory>
+#include <string>
+#include "properties/Configure.h"
+#include "io/tls/TLSSocket.h"
+#include "io/tls/TLSServerSocket.h"
+
+class SimpleSSLTestServer  {
+ public:
+  SimpleSSLTestServer(const SSL_METHOD* method, std::string port, std::string 
path)
+      : port_(port) {
+    ctx_ = SSL_CTX_new(method);
+    configure_context(path);
+  }
+
+  ~SimpleSSLTestServer() {
+      SSL_shutdown(ssl_);
+      SSL_free(ssl_);
+      SSL_CTX_free(ctx_);
+  }
+
+  void waitForConnection() {
+    isRunning_ = true;
+    sock_ = create_socket(std::stoi(port_));
+    server_read_thread_ = std::thread([this]() -> void {
+      while (isRunning_) {
+        struct sockaddr_in addr;
+        uint len = sizeof(addr);
+
+        int client = accept(sock_, (struct sockaddr*)&addr, &len);
+        ssl_ = SSL_new(ctx_);
+        SSL_set_fd(ssl_, client);
+        successful = (SSL_accept(ssl_) == 1);
+      }
+    });
+  }
+
+  bool isRunning_;
+  std::thread server_read_thread_;
+  int sock_;
+  bool successful;
+
+ private:
+  SSL_CTX *ctx_;
+  SSL* ssl_;
+  std::string port_;
+  uint16_t listeners_;
+
+  void configure_context(std::string path) {
+      SSL_CTX_set_ecdh_auto(ctx_, 1);
+      /* Set the key and cert */
+      assert(SSL_CTX_use_certificate_file(ctx_, (path + "cn.crt.pem").c_str(), 
SSL_FILETYPE_PEM) > 0);
+      assert(SSL_CTX_use_PrivateKey_file(ctx_, (path + "cn.ckey.pem").c_str(), 
SSL_FILETYPE_PEM) > 0);
+  }
+
+  int create_socket(int port) {
+    int s;
+    struct sockaddr_in addr;
+
+    addr.sin_family = AF_INET;
+    addr.sin_port = htons(port);
+    addr.sin_addr.s_addr = htonl(INADDR_ANY);
+
+    s = socket(AF_INET, SOCK_STREAM, 0);
+    if (s < 0) {
+      perror("Unable to create socket");

Review comment:
       moved them inside asserts instead, because they are not expected to fail 
but any further testing is impossible without these succeeding




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


Reply via email to