Commit 16466c26feebabce911fd801f48b2da35a48fab4
1 parent
24da657f
Exists in
master
Adicionado teste para criação/edição e exclusão de registro
Showing
5 changed files
with
50 additions
and
22 deletions
Show diff stats
cacic-teste/testcacic.cpp
@@ -132,7 +132,9 @@ void CTestCacic::testSslConnection() | @@ -132,7 +132,9 @@ void CTestCacic::testSslConnection() | ||
132 | { | 132 | { |
133 | bool ok; | 133 | bool ok; |
134 | QJsonObject json = OCacicComm.comm("", &ok, QJsonObject(), true); | 134 | QJsonObject json = OCacicComm.comm("", &ok, QJsonObject(), true); |
135 | - QJsonValue jsonvalue = json["codestatus"]; | 135 | + QJsonValue jsonvalue = (!json["codestatus"].isNull()) ? |
136 | + json["codestatus"] : | ||
137 | + QJsonValue::fromVariant(-1); | ||
136 | // qDebug() << jsonvalue.toDouble(); | 138 | // qDebug() << jsonvalue.toDouble(); |
137 | QVERIFY(jsonvalue.toDouble() == 200 || jsonvalue.toDouble() == 302); | 139 | QVERIFY(jsonvalue.toDouble() == 200 || jsonvalue.toDouble() == 302); |
138 | } | 140 | } |
@@ -140,8 +142,9 @@ void CTestCacic::testSslConnection() | @@ -140,8 +142,9 @@ void CTestCacic::testSslConnection() | ||
140 | void CTestCacic::testEnCrypt(){ | 142 | void CTestCacic::testEnCrypt(){ |
141 | std::string IV = "0123456789123456"; //iv nunca se repete para a mesma senha. | 143 | std::string IV = "0123456789123456"; //iv nunca se repete para a mesma senha. |
142 | std::string input = "aqui vai a url que sera encriptada"; | 144 | std::string input = "aqui vai a url que sera encriptada"; |
145 | + OCacic.setChaveCrypt("testecript123456"); | ||
143 | this->cripTeste = OCacic.enCrypt(input, IV); | 146 | this->cripTeste = OCacic.enCrypt(input, IV); |
144 | - QVERIFY(!this->cripTeste.isNull()); | 147 | + QVERIFY(!this->cripTeste.isEmpty() && !this->cripTeste.isNull()); |
145 | } | 148 | } |
146 | 149 | ||
147 | void CTestCacic::testDeCrypt(){ | 150 | void CTestCacic::testDeCrypt(){ |
@@ -225,6 +228,25 @@ void CTestCacic::testReadConfig() | @@ -225,6 +228,25 @@ void CTestCacic::testReadConfig() | ||
225 | QVERIFY(false); | 228 | QVERIFY(false); |
226 | } | 229 | } |
227 | 230 | ||
231 | +void CTestCacic::testSetRegistry() | ||
232 | +{ | ||
233 | + QVariantMap valueMap; | ||
234 | + valueMap["teste1"] = QString("Teste 1"); | ||
235 | + valueMap["teste2"] = QString("Teste2"); | ||
236 | + OCacic.setValueToRegistry("Lightbase", "Teste", valueMap); | ||
237 | + QSettings confirmaTeste("Lightbase", "Teste"); | ||
238 | + QVERIFY(confirmaTeste.value("teste1") == QVariant("Teste 1")); | ||
239 | +} | ||
240 | + | ||
241 | +void CTestCacic::testRemoveRegistry() | ||
242 | +{ | ||
243 | + OCacic.removeRegistry("Lightbase", "Teste"); | ||
244 | + QSettings confirmaTeste("Lightbase", "Teste"); | ||
245 | + QVERIFY(confirmaTeste.allKeys().isEmpty()); | ||
246 | + confirmaTeste.clear(); | ||
247 | + confirmaTeste.sync(); | ||
248 | +} | ||
249 | + | ||
228 | void CTestCacic::cleanupTestCase() | 250 | void CTestCacic::cleanupTestCase() |
229 | { | 251 | { |
230 | OCacic.deleteFile("configRequest.json"); | 252 | OCacic.deleteFile("configRequest.json"); |
cacic-teste/testcacic.h
@@ -62,6 +62,8 @@ private slots: | @@ -62,6 +62,8 @@ private slots: | ||
62 | void testJsonFromFile(); | 62 | void testJsonFromFile(); |
63 | void testStartService(); | 63 | void testStartService(); |
64 | void testReadConfig(); | 64 | void testReadConfig(); |
65 | + void testSetRegistry(); | ||
66 | + void testRemoveRegistry(); | ||
65 | void cleanupTestCase(); | 67 | void cleanupTestCase(); |
66 | }; | 68 | }; |
67 | 69 |
install-cacic/install-cacic.pro.user
1 | <?xml version="1.0" encoding="UTF-8"?> | 1 | <?xml version="1.0" encoding="UTF-8"?> |
2 | <!DOCTYPE QtCreatorProject> | 2 | <!DOCTYPE QtCreatorProject> |
3 | -<!-- Written by QtCreator 3.1.2, 2014-08-15T17:35:14. --> | 3 | +<!-- Written by QtCreator 3.1.2, 2014-08-15T20:38:37. --> |
4 | <qtcreator> | 4 | <qtcreator> |
5 | <data> | 5 | <data> |
6 | <variable>ProjectExplorer.Project.ActiveTarget</variable> | 6 | <variable>ProjectExplorer.Project.ActiveTarget</variable> |
@@ -221,7 +221,7 @@ | @@ -221,7 +221,7 @@ | ||
221 | <value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">install-cacic</value> | 221 | <value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">install-cacic</value> |
222 | <value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName"></value> | 222 | <value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName"></value> |
223 | <value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">Qt4ProjectManager.Qt4RunConfiguration:E:/LightBase/cacic-agente-project/cacic-agente/install-cacic/install-cacic.pro</value> | 223 | <value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">Qt4ProjectManager.Qt4RunConfiguration:E:/LightBase/cacic-agente-project/cacic-agente/install-cacic/install-cacic.pro</value> |
224 | - <value type="QString" key="Qt4ProjectManager.Qt4RunConfiguration.CommandLineArguments">-host=10.1.0.137/cacic/web/app_dev.php -user=cacic -password=cacic123</value> | 224 | + <value type="QString" key="Qt4ProjectManager.Qt4RunConfiguration.CommandLineArguments">-uninstall</value> |
225 | <value type="QString" key="Qt4ProjectManager.Qt4RunConfiguration.ProFile">install-cacic.pro</value> | 225 | <value type="QString" key="Qt4ProjectManager.Qt4RunConfiguration.ProFile">install-cacic.pro</value> |
226 | <value type="bool" key="Qt4ProjectManager.Qt4RunConfiguration.UseDyldImageSuffix">false</value> | 226 | <value type="bool" key="Qt4ProjectManager.Qt4RunConfiguration.UseDyldImageSuffix">false</value> |
227 | <value type="bool" key="Qt4ProjectManager.Qt4RunConfiguration.UseTerminal">true</value> | 227 | <value type="bool" key="Qt4ProjectManager.Qt4RunConfiguration.UseTerminal">true</value> |
install-cacic/installcacic.cpp
@@ -43,7 +43,7 @@ void InstallCacic::run(QStringList argv, int argc) { | @@ -43,7 +43,7 @@ void InstallCacic::run(QStringList argv, int argc) { | ||
43 | } else if ((param.contains("default")) && (param["default"] == "uninstall")){ | 43 | } else if ((param.contains("default")) && (param["default"] == "uninstall")){ |
44 | oCacic.deleteFolder("c:/cacic"); | 44 | oCacic.deleteFolder("c:/cacic"); |
45 | oCacic.removeRegistry("Lightbase", "Cacic"); | 45 | oCacic.removeRegistry("Lightbase", "Cacic"); |
46 | - | 46 | + std::cout << "Cacic desinstalado com sucesso.\n"; |
47 | } else { | 47 | } else { |
48 | std::cout << "\nInstalador do Agente Cacic.\n\n" | 48 | std::cout << "\nInstalador do Agente Cacic.\n\n" |
49 | << "Parametros incorretos. (<obrigatorios> [opcional])\n\n" | 49 | << "Parametros incorretos. (<obrigatorios> [opcional])\n\n" |
src/ccacic.cpp
@@ -159,16 +159,18 @@ QJsonObject CCacic::getJsonFromFile(QString filepath) | @@ -159,16 +159,18 @@ QJsonObject CCacic::getJsonFromFile(QString filepath) | ||
159 | * */ | 159 | * */ |
160 | QString CCacic::enCrypt(std::string str_in, std::string iv) { | 160 | QString CCacic::enCrypt(std::string str_in, std::string iv) { |
161 | std::string str_out; | 161 | std::string str_out; |
162 | - std::string key = this->getChaveCrypt().toStdString(); | ||
163 | - CryptoPP::CFB_Mode<CryptoPP::AES>::Encryption encryption((byte*)key.c_str(), key.length(), (byte*)iv.c_str()); | ||
164 | - CryptoPP::StringSource encryptor(str_in, true, | ||
165 | - new CryptoPP::StreamTransformationFilter(encryption, | ||
166 | - new CryptoPP::Base64Encoder(new CryptoPP::StringSink(str_out), | ||
167 | - false // do not append a newline | 162 | + if ((!this->getChaveCrypt().isNull())){ |
163 | + std::string key = (!this->getChaveCrypt().isNull()) ? this->getChaveCrypt().toStdString() : ""; | ||
164 | + CryptoPP::CFB_Mode<CryptoPP::AES>::Encryption encryption((byte*)key.c_str(), key.length(), (byte*)iv.c_str()); | ||
165 | + CryptoPP::StringSource encryptor(str_in, true, | ||
166 | + new CryptoPP::StreamTransformationFilter(encryption, | ||
167 | + new CryptoPP::Base64Encoder(new CryptoPP::StringSink(str_out), | ||
168 | + false // do not append a newline | ||
169 | + ) | ||
168 | ) | 170 | ) |
169 | - ) | ||
170 | - ); | ||
171 | - //qDebug(QString::fromStdString(str_out).toLocal8Bit()); | 171 | + ); |
172 | + } | ||
173 | +// qDebug() << QString::fromStdString(str_out); | ||
172 | return QString::fromStdString(str_out); | 174 | return QString::fromStdString(str_out); |
173 | } | 175 | } |
174 | 176 | ||
@@ -184,15 +186,17 @@ QString CCacic::enCrypt(std::string str_in, std::string iv) { | @@ -184,15 +186,17 @@ QString CCacic::enCrypt(std::string str_in, std::string iv) { | ||
184 | // * */ | 186 | // * */ |
185 | QString CCacic::deCrypt(std::string str_in, std::string iv) { | 187 | QString CCacic::deCrypt(std::string str_in, std::string iv) { |
186 | std::string str_out; | 188 | std::string str_out; |
187 | - std::string key = this->getChaveCrypt().toStdString(); | ||
188 | - CryptoPP::CFB_Mode<CryptoPP::AES>::Decryption decryption((byte*)key.c_str(), key.length(), (byte*)iv.c_str()); | 189 | + if ((!this->getChaveCrypt().isNull())){ |
190 | + std::string key = this->getChaveCrypt().toStdString(); | ||
191 | + CryptoPP::CFB_Mode<CryptoPP::AES>::Decryption decryption((byte*)key.c_str(), key.length(), (byte*)iv.c_str()); | ||
189 | 192 | ||
190 | - CryptoPP::StringSource decryptor(str_in, true, | ||
191 | - new CryptoPP::Base64Decoder( | ||
192 | - new CryptoPP::StreamTransformationFilter(decryption, | ||
193 | - new CryptoPP::StringSink(str_out)) | ||
194 | - ) | ||
195 | - ); | 193 | + CryptoPP::StringSource decryptor(str_in, true, |
194 | + new CryptoPP::Base64Decoder( | ||
195 | + new CryptoPP::StreamTransformationFilter(decryption, | ||
196 | + new CryptoPP::StringSink(str_out)) | ||
197 | + ) | ||
198 | + ); | ||
199 | + } | ||
196 | return QString::fromStdString(str_out); | 200 | return QString::fromStdString(str_out); |
197 | } | 201 | } |
198 | 202 |