forked from ondra/colnod-connector
Lot of little changes mostly because of testing
This commit is contained in:
parent
3f57758510
commit
62343bb0b8
@ -2,5 +2,5 @@
|
||||
|
||||
|
||||
TOKEN=$(curl -k --user "spaceti:E7FEA07DBC82FB9BA34B2E453E2EFE89F0583E7187543507EF11E84726071FE428445372F2E46B455EB0C79747C51E362F403CE39473A2A8C2DFA0CE5C9826C0" -d '{"password":"E7FEA07DBC82FB9BA34B2E453E2EFE89F0583E7187543507EF11E84726071FE428445372F2E46B455EB0C79747C51E362F403CE39473A2A8C2DFA0CE5C9826C0","username":"spaceti"}' -H "Content-Type: application/json" https://192.168.1.3:8443/AaaManager/authSession 2>/dev/null | python -c 'import json,sys;obj=json.load(sys.stdin);print obj["id"]')
|
||||
|
||||
echo TOKEN
|
||||
curl -kv -u "$TOKEN:" -X POST https://192.168.1.3:8443/OpenManager/getTokenSubject
|
||||
|
||||
@ -4,18 +4,16 @@ RequestManager::RequestManager()
|
||||
{
|
||||
manager = new QNetworkAccessManager();
|
||||
token = "";
|
||||
loginStatus = false;
|
||||
loginStatus = false; //should be false, true for testing request header
|
||||
|
||||
|
||||
|
||||
QFile configFile(QDir::current().filePath("config.json"));
|
||||
|
||||
if (!configFile.open(QIODevice::ReadOnly)) {
|
||||
qCritical() << "Couldn't open config file config.json" << QDir::current().filePath("config.json");
|
||||
QCoreApplication::exit(-1);
|
||||
return;
|
||||
}
|
||||
|
||||
this->config = QJsonDocument::fromJson(configFile.readAll());
|
||||
QObject::connect(manager, &QNetworkAccessManager::sslErrors, this, &RequestManager::onSSLError);
|
||||
}
|
||||
@ -35,6 +33,7 @@ void RequestManager::login(QString host, QString username, QString password)
|
||||
request.setRawHeader("Authorization", authHeader.toLocal8Bit());
|
||||
request.setHeader(QNetworkRequest::ContentTypeHeader, "application/json; charset=UTF-8");
|
||||
QJsonDocument jsonDocument;
|
||||
|
||||
jsonDocument.setObject(reqBody);
|
||||
QNetworkReply* reply = manager->post(request, jsonDocument.toJson());
|
||||
QObject::connect(reply, &QNetworkReply::finished, [=]() {
|
||||
@ -61,10 +60,24 @@ void RequestManager::getRequest(QString endpoint)
|
||||
QObject::connect(this, &RequestManager::successLogin, &loop, &QEventLoop::quit);
|
||||
loop.exec();
|
||||
}
|
||||
|
||||
//
|
||||
host = config.object()["host"].toString();
|
||||
//
|
||||
|
||||
QNetworkRequest request;
|
||||
request.setUrl(host + endpoint);
|
||||
qDebug() << authHeader;
|
||||
request.setRawHeader("Authorization", authHeader.toLocal8Bit());
|
||||
//request.setRawHeader("User-Agent", "curl/7.65.3");
|
||||
QNetworkReply* reply = manager->post(request, QByteArray());
|
||||
|
||||
//
|
||||
//QEventLoop loop;
|
||||
//QObject::connect(reply, &QNetworkReply::finished, &loop, &QEventLoop::quit);
|
||||
//loop.exec();
|
||||
//
|
||||
|
||||
QObject::connect(reply, &QNetworkReply::finished, [=]() {
|
||||
if (reply->error())
|
||||
{
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
#include <utility>
|
||||
|
||||
#include "Subject.h"
|
||||
#include "subject.h"
|
||||
|
||||
#include <QJsonArray>
|
||||
|
||||
|
||||
@ -26,6 +26,7 @@ void UnitTest::getSubjects()
|
||||
QVERIFY(spy.isValid());
|
||||
QCOMPARE(spy.count(), 1);
|
||||
QString json = testAccess->getResponse();
|
||||
qDebug() << json;
|
||||
QJsonDocument doc = QJsonDocument::fromJson(json.toUtf8());
|
||||
QVERIFY(doc.isObject());
|
||||
QVERIFY2(doc.object().value("items").isArray(), "No parameter 'id' in response");
|
||||
|
||||
5
test/unitTests/config.json
Normal file
5
test/unitTests/config.json
Normal file
@ -0,0 +1,5 @@
|
||||
{
|
||||
"host": "https://192.168.1.3:8443",
|
||||
"username": "spaceti",
|
||||
"password": "spaceti1"
|
||||
}
|
||||
@ -22,7 +22,7 @@ private slots:
|
||||
void connectToDB();
|
||||
|
||||
private:
|
||||
// QString host = "https://localhost:8080"; //colnod server (ssh -L 8080:192.168.254.11:8443 penta-master)
|
||||
//QString host = "http://localhost:8080"; //colnod server (ssh -L 8080:192.168.254.11:8443 penta-master)
|
||||
QString host = "https://192.168.1.3:8443"; //local testing server
|
||||
QString password = "spaceti1";
|
||||
QString email = "spaceti";
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user