Commit 912b7852e9e0855714f7b4634b07254a3018c4a3
1 parent
e9c282ff
Exists in
master
Pequenas alterações
Showing
4 changed files
with
40 additions
and
6 deletions
Show diff stats
cacic-teste/cacic-teste.pro
... | ... | @@ -20,13 +20,16 @@ win32 { |
20 | 20 | SOURCES += \ |
21 | 21 | testcacic.cpp \ |
22 | 22 | ../src/ccacic.cpp \ |
23 | - ../src/cacic_computer.cpp | |
23 | + ../src/cacic_computer.cpp \ | |
24 | + ../src/sslclient.cpp | |
24 | 25 | |
25 | 26 | |
26 | 27 | HEADERS += \ |
27 | 28 | testcacic.h \ |
28 | 29 | ../src/ccacic.h \ |
29 | 30 | ../src/cacic_computer.h \ |
30 | - ../src/cacic_comm.h | |
31 | + ../src/cacic_comm.h \ | |
32 | + ../src/sslclient.h | |
31 | 33 | |
32 | -INCLUDEPATH += ../src | |
34 | +INCLUDEPATH += ../src \ | |
35 | + ../src/crypto++/include/ | ... | ... |
cacic-teste/testcacic.cpp
... | ... | @@ -108,6 +108,17 @@ void CTestCacic::testLogin(){ |
108 | 108 | QVERIFY(!session_str.isNull()); |
109 | 109 | } |
110 | 110 | |
111 | +void CTestCacic::testSslConnection() | |
112 | +{ | |
113 | + QVariantMap login; | |
114 | + login["user"] = "cacic"; | |
115 | + login["password"] = "cacic"; | |
116 | + QJsonObject json = OCacicComm.comm("/ws/get/test", QJsonObject::fromVariantMap(login), true); | |
117 | + QJsonValue jsonvalue = json["key"]; | |
118 | +// qDebug() << jsonvalue.toVariant().toString(); | |
119 | + QVERIFY(!jsonvalue.isNull()); | |
120 | +} | |
121 | + | |
111 | 122 | void CTestCacic::cleanupTestCase() |
112 | 123 | { |
113 | 124 | ... | ... |
cacic-teste/testcacic.h
src/cacic_comm.h
... | ... | @@ -12,6 +12,7 @@ |
12 | 12 | #include <QUrlQuery> |
13 | 13 | #include <QJsonObject> |
14 | 14 | #include <QJsonDocument> |
15 | +#include <sslclient.h> | |
15 | 16 | |
16 | 17 | |
17 | 18 | class CacicComm { |
... | ... | @@ -49,14 +50,18 @@ public: |
49 | 50 | params.addQueryItem("te_so",so); |
50 | 51 | params.addQueryItem("te_versao_cacic",cacicVersion); |
51 | 52 | params.addQueryItem("te_versao_gercols",gercolsVersion); |
53 | + | |
54 | + | |
52 | 55 | } |
53 | 56 | |
54 | - QJsonObject comm(QString route, const QJsonObject &json = QJsonObject()) | |
57 | + QJsonObject comm(QString route, const QJsonObject &json = QJsonObject(), bool isSsl = false) | |
55 | 58 | { |
56 | 59 | QByteArray data; |
57 | 60 | QUrl url = urlGerente + route; |
58 | 61 | QNetworkRequest req(url); |
59 | 62 | req.setHeader(QNetworkRequest::LocationHeader, "Cacic Agente"); |
63 | + if (isSsl) | |
64 | + req.setSslConfiguration(QSslConfiguration::defaultConfiguration()); | |
60 | 65 | if (json.empty()) |
61 | 66 | { |
62 | 67 | //se não for passado QJson, será mandado os valores do get/test antigo. (Será retirado depois) |
... | ... | @@ -79,11 +84,12 @@ public: |
79 | 84 | |
80 | 85 | QNetworkReply *reply = mgr.post(req, data); |
81 | 86 | eventLoop.exec(); // sai do looping chamando o "finished()". |
82 | - | |
83 | 87 | QVariantMap replyValue; |
88 | + //grava o código de retorno | |
84 | 89 | replyValue["codestatus"] = reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toString(); |
85 | 90 | |
86 | 91 | if (reply->error() == QNetworkReply::NoError) { |
92 | + //se não houver erro, grava o retorno; | |
87 | 93 | QString strReply = (QString)reply->readAll(); |
88 | 94 | replyValue["reply"] = strReply; |
89 | 95 | //parse json |
... | ... | @@ -98,6 +104,7 @@ public: |
98 | 104 | |
99 | 105 | |
100 | 106 | } |
107 | + //retorna o json; | |
101 | 108 | QJsonObject jsonObj = QJsonObject::fromVariantMap(replyValue); |
102 | 109 | return jsonObj; |
103 | 110 | } |
... | ... | @@ -117,6 +124,7 @@ public: |
117 | 124 | // a requisição HTTP |
118 | 125 | QUrl url = urlGerente; |
119 | 126 | QNetworkRequest req( url ); |
127 | + req.setHeader(QNetworkRequest::LocationHeader, "Cacic Agente"); | |
120 | 128 | QNetworkReply *reply = mgr.get(req); |
121 | 129 | eventLoop.exec(); // sai do looping chamando o "finished()". |
122 | 130 | |
... | ... | @@ -145,8 +153,19 @@ public: |
145 | 153 | |
146 | 154 | } |
147 | 155 | |
156 | + bool sslConnection(QString host, int port) { | |
157 | + //cria dados para conexão | |
158 | + SslClient client; | |
159 | + client.setHost(host); | |
160 | + client.setPort(port); | |
161 | + | |
162 | + return client.start(); | |
163 | + //cria conexão e retorna json | |
164 | + | |
165 | + } | |
166 | + | |
148 | 167 | signals: |
149 | 168 | void finished(QNetworkReply* reply); |
150 | -}; | |
151 | 169 | |
170 | +}; | |
152 | 171 | #endif // CACIC_COMM_H | ... | ... |