Skip to content

Commit 5a85b45

Browse files
committed
Fix format issues with the test
1 parent 6137643 commit 5a85b45

File tree

1 file changed

+24
-27
lines changed

1 file changed

+24
-27
lines changed

tests/TlsNegotiationTest.cc

Lines changed: 24 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,16 @@
1717
* under the License.
1818
*/
1919
#include <gtest/gtest.h>
20-
#include <pulsar/Client.h>
20+
#include <openssl/ssl.h>
2121
#include <pulsar/Authentication.h>
22-
#include "lib/AsioDefines.h"
22+
#include <pulsar/Client.h>
23+
24+
#include <atomic>
2325
#include <future>
2426
#include <thread>
25-
#include <atomic>
27+
28+
#include "lib/AsioDefines.h"
2629
#include "lib/LogUtils.h"
27-
#include <openssl/ssl.h>
2830

2931
#ifdef USE_ASIO
3032
#include <asio.hpp>
@@ -47,23 +49,19 @@ static const std::string clientPrivateKeyPath = TEST_CONF_DIR "/client-key.pem";
4749
using namespace pulsar;
4850

4951
class MockTlsServer {
50-
public:
52+
public:
5153
MockTlsServer()
5254
: acceptor_(io_context_, ASIO::ip::tcp::endpoint(ASIO::ip::tcp::v4(), 0)),
5355
ctx_(ASIO::ssl::context::sslv23) {
54-
55-
ctx_.set_options(ASIO::ssl::context::default_workarounds |
56-
ASIO::ssl::context::no_sslv2 |
56+
ctx_.set_options(ASIO::ssl::context::default_workarounds | ASIO::ssl::context::no_sslv2 |
5757
ASIO::ssl::context::no_sslv3);
58-
58+
5959
ctx_.use_certificate_chain_file(clientPublicKeyPath);
6060
ctx_.use_private_key_file(clientPrivateKeyPath, ASIO::ssl::context::pem);
6161
ctx_.set_verify_mode(ASIO::ssl::context::verify_none);
6262
}
6363

64-
int getPort() const {
65-
return acceptor_.local_endpoint().port();
66-
}
64+
int getPort() const { return acceptor_.local_endpoint().port(); }
6765

6866
void setTls12Only() {
6967
SSL_CTX* ssl_ctx = ctx_.native_handle();
@@ -88,12 +86,12 @@ class MockTlsServer {
8886
bool acceptAndHandshake() {
8987
auto socket = std::make_shared<ASIO::ip::tcp::socket>(io_context_);
9088
acceptor_.accept(*socket);
91-
89+
9290
ASIO::ssl::stream<ASIO::ip::tcp::socket&> ssl_stream(*socket, ctx_);
93-
91+
9492
ASIO_ERROR error;
9593
ssl_stream.handshake(ASIO::ssl::stream_base::server, error);
96-
94+
9795
if (error) {
9896
LOG_ERROR("Handshake failed: " << error.message());
9997
return false;
@@ -102,15 +100,15 @@ class MockTlsServer {
102100
return true;
103101
}
104102

105-
private:
103+
private:
106104
ASIO::io_context io_context_;
107105
ASIO::ip::tcp::acceptor acceptor_;
108106
ASIO::ssl::context ctx_;
109107
};
110108

111109
TEST(TlsNegotiationTest, testTls12) {
112110
#if !defined(TLS1_2_VERSION)
113-
return; // Skip if TLS 1.2 is not available
111+
return; // Skip if TLS 1.2 is not available
114112
#endif
115113

116114
MockTlsServer server;
@@ -128,28 +126,28 @@ TEST(TlsNegotiationTest, testTls12) {
128126
std::string serviceUrl = "pulsar+ssl://localhost:" + std::to_string(port);
129127
ClientConfiguration config;
130128
config.setTlsTrustCertsFilePath(caPath);
131-
config.setTlsAllowInsecureConnection(true); // Self-signed certs match
129+
config.setTlsAllowInsecureConnection(true); // Self-signed certs match
132130
config.setValidateHostName(false);
133131

134132
Client client(serviceUrl, config);
135-
136-
// Trigger connection by creating a producer.
133+
134+
// Trigger connection by creating a producer.
137135
// It will fail to create producer because mock server doesn't speak Pulsar,
138136
// but we only care about the handshake.
139137
Producer producer;
140-
client.createProducerAsync("topic", [](Result, Producer){});
138+
client.createProducerAsync("topic", [](Result, Producer) {});
141139

142140
// Wait for handshake
143141
ASSERT_TRUE(handshakeFuture.get());
144-
142+
145143
serverThread.join();
146144
client.close();
147145
}
148146

149147
TEST(TlsNegotiationTest, testTls13) {
150148
#if !defined(TLS1_3_VERSION)
151149
LOG_INFO("Skipping TLS 1.3 test because OpenSSL does not support it");
152-
return;
150+
return;
153151
#endif
154152

155153
MockTlsServer server;
@@ -171,12 +169,11 @@ TEST(TlsNegotiationTest, testTls13) {
171169
config.setValidateHostName(false);
172170

173171
Client client(serviceUrl, config);
174-
175-
client.createProducerAsync("topic", [](Result, Producer){});
172+
173+
client.createProducerAsync("topic", [](Result, Producer) {});
176174

177175
ASSERT_TRUE(handshakeFuture.get());
178-
176+
179177
serverThread.join();
180178
client.close();
181179
}
182-

0 commit comments

Comments
 (0)