From 16466c26feebabce911fd801f48b2da35a48fab4 Mon Sep 17 00:00:00 2001 From: ericmenezesn@gmail.com Date: Fri, 15 Aug 2014 20:46:04 -0300 Subject: [PATCH] Adicionado teste para criação/edição e exclusão de registro --- cacic-teste/testcacic.cpp | 26 ++++++++++++++++++++++++-- cacic-teste/testcacic.h | 2 ++ install-cacic/install-cacic.pro.user | 4 ++-- install-cacic/installcacic.cpp | 2 +- src/ccacic.cpp | 38 +++++++++++++++++++++----------------- 5 files changed, 50 insertions(+), 22 deletions(-) diff --git a/cacic-teste/testcacic.cpp b/cacic-teste/testcacic.cpp index 788ae7f..190d343 100644 --- a/cacic-teste/testcacic.cpp +++ b/cacic-teste/testcacic.cpp @@ -132,7 +132,9 @@ void CTestCacic::testSslConnection() { bool ok; QJsonObject json = OCacicComm.comm("", &ok, QJsonObject(), true); - QJsonValue jsonvalue = json["codestatus"]; + QJsonValue jsonvalue = (!json["codestatus"].isNull()) ? + json["codestatus"] : + QJsonValue::fromVariant(-1); // qDebug() << jsonvalue.toDouble(); QVERIFY(jsonvalue.toDouble() == 200 || jsonvalue.toDouble() == 302); } @@ -140,8 +142,9 @@ void CTestCacic::testSslConnection() void CTestCacic::testEnCrypt(){ std::string IV = "0123456789123456"; //iv nunca se repete para a mesma senha. std::string input = "aqui vai a url que sera encriptada"; + OCacic.setChaveCrypt("testecript123456"); this->cripTeste = OCacic.enCrypt(input, IV); - QVERIFY(!this->cripTeste.isNull()); + QVERIFY(!this->cripTeste.isEmpty() && !this->cripTeste.isNull()); } void CTestCacic::testDeCrypt(){ @@ -225,6 +228,25 @@ void CTestCacic::testReadConfig() QVERIFY(false); } +void CTestCacic::testSetRegistry() +{ + QVariantMap valueMap; + valueMap["teste1"] = QString("Teste 1"); + valueMap["teste2"] = QString("Teste2"); + OCacic.setValueToRegistry("Lightbase", "Teste", valueMap); + QSettings confirmaTeste("Lightbase", "Teste"); + QVERIFY(confirmaTeste.value("teste1") == QVariant("Teste 1")); +} + +void CTestCacic::testRemoveRegistry() +{ + OCacic.removeRegistry("Lightbase", "Teste"); + QSettings confirmaTeste("Lightbase", "Teste"); + QVERIFY(confirmaTeste.allKeys().isEmpty()); + confirmaTeste.clear(); + confirmaTeste.sync(); +} + void CTestCacic::cleanupTestCase() { OCacic.deleteFile("configRequest.json"); diff --git a/cacic-teste/testcacic.h b/cacic-teste/testcacic.h index 7b9048e..8d95c00 100644 --- a/cacic-teste/testcacic.h +++ b/cacic-teste/testcacic.h @@ -62,6 +62,8 @@ private slots: void testJsonFromFile(); void testStartService(); void testReadConfig(); + void testSetRegistry(); + void testRemoveRegistry(); void cleanupTestCase(); }; diff --git a/install-cacic/install-cacic.pro.user b/install-cacic/install-cacic.pro.user index 5789ea6..a826b08 100644 --- a/install-cacic/install-cacic.pro.user +++ b/install-cacic/install-cacic.pro.user @@ -1,6 +1,6 @@ - + ProjectExplorer.Project.ActiveTarget @@ -221,7 +221,7 @@ install-cacic Qt4ProjectManager.Qt4RunConfiguration:E:/LightBase/cacic-agente-project/cacic-agente/install-cacic/install-cacic.pro - -host=10.1.0.137/cacic/web/app_dev.php -user=cacic -password=cacic123 + -uninstall install-cacic.pro false true diff --git a/install-cacic/installcacic.cpp b/install-cacic/installcacic.cpp index 03aee70..00539de 100644 --- a/install-cacic/installcacic.cpp +++ b/install-cacic/installcacic.cpp @@ -43,7 +43,7 @@ void InstallCacic::run(QStringList argv, int argc) { } else if ((param.contains("default")) && (param["default"] == "uninstall")){ oCacic.deleteFolder("c:/cacic"); oCacic.removeRegistry("Lightbase", "Cacic"); - + std::cout << "Cacic desinstalado com sucesso.\n"; } else { std::cout << "\nInstalador do Agente Cacic.\n\n" << "Parametros incorretos. ( [opcional])\n\n" diff --git a/src/ccacic.cpp b/src/ccacic.cpp index 5475949..069c150 100644 --- a/src/ccacic.cpp +++ b/src/ccacic.cpp @@ -159,16 +159,18 @@ QJsonObject CCacic::getJsonFromFile(QString filepath) * */ QString CCacic::enCrypt(std::string str_in, std::string iv) { std::string str_out; - std::string key = this->getChaveCrypt().toStdString(); - CryptoPP::CFB_Mode::Encryption encryption((byte*)key.c_str(), key.length(), (byte*)iv.c_str()); - CryptoPP::StringSource encryptor(str_in, true, - new CryptoPP::StreamTransformationFilter(encryption, - new CryptoPP::Base64Encoder(new CryptoPP::StringSink(str_out), - false // do not append a newline + if ((!this->getChaveCrypt().isNull())){ + std::string key = (!this->getChaveCrypt().isNull()) ? this->getChaveCrypt().toStdString() : ""; + CryptoPP::CFB_Mode::Encryption encryption((byte*)key.c_str(), key.length(), (byte*)iv.c_str()); + CryptoPP::StringSource encryptor(str_in, true, + new CryptoPP::StreamTransformationFilter(encryption, + new CryptoPP::Base64Encoder(new CryptoPP::StringSink(str_out), + false // do not append a newline + ) ) - ) - ); - //qDebug(QString::fromStdString(str_out).toLocal8Bit()); + ); + } +// qDebug() << QString::fromStdString(str_out); return QString::fromStdString(str_out); } @@ -184,15 +186,17 @@ QString CCacic::enCrypt(std::string str_in, std::string iv) { // * */ QString CCacic::deCrypt(std::string str_in, std::string iv) { std::string str_out; - std::string key = this->getChaveCrypt().toStdString(); - CryptoPP::CFB_Mode::Decryption decryption((byte*)key.c_str(), key.length(), (byte*)iv.c_str()); + if ((!this->getChaveCrypt().isNull())){ + std::string key = this->getChaveCrypt().toStdString(); + CryptoPP::CFB_Mode::Decryption decryption((byte*)key.c_str(), key.length(), (byte*)iv.c_str()); - CryptoPP::StringSource decryptor(str_in, true, - new CryptoPP::Base64Decoder( - new CryptoPP::StreamTransformationFilter(decryption, - new CryptoPP::StringSink(str_out)) - ) - ); + CryptoPP::StringSource decryptor(str_in, true, + new CryptoPP::Base64Decoder( + new CryptoPP::StreamTransformationFilter(decryption, + new CryptoPP::StringSink(str_out)) + ) + ); + } return QString::fromStdString(str_out); } -- libgit2 0.21.2