mirror of
https://gitlab.com/spaceti-app/integrations/acs/colnod-connector.git
synced 2026-07-12 16:50:48 +02:00
Merge branch 'finish-tests' into 'master'
WIP: Finish tests See merge request spaceti-app/integrations/acs/colnod-connector!5
This commit is contained in:
commit
59e0e7ccdb
9
http/curlauth.txt
Normal file
9
http/curlauth.txt
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
POST /AaaManager/authSession HTTP/1.1
|
||||||
|
Host: localhost:8080
|
||||||
|
Authorization: Basic c3BhY2V0aTpFN0ZFQTA3REJDODJGQjlCQTM0QjJFNDUzRTJFRkU4OUYwNTgzRTcxODc1NDM1MDdFRjExRTg0NzI2MDcxRkU0Mjg0NDUzNzJGMkU0NkI0NTVFQjBDNzk3NDdDNTFFMzYyRjQwM0NFMzk0NzNBMkE4QzJERkEwQ0U1Qzk4MjZDMA==
|
||||||
|
User-Agent: curl/7.65.3
|
||||||
|
Accept: */*
|
||||||
|
Content-Type: application/json
|
||||||
|
Content-Length: 164
|
||||||
|
|
||||||
|
{"password":"E7FEA07DBC82FB9BA34B2E453E2EFE89F0583E7187543507EF11E84726071FE428445372F2E46B455EB0C79747C51E362F403CE39473A2A8C2DFA0CE5C9826C0","username":"spaceti"}
|
||||||
6
http/curlsubject.txt
Normal file
6
http/curlsubject.txt
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
POST /SubjectManager/getSubjects HTTP/1.1
|
||||||
|
Host: localhost:8080
|
||||||
|
Authorization: Basic ZmYwMzYwZjYtMzRmZC00ZjAwLTlhNTYtMWZiMzhmNjlhNDIzOg==
|
||||||
|
User-Agent: curl/7.65.3
|
||||||
|
Accept: */*
|
||||||
|
|
||||||
14
http/qtauth.txt
Normal file
14
http/qtauth.txt
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
POST /AaaManager/authSession HTTP/1.1
|
||||||
|
Host: localhost:8080
|
||||||
|
Authorization: Basic c3BhY2V0aTpFN0ZFQTA3REJDODJGQjlCQTM0QjJFNDUzRTJFRkU4OUYwNTgzRTcxODc1NDM1MDdFRjExRTg0NzI2MDcxRkU0Mjg0NDUzNzJGMkU0NkI0NTVFQjBDNzk3NDdDNTFFMzYyRjQwM0NFMzk0NzNBMkE4QzJERkEwQ0U1Qzk4MjZDMA==
|
||||||
|
Content-Type: application/json; charset=UTF-8
|
||||||
|
Content-Length: 178
|
||||||
|
Connection: Keep-Alive
|
||||||
|
Accept-Encoding: gzip, deflate
|
||||||
|
Accept-Language: en-AI,*
|
||||||
|
User-Agent: Mozilla/5.0
|
||||||
|
|
||||||
|
{
|
||||||
|
"password": "E7FEA07DBC82FB9BA34B2E453E2EFE89F0583E7187543507EF11E84726071FE428445372F2E46B455EB0C79747C51E362F403CE39473A2A8C2DFA0CE5C9826C0",
|
||||||
|
"username": "spaceti"
|
||||||
|
}
|
||||||
14
http/qtrequestoutput.txt
Normal file
14
http/qtrequestoutput.txt
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
POST /AaaManager/authSession HTTP/1.1
|
||||||
|
Host: localhost:8080
|
||||||
|
Authorization: Basic c3BhY2V0aTpFN0ZFQTA3REJDODJGQjlCQTM0QjJFNDUzRTJFRkU4OUYwNTgzRTcxODc1NDM1MDdFRjExRTg0NzI2MDcxRkU0Mjg0NDUzNzJGMkU0NkI0NTVFQjBDNzk3NDdDNTFFMzYyRjQwM0NFMzk0NzNBMkE4QzJERkEwQ0U1Qzk4MjZDMA==
|
||||||
|
Content-Type: application/json; charset=UTF-8
|
||||||
|
Content-Length: 178
|
||||||
|
Connection: Keep-Alive
|
||||||
|
Accept-Encoding: gzip, deflate
|
||||||
|
Accept-Language: en-AI,*
|
||||||
|
User-Agent: Mozilla/5.0
|
||||||
|
|
||||||
|
{
|
||||||
|
"password": "E7FEA07DBC82FB9BA34B2E453E2EFE89F0583E7187543507EF11E84726071FE428445372F2E46B455EB0C79747C51E362F403CE39473A2A8C2DFA0CE5C9826C0",
|
||||||
|
"username": "spaceti"
|
||||||
|
}
|
||||||
8
http/qtrequestoutputsubject.txt
Normal file
8
http/qtrequestoutputsubject.txt
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
POST /SubjectManager/getSubjects HTTP/1.1
|
||||||
|
Host: localhost:8080
|
||||||
|
Content-Length: 0
|
||||||
|
Connection: Keep-Alive
|
||||||
|
Accept-Encoding: gzip, deflate
|
||||||
|
Accept-Language: en-AI,*
|
||||||
|
User-Agent: Mozilla/5.0
|
||||||
|
|
||||||
8
http/qtsubject.txt
Normal file
8
http/qtsubject.txt
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
POST /SubjectManager/getSubjects HTTP/1.1
|
||||||
|
Host: localhost:8080
|
||||||
|
Content-Length: 0
|
||||||
|
Connection: Keep-Alive
|
||||||
|
Accept-Encoding: gzip, deflate
|
||||||
|
Accept-Language: en-AI,*
|
||||||
|
User-Agent: Mozilla/5.0
|
||||||
|
|
||||||
@ -1,10 +1,20 @@
|
|||||||
#include <QCoreApplication>
|
#include <QCoreApplication>
|
||||||
#include "requestmanager.h"
|
|
||||||
|
#include "data.h"
|
||||||
|
#include "datamanager.h"
|
||||||
|
#include "colnodapi.h"
|
||||||
|
|
||||||
int main(int argc, char *argv[])
|
int main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
QCoreApplication a(argc, argv);
|
QCoreApplication a(argc, argv);
|
||||||
//RequestManager *reqman = new RequestManager();
|
ColnodAPI *api = new ColnodAPI();
|
||||||
|
|
||||||
|
api->downloadData(); // this will start downloading data
|
||||||
|
QObject::connect(api, &ColnodAPI::dataDownloaded, [=](){
|
||||||
|
qDebug() << "now I have all data";
|
||||||
|
api->syncData();
|
||||||
|
QCoreApplication::quit();
|
||||||
|
});
|
||||||
|
|
||||||
return a.exec();
|
return a.exec();
|
||||||
}
|
}
|
||||||
|
|||||||
@ -2,18 +2,24 @@ INCLUDEPATH += $$PWD
|
|||||||
#SRC_DIR = $$PWD
|
#SRC_DIR = $$PWD
|
||||||
message($$PWD)
|
message($$PWD)
|
||||||
SOURCES += \
|
SOURCES += \
|
||||||
|
$$PWD/colnodapi.cpp \
|
||||||
|
$$PWD/data.cpp \
|
||||||
$$PWD/databasemanager.cpp \
|
$$PWD/databasemanager.cpp \
|
||||||
$$PWD/dataprocessor.cpp \
|
$$PWD/datamanager.cpp \
|
||||||
$$PWD/entity.cpp \
|
$$PWD/entity.cpp \
|
||||||
$$PWD/requestmanager.cpp \
|
$$PWD/requestmanager.cpp \
|
||||||
|
$$PWD/response.cpp \
|
||||||
$$PWD/subject.cpp \
|
$$PWD/subject.cpp \
|
||||||
$$PWD/token.cpp
|
$$PWD/token.cpp
|
||||||
|
|
||||||
HEADERS += \
|
HEADERS += \
|
||||||
|
$$PWD/colnodapi.h \
|
||||||
|
$$PWD/data.h \
|
||||||
$$PWD/databasemanager.h \
|
$$PWD/databasemanager.h \
|
||||||
$$PWD/dataprocessor.h \
|
$$PWD/datamanager.h \
|
||||||
$$PWD/entity.h \
|
$$PWD/entity.h \
|
||||||
$$PWD/requestmanager.h \
|
$$PWD/requestmanager.h \
|
||||||
|
$$PWD/response.h \
|
||||||
$$PWD/subject.h \
|
$$PWD/subject.h \
|
||||||
$$PWD/token.h
|
$$PWD/token.h
|
||||||
message($$SOURCES)
|
message($$SOURCES)
|
||||||
|
|||||||
54
src/colnod/colnodapi.cpp
Normal file
54
src/colnod/colnodapi.cpp
Normal file
@ -0,0 +1,54 @@
|
|||||||
|
#include "colnodapi.h"
|
||||||
|
|
||||||
|
ColnodAPI::ColnodAPI()
|
||||||
|
{
|
||||||
|
reqMan = new RequestManager();
|
||||||
|
//data = new Data();
|
||||||
|
dataMan = new DataManager();
|
||||||
|
connect(this, &ColnodAPI::partReady, this, &ColnodAPI::checkPartOfData);
|
||||||
|
connect(this, &ColnodAPI::partReady, this, &ColnodAPI::areDataReady);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// PUBLIC FUNCTIONS
|
||||||
|
void ColnodAPI::downloadData()
|
||||||
|
{
|
||||||
|
Response* resp0 = reqMan->getSubjects();
|
||||||
|
connect(resp0, &Response::finished, [=](){
|
||||||
|
dataMan->localSaveSubjects(resp0->reply->readAll());
|
||||||
|
emit partReady();
|
||||||
|
});
|
||||||
|
|
||||||
|
Response* resp1 = reqMan->getTokens();
|
||||||
|
connect(resp1, &Response::finished, [=](){
|
||||||
|
dataMan->localSaveTokens(resp1->reply->readAll());
|
||||||
|
emit partReady();
|
||||||
|
});
|
||||||
|
|
||||||
|
/*
|
||||||
|
QNetworkReply* reply2 = reqMan->getTokens();
|
||||||
|
connect(reply2, &QNetworkReply::finished, [=](){
|
||||||
|
data->saveTokens(reply2->readAll());
|
||||||
|
});
|
||||||
|
*/
|
||||||
|
}
|
||||||
|
|
||||||
|
void ColnodAPI::syncData()
|
||||||
|
{
|
||||||
|
dataMan->pushDataToDB();
|
||||||
|
}
|
||||||
|
|
||||||
|
// PRIVATE FUNCTIONS
|
||||||
|
void ColnodAPI::areDataReady()
|
||||||
|
{
|
||||||
|
if (index >= numOfMembers)
|
||||||
|
{
|
||||||
|
emit dataDownloaded();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void ColnodAPI::checkPartOfData()
|
||||||
|
{
|
||||||
|
index++;
|
||||||
|
}
|
||||||
|
|
||||||
39
src/colnod/colnodapi.h
Normal file
39
src/colnod/colnodapi.h
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
#ifndef COLNODAPI_H
|
||||||
|
#define COLNODAPI_H
|
||||||
|
|
||||||
|
#include "requestmanager.h"
|
||||||
|
#include "data.h"
|
||||||
|
#include "datamanager.h"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
class ColnodAPI : public QObject
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
ColnodAPI();
|
||||||
|
void downloadData();
|
||||||
|
void syncData();
|
||||||
|
|
||||||
|
signals:
|
||||||
|
void dataDownloaded();
|
||||||
|
void partReady();
|
||||||
|
|
||||||
|
private slots:
|
||||||
|
void areDataReady();
|
||||||
|
void checkPartOfData();
|
||||||
|
|
||||||
|
|
||||||
|
private:
|
||||||
|
RequestManager* reqMan = nullptr;
|
||||||
|
// Data* data = nullptr;
|
||||||
|
DataManager* dataMan = nullptr;
|
||||||
|
bool dataReady[2] = {false};
|
||||||
|
int index = 0;
|
||||||
|
const int numOfMembers = 2;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // COLNODAPI_H
|
||||||
7
src/colnod/data.cpp
Normal file
7
src/colnod/data.cpp
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
#include "data.h"
|
||||||
|
|
||||||
|
Data::Data()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
24
src/colnod/data.h
Normal file
24
src/colnod/data.h
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
#ifndef DATA_H
|
||||||
|
#define DATA_H
|
||||||
|
#include <QObject>
|
||||||
|
|
||||||
|
#include "subject.h"
|
||||||
|
#include "token.h"
|
||||||
|
#include <qjsondocument.h>
|
||||||
|
#include <qjsonarray.h>
|
||||||
|
|
||||||
|
class Data : public QObject
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
|
public:
|
||||||
|
Data();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
private:
|
||||||
|
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // DATA_H
|
||||||
@ -17,14 +17,24 @@ DatabaseManager::DatabaseManager(QString host, QString dbName, QString user, QSt
|
|||||||
query = QSqlQuery("query", db);
|
query = QSqlQuery("query", db);
|
||||||
}
|
}
|
||||||
|
|
||||||
void DatabaseManager::saveSubject(Subject subject, QString table)
|
void DatabaseManager::saveSubject(Subject* subject, QString table)
|
||||||
{
|
{
|
||||||
//TODO
|
query.prepare("INSERT INTO subject (id, name) VALUES (:id, :name)");
|
||||||
|
query.bindValue(":table", table);
|
||||||
|
query.bindValue(":id",subject->getId().toString());
|
||||||
|
qDebug() << subject->getId().toString() << subject->getName();
|
||||||
|
query.bindValue(":name", subject->getName());
|
||||||
|
query.exec();
|
||||||
}
|
}
|
||||||
|
|
||||||
void DatabaseManager::saveToken(Subject subject, QString table)
|
void DatabaseManager::saveToken(Token* token, QString table)
|
||||||
{
|
{
|
||||||
//TODO
|
query.prepare("INSERT INTO :table (id, name) VALUES (:id, :data, :subject_id)");
|
||||||
|
query.bindValue(":table", table);
|
||||||
|
query.bindValue(":id",token->getId());
|
||||||
|
query.bindValue(":data", token->getTokenData());
|
||||||
|
query.bindValue(":subject_id", token->getSubjectId());
|
||||||
|
query.exec();
|
||||||
}
|
}
|
||||||
|
|
||||||
QString DatabaseManager::getTestMessage(int id)
|
QString DatabaseManager::getTestMessage(int id)
|
||||||
@ -42,8 +52,13 @@ void DatabaseManager::createTestRecord(QString msg)
|
|||||||
query.exec("SELECT MAX(id) FROM test");
|
query.exec("SELECT MAX(id) FROM test");
|
||||||
query.next();
|
query.next();
|
||||||
int id = query.value(0).toInt() + 1;
|
int id = query.value(0).toInt() + 1;
|
||||||
QString statement = QString("INSERT INTO test (id, message) VALUES (%1, '%2')").arg(id).arg(msg);
|
//QString statement = QString("INSERT INTO test (id, message) VALUES (%1, '%2')").arg(id).arg(msg);
|
||||||
query.exec(statement);
|
//query.exec(statement);
|
||||||
|
|
||||||
|
query.prepare("INSERT INTO test (id, message) VALUES (:id, :msg)");
|
||||||
|
query.bindValue(":id", id);
|
||||||
|
query.bindValue(":msg", msg);
|
||||||
|
query.exec();
|
||||||
query.next();
|
query.next();
|
||||||
qDebug() << "U inserted new row, id: " << id << "msg: " << getTestMessage(id);
|
qDebug() << "U inserted new row, id: " << id << "msg: " << getTestMessage(id);
|
||||||
|
|
||||||
|
|||||||
@ -17,8 +17,8 @@ class DatabaseManager : public QObject
|
|||||||
public:
|
public:
|
||||||
DatabaseManager(QString host, QString dbName, QString user, QString password);
|
DatabaseManager(QString host, QString dbName, QString user, QString password);
|
||||||
|
|
||||||
void saveSubject(Subject subject, QString table);
|
void saveSubject(Subject* subject, QString table);
|
||||||
void saveToken(Subject subject, QString table);
|
void saveToken(Token* token, QString table);
|
||||||
|
|
||||||
QString getTestMessage(int id);
|
QString getTestMessage(int id);
|
||||||
void createTestRecord(QString msg);
|
void createTestRecord(QString msg);
|
||||||
|
|||||||
44
src/colnod/datamanager.cpp
Normal file
44
src/colnod/datamanager.cpp
Normal file
@ -0,0 +1,44 @@
|
|||||||
|
#include "datamanager.h"
|
||||||
|
|
||||||
|
DataManager::DataManager()
|
||||||
|
{
|
||||||
|
db = new DatabaseManager("192.168.1.94", "deloitte", "postgres", "34rjkciea12");
|
||||||
|
}
|
||||||
|
|
||||||
|
void DataManager::localSaveSubjects(QString response)
|
||||||
|
{
|
||||||
|
QJsonDocument doc = QJsonDocument::fromJson(response.toUtf8());
|
||||||
|
QJsonArray items = doc.object()["items"].toArray();
|
||||||
|
for (QJsonValueRef item : items)
|
||||||
|
{
|
||||||
|
auto subject = new Subject();
|
||||||
|
subject->fromJSON(item.toObject());
|
||||||
|
subjects.append(subject);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void DataManager::localSaveTokens(QString response)
|
||||||
|
{
|
||||||
|
QJsonDocument doc = QJsonDocument::fromJson(response.toUtf8());
|
||||||
|
QJsonArray items = doc.object()["items"].toArray();
|
||||||
|
for (QJsonValueRef item : items)
|
||||||
|
{
|
||||||
|
auto token = new Token();
|
||||||
|
token->fromJSON(item.toObject());
|
||||||
|
tokens.append(token);
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void DataManager::pushDataToDB()
|
||||||
|
{
|
||||||
|
for (auto subject : subjects)
|
||||||
|
{
|
||||||
|
db->saveSubject(subject, "subject");
|
||||||
|
}
|
||||||
|
|
||||||
|
for (auto token : tokens)
|
||||||
|
{
|
||||||
|
db->saveToken(token, "Subjects");
|
||||||
|
}
|
||||||
|
}
|
||||||
35
src/colnod/datamanager.h
Normal file
35
src/colnod/datamanager.h
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
#ifndef DATAMANAGER_H
|
||||||
|
#define DATAMANAGER_H
|
||||||
|
|
||||||
|
#include "token.h"
|
||||||
|
#include "subject.h"
|
||||||
|
#include "requestmanager.h"
|
||||||
|
#include "databasemanager.h"
|
||||||
|
#include <QJsonDocument>
|
||||||
|
#include <qjsonarray.h>
|
||||||
|
#include "data.h"
|
||||||
|
|
||||||
|
|
||||||
|
class DataManager : public QObject
|
||||||
|
{
|
||||||
|
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
|
public:
|
||||||
|
DataManager();
|
||||||
|
|
||||||
|
void localSaveSubjects(QString jsonResponse);
|
||||||
|
void localSaveTokens(QString jsonResponse);
|
||||||
|
void pushDataToDB();
|
||||||
|
|
||||||
|
|
||||||
|
private:
|
||||||
|
DatabaseManager *db = nullptr;
|
||||||
|
QList<QPointer<Subject>> subjects;
|
||||||
|
QList<QPointer<Token>> tokens;
|
||||||
|
//Data *dataToProcess = nullptr;
|
||||||
|
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // DATAMANAGER_H
|
||||||
@ -1,56 +0,0 @@
|
|||||||
#include "dataprocessor.h"
|
|
||||||
|
|
||||||
DataProcessor::DataProcessor()
|
|
||||||
{
|
|
||||||
|
|
||||||
db = new DatabaseManager("192.168.1.94", "deloitte", "postgres", "34rjkciea12");
|
|
||||||
reqMan = new RequestManager;
|
|
||||||
}
|
|
||||||
|
|
||||||
void DataProcessor::processSubjects()
|
|
||||||
{
|
|
||||||
reqMan->getSubjects();
|
|
||||||
QEventLoop loop;
|
|
||||||
QObject::connect(reqMan, &RequestManager::responseReady, &loop, &QEventLoop::quit);
|
|
||||||
loop.exec();
|
|
||||||
prepareSubjectJson(reqMan->getResponse());
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
QUuid DataProcessor::getSubjectId(const QString &email) const
|
|
||||||
{
|
|
||||||
auto subject = this->getSubjectByEmail(email);
|
|
||||||
if (!subject)
|
|
||||||
{
|
|
||||||
return "";
|
|
||||||
}
|
|
||||||
return subject->getId();
|
|
||||||
}
|
|
||||||
|
|
||||||
Subject *DataProccesor::getSubjectById(const QUuid &id) const
|
|
||||||
{
|
|
||||||
return this->subjectsById.value(id);
|
|
||||||
}
|
|
||||||
|
|
||||||
Subject DataProcessor::getSubjectByEmail(const QString &email) const
|
|
||||||
{
|
|
||||||
return this->subjectsByEmail.value(email);
|
|
||||||
}
|
|
||||||
|
|
||||||
Token *Client::getTokenById(const QUuid &id) const
|
|
||||||
{
|
|
||||||
return this->tokensById.value(id);
|
|
||||||
}
|
|
||||||
|
|
||||||
Token *Client::getTokenByData(const QString &data) const
|
|
||||||
{
|
|
||||||
return this->tokensByData.value(data);
|
|
||||||
}*/
|
|
||||||
|
|
||||||
void DataProcessor::prepareSubjectJson(QString json)
|
|
||||||
{
|
|
||||||
QJsonDocument doc = QJsonDocument::fromJson(json.toUtf8());
|
|
||||||
subjectArr = doc.object()["items"].toArray();
|
|
||||||
}
|
|
||||||
@ -1,41 +0,0 @@
|
|||||||
#ifndef DATAPROCESSOR_H
|
|
||||||
#define DATAPROCESSOR_H
|
|
||||||
|
|
||||||
#include "token.h"
|
|
||||||
#include "subject.h"
|
|
||||||
#include "requestmanager.h"
|
|
||||||
#include "databasemanager.h"
|
|
||||||
#include <QJsonDocument>
|
|
||||||
#include <qjsonarray.h>
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class DataProcessor : public QObject
|
|
||||||
{
|
|
||||||
|
|
||||||
Q_OBJECT
|
|
||||||
|
|
||||||
public:
|
|
||||||
DataProcessor();
|
|
||||||
|
|
||||||
void processSubjects();
|
|
||||||
|
|
||||||
Subject *getSubjectById(const QUuid &id) const;
|
|
||||||
Subject *getSubjectByEmail(const QString &email) const;
|
|
||||||
QUuid getSubjectId(const QString &email) const;
|
|
||||||
|
|
||||||
Token *getTokenById(const QUuid &id) const;
|
|
||||||
Token *getTokenByData(const QString &data) const;
|
|
||||||
|
|
||||||
private slots:
|
|
||||||
void prepareSubjectJson(QString json);
|
|
||||||
|
|
||||||
private:
|
|
||||||
RequestManager *reqMan;
|
|
||||||
DatabaseManager *db;
|
|
||||||
QJsonArray subjectArr;
|
|
||||||
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif // DATAPROCESSOR_H
|
|
||||||
@ -5,35 +5,34 @@ RequestManager::RequestManager()
|
|||||||
manager = new QNetworkAccessManager();
|
manager = new QNetworkAccessManager();
|
||||||
token = "";
|
token = "";
|
||||||
loginStatus = false; //should be false, true for testing request header
|
loginStatus = false; //should be false, true for testing request header
|
||||||
|
/*
|
||||||
|
|
||||||
|
|
||||||
QFile configFile(QDir::current().filePath("config.json"));
|
QFile configFile(QDir::current().filePath("config.json"));
|
||||||
if (!configFile.open(QIODevice::ReadOnly)) {
|
if (!configFile.open(QIODevice::ReadOnly)) {
|
||||||
qCritical() << "Couldn't open config file config.json" << QDir::current().filePath("config.json");
|
qCritical() << "Couldn't open config file config.json" << QDir::current().filePath("config.json");
|
||||||
QCoreApplication::exit(-1);
|
QCoreApplication::exit(-1);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
this->config = QJsonDocument::fromJson(configFile.readAll());
|
this->config = QJsonDocument::fromJson(configFile.readAll());*/
|
||||||
QObject::connect(manager, &QNetworkAccessManager::sslErrors, this, &RequestManager::onSSLError);
|
QObject::connect(manager, &QNetworkAccessManager::sslErrors, this, &RequestManager::onSSLError);
|
||||||
}
|
}
|
||||||
|
|
||||||
void RequestManager::login(QString host, QString username, QString password)
|
void RequestManager::login(QString host, QString username, QString password)
|
||||||
{
|
{
|
||||||
|
|
||||||
QNetworkRequest request;
|
QNetworkRequest request;
|
||||||
QString hash = encryptedPassword(password);
|
QString hash = encryptedPassword(this->password);
|
||||||
authHeader = getLoginHeader(username, hash);
|
authHeader = getLoginHeader(this->user, hash);
|
||||||
QJsonObject reqBody = {
|
QJsonObject reqBody = {
|
||||||
{"password", hash},
|
{"password", hash},
|
||||||
{"username", username}
|
{"username", this->user}
|
||||||
};
|
};
|
||||||
this->host = host;
|
//this->host = host;
|
||||||
|
|
||||||
request.setUrl(host + "/AaaManager/authSession");
|
request.setUrl(this->host + "/AaaManager/authSession");
|
||||||
request.setRawHeader("Authorization", authHeader.toLocal8Bit());
|
request.setRawHeader("Authorization", authHeader.toLocal8Bit());
|
||||||
request.setHeader(QNetworkRequest::ContentTypeHeader, "application/json; charset=UTF-8");
|
request.setHeader(QNetworkRequest::ContentTypeHeader, "application/json; charset=UTF-8");
|
||||||
QJsonDocument jsonDocument;
|
|
||||||
|
|
||||||
|
QJsonDocument jsonDocument;
|
||||||
jsonDocument.setObject(reqBody);
|
jsonDocument.setObject(reqBody);
|
||||||
QNetworkReply* reply = manager->post(request, jsonDocument.toJson());
|
QNetworkReply* reply = manager->post(request, jsonDocument.toJson());
|
||||||
QObject::connect(reply, &QNetworkReply::finished, [=]() {
|
QObject::connect(reply, &QNetworkReply::finished, [=]() {
|
||||||
@ -43,6 +42,8 @@ void RequestManager::login(QString host, QString username, QString password)
|
|||||||
loginStatus = false;
|
loginStatus = false;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
if (loginStatus)
|
||||||
|
return;
|
||||||
jsonResponse = reply->readAll();
|
jsonResponse = reply->readAll();
|
||||||
prepareAuthHeader();
|
prepareAuthHeader();
|
||||||
loginStatus = true;
|
loginStatus = true;
|
||||||
@ -51,51 +52,25 @@ void RequestManager::login(QString host, QString username, QString password)
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
void RequestManager::getRequest(QString endpoint)
|
QNetworkReply* RequestManager::getRequest(QString endpoint)
|
||||||
{
|
{
|
||||||
if (!loginStatus)
|
|
||||||
{
|
|
||||||
login(config.object()["host"].toString(), config.object()["username"].toString(), config.object()["password"].toString());
|
|
||||||
// QEventLoop loop;
|
|
||||||
// QObject::connect(this, &RequestManager::successLogin, &loop, &QEventLoop::quit);
|
|
||||||
// loop.exec();
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
//host = config.object()["host"].toString();
|
|
||||||
//
|
|
||||||
|
|
||||||
QNetworkRequest request;
|
QNetworkRequest request;
|
||||||
request.setUrl(host + endpoint);
|
request.setUrl(host + endpoint);
|
||||||
qDebug() << authHeader;
|
qDebug() << "Auth: " << authHeader;
|
||||||
request.setRawHeader("Authorization", authHeader.toLocal8Bit());
|
request.setRawHeader("Authorization", authHeader.toLocal8Bit());
|
||||||
request.setRawHeader("User-Agent", "curl/7.65.3");
|
|
||||||
request.setRawHeader("Connection", "Keep-Alive");
|
|
||||||
request.setRawHeader("Accept", "*/*");
|
|
||||||
request.setRawHeader("Accept-Encoding", "*");
|
|
||||||
request.setRawHeader("Accept-Language", "*");
|
|
||||||
|
|
||||||
QNetworkReply* reply = manager->post(request, QByteArray());
|
QNetworkReply* reply = manager->post(request, QByteArray());
|
||||||
|
|
||||||
//
|
|
||||||
//QEventLoop loop;
|
|
||||||
//QObject::connect(reply, &QNetworkReply::finished, &loop, &QEventLoop::quit);
|
|
||||||
// loop.exec();
|
|
||||||
//
|
|
||||||
|
|
||||||
QObject::connect(reply, &QNetworkReply::finished, [=]() {
|
QObject::connect(reply, &QNetworkReply::finished, [=]() {
|
||||||
if (reply->error())
|
if (reply->error())
|
||||||
{
|
{
|
||||||
qDebug() << reply->errorString();
|
qDebug() << reply->errorString();
|
||||||
qDebug() << reply->readAll();
|
|
||||||
loginStatus = false;
|
loginStatus = false;
|
||||||
getRequest(endpoint);
|
//getRequest(endpoint);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
qDebug() << reply->attribute(QNetworkRequest::HttpStatusCodeAttribute);
|
|
||||||
jsonResponse = reply->readAll();
|
|
||||||
emit responseReady();
|
emit responseReady();
|
||||||
});
|
});
|
||||||
|
return reply;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
QString RequestManager::getFromJson(QString json, const QString &member)
|
QString RequestManager::getFromJson(QString json, const QString &member)
|
||||||
@ -139,7 +114,62 @@ void RequestManager::onSSLError(QNetworkReply *reply, const QList<QSslError> &er
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void RequestManager::getSubjects()
|
Response* RequestManager::getSubjects()
|
||||||
{
|
{
|
||||||
getRequest("/SubjectManager/getSubjects");
|
auto response = new Response;
|
||||||
|
if (!loginStatus){
|
||||||
|
login(host, user, password);
|
||||||
|
connect(this, &RequestManager::successLogin, [=](){
|
||||||
|
auto subjectReply = getRequest("/SubjectManager/getSubjects");
|
||||||
|
response->reply = subjectReply;
|
||||||
|
connect(subjectReply, &QNetworkReply::finished, response, &Response::finished);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
QNetworkReply* reply = getRequest("/SubjectManager/getSubjects");
|
||||||
|
connect(reply, &QNetworkReply::finished, response, &Response::finished);
|
||||||
|
}
|
||||||
|
|
||||||
|
return response;
|
||||||
|
}
|
||||||
|
|
||||||
|
Response* RequestManager::getTokens()
|
||||||
|
{
|
||||||
|
auto response = new Response;
|
||||||
|
if (!loginStatus){
|
||||||
|
login(host, user, password);
|
||||||
|
connect(this, &RequestManager::successLogin, [=](){
|
||||||
|
auto subjectReply = getRequest("/TokenManager/getTokens");
|
||||||
|
response->reply = subjectReply;
|
||||||
|
connect(subjectReply, &QNetworkReply::finished, response, &Response::finished);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
QNetworkReply* reply = getRequest("/TokenManager/getTokens");
|
||||||
|
connect(reply, &QNetworkReply::finished, response, &Response::finished);
|
||||||
|
}
|
||||||
|
|
||||||
|
return response;
|
||||||
|
}
|
||||||
|
|
||||||
|
Response* RequestManager::getTokenSubject()
|
||||||
|
{
|
||||||
|
auto response = new Response;
|
||||||
|
if (!loginStatus){
|
||||||
|
login(host, user, password);
|
||||||
|
connect(this, &RequestManager::successLogin, [=](){
|
||||||
|
auto subjectReply = getRequest("/OpenManager/getTokenSubject");
|
||||||
|
response->reply = subjectReply;
|
||||||
|
connect(subjectReply, &QNetworkReply::finished, response, &Response::finished);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
QNetworkReply* reply = getRequest("/OpenManager/getTokenSubject");
|
||||||
|
connect(reply, &QNetworkReply::finished, response, &Response::finished);
|
||||||
|
}
|
||||||
|
|
||||||
|
return response;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -21,9 +21,7 @@
|
|||||||
#include <QSslError>
|
#include <QSslError>
|
||||||
|
|
||||||
|
|
||||||
#include "databasemanager.h"
|
#include "response.h"
|
||||||
#include "token.h"
|
|
||||||
#include "subject.h"
|
|
||||||
|
|
||||||
class RequestManager : public QObject
|
class RequestManager : public QObject
|
||||||
{
|
{
|
||||||
@ -31,19 +29,16 @@ class RequestManager : public QObject
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
RequestManager();
|
RequestManager();
|
||||||
void getSubjects();
|
Response* getSubjects();
|
||||||
void login(QString endpoint, QString username, QString password);
|
Response* getTokens();
|
||||||
void getRequest(QString endpoint);
|
Response* getTokenSubject();
|
||||||
void loadSubjectsFromColnodToDB();
|
void login(QString endpoint, QString username, QString password); //I want it private, but unittest???
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
const QJsonDocument &getConfig() const {return config;}
|
const QJsonDocument &getConfig() const {return config;}
|
||||||
const QString &getResponse() const {return jsonResponse;}
|
const QString &getResponse() const {return jsonResponse;}
|
||||||
QString getToken(){return token;}
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
QNetworkReply* getRequest(QString endpoint);
|
||||||
QString getFromJson(QString json, const QString &member);
|
QString getFromJson(QString json, const QString &member);
|
||||||
QString encryptedPassword(QString password);
|
QString encryptedPassword(QString password);
|
||||||
QString getLoginHeader(QString username, QString hash);
|
QString getLoginHeader(QString username, QString hash);
|
||||||
@ -52,21 +47,25 @@ private:
|
|||||||
private slots:
|
private slots:
|
||||||
void onSSLError(QNetworkReply *reply, const QList<QSslError> &errors);
|
void onSSLError(QNetworkReply *reply, const QList<QSslError> &errors);
|
||||||
|
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void successLogin();
|
void successLogin();
|
||||||
void responseReady();
|
void responseReady();
|
||||||
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QNetworkAccessManager* manager;
|
QNetworkAccessManager* manager = nullptr;
|
||||||
QJsonDocument config;
|
QJsonDocument config;
|
||||||
QString authHeader;
|
QString authHeader;
|
||||||
QString host;
|
QString host = "https://192.168.1.3:8443";
|
||||||
|
//QString host = "http://localhost:8080";
|
||||||
|
|
||||||
|
QString password = "spaceti1";
|
||||||
|
QString user = "spaceti";
|
||||||
QString token;
|
QString token;
|
||||||
QString jsonResponse;
|
QString jsonResponse;
|
||||||
bool loginStatus;
|
bool loginStatus;
|
||||||
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // REQUESTMANAGER_H
|
#endif // REQUESTMANAGER_H
|
||||||
|
|||||||
6
src/colnod/response.cpp
Normal file
6
src/colnod/response.cpp
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
#include "response.h"
|
||||||
|
|
||||||
|
Response::Response()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
25
src/colnod/response.h
Normal file
25
src/colnod/response.h
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
#ifndef RESPONSE_H
|
||||||
|
#define RESPONSE_H
|
||||||
|
|
||||||
|
#include <QObject>
|
||||||
|
#include <qnetworkreply.h>
|
||||||
|
|
||||||
|
class Response : public QObject
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
public:
|
||||||
|
Response();
|
||||||
|
|
||||||
|
public:
|
||||||
|
QNetworkReply *reply = nullptr;
|
||||||
|
|
||||||
|
signals:
|
||||||
|
void finished();
|
||||||
|
|
||||||
|
public slots:
|
||||||
|
|
||||||
|
private:
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // RESPONSE_H
|
||||||
@ -20,12 +20,11 @@ void UnitTest::getSubjects()
|
|||||||
{
|
{
|
||||||
RequestManager* testAccess = new RequestManager();
|
RequestManager* testAccess = new RequestManager();
|
||||||
QSignalSpy spy(testAccess, SIGNAL(responseReady()));
|
QSignalSpy spy(testAccess, SIGNAL(responseReady()));
|
||||||
testAccess->getRequest("/SubjectManager/getSubjects");
|
testAccess->getSubjects();
|
||||||
spy.wait();
|
spy.wait();
|
||||||
QVERIFY(spy.isValid());
|
QVERIFY(spy.isValid());
|
||||||
QCOMPARE(spy.count(), 1);
|
QCOMPARE(spy.count(), 1);
|
||||||
QString json = testAccess->getResponse();
|
QString json = testAccess->getResponse();
|
||||||
qDebug() << json;
|
|
||||||
QJsonDocument doc = QJsonDocument::fromJson(json.toUtf8());
|
QJsonDocument doc = QJsonDocument::fromJson(json.toUtf8());
|
||||||
QVERIFY(doc.isObject());
|
QVERIFY(doc.isObject());
|
||||||
QVERIFY2(doc.object().value("items").isArray(), "No parameter 'id' in response");
|
QVERIFY2(doc.object().value("items").isArray(), "No parameter 'id' in response");
|
||||||
@ -38,19 +37,24 @@ void UnitTest::getTokens()
|
|||||||
{
|
{
|
||||||
RequestManager* testAccess = new RequestManager();
|
RequestManager* testAccess = new RequestManager();
|
||||||
QSignalSpy spy(testAccess, SIGNAL(responseReady()));
|
QSignalSpy spy(testAccess, SIGNAL(responseReady()));
|
||||||
testAccess->getRequest("/TokenManager/getTokens");
|
testAccess->getTokens();
|
||||||
QCOMPARE(spy.count(), 0);
|
QCOMPARE(spy.count(), 0);
|
||||||
spy.wait();
|
spy.wait();
|
||||||
QVERIFY(spy.isValid());
|
QVERIFY(spy.isValid());
|
||||||
QCOMPARE(spy.count(), 1);
|
QCOMPARE(spy.count(), 1);
|
||||||
qDebug() << testAccess->getResponse();
|
QString json = testAccess->getResponse();
|
||||||
|
QJsonDocument doc = QJsonDocument::fromJson(json.toUtf8());
|
||||||
|
QVERIFY(doc.isObject());
|
||||||
|
QVERIFY2(doc.object().value("items").isArray(), "No parameter 'id' in response");
|
||||||
|
qDebug() << doc.object().value("items").toArray()[0].toObject()["id"].toString();
|
||||||
|
QVERIFY2(doc.object().value("items").toArray()[0].toObject()["id"].isString(), "ada");
|
||||||
}
|
}
|
||||||
|
|
||||||
void UnitTest::getTokensOpenManager()
|
void UnitTest::getTokenSubject()
|
||||||
{
|
{
|
||||||
RequestManager* testAccess = new RequestManager();
|
RequestManager* testAccess = new RequestManager();
|
||||||
QSignalSpy spy(testAccess, SIGNAL(responseReady()));
|
QSignalSpy spy(testAccess, SIGNAL(responseReady()));
|
||||||
testAccess->getRequest("/OpenManager/getTokenSubject");
|
testAccess->getTokenSubject();
|
||||||
QCOMPARE(spy.count(), 0);
|
QCOMPARE(spy.count(), 0);
|
||||||
spy.wait();
|
spy.wait();
|
||||||
QVERIFY(spy.isValid());
|
QVERIFY(spy.isValid());
|
||||||
@ -75,13 +79,10 @@ void UnitTest::subjectJSONParser()
|
|||||||
QJsonObject obj = doc.object();
|
QJsonObject obj = doc.object();
|
||||||
QJsonArray arr = obj["items"].toArray();
|
QJsonArray arr = obj["items"].toArray();
|
||||||
*/
|
*/
|
||||||
QVERIFY(true);
|
|
||||||
return;
|
|
||||||
|
|
||||||
|
|
||||||
RequestManager* testAccess = new RequestManager();
|
RequestManager* testAccess = new RequestManager();
|
||||||
QSignalSpy spy(testAccess, SIGNAL(responseReady()));
|
QSignalSpy spy(testAccess, SIGNAL(responseReady()));
|
||||||
testAccess->getRequest("/SubjectManager/getSubjects");
|
testAccess->getSubjects();
|
||||||
spy.wait();
|
spy.wait();
|
||||||
QString response = testAccess->getResponse();
|
QString response = testAccess->getResponse();
|
||||||
QJsonDocument doc = QJsonDocument::fromJson(response.toUtf8());
|
QJsonDocument doc = QJsonDocument::fromJson(response.toUtf8());
|
||||||
@ -96,19 +97,15 @@ void UnitTest::tokenJSONParser()
|
|||||||
{
|
{
|
||||||
RequestManager* testAccess = new RequestManager();
|
RequestManager* testAccess = new RequestManager();
|
||||||
QSignalSpy spy(testAccess, SIGNAL(responseReady()));
|
QSignalSpy spy(testAccess, SIGNAL(responseReady()));
|
||||||
testAccess->getRequest("/TokenManager/getTokens");
|
testAccess->getTokens();
|
||||||
spy.wait();
|
spy.wait();
|
||||||
QString response = testAccess->getResponse();
|
QString response = testAccess->getResponse();
|
||||||
|
QJsonDocument doc = QJsonDocument::fromJson(response.toUtf8());
|
||||||
//TODO
|
|
||||||
/* QJsonDocument doc = QJsonDocument::fromJson(response.toUtf8());
|
|
||||||
QJsonArray arr = doc.object()["items"].toArray();
|
QJsonArray arr = doc.object()["items"].toArray();
|
||||||
auto testSubject = new Subject();
|
auto testToken = new Token();
|
||||||
testSubject->fromJSON(arr[1].toObject());
|
testToken->fromJSON(arr[5].toObject());
|
||||||
qDebug() << testSubject->getName();
|
qDebug() << testToken->getName() << " Size: " << arr.size();
|
||||||
QVERIFY(!testSubject->getName().isEmpty());*/
|
QVERIFY(!testToken->getName().isEmpty());
|
||||||
QVERIFY(true);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void UnitTest::connectToDB()
|
void UnitTest::connectToDB()
|
||||||
@ -118,7 +115,7 @@ void UnitTest::connectToDB()
|
|||||||
qDebug() << db->getTestMessage(1);
|
qDebug() << db->getTestMessage(1);
|
||||||
QVERIFY(true);
|
QVERIFY(true);
|
||||||
QCOMPARE(db->getTestMessage(1), QStringLiteral("Hello world"));
|
QCOMPARE(db->getTestMessage(1), QStringLiteral("Hello world"));
|
||||||
db->createTestRecord("Does it work?");
|
db->createTestRecord("Now it's diffrent");
|
||||||
QCOMPARE(db->getTestMessage(2), QStringLiteral("Does it work?"));
|
QCOMPARE(db->getTestMessage(2), QStringLiteral("Does it work?"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -132,44 +129,43 @@ void UnitTest::debugConnection()
|
|||||||
qDebug() << ssl.errorString();
|
qDebug() << ssl.errorString();
|
||||||
}
|
}
|
||||||
QString tmp = "POST /AaaManager/authSession HTTP/1.1\r\nHost: 192.168.1.3:8443\r\nAuthorization: Basic c3BhY2V0aTpFN0ZFQTA3REJDODJGQjlCQTM0QjJFNDUzRTJFRkU4OUYwNTgzRTcxODc1NDM1MDdFRjExRTg0NzI2MDcxRkU0Mjg0NDUzNzJGMkU0NkI0NTVFQjBDNzk3NDdDNTFFMzYyRjQwM0NFMzk0NzNBMkE4QzJERkEwQ0U1Qzk4MjZDMA==\r\nUser-Agent: curl/7.65.3\r\nAccept: */*\r\nContent-Type: application/json\r\nContent-Length: 164\r\n\r\n{\"password\":\"E7FEA07DBC82FB9BA34B2E453E2EFE89F0583E7187543507EF11E84726071FE428445372F2E46B455EB0C79747C51E362F403CE39473A2A8C2DFA0CE5C9826C0\",\"username\":\"spaceti\"}";
|
QString tmp = "POST /AaaManager/authSession HTTP/1.1\r\nHost: 192.168.1.3:8443\r\nAuthorization: Basic c3BhY2V0aTpFN0ZFQTA3REJDODJGQjlCQTM0QjJFNDUzRTJFRkU4OUYwNTgzRTcxODc1NDM1MDdFRjExRTg0NzI2MDcxRkU0Mjg0NDUzNzJGMkU0NkI0NTVFQjBDNzk3NDdDNTFFMzYyRjQwM0NFMzk0NzNBMkE4QzJERkEwQ0U1Qzk4MjZDMA==\r\nUser-Agent: curl/7.65.3\r\nAccept: */*\r\nContent-Type: application/json\r\nContent-Length: 164\r\n\r\n{\"password\":\"E7FEA07DBC82FB9BA34B2E453E2EFE89F0583E7187543507EF11E84726071FE428445372F2E46B455EB0C79747C51E362F403CE39473A2A8C2DFA0CE5C9826C0\",\"username\":\"spaceti\"}";
|
||||||
/*POST /AaaManager/authSession HTTP/1.1
|
qDebug().noquote() << tmp.toUtf8();
|
||||||
Host: localhost:8080
|
|
||||||
Authorization: Basic c3BhY2V0aTpFN0ZFQTA3REJDODJGQjlCQTM0QjJFNDUzRTJFRkU4OUYwNTgzRTcxODc1NDM1MDdFRjExRTg0NzI2MDcxRkU0Mjg0NDUzNzJGMkU0NkI0NTVFQjBDNzk3NDdDNTFFMzYyRjQwM0NFMzk0NzNBMkE4QzJERkEwQ0U1Qzk4MjZDMA==
|
|
||||||
User-Agent: curl/7.65.3
|
|
||||||
Accept:
|
|
||||||
Content-Type: application/json
|
|
||||||
Content-Length: 164
|
|
||||||
|
|
||||||
{"password":"E7FEA07DBC82FB9BA34B2E453E2EFE89F0583E7187543507EF11E84726071FE428445372F2E46B455EB0C79747C51E362F403CE39473A2A8C2DFA0CE5C9826C0","username":"spaceti"}*/
|
|
||||||
qDebug() << tmp.toUtf8();
|
|
||||||
ssl.write(tmp.toUtf8());
|
ssl.write(tmp.toUtf8());
|
||||||
QString data;
|
QString data;
|
||||||
while (ssl.waitForReadyRead() && data.isEmpty())
|
while (ssl.waitForReadyRead() && data.isEmpty())
|
||||||
{
|
{
|
||||||
data.append(ssl.readAll().data());
|
data.append(ssl.readAll().data());
|
||||||
}
|
}
|
||||||
qDebug() << data;
|
qDebug().noquote() << data;
|
||||||
int index = data.lastIndexOf("id");
|
int index = data.lastIndexOf("id");
|
||||||
QString tkn = data.mid( index + 5, 36);
|
QString tkn = data.mid( index + 5, 36);
|
||||||
tkn = tkn + ":";
|
tkn = tkn + ":";
|
||||||
qDebug() << "parsed token : " <<tkn;
|
qDebug() << "parsed token : " <<tkn;
|
||||||
/*
|
tmp = "POST /SubjectManager/getSubjects HTTP/1.1\r\nHost: 192.168.1.3:8443\r\nAuthorization: Basic " + tkn.toUtf8().toBase64() + "\r\nUser-Agent: curl/7.65.3\r\nAccept: */*\r\n\r\n";
|
||||||
RequestManager* testAccess = new RequestManager();
|
QFile file("output1234.txt");
|
||||||
QJsonDocument config = testAccess->getConfig();
|
file.open(QIODevice::ReadWrite);
|
||||||
QSignalSpy spy(testAccess, SIGNAL(successLogin()));
|
QTextStream st(&file);
|
||||||
testAccess->login(host, email, password);
|
st << tmp;
|
||||||
spy.wait();
|
file.close();
|
||||||
|
qDebug().noquote() << tmp.toUtf8();
|
||||||
QString token = testAccess->getToken();
|
|
||||||
token = token + ":";*/
|
|
||||||
tmp = "POST /SubjectManager/getSubjects\r\nHTTP/1.1 Host: 192.168.1.3:8443\r\nAuthorization: Basic " + tkn.toUtf8().toBase64() + "\r\nUser-Agent: curl/7.65.3\r\nAccept: */*)";
|
|
||||||
qDebug() << tmp.toUtf8();
|
|
||||||
ssl.write(tmp.toUtf8());
|
ssl.write(tmp.toUtf8());
|
||||||
while (ssl.waitForReadyRead())
|
while (ssl.waitForReadyRead())
|
||||||
|
{
|
||||||
qDebug() << ssl.readAll().data();
|
qDebug() << ssl.readAll().data();
|
||||||
|
}
|
||||||
|
qDebug() << ssl.errorString();
|
||||||
|
|
||||||
QVERIFY(true);
|
QVERIFY(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void UnitTest::saveDataToDB()
|
||||||
|
{
|
||||||
|
DataManager* dataMan = new DataManager();
|
||||||
|
|
||||||
|
// dataMan->localSaveTokens();
|
||||||
|
QVERIFY(true);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
QTEST_MAIN(UnitTest)
|
QTEST_MAIN(UnitTest)
|
||||||
|
|||||||
@ -7,6 +7,7 @@
|
|||||||
#include "subject.h"
|
#include "subject.h"
|
||||||
#include "databasemanager.h"
|
#include "databasemanager.h"
|
||||||
#include <QSslSocket>
|
#include <QSslSocket>
|
||||||
|
#include "datamanager.h"
|
||||||
|
|
||||||
|
|
||||||
class UnitTest : public QObject
|
class UnitTest : public QObject
|
||||||
@ -18,11 +19,12 @@ private slots:
|
|||||||
void loginSuccessfully(); // /AaaManager/authSession
|
void loginSuccessfully(); // /AaaManager/authSession
|
||||||
void getSubjects(); // /SubjectManager/getSubjects
|
void getSubjects(); // /SubjectManager/getSubjects
|
||||||
void getTokens(); // /TokenManager/getTokens
|
void getTokens(); // /TokenManager/getTokens
|
||||||
void getTokensOpenManager(); // /OpenManager/getTokenSubject
|
void getTokenSubject(); // /OpenManager/getTokenSubject
|
||||||
void subjectJSONParser();
|
void subjectJSONParser();
|
||||||
void tokenJSONParser();
|
void tokenJSONParser();
|
||||||
void connectToDB();
|
void connectToDB();
|
||||||
void debugConnection();
|
void debugConnection();
|
||||||
|
void saveDataToDB();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
//QString host = "http://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)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user