瀏覽代碼

Prettify sslclienttest code

Viktor Kopp 5 年之前
父節點
當前提交
bdeda92f2c
共有 2 個文件被更改,包括 7 次插入14 次删除
  1. 2 1
      src/grpc/http2channel.cpp
  2. 5 13
      tests/test_grpc/sslclienttest.cpp

+ 2 - 1
src/grpc/http2channel.cpp

@@ -129,6 +129,7 @@ struct Http2ChannelPrivate {
         QObject::connect(networkReply, &QNetworkReply::sslErrors, [networkReply](const QList<QSslError> &errors) {
            qProtoCritical() << errors;
            // TODO: filter out noncritical SSL handshake errors
+           // FIXME: error due to ssl failure is not transferred to the client: last error will be Operation canceled
            Http2ChannelPrivate::abortNetworkReply(networkReply);
         });
 
@@ -150,7 +151,7 @@ struct Http2ChannelPrivate {
     static QByteArray processReply(QNetworkReply *networkReply, AbstractChannel::StatusCodes &statusCode) {
         //Check if no network error occured
         if (networkReply->error() != QNetworkReply::NoError) {
-            qProtoWarning() << "Network error occured" << networkReply->errorString();
+            qProtoWarning() << networkReply->error() << ":" << networkReply->errorString();
             statusCode = StatusCodeMap.at(networkReply->error());
             return {};
         }

+ 5 - 13
tests/test_grpc/sslclienttest.cpp

@@ -49,29 +49,21 @@ protected:
 
 int ClientTest::m_argc(0);
 QCoreApplication ClientTest::m_app(m_argc, nullptr);
-QUrl ClientTest::m_echoServerAddress("https://localhost:60051", QUrl::StrictMode);
 
 TEST_F(ClientTest, IncorrectSecureCredentialsTest)
 {
     //Prepare ssl configuration
     QSslConfiguration conf = QSslConfiguration::defaultConfiguration();
-
-    //NOTE: CA certificate setup is ommited on purpose
+    conf.setProtocol(QSsl::TlsV1_2);
+    // NOTE: CA certificate is not setup on purpose to induce the ssl handshake error
     //  QFile certFile("cert.pem");
     //  certFile.open(QIODevice::ReadOnly);
     //  QByteArray cert = certFile.readAll();
     //  conf.setCaCertificates({QSslCertificate(cert)});
 
-    conf.setProtocol(QSsl::TlsV1_2);
-    //conf.setAllowedNextProtocols({QSslConfiguration::ALPNProtocolHTTP2});
-
-    std::shared_ptr<qtprotobuf::AbstractChannel> channel(new qtprotobuf::Http2Channel(m_echoServerAddress, qtprotobuf::SslCredentials(conf)));
-
     TestServiceClient testClient;
-    testClient.attachChannel(channel);
-
-    QPointer<SimpleStringMessage> result(new SimpleStringMessage);
-    EXPECT_FALSE(testClient.testMethod(SimpleStringMessage{"Hello beach!"}, result));
+    testClient.attachChannel(std::make_shared<qtprotobuf::Http2Channel>(QUrl("https://localhost:60051", QUrl::StrictMode), qtprotobuf::SslCredentials(conf)));
 
-    delete result;
+    std::unique_ptr<SimpleStringMessage> result = std::make_unique<SimpleStringMessage>();
+    EXPECT_FALSE(testClient.testMethod(SimpleStringMessage{"Hello beach!"}, result.get()));
 }