From da391a44d56797aca4c8e5deb54046126396be32 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20Fischer?= Date: Tue, 1 Oct 2019 13:31:25 +0200 Subject: [PATCH 01/12] Add database class --- src/colnod/colnod.pri | 2 ++ src/colnod/databasemanager.cpp | 19 +++++++++++++++++++ src/colnod/databasemanager.h | 23 +++++++++++++++++++++++ 3 files changed, 44 insertions(+) create mode 100644 src/colnod/databasemanager.cpp create mode 100644 src/colnod/databasemanager.h diff --git a/src/colnod/colnod.pri b/src/colnod/colnod.pri index 0e9925b..29e82cd 100644 --- a/src/colnod/colnod.pri +++ b/src/colnod/colnod.pri @@ -2,8 +2,10 @@ INCLUDEPATH += $$PWD #SRC_DIR = $$PWD message($$PWD) SOURCES += \ + $$PWD/databasemanager.cpp \ $$PWD/requestmanager.cpp HEADERS += \ + $$PWD/databasemanager.h \ $$PWD/requestmanager.h message($$SOURCES) diff --git a/src/colnod/databasemanager.cpp b/src/colnod/databasemanager.cpp new file mode 100644 index 0000000..c9ae476 --- /dev/null +++ b/src/colnod/databasemanager.cpp @@ -0,0 +1,19 @@ +#include "databasemanager.h" + +DatabaseManager::DatabaseManager(QString dbName, QString user, QString password) +{ + + db = QSqlDatabase::addDatabase("QPSQL"); + + db.setDatabaseName(dbName); + db.setHostName("localhost"); + //db.setHostName("192.168.1.201"); + db.setUserName(user); + db.setPassword(password); + if (!db.open()) + { + qDebug() << "Opening error" + db.lastError().text(); + } + query = QSqlQuery("query", db); +} + diff --git a/src/colnod/databasemanager.h b/src/colnod/databasemanager.h new file mode 100644 index 0000000..dcaa616 --- /dev/null +++ b/src/colnod/databasemanager.h @@ -0,0 +1,23 @@ +#ifndef DATABASEMANAGER_H +#define DATABASEMANAGER_H +#include +#include +#include +#include + +#include +#include + + + +class DatabaseManager +{ +public: + DatabaseManager(QString dbName, QString user, QString password); + +private: + QSqlDatabase db; + QSqlQuery query; +}; + +#endif // DATABASEMANAGER_H From c44def76503d4f8a0c8359ee3387fababc77329d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20Fischer?= Date: Tue, 1 Oct 2019 13:33:00 +0200 Subject: [PATCH 02/12] fix for Qt 5.9 --- src/colnod/requestmanager.cpp | 5 +++-- src/colnod/requestmanager.h | 2 +- test/unitTests/UnitTest.cpp | 10 +++++----- test/unitTests/unittest.h | 10 ++++------ 4 files changed, 13 insertions(+), 14 deletions(-) diff --git a/src/colnod/requestmanager.cpp b/src/colnod/requestmanager.cpp index 959d78a..0e70863 100644 --- a/src/colnod/requestmanager.cpp +++ b/src/colnod/requestmanager.cpp @@ -78,11 +78,12 @@ void RequestManager::getRequest(QString endpoint) qDebug() << reply->attribute(QNetworkRequest::HttpStatusCodeAttribute); jsonResponse = reply->readAll(); + //qDebug() << jsonResponse; emit responseReady(); }); } -QString RequestManager::getFromJson(QString json, QString member) +QString RequestManager::getFromJson(QString json, const QString &member) { QJsonParseError err; QJsonDocument document = QJsonDocument::fromJson(json.toUtf8(),&err); @@ -90,7 +91,7 @@ QString RequestManager::getFromJson(QString json, QString member) { qDebug() << err.errorString(); } - return document[member].toString(); + return document.object().value(member).toString(); } QString RequestManager::encryptedPassword(QString password) diff --git a/src/colnod/requestmanager.h b/src/colnod/requestmanager.h index e2b1923..b905c1c 100644 --- a/src/colnod/requestmanager.h +++ b/src/colnod/requestmanager.h @@ -34,7 +34,7 @@ public: QString getToken(){return token;} private: - QString getFromJson(QString json, QString member); + QString getFromJson(QString json, const QString &member); QString encryptedPassword(QString password); QString getLoginHeader(QString username, QString hash); void prepareAuthHeader(); diff --git a/test/unitTests/UnitTest.cpp b/test/unitTests/UnitTest.cpp index abf55aa..bf9fc29 100644 --- a/test/unitTests/UnitTest.cpp +++ b/test/unitTests/UnitTest.cpp @@ -12,7 +12,7 @@ void UnitTest::loginSuccessfully() QString json = testAccess->getResponse(); qDebug() << json; QJsonDocument doc = QJsonDocument::fromJson(json.toUtf8()); - QVERIFY2(doc["id"].isString(), "No parameter 'id' in response"); + QVERIFY2(doc.object().value("id").isString(), "No parameter 'id' in response"); } //POST request w/o datas @@ -28,9 +28,9 @@ void UnitTest::getSubjects() QString json = testAccess->getResponse(); QJsonDocument doc = QJsonDocument::fromJson(json.toUtf8()); QVERIFY(doc.isObject()); - QVERIFY2(doc["items"].isArray(), "No parameter 'id' in response"); - qDebug() << doc["items"].toArray()[0].toObject()["id"].toString(); - QVERIFY2(doc["items"].toArray()[0].toObject()["id"].isString(), "ada"); + 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"); } @@ -58,8 +58,8 @@ void UnitTest::getTokensOpenManager() QVERIFY(spy.isValid()); QCOMPARE(spy.count(), 1); QString response = testAccess->getResponse(); - QVERIFY(!response.isEmpty()); qDebug() << response; + QVERIFY(!response.isEmpty()); } diff --git a/test/unitTests/unittest.h b/test/unitTests/unittest.h index ae27657..e22c253 100644 --- a/test/unitTests/unittest.h +++ b/test/unitTests/unittest.h @@ -11,12 +11,10 @@ class UnitTest : public QObject private slots: - void loginSuccessfully(); - - - void getTokens(); - void getTokensOpenManager(); - void getSubjects(); + void loginSuccessfully(); // /AaaManager/authSession + void getSubjects(); // /SubjectManager/getSubjects + void getTokens(); // /TokenManager/getTokens + void getTokensOpenManager(); // /OpenManager/getTokenSubject private: // QString host = "https://localhost:8080"; //colnod server (ssh -L 8080:192.168.254.11:8443 penta-master) From 41fdabd5f6471a324c9c277c84f0d3a879f5a277 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20Fischer?= Date: Tue, 1 Oct 2019 16:11:17 +0200 Subject: [PATCH 03/12] Add classes to interpret data from colnod api --- src/colnod/colnod.pri | 10 +++- src/colnod/entity.cpp | 52 +++++++++++++++++ src/colnod/entity.h | 37 ++++++++++++ src/colnod/subject.cpp | 74 ++++++++++++++++++++++++ src/colnod/subject.h | 35 ++++++++++++ src/colnod/token.cpp | 108 ++++++++++++++++++++++++++++++++++++ src/colnod/token.h | 48 ++++++++++++++++ test/unitTests/UnitTest.cpp | 27 +++++++++ test/unitTests/unittest.h | 3 +- 9 files changed, 391 insertions(+), 3 deletions(-) create mode 100644 src/colnod/entity.cpp create mode 100644 src/colnod/entity.h create mode 100644 src/colnod/subject.cpp create mode 100644 src/colnod/subject.h create mode 100644 src/colnod/token.cpp create mode 100644 src/colnod/token.h diff --git a/src/colnod/colnod.pri b/src/colnod/colnod.pri index 29e82cd..e57065b 100644 --- a/src/colnod/colnod.pri +++ b/src/colnod/colnod.pri @@ -3,9 +3,15 @@ INCLUDEPATH += $$PWD message($$PWD) SOURCES += \ $$PWD/databasemanager.cpp \ - $$PWD/requestmanager.cpp + $$PWD/entity.cpp \ + $$PWD/requestmanager.cpp \ + $$PWD/subject.cpp \ + $$PWD/token.cpp HEADERS += \ $$PWD/databasemanager.h \ - $$PWD/requestmanager.h + $$PWD/entity.h \ + $$PWD/requestmanager.h \ + $$PWD/subject.h \ + $$PWD/token.h message($$SOURCES) diff --git a/src/colnod/entity.cpp b/src/colnod/entity.cpp new file mode 100644 index 0000000..f90314f --- /dev/null +++ b/src/colnod/entity.cpp @@ -0,0 +1,52 @@ +#include +#include "entity.h" + +const QUuid &Entity::getId() const { + return id; +} + +void Entity::setId(const QUuid &id) { + Entity::id = id; +} + +const QString &Entity::getName() const { + return name; +} + +void Entity::setName(const QString &name) { + Entity::name = name; +} + +const QString &Entity::getDescription() const { + return description; +} + +void Entity::setDescription(const QString &description) { + Entity::description = description; +} + +uint64_t Entity::getLastUpdate() const { + return lastUpdate; +} + +void Entity::setLastUpdate(uint64_t lastUpdate) { + this->lastUpdate = lastUpdate; +} + +void Entity::fromJSON(const QJsonObject &json) { + id = json.value("id").toString(); + name = json.value("name").toString(); + description = json.value("description").toString(); + lastUpdate = json.value("lastUpdate").toDouble(); +} + +QJsonObject Entity::toJSON() const { + QJsonObject json; + + json.value("id") = id.toString(QUuid::WithoutBraces); + json.value("name") = name; + json.value("description") = description; + json.value("lastUpdate") = lastUpdate; + + return json; +} diff --git a/src/colnod/entity.h b/src/colnod/entity.h new file mode 100644 index 0000000..e416b51 --- /dev/null +++ b/src/colnod/entity.h @@ -0,0 +1,37 @@ +#ifndef COLNOD_CONNECTOR_ENTITY_H +#define COLNOD_CONNECTOR_ENTITY_H + +#include +#include +#include + + +class Entity : public QObject { +Q_OBJECT +public: + using QObject::QObject; + + const QUuid &getId() const; + void setId(const QUuid &id); + + const QString &getName() const; + void setName(const QString &name); + + const QString &getDescription() const; + void setDescription(const QString &description); + + uint64_t getLastUpdate() const; + void setLastUpdate(uint64_t lastUpdate); + + virtual void fromJSON(const QJsonObject &json); + virtual QJsonObject toJSON() const; +protected: + QUuid id; + QString name; + QString description; + qint64 lastUpdate; +}; + + + +#endif //COLNOD_CONNECTOR_ENTITY_H diff --git a/src/colnod/subject.cpp b/src/colnod/subject.cpp new file mode 100644 index 0000000..1793f4e --- /dev/null +++ b/src/colnod/subject.cpp @@ -0,0 +1,74 @@ +#include + +#include "Subject.h" + +#include + +QString Subject::getEmail() const { + return attributes["email"].toString(); +} + +void Subject::fromJSON(const QJsonObject &json) { + Entity::fromJSON(json); + + attributes = json["attributes"]["items"].toObject(); + + attributes = json.value("attributes").toObject().value("items").toObject(); + + const auto &tokenFlagsArray = json.value("tokenFlags").toArray(); + for(const auto &flag : tokenFlagsArray){ + tokenFlags.insert(flag.toString()); + } + + pin = json.value("pin").toString(); + + const auto &pinFlagsArray = json.value("pinFlags").toArray(); + for(const auto &flag : pinFlagsArray){ + pinFlags.insert(flag.toString()); + } + +} + +QJsonObject Subject::toJSON() const { + QJsonObject json = Entity::toJSON(); + + QJsonObject items({{"items", attributes}}); + json.value("atributes") = items; + json.value("tokenFlags") = QJsonArray::fromStringList(tokenFlags.toList()); + json.value("pin") = pin; + json.value("pinFlags") = QJsonArray::fromStringList(pinFlags.toList()); + + return json; +} + +const QJsonObject &Subject::getAttributes() const { + return attributes; +} + +void Subject::setAttributes(const QJsonObject &attributes) { + Subject::attributes = attributes; +} + +const QSet &Subject::getTokenFlags() const { + return tokenFlags; +} + +void Subject::setTokenFlags(const QSet &tokenFlags) { + Subject::tokenFlags = tokenFlags; +} + +const QString &Subject::getPin() const { + return pin; +} + +void Subject::setPin(const QString &pin) { + Subject::pin = pin; +} + +const QSet &Subject::getPinFlags() const { + return pinFlags; +} + +void Subject::setPinFlags(const QSet &pinFlags) { + Subject::pinFlags = pinFlags; +} diff --git a/src/colnod/subject.h b/src/colnod/subject.h new file mode 100644 index 0000000..8659c11 --- /dev/null +++ b/src/colnod/subject.h @@ -0,0 +1,35 @@ +#ifndef COLNOD_CONNECTOR_SUBJECT_H +#define COLNOD_CONNECTOR_SUBJECT_H + +#include + +#include "entity.h" + + +class Subject : public Entity { + +public: + using Entity::Entity; + + QString getEmail() const; + + const QJsonObject &getAttributes() const; + void setAttributes(const QJsonObject &attributes); + const QSet &getTokenFlags() const; + void setTokenFlags(const QSet &tokenFlags); + const QString &getPin() const; + void setPin(const QString &pin); + const QSet &getPinFlags() const; + void setPinFlags(const QSet &pinFlags); + + void fromJSON(const QJsonObject &json) override; + QJsonObject toJSON() const override; +protected: + QJsonObject attributes; + QSet tokenFlags; + QString pin; + QSet pinFlags; +}; + + +#endif //COLNOD_CONNECTOR_SUBJECT_H diff --git a/src/colnod/token.cpp b/src/colnod/token.cpp new file mode 100644 index 0000000..cf07779 --- /dev/null +++ b/src/colnod/token.cpp @@ -0,0 +1,108 @@ +#include "token.h" + +#include + +void Token::fromJSON(const QJsonObject &json) { + Entity::fromJSON(json); + + tokenType = json.value("tokenType").toString(); + tokenBits = json.value("tokenBits").toInt(); + tokenData = json.value("tokenData").toString(); + validFrom = json.value("validFrom").toDouble(); + validTo = json.value("validTo").toDouble(); + timeToLive = json.value("timeToLive").toInt(); + authErrors = json["authErrors"].toInt(); + const auto &flagsArray = json["flags"].toArray(); + for(const auto &flag : flagsArray){ + flags.insert(flag.toString()); + } + subjectId = json.value("subjectId").toString(); +} + +QJsonObject Token::toJSON() const { + QJsonObject json = Entity::toJSON(); + + json.value("tokenType") = tokenType; + json.value("tokenBits") = tokenBits; + json.value("tokenData") = tokenData; + json.value("validFrom") = validFrom; + json.value("validTo") = validTo; + json.value("timeToLive") = timeToLive; + json.value("authErrors") = authErrors; + json.value("flags") = QJsonArray::fromStringList(flags.toList()); + json.value("subjectId") = subjectId.toString(QUuid::WithoutBraces); + + return json; +} + +const QString &Token::getTokenType() const { + return tokenType; +} + +void Token::setTokenType(const QString &tokenType) { + Token::tokenType = tokenType; +} + +int Token::getTokenBits() const { + return tokenBits; +} + +void Token::setTokenBits(int tokenBits) { + Token::tokenBits = tokenBits; +} + +const QString &Token::getTokenData() const { + return tokenData; +} + +void Token::setTokenData(const QString &tokenData) { + Token::tokenData = tokenData; +} + +qint64 Token::getValidFrom() const { + return validFrom; +} + +void Token::setValidFrom(qint64 validFrom) { + Token::validFrom = validFrom; +} + +qint64 Token::getValidTo() const { + return validTo; +} + +void Token::setValidTo(qint64 validTo) { + Token::validTo = validTo; +} + +int Token::getTimeToLive() const { + return timeToLive; +} + +void Token::setTimeToLive(int timeToLive) { + Token::timeToLive = timeToLive; +} + +int Token::getAuthErrors() const { + return authErrors; +} + +void Token::setAuthErrors(int authErrors) { + Token::authErrors = authErrors; +} + +const QSet &Token::getFlags() const { + return flags; +} + +void Token::setFlags(const QSet &flags) { + Token::flags = flags; +} + +const QUuid &Token::getSubjectId() const { + return subjectId; +} + +void Token::setSubjectId(const QUuid &subjectId) { + Token::subjectId = subjectId; +} diff --git a/src/colnod/token.h b/src/colnod/token.h new file mode 100644 index 0000000..fe06222 --- /dev/null +++ b/src/colnod/token.h @@ -0,0 +1,48 @@ +#ifndef COLNOD_CONNECTOR_TOKEN_H +#define COLNOD_CONNECTOR_TOKEN_H + +#include "entity.h" + +#include + + +class Token : public Entity { +public: + // using Entity::Entity; + + const QString &getTokenType() const; + void setTokenType(const QString &tokenType); + int getTokenBits() const; + void setTokenBits(int tokenBits); + const QString &getTokenData() const; + void setTokenData(const QString &tokenData); + qint64 getValidFrom() const; + void setValidFrom(qint64 validFrom); + qint64 getValidTo() const; + void setValidTo(qint64 validTo); + int getTimeToLive() const; + void setTimeToLive(int timeToLive); + int getAuthErrors() const; + void setAuthErrors(int authErrors); + const QSet &getFlags() const; + void setFlags(const QSet &flags); + const QUuid &getSubjectId() const; + void setSubjectId(const QUuid &subjectId); + + + void fromJSON(const QJsonObject &json) override; + QJsonObject toJSON() const override; +protected: + QString tokenType; + int tokenBits; + QString tokenData; + qint64 validFrom; + qint64 validTo; + int timeToLive; + int authErrors; + QSet flags; + QUuid subjectId; +}; + + +#endif //COLNOD_CONNECTOR_TOKEN_H diff --git a/test/unitTests/UnitTest.cpp b/test/unitTests/UnitTest.cpp index bf9fc29..b500937 100644 --- a/test/unitTests/UnitTest.cpp +++ b/test/unitTests/UnitTest.cpp @@ -62,5 +62,32 @@ void UnitTest::getTokensOpenManager() QVERIFY(!response.isEmpty()); } +void UnitTest::subjectJSONParser() +{ + QFile jsonData(QDir::current().filePath("subjects.json")); + + if (!jsonData.open(QIODevice::ReadOnly)) { + qCritical() << "Couldn't open config file config.json" << QDir::current().filePath("subjects.json"); + QCoreApplication::exit(-1); + return; + } + + QJsonDocument doc = QJsonDocument::fromJson(jsonData.readAll()); + QJsonObject obj = doc.object(); + QJsonArray arr = obj["items"].toArray(); + /* + for(auto item : arr) + { + auto subject = new Subject(); + subject->fromJSON(item.toObject()); + }*/ + auto testSubject = new Subject(); + testSubject->fromJSON(arr[1].toObject()); + qDebug() << testSubject->getEmail(); + qDebug() << testSubject->getName(); + + QVERIFY(true); +} + QTEST_MAIN(UnitTest) diff --git a/test/unitTests/unittest.h b/test/unitTests/unittest.h index e22c253..66d5cf3 100644 --- a/test/unitTests/unittest.h +++ b/test/unitTests/unittest.h @@ -3,6 +3,7 @@ #include #include #include +#include "subject.h" class UnitTest : public QObject @@ -15,7 +16,7 @@ private slots: void getSubjects(); // /SubjectManager/getSubjects void getTokens(); // /TokenManager/getTokens void getTokensOpenManager(); // /OpenManager/getTokenSubject - + void subjectJSONParser(); private: // QString host = "https://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 From 06e5d7a9c432ba79bf20cd29a3987f7675cdea3f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20Fischer?= Date: Wed, 2 Oct 2019 11:31:51 +0200 Subject: [PATCH 04/12] Add test for subject JSON parser --- src/colnod/requestmanager.cpp | 14 -------------- test/unitTests/UnitTest.cpp | 21 ++++++++++++--------- 2 files changed, 12 insertions(+), 23 deletions(-) diff --git a/src/colnod/requestmanager.cpp b/src/colnod/requestmanager.cpp index 0e70863..9704302 100644 --- a/src/colnod/requestmanager.cpp +++ b/src/colnod/requestmanager.cpp @@ -63,22 +63,8 @@ void RequestManager::getRequest(QString endpoint) qDebug() << reply->readAll(); return; } - - //print reply info - auto items = reply->rawHeaderPairs(); - for (auto item : items) - { - qDebug() << item; - } - auto reqHeaderName = reply->request().rawHeaderList(); - for (QString header : reqHeaderName) - { - qDebug() << reply->request().rawHeader(header.toUtf8()); - } qDebug() << reply->attribute(QNetworkRequest::HttpStatusCodeAttribute); - jsonResponse = reply->readAll(); - //qDebug() << jsonResponse; emit responseReady(); }); } diff --git a/test/unitTests/UnitTest.cpp b/test/unitTests/UnitTest.cpp index b500937..902dad0 100644 --- a/test/unitTests/UnitTest.cpp +++ b/test/unitTests/UnitTest.cpp @@ -64,6 +64,7 @@ void UnitTest::getTokensOpenManager() void UnitTest::subjectJSONParser() { + /* QFile jsonData(QDir::current().filePath("subjects.json")); if (!jsonData.open(QIODevice::ReadOnly)) { @@ -75,18 +76,20 @@ void UnitTest::subjectJSONParser() QJsonDocument doc = QJsonDocument::fromJson(jsonData.readAll()); QJsonObject obj = doc.object(); QJsonArray arr = obj["items"].toArray(); - /* - for(auto item : arr) - { - auto subject = new Subject(); - subject->fromJSON(item.toObject()); - }*/ + */ + + RequestManager* testAccess = new RequestManager(); + testAccess->login(host, email, password); + QSignalSpy spy(testAccess, SIGNAL(responseReady())); + testAccess->getRequest("/SubjectManager/getSubjects"); + spy.wait(); + QString response = testAccess->getResponse(); + QJsonDocument doc = QJsonDocument::fromJson(response.toUtf8()); + QJsonArray arr = doc.object()["items"].toArray(); auto testSubject = new Subject(); testSubject->fromJSON(arr[1].toObject()); - qDebug() << testSubject->getEmail(); qDebug() << testSubject->getName(); - - QVERIFY(true); + QVERIFY(!testSubject->getName().isEmpty()); } From d16b8e67ba1d6de8f2405903938e348db645e638 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20Fischer?= Date: Wed, 2 Oct 2019 17:17:54 +0200 Subject: [PATCH 05/12] Add class for proccesing data --- src/colnod/colnod.pri | 2 ++ src/colnod/databasemanager.cpp | 18 ++++++++--- src/colnod/databasemanager.h | 17 ++++++++-- src/colnod/dataprocessor.cpp | 56 ++++++++++++++++++++++++++++++++ src/colnod/dataprocessor.h | 41 ++++++++++++++++++++++++ src/colnod/requestmanager.cpp | 18 ++++++++++- src/colnod/requestmanager.h | 16 ++++++++-- src/config.json | 4 +-- src/subjects.json | 58 ++++++++++++++++++++++++++++++++++ test/unitTests/UnitTest.cpp | 37 +++++++++++++++++++--- test/unitTests/config.json | 5 --- test/unitTests/unittest.h | 4 +++ 12 files changed, 253 insertions(+), 23 deletions(-) create mode 100644 src/colnod/dataprocessor.cpp create mode 100644 src/colnod/dataprocessor.h create mode 100644 src/subjects.json delete mode 100644 test/unitTests/config.json diff --git a/src/colnod/colnod.pri b/src/colnod/colnod.pri index e57065b..21bb360 100644 --- a/src/colnod/colnod.pri +++ b/src/colnod/colnod.pri @@ -3,6 +3,7 @@ INCLUDEPATH += $$PWD message($$PWD) SOURCES += \ $$PWD/databasemanager.cpp \ + $$PWD/dataprocessor.cpp \ $$PWD/entity.cpp \ $$PWD/requestmanager.cpp \ $$PWD/subject.cpp \ @@ -10,6 +11,7 @@ SOURCES += \ HEADERS += \ $$PWD/databasemanager.h \ + $$PWD/dataprocessor.h \ $$PWD/entity.h \ $$PWD/requestmanager.h \ $$PWD/subject.h \ diff --git a/src/colnod/databasemanager.cpp b/src/colnod/databasemanager.cpp index c9ae476..5fae9e4 100644 --- a/src/colnod/databasemanager.cpp +++ b/src/colnod/databasemanager.cpp @@ -1,19 +1,29 @@ #include "databasemanager.h" -DatabaseManager::DatabaseManager(QString dbName, QString user, QString password) +DatabaseManager::DatabaseManager(QString host, QString dbName, QString user, QString password) { db = QSqlDatabase::addDatabase("QPSQL"); db.setDatabaseName(dbName); - db.setHostName("localhost"); - //db.setHostName("192.168.1.201"); + db.setHostName(host); db.setUserName(user); db.setPassword(password); - if (!db.open()) + opened = db.open(); + if (!opened) { qDebug() << "Opening error" + db.lastError().text(); } query = QSqlQuery("query", db); } +void DatabaseManager::saveSubject(Subject subject, QString table) +{ + //TODO +} + +void DatabaseManager::saveToken(Subject subject, QString table) +{ + //TODO +} + diff --git a/src/colnod/databasemanager.h b/src/colnod/databasemanager.h index dcaa616..3cc175c 100644 --- a/src/colnod/databasemanager.h +++ b/src/colnod/databasemanager.h @@ -7,17 +7,28 @@ #include #include +#include "subject.h" +#include "token.h" - -class DatabaseManager +class DatabaseManager : public QObject { + Q_OBJECT public: - DatabaseManager(QString dbName, QString user, QString password); + DatabaseManager(QString host, QString dbName, QString user, QString password); + + void saveSubject(Subject subject, QString table); + void saveToken(Subject subject, QString table); + + bool getOpened() {return opened;} private: QSqlDatabase db; QSqlQuery query; + + bool opened; + + }; #endif // DATABASEMANAGER_H diff --git a/src/colnod/dataprocessor.cpp b/src/colnod/dataprocessor.cpp new file mode 100644 index 0000000..efcd9f6 --- /dev/null +++ b/src/colnod/dataprocessor.cpp @@ -0,0 +1,56 @@ +#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(); +} diff --git a/src/colnod/dataprocessor.h b/src/colnod/dataprocessor.h new file mode 100644 index 0000000..54554bf --- /dev/null +++ b/src/colnod/dataprocessor.h @@ -0,0 +1,41 @@ +#ifndef DATAPROCESSOR_H +#define DATAPROCESSOR_H + +#include "token.h" +#include "subject.h" +#include "requestmanager.h" +#include "databasemanager.h" +#include +#include + + + +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 diff --git a/src/colnod/requestmanager.cpp b/src/colnod/requestmanager.cpp index 9704302..2f4c7a1 100644 --- a/src/colnod/requestmanager.cpp +++ b/src/colnod/requestmanager.cpp @@ -6,6 +6,8 @@ RequestManager::RequestManager() token = ""; loginStatus = false; + + QFile configFile(QDir::current().filePath("config.json")); if (!configFile.open(QIODevice::ReadOnly)) { @@ -40,11 +42,11 @@ void RequestManager::login(QString host, QString username, QString password) { qDebug() << reply->errorString(); loginStatus = false; - qDebug() << reply->readAll(); return; } jsonResponse = reply->readAll(); prepareAuthHeader(); + loginStatus = true; emit successLogin(); reply->deleteLater(); }); @@ -52,6 +54,13 @@ void RequestManager::login(QString host, QString username, QString password) void 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(); + } QNetworkRequest request; request.setUrl(host + endpoint); request.setRawHeader("Authorization", authHeader.toLocal8Bit()); @@ -61,6 +70,8 @@ void RequestManager::getRequest(QString endpoint) { qDebug() << reply->errorString(); qDebug() << reply->readAll(); + loginStatus = false; + getRequest(endpoint); return; } qDebug() << reply->attribute(QNetworkRequest::HttpStatusCodeAttribute); @@ -109,3 +120,8 @@ void RequestManager::onSSLError(QNetworkReply *reply, const QList &er } } + +void RequestManager::getSubjects() +{ + getRequest("/SubjectManager/getSubjects"); +} diff --git a/src/colnod/requestmanager.h b/src/colnod/requestmanager.h index b905c1c..cf5ecf3 100644 --- a/src/colnod/requestmanager.h +++ b/src/colnod/requestmanager.h @@ -20,24 +20,35 @@ #include #include + +#include "databasemanager.h" +#include "token.h" +#include "subject.h" + class RequestManager : public QObject { Q_OBJECT public: RequestManager(); + void getSubjects(); void login(QString endpoint, QString username, QString password); void getRequest(QString endpoint); - void fetchSubjects(QString endpoint); + void loadSubjectsFromColnodToDB(); + + + const QJsonDocument &getConfig() const {return config;} const QString &getResponse() const {return jsonResponse;} QString getToken(){return token;} + private: QString getFromJson(QString json, const QString &member); QString encryptedPassword(QString password); QString getLoginHeader(QString username, QString hash); void prepareAuthHeader(); + private slots: void onSSLError(QNetworkReply *reply, const QList &errors); @@ -48,14 +59,13 @@ signals: private: QNetworkAccessManager* manager; - QJsonDocument config; QString authHeader; QString host; QString token; QString jsonResponse; bool loginStatus; - QString tenant; + }; diff --git a/src/config.json b/src/config.json index 7ac48e0..371838d 100644 --- a/src/config.json +++ b/src/config.json @@ -1,5 +1,5 @@ { - "host": "https://localhost:8080", + "host": "https://192.168.1.3", "username": "spaceti", - "password": "SuperSecretPassword" + "password": "spaceti1" } \ No newline at end of file diff --git a/src/subjects.json b/src/subjects.json new file mode 100644 index 0000000..e96cb2f --- /dev/null +++ b/src/subjects.json @@ -0,0 +1,58 @@ +{ + "items":[ + { + "id":"6d809c12-3255-4b0a-bf8f-3af86912a40f", + "name":"Person2", + "description":"", + "lastUpdate":1543843828247, + "attributes":{ + "items":{ + + } + }, + "tokenFlags":[ + "NoPin" + ], + "pin":"", + "pinFlags":[ + "Access" + ] + }, + { + "id":"1a23c502-1665-4492-94ea-039bb7505cae", + "name":"Person3", + "description":"", + "lastUpdate":1553868160516, + "attributes":{ + "items":{ + "email":"person3@gmail.com" + } + }, + "tokenFlags":[ + "NoPin" + ], + "pin":"", + "pinFlags":[ + "Access" + ] + }, + { + "id":"7ad58bd8-a1ec-40b4-a54f-347ee6a4ba29", + "name":"Person1", + "description":"", + "lastUpdate":1560786050717, + "attributes":{ + "items":{ + "email":"person1@gmail.com" + } + }, + "tokenFlags":[ + "NoPin" + ], + "pin":"", + "pinFlags":[ + "Access" + ] + } + ] + } \ No newline at end of file diff --git a/test/unitTests/UnitTest.cpp b/test/unitTests/UnitTest.cpp index 902dad0..7b5fe85 100644 --- a/test/unitTests/UnitTest.cpp +++ b/test/unitTests/UnitTest.cpp @@ -19,7 +19,7 @@ void UnitTest::loginSuccessfully() void UnitTest::getSubjects() { RequestManager* testAccess = new RequestManager(); - testAccess->login(host, email, password); + // testAccess->login(host, email, password); QSignalSpy spy(testAccess, SIGNAL(responseReady())); testAccess->getRequest("/SubjectManager/getSubjects"); spy.wait(); @@ -37,7 +37,7 @@ void UnitTest::getSubjects() void UnitTest::getTokens() { RequestManager* testAccess = new RequestManager(); - testAccess->login(host, email, password); + // testAccess->login(host, email, password); QSignalSpy spy(testAccess, SIGNAL(responseReady())); testAccess->getRequest("/TokenManager/getTokens"); QCOMPARE(spy.count(), 0); @@ -50,7 +50,7 @@ void UnitTest::getTokens() void UnitTest::getTokensOpenManager() { RequestManager* testAccess = new RequestManager(); - testAccess->login(host, email, password); + // testAccess->login(host, email, password); QSignalSpy spy(testAccess, SIGNAL(responseReady())); testAccess->getRequest("/OpenManager/getTokenSubject"); QCOMPARE(spy.count(), 0); @@ -79,7 +79,7 @@ void UnitTest::subjectJSONParser() */ RequestManager* testAccess = new RequestManager(); - testAccess->login(host, email, password); + // testAccess->login(host, email, password); QSignalSpy spy(testAccess, SIGNAL(responseReady())); testAccess->getRequest("/SubjectManager/getSubjects"); spy.wait(); @@ -88,9 +88,36 @@ void UnitTest::subjectJSONParser() QJsonArray arr = doc.object()["items"].toArray(); auto testSubject = new Subject(); testSubject->fromJSON(arr[1].toObject()); - qDebug() << testSubject->getName(); + qDebug() << testSubject->getName() << " Size: " << arr.size(); QVERIFY(!testSubject->getName().isEmpty()); } +void UnitTest::tokenJSONParser() +{ + RequestManager* testAccess = new RequestManager(); + // testAccess->login(host, email, password); + QSignalSpy spy(testAccess, SIGNAL(responseReady())); + testAccess->getRequest("/TokenManager/getTokens"); + spy.wait(); + QString response = testAccess->getResponse(); + + //TODO + /* QJsonDocument doc = QJsonDocument::fromJson(response.toUtf8()); + QJsonArray arr = doc.object()["items"].toArray(); + auto testSubject = new Subject(); + testSubject->fromJSON(arr[1].toObject()); + qDebug() << testSubject->getName(); + QVERIFY(!testSubject->getName().isEmpty());*/ + QVERIFY(true); + +} + +void UnitTest::connectToDB() +{ + DatabaseManager *db = new DatabaseManager("192.168.1.94", "deloitte", "postgres", "34rjkciea12"); + QVERIFY(db->getOpened()); + QVERIFY(true); + +} QTEST_MAIN(UnitTest) diff --git a/test/unitTests/config.json b/test/unitTests/config.json deleted file mode 100644 index 7ac48e0..0000000 --- a/test/unitTests/config.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "host": "https://localhost:8080", - "username": "spaceti", - "password": "SuperSecretPassword" -} \ No newline at end of file diff --git a/test/unitTests/unittest.h b/test/unitTests/unittest.h index 66d5cf3..3444490 100644 --- a/test/unitTests/unittest.h +++ b/test/unitTests/unittest.h @@ -4,6 +4,7 @@ #include #include #include "subject.h" +#include "databasemanager.h" class UnitTest : public QObject @@ -17,6 +18,9 @@ private slots: void getTokens(); // /TokenManager/getTokens void getTokensOpenManager(); // /OpenManager/getTokenSubject void subjectJSONParser(); + void tokenJSONParser(); + void connectToDB(); + private: // QString host = "https://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 From 62343bb0b8e2cd602d0ba1ce675eefb1b2aa39d0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20Fischer?= Date: Thu, 3 Oct 2019 12:25:10 +0200 Subject: [PATCH 06/12] Lot of little changes mostly because of testing --- Insomnia_2019-10-01.yaml | 480 +++++++++++++++--------------- Insomnia_2019-10-02.yaml | 540 +++++++++++++++++----------------- curl/subjects.sh | 14 +- curl/tokens.sh | 14 +- curl/tokenssubjects.sh | 12 +- src/colnod/requestmanager.cpp | 267 +++++++++-------- src/colnod/subject.cpp | 148 +++++----- test/unitTests/UnitTest.cpp | 247 ++++++++-------- test/unitTests/config.json | 5 + test/unitTests/unittest.h | 58 ++-- 10 files changed, 902 insertions(+), 883 deletions(-) create mode 100644 test/unitTests/config.json diff --git a/Insomnia_2019-10-01.yaml b/Insomnia_2019-10-01.yaml index 4bf5d6c..2b5cc16 100644 --- a/Insomnia_2019-10-01.yaml +++ b/Insomnia_2019-10-01.yaml @@ -1,240 +1,240 @@ -_type: export -__export_format: 4 -__export_date: 2019-10-01T14:13:03.279Z -__export_source: insomnia.desktop.app:v6.6.2 -resources: - - _id: req_f0797b6411b144f0bf0a40d9300ee92f - authentication: - disabled: false - password: E7FEA07DBC82FB9BA34B2E453E2EFE89F0583E7187543507EF11E84726071FE428445372F2E46B455EB0C79747C51E362F403CE39473A2A8C2DFA0CE5C9826C0 - type: basic - username: spaceti - body: - mimeType: application/json - text: >- - { - "username": "spaceti", - "password": "E7FEA07DBC82FB9BA34B2E453E2EFE89F0583E7187543507EF11E84726071FE428445372F2E46B455EB0C79747C51E362F403CE39473A2A8C2DFA0CE5C9826C0" - } - created: 1569905755136 - description: "" - headers: - - id: pair_061d15d1294e412caca8300559541695 - name: content-type - value: application/json - isPrivate: false - metaSortKey: -1569905755136 - method: POST - modified: 1569934518963 - name: Login user - parameters: [] - parentId: fld_9ef1d96e0e6d40ef9094250114269496 - settingDisableRenderRequestBody: false - settingEncodeUrl: true - settingRebuildPath: true - settingSendCookies: true - settingStoreCookies: true - url: "{{ base_url }}/AaaManager/authSession" - _type: request - - _id: fld_9ef1d96e0e6d40ef9094250114269496 - created: 1569905755142 - description: Login information ( token ) - environment: {} - environmentPropertyOrder: null - metaSortKey: -1569905755142 - modified: 1569905755142 - name: login - parentId: wrk_43652e59afaf4825a8bbbf31e346f616 - _type: request_group - - _id: wrk_43652e59afaf4825a8bbbf31e346f616 - created: 1569905755149 - description: "Colnod system: [Product information](http://produkty.colsys.cz/colnod) - Jira issues: [Communicaiton with - Colnod](https://spaceti.atlassian.net/secure/RapidBoard.jspa?rapidView=78\ - &projectKey=INT&modal=detail&selectedIssue=INT-3563)" - modified: 1569905755149 - name: Colnod server 1.0.0 - parentId: null - _type: workspace - - _id: req_00f9f99d933c4638900385ffbbd4f8f7 - authentication: - disabled: false - token: "{% response 'body', 'req_f0797b6411b144f0bf0a40d9300ee92f', - 'b64::JC5pZA==::46b', 'never' %}" - type: bearer - body: - mimeType: application/json - text: "" - created: 1569905755134 - description: "" - headers: - - id: pair_a2a3c43a20f64efbb8a4752c7e983c8e - name: Content-Type - value: application/json - isPrivate: false - metaSortKey: -1569905755134 - method: POST - modified: 1569937805044 - name: Get subjects - parameters: [] - parentId: fld_2fb4c2cef1f44cff83d6b00fe0886384 - settingDisableRenderRequestBody: false - settingEncodeUrl: true - settingRebuildPath: true - settingSendCookies: true - settingStoreCookies: true - url: "{{ base_url }}/SubjectManager/getSubjects" - _type: request - - _id: fld_2fb4c2cef1f44cff83d6b00fe0886384 - created: 1569905755140 - description: Operations about user - environment: {} - environmentPropertyOrder: null - metaSortKey: -1569905755140 - modified: 1569905755140 - name: user - parentId: wrk_43652e59afaf4825a8bbbf31e346f616 - _type: request_group - - _id: req_9e42a5023f9d4235a5de099cd7573d2b - authentication: - token: "{% response 'body', 'req_f0797b6411b144f0bf0a40d9300ee92f', - 'b64::JC5pZA==::46b', 'never' %}" - type: bearer - body: - mimeType: application/json - text: |- - { - "id": "1a23c502-1665-4492-94ea-039bb7505cae" - } - created: 1569905755131 - description: "" - headers: - - disabled: false - id: pair_e888b6c679d74b0988f0dd2d77690383 - name: Content-Type - value: application/json - isPrivate: false - metaSortKey: -1569905755131 - method: POST - modified: 1569939013152 - name: Get Tokens - parameters: [] - parentId: fld_36a4be72380440a0ace83ad508a0458d - settingDisableRenderRequestBody: false - settingEncodeUrl: true - settingRebuildPath: true - settingSendCookies: true - settingStoreCookies: true - url: "{{ base_url }}/TokenManager/getTokens/" - _type: request - - _id: fld_36a4be72380440a0ace83ad508a0458d - created: 1569905755138 - description: Working with tokens ( keys ) - environment: {} - environmentPropertyOrder: null - metaSortKey: -1569905755138 - modified: 1569934361048 - name: Token Manager - parentId: wrk_43652e59afaf4825a8bbbf31e346f616 - _type: request_group - - _id: req_4f99d61a83c14da29882cc80c07ddf54 - authentication: - token: "{% response 'body', 'req_f0797b6411b144f0bf0a40d9300ee92f', - 'b64::JC5pZA==::46b', 'never' %}" - type: bearer - body: {} - created: 1569905755127 - description: "" - headers: [] - isPrivate: false - metaSortKey: -1569905755129 - method: POST - modified: 1569938955854 - name: Set Tokens - parameters: [] - parentId: fld_36a4be72380440a0ace83ad508a0458d - settingDisableRenderRequestBody: false - settingEncodeUrl: true - settingRebuildPath: true - settingSendCookies: true - settingStoreCookies: true - url: /TokenManager/setTokens - _type: request - - _id: req_fd2e096f45554b46b31755564a0932bf - authentication: - token: "{% response 'body', 'req_f0797b6411b144f0bf0a40d9300ee92f', - 'b64::JC5pZA==::46b', 'never' %}" - type: bearer - body: {} - created: 1569934364782 - description: "" - headers: [] - isPrivate: false - metaSortKey: -1569905755130.5 - method: POST - modified: 1569937740242 - name: Get Token Subject - parameters: [] - parentId: fld_8d34eca167ef426c8aa998c98bbe74e2 - settingDisableRenderRequestBody: false - settingEncodeUrl: true - settingRebuildPath: true - settingSendCookies: true - settingStoreCookies: true - url: "{{ base_url }}/OpenManager/getTokenSubject" - _type: request - - _id: fld_8d34eca167ef426c8aa998c98bbe74e2 - created: 1569934364777 - description: Working with tokens ( keys ) - environment: {} - environmentPropertyOrder: null - metaSortKey: -1569905755088 - modified: 1569934370959 - name: Open Manager - parentId: wrk_43652e59afaf4825a8bbbf31e346f616 - _type: request_group - - _id: env_7bc4918f1ec5467393a2ab36a460e4d0 - color: null - created: 1569905755147 - data: - base_url: "{{ scheme }}://{{ host }}{{ base_path }}" - dataPropertyOrder: - "&": - - base_url - isPrivate: false - metaSortKey: 1569905755147 - modified: 1569905805832 - name: Base environment - parentId: wrk_43652e59afaf4825a8bbbf31e346f616 - _type: environment - - _id: jar_61bbb3fdc5ee80a49ee817b3e5341053a6022960 - cookies: - - creation: 2019-10-01T04:57:46.521Z - domain: 192.168.1.3 - hostOnly: true - httpOnly: true - id: "40058861704510274" - key: JSESSIONID - lastAccessed: 2019-10-01T14:08:27.635Z - path: / - secure: true - value: 2A63FF79AC604DB88D26DE41876B8B88 - created: 1569905764431 - modified: 1569938907635 - name: Default Jar - parentId: wrk_43652e59afaf4825a8bbbf31e346f616 - _type: cookie_jar - - _id: env_92b9543a27e847689c951d1b1eeff229 - color: "#cb5dc2" - created: 1569905755144 - data: - base_path: / - host: 192.168.1.3:8443 - scheme: https - dataPropertyOrder: null - isPrivate: false - metaSortKey: 1569905755144 - modified: 1569935791597 - name: colnod-test - parentId: env_7bc4918f1ec5467393a2ab36a460e4d0 - _type: environment +_type: export +__export_format: 4 +__export_date: 2019-10-01T14:13:03.279Z +__export_source: insomnia.desktop.app:v6.6.2 +resources: + - _id: req_f0797b6411b144f0bf0a40d9300ee92f + authentication: + disabled: false + password: E7FEA07DBC82FB9BA34B2E453E2EFE89F0583E7187543507EF11E84726071FE428445372F2E46B455EB0C79747C51E362F403CE39473A2A8C2DFA0CE5C9826C0 + type: basic + username: spaceti + body: + mimeType: application/json + text: >- + { + "username": "spaceti", + "password": "E7FEA07DBC82FB9BA34B2E453E2EFE89F0583E7187543507EF11E84726071FE428445372F2E46B455EB0C79747C51E362F403CE39473A2A8C2DFA0CE5C9826C0" + } + created: 1569905755136 + description: "" + headers: + - id: pair_061d15d1294e412caca8300559541695 + name: content-type + value: application/json + isPrivate: false + metaSortKey: -1569905755136 + method: POST + modified: 1569934518963 + name: Login user + parameters: [] + parentId: fld_9ef1d96e0e6d40ef9094250114269496 + settingDisableRenderRequestBody: false + settingEncodeUrl: true + settingRebuildPath: true + settingSendCookies: true + settingStoreCookies: true + url: "{{ base_url }}/AaaManager/authSession" + _type: request + - _id: fld_9ef1d96e0e6d40ef9094250114269496 + created: 1569905755142 + description: Login information ( token ) + environment: {} + environmentPropertyOrder: null + metaSortKey: -1569905755142 + modified: 1569905755142 + name: login + parentId: wrk_43652e59afaf4825a8bbbf31e346f616 + _type: request_group + - _id: wrk_43652e59afaf4825a8bbbf31e346f616 + created: 1569905755149 + description: "Colnod system: [Product information](http://produkty.colsys.cz/colnod) + Jira issues: [Communicaiton with + Colnod](https://spaceti.atlassian.net/secure/RapidBoard.jspa?rapidView=78\ + &projectKey=INT&modal=detail&selectedIssue=INT-3563)" + modified: 1569905755149 + name: Colnod server 1.0.0 + parentId: null + _type: workspace + - _id: req_00f9f99d933c4638900385ffbbd4f8f7 + authentication: + disabled: false + token: "{% response 'body', 'req_f0797b6411b144f0bf0a40d9300ee92f', + 'b64::JC5pZA==::46b', 'never' %}" + type: bearer + body: + mimeType: application/json + text: "" + created: 1569905755134 + description: "" + headers: + - id: pair_a2a3c43a20f64efbb8a4752c7e983c8e + name: Content-Type + value: application/json + isPrivate: false + metaSortKey: -1569905755134 + method: POST + modified: 1569937805044 + name: Get subjects + parameters: [] + parentId: fld_2fb4c2cef1f44cff83d6b00fe0886384 + settingDisableRenderRequestBody: false + settingEncodeUrl: true + settingRebuildPath: true + settingSendCookies: true + settingStoreCookies: true + url: "{{ base_url }}/SubjectManager/getSubjects" + _type: request + - _id: fld_2fb4c2cef1f44cff83d6b00fe0886384 + created: 1569905755140 + description: Operations about user + environment: {} + environmentPropertyOrder: null + metaSortKey: -1569905755140 + modified: 1569905755140 + name: user + parentId: wrk_43652e59afaf4825a8bbbf31e346f616 + _type: request_group + - _id: req_9e42a5023f9d4235a5de099cd7573d2b + authentication: + token: "{% response 'body', 'req_f0797b6411b144f0bf0a40d9300ee92f', + 'b64::JC5pZA==::46b', 'never' %}" + type: bearer + body: + mimeType: application/json + text: |- + { + "id": "1a23c502-1665-4492-94ea-039bb7505cae" + } + created: 1569905755131 + description: "" + headers: + - disabled: false + id: pair_e888b6c679d74b0988f0dd2d77690383 + name: Content-Type + value: application/json + isPrivate: false + metaSortKey: -1569905755131 + method: POST + modified: 1569939013152 + name: Get Tokens + parameters: [] + parentId: fld_36a4be72380440a0ace83ad508a0458d + settingDisableRenderRequestBody: false + settingEncodeUrl: true + settingRebuildPath: true + settingSendCookies: true + settingStoreCookies: true + url: "{{ base_url }}/TokenManager/getTokens/" + _type: request + - _id: fld_36a4be72380440a0ace83ad508a0458d + created: 1569905755138 + description: Working with tokens ( keys ) + environment: {} + environmentPropertyOrder: null + metaSortKey: -1569905755138 + modified: 1569934361048 + name: Token Manager + parentId: wrk_43652e59afaf4825a8bbbf31e346f616 + _type: request_group + - _id: req_4f99d61a83c14da29882cc80c07ddf54 + authentication: + token: "{% response 'body', 'req_f0797b6411b144f0bf0a40d9300ee92f', + 'b64::JC5pZA==::46b', 'never' %}" + type: bearer + body: {} + created: 1569905755127 + description: "" + headers: [] + isPrivate: false + metaSortKey: -1569905755129 + method: POST + modified: 1569938955854 + name: Set Tokens + parameters: [] + parentId: fld_36a4be72380440a0ace83ad508a0458d + settingDisableRenderRequestBody: false + settingEncodeUrl: true + settingRebuildPath: true + settingSendCookies: true + settingStoreCookies: true + url: /TokenManager/setTokens + _type: request + - _id: req_fd2e096f45554b46b31755564a0932bf + authentication: + token: "{% response 'body', 'req_f0797b6411b144f0bf0a40d9300ee92f', + 'b64::JC5pZA==::46b', 'never' %}" + type: bearer + body: {} + created: 1569934364782 + description: "" + headers: [] + isPrivate: false + metaSortKey: -1569905755130.5 + method: POST + modified: 1569937740242 + name: Get Token Subject + parameters: [] + parentId: fld_8d34eca167ef426c8aa998c98bbe74e2 + settingDisableRenderRequestBody: false + settingEncodeUrl: true + settingRebuildPath: true + settingSendCookies: true + settingStoreCookies: true + url: "{{ base_url }}/OpenManager/getTokenSubject" + _type: request + - _id: fld_8d34eca167ef426c8aa998c98bbe74e2 + created: 1569934364777 + description: Working with tokens ( keys ) + environment: {} + environmentPropertyOrder: null + metaSortKey: -1569905755088 + modified: 1569934370959 + name: Open Manager + parentId: wrk_43652e59afaf4825a8bbbf31e346f616 + _type: request_group + - _id: env_7bc4918f1ec5467393a2ab36a460e4d0 + color: null + created: 1569905755147 + data: + base_url: "{{ scheme }}://{{ host }}{{ base_path }}" + dataPropertyOrder: + "&": + - base_url + isPrivate: false + metaSortKey: 1569905755147 + modified: 1569905805832 + name: Base environment + parentId: wrk_43652e59afaf4825a8bbbf31e346f616 + _type: environment + - _id: jar_61bbb3fdc5ee80a49ee817b3e5341053a6022960 + cookies: + - creation: 2019-10-01T04:57:46.521Z + domain: 192.168.1.3 + hostOnly: true + httpOnly: true + id: "40058861704510274" + key: JSESSIONID + lastAccessed: 2019-10-01T14:08:27.635Z + path: / + secure: true + value: 2A63FF79AC604DB88D26DE41876B8B88 + created: 1569905764431 + modified: 1569938907635 + name: Default Jar + parentId: wrk_43652e59afaf4825a8bbbf31e346f616 + _type: cookie_jar + - _id: env_92b9543a27e847689c951d1b1eeff229 + color: "#cb5dc2" + created: 1569905755144 + data: + base_path: / + host: 192.168.1.3:8443 + scheme: https + dataPropertyOrder: null + isPrivate: false + metaSortKey: 1569905755144 + modified: 1569935791597 + name: colnod-test + parentId: env_7bc4918f1ec5467393a2ab36a460e4d0 + _type: environment diff --git a/Insomnia_2019-10-02.yaml b/Insomnia_2019-10-02.yaml index a5cdc2d..32f429b 100644 --- a/Insomnia_2019-10-02.yaml +++ b/Insomnia_2019-10-02.yaml @@ -1,270 +1,270 @@ -_type: export -__export_format: 4 -__export_date: 2019-10-02T15:35:40.243Z -__export_source: insomnia.desktop.app:v6.6.2 -resources: - - _id: req_f0797b6411b144f0bf0a40d9300ee92f - authentication: - disabled: false - password: E7FEA07DBC82FB9BA34B2E453E2EFE89F0583E7187543507EF11E84726071FE428445372F2E46B455EB0C79747C51E362F403CE39473A2A8C2DFA0CE5C9826C0 - type: basic - username: spaceti - body: - mimeType: application/json - text: >- - { - "username": "spaceti", - "password": "E7FEA07DBC82FB9BA34B2E453E2EFE89F0583E7187543507EF11E84726071FE428445372F2E46B455EB0C79747C51E362F403CE39473A2A8C2DFA0CE5C9826C0" - } - created: 1569905755136 - description: "" - headers: - - id: pair_061d15d1294e412caca8300559541695 - name: content-type - value: application/json - isPrivate: false - metaSortKey: -1569905755136 - method: POST - modified: 1570026752164 - name: Login user - parameters: [] - parentId: fld_9ef1d96e0e6d40ef9094250114269496 - settingDisableRenderRequestBody: false - settingEncodeUrl: true - settingRebuildPath: true - settingSendCookies: true - settingStoreCookies: true - url: "{{ base_url }}/AaaManager/authSession" - _type: request - - _id: fld_9ef1d96e0e6d40ef9094250114269496 - created: 1569905755142 - description: Login information ( token ) - environment: {} - environmentPropertyOrder: null - metaSortKey: -1569905755142 - modified: 1569905755142 - name: login - parentId: wrk_43652e59afaf4825a8bbbf31e346f616 - _type: request_group - - _id: wrk_43652e59afaf4825a8bbbf31e346f616 - created: 1569905755149 - description: "Colnod system: [Product information](http://produkty.colsys.cz/colnod) - Jira issues: [Communicaiton with - Colnod](https://spaceti.atlassian.net/secure/RapidBoard.jspa?rapidView=78\ - &projectKey=INT&modal=detail&selectedIssue=INT-3563)" - modified: 1569905755149 - name: Colnod server 1.0.0 - parentId: null - _type: workspace - - _id: req_00f9f99d933c4638900385ffbbd4f8f7 - authentication: - disabled: false - token: "{% response 'body', 'req_f0797b6411b144f0bf0a40d9300ee92f', - 'b64::JC5pZA==::46b', 'no-history' %}" - type: bearer - body: - mimeType: application/json - text: "" - created: 1569905755134 - description: "" - headers: - - id: pair_a2a3c43a20f64efbb8a4752c7e983c8e - name: Content-Type - value: application/json - isPrivate: false - metaSortKey: -1569905755134 - method: POST - modified: 1570025488293 - name: Get subjects - parameters: [] - parentId: fld_2fb4c2cef1f44cff83d6b00fe0886384 - settingDisableRenderRequestBody: false - settingEncodeUrl: true - settingRebuildPath: true - settingSendCookies: true - settingStoreCookies: true - url: "{{ base_url }}/SubjectManager/getSubjects" - _type: request - - _id: fld_2fb4c2cef1f44cff83d6b00fe0886384 - created: 1569905755140 - description: Operations about user - environment: {} - environmentPropertyOrder: null - metaSortKey: -1569905755140 - modified: 1569905755140 - name: user - parentId: wrk_43652e59afaf4825a8bbbf31e346f616 - _type: request_group - - _id: req_9e42a5023f9d4235a5de099cd7573d2b - authentication: - token: "{% response 'body', 'req_f0797b6411b144f0bf0a40d9300ee92f', - 'b64::JC5pZA==::46b', 'never' %}" - type: bearer - body: - mimeType: application/json - text: "" - created: 1569905755131 - description: "" - headers: - - disabled: false - id: pair_e888b6c679d74b0988f0dd2d77690383 - name: Content-Type - value: application/json - isPrivate: false - metaSortKey: -1569905755131 - method: POST - modified: 1569998661557 - name: Get Tokens - parameters: [] - parentId: fld_36a4be72380440a0ace83ad508a0458d - settingDisableRenderRequestBody: false - settingEncodeUrl: true - settingRebuildPath: true - settingSendCookies: true - settingStoreCookies: true - url: "{{ base_url }}/TokenManager/getTokens/" - _type: request - - _id: fld_36a4be72380440a0ace83ad508a0458d - created: 1569905755138 - description: Working with tokens ( keys ) - environment: {} - environmentPropertyOrder: null - metaSortKey: -1569905755138 - modified: 1569934361048 - name: Token Manager - parentId: wrk_43652e59afaf4825a8bbbf31e346f616 - _type: request_group - - _id: req_4f99d61a83c14da29882cc80c07ddf54 - authentication: - token: "{% response 'body', 'req_f0797b6411b144f0bf0a40d9300ee92f', - 'b64::JC5pZA==::46b', 'never' %}" - type: bearer - body: {} - created: 1569905755127 - description: "" - headers: [] - isPrivate: false - metaSortKey: -1569905755129 - method: POST - modified: 1569938955854 - name: Set Tokens - parameters: [] - parentId: fld_36a4be72380440a0ace83ad508a0458d - settingDisableRenderRequestBody: false - settingEncodeUrl: true - settingRebuildPath: true - settingSendCookies: true - settingStoreCookies: true - url: /TokenManager/setTokens - _type: request - - _id: req_fd2e096f45554b46b31755564a0932bf - authentication: - token:  {% response 'body', 'req_f0797b6411b144f0bf0a40d9300ee92f', - 'b64::JC5pZA==::46b', 'no-history' %} - type: bearer - body: {} - created: 1569934364782 - description: "" - headers: [] - isPrivate: false - metaSortKey: -1569905755130.5 - method: POST - modified: 1570028425988 - name: Get Token Subject - parameters: [] - parentId: fld_8d34eca167ef426c8aa998c98bbe74e2 - settingDisableRenderRequestBody: false - settingEncodeUrl: true - settingRebuildPath: true - settingSendCookies: true - settingStoreCookies: true - url: "{{ base_url }}/OpenManager/getTokenSubject" - _type: request - - _id: fld_8d34eca167ef426c8aa998c98bbe74e2 - created: 1569934364777 - description: Working with tokens ( keys ) - environment: {} - environmentPropertyOrder: null - metaSortKey: -1569905755088 - modified: 1569934370959 - name: Open Manager - parentId: wrk_43652e59afaf4825a8bbbf31e346f616 - _type: request_group - - _id: req_7007bb1f6a0243a7b0568741f691f6d1 - authentication: - disabled: false - password: E7FEA07DBC82FB9BA34B2E453E2EFE89F0583E7187543507EF11E84726071FE428445372F2E46B455EB0C79747C51E362F403CE39473A2A8C2DFA0CE5C9826C0 - type: basic - username: spaceti - body: - mimeType: application/json - text: >- - { - "username": "spaceti", - "password": "E7FEA07DBC82FB9BA34B2E453E2EFE89F0583E7187543507EF11E84726071FE428445372F2E46B455EB0C79747C51E362F403CE39473A2A8C2DFA0CE5C9826C0" - } - created: 1570025458784 - description: "" - headers: - - id: pair_74b4df5d54d1446a90e6a668d373fb79 - name: Content-Type - value: application/json - isPrivate: false - metaSortKey: -1569905755129.75 - method: POST - modified: 1570030518745 - name: Get Token Subject Full authorization - parameters: [] - parentId: fld_8d34eca167ef426c8aa998c98bbe74e2 - settingDisableRenderRequestBody: false - settingEncodeUrl: true - settingRebuildPath: true - settingSendCookies: true - settingStoreCookies: true - url: "{{ base_url }}/OpenManager/getTokenSubject" - _type: request - - _id: env_7bc4918f1ec5467393a2ab36a460e4d0 - color: null - created: 1569905755147 - data: - base_url: "{{ scheme }}://{{ host }}{{ base_path }}" - dataPropertyOrder: - "&": - - base_url - isPrivate: false - metaSortKey: 1569905755147 - modified: 1569905805832 - name: Base environment - parentId: wrk_43652e59afaf4825a8bbbf31e346f616 - _type: environment - - _id: jar_61bbb3fdc5ee80a49ee817b3e5341053a6022960 - cookies: - - creation: 2019-10-01T04:57:46.521Z - domain: 192.168.1.3 - hostOnly: true - httpOnly: true - id: "9919962998126108" - key: JSESSIONID - lastAccessed: 2019-10-02T15:35:00.995Z - path: / - secure: true - value: D64B135F2F3D5103F02F0B9235B13722 - created: 1569905764431 - modified: 1570030500995 - name: Default Jar - parentId: wrk_43652e59afaf4825a8bbbf31e346f616 - _type: cookie_jar - - _id: env_92b9543a27e847689c951d1b1eeff229 - color: "#cb5dc2" - created: 1569905755144 - data: - base_path: / - host: 192.168.1.3:8443 - scheme: https - dataPropertyOrder: null - isPrivate: false - metaSortKey: 1569905755144 - modified: 1569935791597 - name: colnod-test - parentId: env_7bc4918f1ec5467393a2ab36a460e4d0 - _type: environment +_type: export +__export_format: 4 +__export_date: 2019-10-02T15:35:40.243Z +__export_source: insomnia.desktop.app:v6.6.2 +resources: + - _id: req_f0797b6411b144f0bf0a40d9300ee92f + authentication: + disabled: false + password: E7FEA07DBC82FB9BA34B2E453E2EFE89F0583E7187543507EF11E84726071FE428445372F2E46B455EB0C79747C51E362F403CE39473A2A8C2DFA0CE5C9826C0 + type: basic + username: spaceti + body: + mimeType: application/json + text: >- + { + "username": "spaceti", + "password": "E7FEA07DBC82FB9BA34B2E453E2EFE89F0583E7187543507EF11E84726071FE428445372F2E46B455EB0C79747C51E362F403CE39473A2A8C2DFA0CE5C9826C0" + } + created: 1569905755136 + description: "" + headers: + - id: pair_061d15d1294e412caca8300559541695 + name: content-type + value: application/json + isPrivate: false + metaSortKey: -1569905755136 + method: POST + modified: 1570026752164 + name: Login user + parameters: [] + parentId: fld_9ef1d96e0e6d40ef9094250114269496 + settingDisableRenderRequestBody: false + settingEncodeUrl: true + settingRebuildPath: true + settingSendCookies: true + settingStoreCookies: true + url: "{{ base_url }}/AaaManager/authSession" + _type: request + - _id: fld_9ef1d96e0e6d40ef9094250114269496 + created: 1569905755142 + description: Login information ( token ) + environment: {} + environmentPropertyOrder: null + metaSortKey: -1569905755142 + modified: 1569905755142 + name: login + parentId: wrk_43652e59afaf4825a8bbbf31e346f616 + _type: request_group + - _id: wrk_43652e59afaf4825a8bbbf31e346f616 + created: 1569905755149 + description: "Colnod system: [Product information](http://produkty.colsys.cz/colnod) + Jira issues: [Communicaiton with + Colnod](https://spaceti.atlassian.net/secure/RapidBoard.jspa?rapidView=78\ + &projectKey=INT&modal=detail&selectedIssue=INT-3563)" + modified: 1569905755149 + name: Colnod server 1.0.0 + parentId: null + _type: workspace + - _id: req_00f9f99d933c4638900385ffbbd4f8f7 + authentication: + disabled: false + token: "{% response 'body', 'req_f0797b6411b144f0bf0a40d9300ee92f', + 'b64::JC5pZA==::46b', 'no-history' %}" + type: bearer + body: + mimeType: application/json + text: "" + created: 1569905755134 + description: "" + headers: + - id: pair_a2a3c43a20f64efbb8a4752c7e983c8e + name: Content-Type + value: application/json + isPrivate: false + metaSortKey: -1569905755134 + method: POST + modified: 1570025488293 + name: Get subjects + parameters: [] + parentId: fld_2fb4c2cef1f44cff83d6b00fe0886384 + settingDisableRenderRequestBody: false + settingEncodeUrl: true + settingRebuildPath: true + settingSendCookies: true + settingStoreCookies: true + url: "{{ base_url }}/SubjectManager/getSubjects" + _type: request + - _id: fld_2fb4c2cef1f44cff83d6b00fe0886384 + created: 1569905755140 + description: Operations about user + environment: {} + environmentPropertyOrder: null + metaSortKey: -1569905755140 + modified: 1569905755140 + name: user + parentId: wrk_43652e59afaf4825a8bbbf31e346f616 + _type: request_group + - _id: req_9e42a5023f9d4235a5de099cd7573d2b + authentication: + token: "{% response 'body', 'req_f0797b6411b144f0bf0a40d9300ee92f', + 'b64::JC5pZA==::46b', 'never' %}" + type: bearer + body: + mimeType: application/json + text: "" + created: 1569905755131 + description: "" + headers: + - disabled: false + id: pair_e888b6c679d74b0988f0dd2d77690383 + name: Content-Type + value: application/json + isPrivate: false + metaSortKey: -1569905755131 + method: POST + modified: 1569998661557 + name: Get Tokens + parameters: [] + parentId: fld_36a4be72380440a0ace83ad508a0458d + settingDisableRenderRequestBody: false + settingEncodeUrl: true + settingRebuildPath: true + settingSendCookies: true + settingStoreCookies: true + url: "{{ base_url }}/TokenManager/getTokens/" + _type: request + - _id: fld_36a4be72380440a0ace83ad508a0458d + created: 1569905755138 + description: Working with tokens ( keys ) + environment: {} + environmentPropertyOrder: null + metaSortKey: -1569905755138 + modified: 1569934361048 + name: Token Manager + parentId: wrk_43652e59afaf4825a8bbbf31e346f616 + _type: request_group + - _id: req_4f99d61a83c14da29882cc80c07ddf54 + authentication: + token: "{% response 'body', 'req_f0797b6411b144f0bf0a40d9300ee92f', + 'b64::JC5pZA==::46b', 'never' %}" + type: bearer + body: {} + created: 1569905755127 + description: "" + headers: [] + isPrivate: false + metaSortKey: -1569905755129 + method: POST + modified: 1569938955854 + name: Set Tokens + parameters: [] + parentId: fld_36a4be72380440a0ace83ad508a0458d + settingDisableRenderRequestBody: false + settingEncodeUrl: true + settingRebuildPath: true + settingSendCookies: true + settingStoreCookies: true + url: /TokenManager/setTokens + _type: request + - _id: req_fd2e096f45554b46b31755564a0932bf + authentication: + token:  {% response 'body', 'req_f0797b6411b144f0bf0a40d9300ee92f', + 'b64::JC5pZA==::46b', 'no-history' %} + type: bearer + body: {} + created: 1569934364782 + description: "" + headers: [] + isPrivate: false + metaSortKey: -1569905755130.5 + method: POST + modified: 1570028425988 + name: Get Token Subject + parameters: [] + parentId: fld_8d34eca167ef426c8aa998c98bbe74e2 + settingDisableRenderRequestBody: false + settingEncodeUrl: true + settingRebuildPath: true + settingSendCookies: true + settingStoreCookies: true + url: "{{ base_url }}/OpenManager/getTokenSubject" + _type: request + - _id: fld_8d34eca167ef426c8aa998c98bbe74e2 + created: 1569934364777 + description: Working with tokens ( keys ) + environment: {} + environmentPropertyOrder: null + metaSortKey: -1569905755088 + modified: 1569934370959 + name: Open Manager + parentId: wrk_43652e59afaf4825a8bbbf31e346f616 + _type: request_group + - _id: req_7007bb1f6a0243a7b0568741f691f6d1 + authentication: + disabled: false + password: E7FEA07DBC82FB9BA34B2E453E2EFE89F0583E7187543507EF11E84726071FE428445372F2E46B455EB0C79747C51E362F403CE39473A2A8C2DFA0CE5C9826C0 + type: basic + username: spaceti + body: + mimeType: application/json + text: >- + { + "username": "spaceti", + "password": "E7FEA07DBC82FB9BA34B2E453E2EFE89F0583E7187543507EF11E84726071FE428445372F2E46B455EB0C79747C51E362F403CE39473A2A8C2DFA0CE5C9826C0" + } + created: 1570025458784 + description: "" + headers: + - id: pair_74b4df5d54d1446a90e6a668d373fb79 + name: Content-Type + value: application/json + isPrivate: false + metaSortKey: -1569905755129.75 + method: POST + modified: 1570030518745 + name: Get Token Subject Full authorization + parameters: [] + parentId: fld_8d34eca167ef426c8aa998c98bbe74e2 + settingDisableRenderRequestBody: false + settingEncodeUrl: true + settingRebuildPath: true + settingSendCookies: true + settingStoreCookies: true + url: "{{ base_url }}/OpenManager/getTokenSubject" + _type: request + - _id: env_7bc4918f1ec5467393a2ab36a460e4d0 + color: null + created: 1569905755147 + data: + base_url: "{{ scheme }}://{{ host }}{{ base_path }}" + dataPropertyOrder: + "&": + - base_url + isPrivate: false + metaSortKey: 1569905755147 + modified: 1569905805832 + name: Base environment + parentId: wrk_43652e59afaf4825a8bbbf31e346f616 + _type: environment + - _id: jar_61bbb3fdc5ee80a49ee817b3e5341053a6022960 + cookies: + - creation: 2019-10-01T04:57:46.521Z + domain: 192.168.1.3 + hostOnly: true + httpOnly: true + id: "9919962998126108" + key: JSESSIONID + lastAccessed: 2019-10-02T15:35:00.995Z + path: / + secure: true + value: D64B135F2F3D5103F02F0B9235B13722 + created: 1569905764431 + modified: 1570030500995 + name: Default Jar + parentId: wrk_43652e59afaf4825a8bbbf31e346f616 + _type: cookie_jar + - _id: env_92b9543a27e847689c951d1b1eeff229 + color: "#cb5dc2" + created: 1569905755144 + data: + base_path: / + host: 192.168.1.3:8443 + scheme: https + dataPropertyOrder: null + isPrivate: false + metaSortKey: 1569905755144 + modified: 1569935791597 + name: colnod-test + parentId: env_7bc4918f1ec5467393a2ab36a460e4d0 + _type: environment diff --git a/curl/subjects.sh b/curl/subjects.sh index 4b7917f..35f5a66 100755 --- a/curl/subjects.sh +++ b/curl/subjects.sh @@ -1,7 +1,7 @@ -#!/bin/bash - - -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"]') - - -curl -kv -u "$TOKEN:" -X POST https://192.168.1.3:8443/SubjectManager/getSubjects +#!/bin/bash + + +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"]') + + +curl -kv -u "$TOKEN:" -X POST https://192.168.1.3:8443/SubjectManager/getSubjects diff --git a/curl/tokens.sh b/curl/tokens.sh index 06f00ab..a804717 100755 --- a/curl/tokens.sh +++ b/curl/tokens.sh @@ -1,7 +1,7 @@ -#!/bin/bash - - -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"]') - - -curl -kv -u "$TOKEN:" -X POST https://192.168.1.3:8443/TokenManager/getTokens/ +#!/bin/bash + + +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"]') + + +curl -kv -u "$TOKEN:" -X POST https://192.168.1.3:8443/TokenManager/getTokens/ diff --git a/curl/tokenssubjects.sh b/curl/tokenssubjects.sh index 0041961..b2386d3 100755 --- a/curl/tokenssubjects.sh +++ b/curl/tokenssubjects.sh @@ -1,6 +1,6 @@ -#!/bin/bash - - -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"]') - -curl -kv -u "$TOKEN:" -X POST https://192.168.1.3:8443/OpenManager/getTokenSubject +#!/bin/bash + + +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 diff --git a/src/colnod/requestmanager.cpp b/src/colnod/requestmanager.cpp index 2f4c7a1..d72660b 100644 --- a/src/colnod/requestmanager.cpp +++ b/src/colnod/requestmanager.cpp @@ -1,127 +1,140 @@ -#include "requestmanager.h" - -RequestManager::RequestManager() -{ - manager = new QNetworkAccessManager(); - token = ""; - loginStatus = false; - - - - 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); -} - -void RequestManager::login(QString host, QString username, QString password) -{ - QNetworkRequest request; - QString hash = encryptedPassword(password); - authHeader = getLoginHeader(username, hash); - QJsonObject reqBody = { - {"password", hash}, - {"username", username} - }; - this->host = host; - - request.setUrl(host + "/AaaManager/authSession"); - 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, [=]() { - if (reply->error()) - { - qDebug() << reply->errorString(); - loginStatus = false; - return; - } - jsonResponse = reply->readAll(); - prepareAuthHeader(); - loginStatus = true; - emit successLogin(); - reply->deleteLater(); - }); -} - -void 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(); - } - QNetworkRequest request; - request.setUrl(host + endpoint); - request.setRawHeader("Authorization", authHeader.toLocal8Bit()); - QNetworkReply* reply = manager->post(request, QByteArray()); - QObject::connect(reply, &QNetworkReply::finished, [=]() { - if (reply->error()) - { - qDebug() << reply->errorString(); - qDebug() << reply->readAll(); - loginStatus = false; - getRequest(endpoint); - return; - } - qDebug() << reply->attribute(QNetworkRequest::HttpStatusCodeAttribute); - jsonResponse = reply->readAll(); - emit responseReady(); - }); -} - -QString RequestManager::getFromJson(QString json, const QString &member) -{ - QJsonParseError err; - QJsonDocument document = QJsonDocument::fromJson(json.toUtf8(),&err); - if (err.error != 0) - { - qDebug() << err.errorString(); - } - return document.object().value(member).toString(); -} - -QString RequestManager::encryptedPassword(QString password) -{ - return QCryptographicHash::hash(password.toLocal8Bit(), QCryptographicHash::Sha512).toHex().toUpper(); -} - -QString RequestManager::getLoginHeader(QString username, QString hash) -{ - QString authValue = username + ":" + hash; - return "Basic " + authValue.toLocal8Bit().toBase64(); -} - -void RequestManager::prepareAuthHeader() -{ - token = getFromJson(jsonResponse, "id"); - QString authValue = token + ":"; - authHeader = "Basic" + authValue.toLocal8Bit().toBase64(); -} - -void RequestManager::onSSLError(QNetworkReply *reply, const QList &errors) -{ - qDebug() << "Network SSL errors"; - for (const auto &error : errors) - { - if (error.error() == QSslError::SelfSignedCertificate) - reply->ignoreSslErrors(errors); - qDebug() << error.errorString(); - } - -} - -void RequestManager::getSubjects() -{ - getRequest("/SubjectManager/getSubjects"); -} +#include "requestmanager.h" + +RequestManager::RequestManager() +{ + manager = new QNetworkAccessManager(); + token = ""; + 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); +} + +void RequestManager::login(QString host, QString username, QString password) +{ + QNetworkRequest request; + QString hash = encryptedPassword(password); + authHeader = getLoginHeader(username, hash); + QJsonObject reqBody = { + {"password", hash}, + {"username", username} + }; + this->host = host; + + request.setUrl(host + "/AaaManager/authSession"); + 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, [=]() { + if (reply->error()) + { + qDebug() << reply->errorString(); + loginStatus = false; + return; + } + jsonResponse = reply->readAll(); + prepareAuthHeader(); + loginStatus = true; + emit successLogin(); + reply->deleteLater(); + }); +} + +void 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; + 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()) + { + qDebug() << reply->errorString(); + qDebug() << reply->readAll(); + loginStatus = false; + getRequest(endpoint); + return; + } + qDebug() << reply->attribute(QNetworkRequest::HttpStatusCodeAttribute); + jsonResponse = reply->readAll(); + emit responseReady(); + }); +} + +QString RequestManager::getFromJson(QString json, const QString &member) +{ + QJsonParseError err; + QJsonDocument document = QJsonDocument::fromJson(json.toUtf8(),&err); + if (err.error != 0) + { + qDebug() << err.errorString(); + } + return document.object().value(member).toString(); +} + +QString RequestManager::encryptedPassword(QString password) +{ + return QCryptographicHash::hash(password.toLocal8Bit(), QCryptographicHash::Sha512).toHex().toUpper(); +} + +QString RequestManager::getLoginHeader(QString username, QString hash) +{ + QString authValue = username + ":" + hash; + return "Basic " + authValue.toLocal8Bit().toBase64(); +} + +void RequestManager::prepareAuthHeader() +{ + token = getFromJson(jsonResponse, "id"); + QString authValue = token + ":"; + authHeader = "Basic" + authValue.toLocal8Bit().toBase64(); +} + +void RequestManager::onSSLError(QNetworkReply *reply, const QList &errors) +{ + qDebug() << "Network SSL errors"; + for (const auto &error : errors) + { + if (error.error() == QSslError::SelfSignedCertificate) + reply->ignoreSslErrors(errors); + qDebug() << error.errorString(); + } + +} + +void RequestManager::getSubjects() +{ + getRequest("/SubjectManager/getSubjects"); +} diff --git a/src/colnod/subject.cpp b/src/colnod/subject.cpp index 1793f4e..22dd172 100644 --- a/src/colnod/subject.cpp +++ b/src/colnod/subject.cpp @@ -1,74 +1,74 @@ -#include - -#include "Subject.h" - -#include - -QString Subject::getEmail() const { - return attributes["email"].toString(); -} - -void Subject::fromJSON(const QJsonObject &json) { - Entity::fromJSON(json); - - attributes = json["attributes"]["items"].toObject(); - - attributes = json.value("attributes").toObject().value("items").toObject(); - - const auto &tokenFlagsArray = json.value("tokenFlags").toArray(); - for(const auto &flag : tokenFlagsArray){ - tokenFlags.insert(flag.toString()); - } - - pin = json.value("pin").toString(); - - const auto &pinFlagsArray = json.value("pinFlags").toArray(); - for(const auto &flag : pinFlagsArray){ - pinFlags.insert(flag.toString()); - } - -} - -QJsonObject Subject::toJSON() const { - QJsonObject json = Entity::toJSON(); - - QJsonObject items({{"items", attributes}}); - json.value("atributes") = items; - json.value("tokenFlags") = QJsonArray::fromStringList(tokenFlags.toList()); - json.value("pin") = pin; - json.value("pinFlags") = QJsonArray::fromStringList(pinFlags.toList()); - - return json; -} - -const QJsonObject &Subject::getAttributes() const { - return attributes; -} - -void Subject::setAttributes(const QJsonObject &attributes) { - Subject::attributes = attributes; -} - -const QSet &Subject::getTokenFlags() const { - return tokenFlags; -} - -void Subject::setTokenFlags(const QSet &tokenFlags) { - Subject::tokenFlags = tokenFlags; -} - -const QString &Subject::getPin() const { - return pin; -} - -void Subject::setPin(const QString &pin) { - Subject::pin = pin; -} - -const QSet &Subject::getPinFlags() const { - return pinFlags; -} - -void Subject::setPinFlags(const QSet &pinFlags) { - Subject::pinFlags = pinFlags; -} +#include + +#include "subject.h" + +#include + +QString Subject::getEmail() const { + return attributes["email"].toString(); +} + +void Subject::fromJSON(const QJsonObject &json) { + Entity::fromJSON(json); + + attributes = json["attributes"]["items"].toObject(); + + attributes = json.value("attributes").toObject().value("items").toObject(); + + const auto &tokenFlagsArray = json.value("tokenFlags").toArray(); + for(const auto &flag : tokenFlagsArray){ + tokenFlags.insert(flag.toString()); + } + + pin = json.value("pin").toString(); + + const auto &pinFlagsArray = json.value("pinFlags").toArray(); + for(const auto &flag : pinFlagsArray){ + pinFlags.insert(flag.toString()); + } + +} + +QJsonObject Subject::toJSON() const { + QJsonObject json = Entity::toJSON(); + + QJsonObject items({{"items", attributes}}); + json.value("atributes") = items; + json.value("tokenFlags") = QJsonArray::fromStringList(tokenFlags.toList()); + json.value("pin") = pin; + json.value("pinFlags") = QJsonArray::fromStringList(pinFlags.toList()); + + return json; +} + +const QJsonObject &Subject::getAttributes() const { + return attributes; +} + +void Subject::setAttributes(const QJsonObject &attributes) { + Subject::attributes = attributes; +} + +const QSet &Subject::getTokenFlags() const { + return tokenFlags; +} + +void Subject::setTokenFlags(const QSet &tokenFlags) { + Subject::tokenFlags = tokenFlags; +} + +const QString &Subject::getPin() const { + return pin; +} + +void Subject::setPin(const QString &pin) { + Subject::pin = pin; +} + +const QSet &Subject::getPinFlags() const { + return pinFlags; +} + +void Subject::setPinFlags(const QSet &pinFlags) { + Subject::pinFlags = pinFlags; +} diff --git a/test/unitTests/UnitTest.cpp b/test/unitTests/UnitTest.cpp index 7b5fe85..61dc3b5 100644 --- a/test/unitTests/UnitTest.cpp +++ b/test/unitTests/UnitTest.cpp @@ -1,123 +1,124 @@ -#include "unittest.h" - -void UnitTest::loginSuccessfully() -{ - RequestManager* testAccess = new RequestManager(); - QJsonDocument config = testAccess->getConfig(); - QSignalSpy spy(testAccess, SIGNAL(successLogin())); - testAccess->login(host, email, password); - spy.wait(); - QVERIFY(spy.isValid()); - QCOMPARE(spy.count(), 1); - QString json = testAccess->getResponse(); - qDebug() << json; - QJsonDocument doc = QJsonDocument::fromJson(json.toUtf8()); - QVERIFY2(doc.object().value("id").isString(), "No parameter 'id' in response"); -} - -//POST request w/o datas -void UnitTest::getSubjects() -{ - RequestManager* testAccess = new RequestManager(); - // testAccess->login(host, email, password); - QSignalSpy spy(testAccess, SIGNAL(responseReady())); - testAccess->getRequest("/SubjectManager/getSubjects"); - spy.wait(); - QVERIFY(spy.isValid()); - QCOMPARE(spy.count(), 1); - 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::getTokens() -{ - RequestManager* testAccess = new RequestManager(); - // testAccess->login(host, email, password); - QSignalSpy spy(testAccess, SIGNAL(responseReady())); - testAccess->getRequest("/TokenManager/getTokens"); - QCOMPARE(spy.count(), 0); - spy.wait(); - QVERIFY(spy.isValid()); - QCOMPARE(spy.count(), 1); - qDebug() << testAccess->getResponse(); -} - -void UnitTest::getTokensOpenManager() -{ - RequestManager* testAccess = new RequestManager(); - // testAccess->login(host, email, password); - QSignalSpy spy(testAccess, SIGNAL(responseReady())); - testAccess->getRequest("/OpenManager/getTokenSubject"); - QCOMPARE(spy.count(), 0); - spy.wait(); - QVERIFY(spy.isValid()); - QCOMPARE(spy.count(), 1); - QString response = testAccess->getResponse(); - qDebug() << response; - QVERIFY(!response.isEmpty()); -} - -void UnitTest::subjectJSONParser() -{ - /* - QFile jsonData(QDir::current().filePath("subjects.json")); - - if (!jsonData.open(QIODevice::ReadOnly)) { - qCritical() << "Couldn't open config file config.json" << QDir::current().filePath("subjects.json"); - QCoreApplication::exit(-1); - return; - } - - QJsonDocument doc = QJsonDocument::fromJson(jsonData.readAll()); - QJsonObject obj = doc.object(); - QJsonArray arr = obj["items"].toArray(); - */ - - RequestManager* testAccess = new RequestManager(); - // testAccess->login(host, email, password); - QSignalSpy spy(testAccess, SIGNAL(responseReady())); - testAccess->getRequest("/SubjectManager/getSubjects"); - spy.wait(); - QString response = testAccess->getResponse(); - QJsonDocument doc = QJsonDocument::fromJson(response.toUtf8()); - QJsonArray arr = doc.object()["items"].toArray(); - auto testSubject = new Subject(); - testSubject->fromJSON(arr[1].toObject()); - qDebug() << testSubject->getName() << " Size: " << arr.size(); - QVERIFY(!testSubject->getName().isEmpty()); -} - -void UnitTest::tokenJSONParser() -{ - RequestManager* testAccess = new RequestManager(); - // testAccess->login(host, email, password); - QSignalSpy spy(testAccess, SIGNAL(responseReady())); - testAccess->getRequest("/TokenManager/getTokens"); - spy.wait(); - QString response = testAccess->getResponse(); - - //TODO - /* QJsonDocument doc = QJsonDocument::fromJson(response.toUtf8()); - QJsonArray arr = doc.object()["items"].toArray(); - auto testSubject = new Subject(); - testSubject->fromJSON(arr[1].toObject()); - qDebug() << testSubject->getName(); - QVERIFY(!testSubject->getName().isEmpty());*/ - QVERIFY(true); - -} - -void UnitTest::connectToDB() -{ - DatabaseManager *db = new DatabaseManager("192.168.1.94", "deloitte", "postgres", "34rjkciea12"); - QVERIFY(db->getOpened()); - QVERIFY(true); - -} - -QTEST_MAIN(UnitTest) +#include "unittest.h" + +void UnitTest::loginSuccessfully() +{ + RequestManager* testAccess = new RequestManager(); + QJsonDocument config = testAccess->getConfig(); + QSignalSpy spy(testAccess, SIGNAL(successLogin())); + testAccess->login(host, email, password); + spy.wait(); + QVERIFY(spy.isValid()); + QCOMPARE(spy.count(), 1); + QString json = testAccess->getResponse(); + qDebug() << json; + QJsonDocument doc = QJsonDocument::fromJson(json.toUtf8()); + QVERIFY2(doc.object().value("id").isString(), "No parameter 'id' in response"); +} + +//POST request w/o datas +void UnitTest::getSubjects() +{ + RequestManager* testAccess = new RequestManager(); + // testAccess->login(host, email, password); + QSignalSpy spy(testAccess, SIGNAL(responseReady())); + testAccess->getRequest("/SubjectManager/getSubjects"); + spy.wait(); + 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"); + qDebug() << doc.object().value("items").toArray()[0].toObject()["id"].toString(); + QVERIFY2(doc.object().value("items").toArray()[0].toObject()["id"].isString(), "ada"); + +} + +void UnitTest::getTokens() +{ + RequestManager* testAccess = new RequestManager(); + // testAccess->login(host, email, password); + QSignalSpy spy(testAccess, SIGNAL(responseReady())); + testAccess->getRequest("/TokenManager/getTokens"); + QCOMPARE(spy.count(), 0); + spy.wait(); + QVERIFY(spy.isValid()); + QCOMPARE(spy.count(), 1); + qDebug() << testAccess->getResponse(); +} + +void UnitTest::getTokensOpenManager() +{ + RequestManager* testAccess = new RequestManager(); + // testAccess->login(host, email, password); + QSignalSpy spy(testAccess, SIGNAL(responseReady())); + testAccess->getRequest("/OpenManager/getTokenSubject"); + QCOMPARE(spy.count(), 0); + spy.wait(); + QVERIFY(spy.isValid()); + QCOMPARE(spy.count(), 1); + QString response = testAccess->getResponse(); + qDebug() << response; + QVERIFY(!response.isEmpty()); +} + +void UnitTest::subjectJSONParser() +{ + /* + QFile jsonData(QDir::current().filePath("subjects.json")); + + if (!jsonData.open(QIODevice::ReadOnly)) { + qCritical() << "Couldn't open config file config.json" << QDir::current().filePath("subjects.json"); + QCoreApplication::exit(-1); + return; + } + + QJsonDocument doc = QJsonDocument::fromJson(jsonData.readAll()); + QJsonObject obj = doc.object(); + QJsonArray arr = obj["items"].toArray(); + */ + + RequestManager* testAccess = new RequestManager(); + // testAccess->login(host, email, password); + QSignalSpy spy(testAccess, SIGNAL(responseReady())); + testAccess->getRequest("/SubjectManager/getSubjects"); + spy.wait(); + QString response = testAccess->getResponse(); + QJsonDocument doc = QJsonDocument::fromJson(response.toUtf8()); + QJsonArray arr = doc.object()["items"].toArray(); + auto testSubject = new Subject(); + testSubject->fromJSON(arr[1].toObject()); + qDebug() << testSubject->getName() << " Size: " << arr.size(); + QVERIFY(!testSubject->getName().isEmpty()); +} + +void UnitTest::tokenJSONParser() +{ + RequestManager* testAccess = new RequestManager(); + // testAccess->login(host, email, password); + QSignalSpy spy(testAccess, SIGNAL(responseReady())); + testAccess->getRequest("/TokenManager/getTokens"); + spy.wait(); + QString response = testAccess->getResponse(); + + //TODO + /* QJsonDocument doc = QJsonDocument::fromJson(response.toUtf8()); + QJsonArray arr = doc.object()["items"].toArray(); + auto testSubject = new Subject(); + testSubject->fromJSON(arr[1].toObject()); + qDebug() << testSubject->getName(); + QVERIFY(!testSubject->getName().isEmpty());*/ + QVERIFY(true); + +} + +void UnitTest::connectToDB() +{ + DatabaseManager *db = new DatabaseManager("192.168.1.94", "deloitte", "postgres", "34rjkciea12"); + QVERIFY(db->getOpened()); + QVERIFY(true); + +} + +QTEST_MAIN(UnitTest) diff --git a/test/unitTests/config.json b/test/unitTests/config.json new file mode 100644 index 0000000..5b2d2a5 --- /dev/null +++ b/test/unitTests/config.json @@ -0,0 +1,5 @@ +{ + "host": "https://192.168.1.3:8443", + "username": "spaceti", + "password": "spaceti1" +} \ No newline at end of file diff --git a/test/unitTests/unittest.h b/test/unitTests/unittest.h index 3444490..f890afb 100644 --- a/test/unitTests/unittest.h +++ b/test/unitTests/unittest.h @@ -1,29 +1,29 @@ -#pragma once - -#include -#include -#include -#include "subject.h" -#include "databasemanager.h" - - -class UnitTest : public QObject -{ - Q_OBJECT - -private slots: - - void loginSuccessfully(); // /AaaManager/authSession - void getSubjects(); // /SubjectManager/getSubjects - void getTokens(); // /TokenManager/getTokens - void getTokensOpenManager(); // /OpenManager/getTokenSubject - void subjectJSONParser(); - void tokenJSONParser(); - void connectToDB(); - -private: - // QString host = "https://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"; -}; +#pragma once + +#include +#include +#include +#include "subject.h" +#include "databasemanager.h" + + +class UnitTest : public QObject +{ + Q_OBJECT + +private slots: + + void loginSuccessfully(); // /AaaManager/authSession + void getSubjects(); // /SubjectManager/getSubjects + void getTokens(); // /TokenManager/getTokens + void getTokensOpenManager(); // /OpenManager/getTokenSubject + void subjectJSONParser(); + void tokenJSONParser(); + void connectToDB(); + +private: + //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"; +}; From ce060a425ff5989ede358ae56931746036b0ebf2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20Fischer?= Date: Thu, 3 Oct 2019 13:35:44 +0200 Subject: [PATCH 07/12] fix for Qt 5.9 --- src/colnod/entity.cpp | 104 ++++++++-------- src/colnod/requestmanager.cpp | 6 +- src/colnod/subject.cpp | 2 +- src/colnod/token.cpp | 216 +++++++++++++++++----------------- 4 files changed, 166 insertions(+), 162 deletions(-) diff --git a/src/colnod/entity.cpp b/src/colnod/entity.cpp index f90314f..96eb597 100644 --- a/src/colnod/entity.cpp +++ b/src/colnod/entity.cpp @@ -1,52 +1,52 @@ -#include -#include "entity.h" - -const QUuid &Entity::getId() const { - return id; -} - -void Entity::setId(const QUuid &id) { - Entity::id = id; -} - -const QString &Entity::getName() const { - return name; -} - -void Entity::setName(const QString &name) { - Entity::name = name; -} - -const QString &Entity::getDescription() const { - return description; -} - -void Entity::setDescription(const QString &description) { - Entity::description = description; -} - -uint64_t Entity::getLastUpdate() const { - return lastUpdate; -} - -void Entity::setLastUpdate(uint64_t lastUpdate) { - this->lastUpdate = lastUpdate; -} - -void Entity::fromJSON(const QJsonObject &json) { - id = json.value("id").toString(); - name = json.value("name").toString(); - description = json.value("description").toString(); - lastUpdate = json.value("lastUpdate").toDouble(); -} - -QJsonObject Entity::toJSON() const { - QJsonObject json; - - json.value("id") = id.toString(QUuid::WithoutBraces); - json.value("name") = name; - json.value("description") = description; - json.value("lastUpdate") = lastUpdate; - - return json; -} +#include +#include "entity.h" + +const QUuid &Entity::getId() const { + return id; +} + +void Entity::setId(const QUuid &id) { + Entity::id = id; +} + +const QString &Entity::getName() const { + return name; +} + +void Entity::setName(const QString &name) { + Entity::name = name; +} + +const QString &Entity::getDescription() const { + return description; +} + +void Entity::setDescription(const QString &description) { + Entity::description = description; +} + +uint64_t Entity::getLastUpdate() const { + return lastUpdate; +} + +void Entity::setLastUpdate(uint64_t lastUpdate) { + this->lastUpdate = lastUpdate; +} + +void Entity::fromJSON(const QJsonObject &json) { + id = json.value("id").toString(); + name = json.value("name").toString(); + description = json.value("description").toString(); + lastUpdate = json.value("lastUpdate").toDouble(); +} + +QJsonObject Entity::toJSON() const { + QJsonObject json; + + json.value("id") = id.toString(); + json.value("name") = name; + json.value("description") = description; + json.value("lastUpdate") = lastUpdate; + + return json; +} diff --git a/src/colnod/requestmanager.cpp b/src/colnod/requestmanager.cpp index d72660b..8b24aa5 100644 --- a/src/colnod/requestmanager.cpp +++ b/src/colnod/requestmanager.cpp @@ -70,12 +70,16 @@ void RequestManager::getRequest(QString endpoint) qDebug() << authHeader; request.setRawHeader("Authorization", authHeader.toLocal8Bit()); //request.setRawHeader("User-Agent", "curl/7.65.3"); + //request.setRawHeader("Accept", "*/*"); + //request.setRawHeader("Accept-Encoding", "*"); + // request.setRawHeader("Accept-Language", "*"); + QNetworkReply* reply = manager->post(request, QByteArray()); // //QEventLoop loop; //QObject::connect(reply, &QNetworkReply::finished, &loop, &QEventLoop::quit); - //loop.exec(); + // loop.exec(); // QObject::connect(reply, &QNetworkReply::finished, [=]() { diff --git a/src/colnod/subject.cpp b/src/colnod/subject.cpp index 22dd172..6ddff51 100644 --- a/src/colnod/subject.cpp +++ b/src/colnod/subject.cpp @@ -11,7 +11,7 @@ QString Subject::getEmail() const { void Subject::fromJSON(const QJsonObject &json) { Entity::fromJSON(json); - attributes = json["attributes"]["items"].toObject(); + //attributes = json["attributes"]["items"].toObject(); attributes = json.value("attributes").toObject().value("items").toObject(); diff --git a/src/colnod/token.cpp b/src/colnod/token.cpp index cf07779..bf306bf 100644 --- a/src/colnod/token.cpp +++ b/src/colnod/token.cpp @@ -1,108 +1,108 @@ -#include "token.h" - -#include - -void Token::fromJSON(const QJsonObject &json) { - Entity::fromJSON(json); - - tokenType = json.value("tokenType").toString(); - tokenBits = json.value("tokenBits").toInt(); - tokenData = json.value("tokenData").toString(); - validFrom = json.value("validFrom").toDouble(); - validTo = json.value("validTo").toDouble(); - timeToLive = json.value("timeToLive").toInt(); - authErrors = json["authErrors"].toInt(); - const auto &flagsArray = json["flags"].toArray(); - for(const auto &flag : flagsArray){ - flags.insert(flag.toString()); - } - subjectId = json.value("subjectId").toString(); -} - -QJsonObject Token::toJSON() const { - QJsonObject json = Entity::toJSON(); - - json.value("tokenType") = tokenType; - json.value("tokenBits") = tokenBits; - json.value("tokenData") = tokenData; - json.value("validFrom") = validFrom; - json.value("validTo") = validTo; - json.value("timeToLive") = timeToLive; - json.value("authErrors") = authErrors; - json.value("flags") = QJsonArray::fromStringList(flags.toList()); - json.value("subjectId") = subjectId.toString(QUuid::WithoutBraces); - - return json; -} - -const QString &Token::getTokenType() const { - return tokenType; -} - -void Token::setTokenType(const QString &tokenType) { - Token::tokenType = tokenType; -} - -int Token::getTokenBits() const { - return tokenBits; -} - -void Token::setTokenBits(int tokenBits) { - Token::tokenBits = tokenBits; -} - -const QString &Token::getTokenData() const { - return tokenData; -} - -void Token::setTokenData(const QString &tokenData) { - Token::tokenData = tokenData; -} - -qint64 Token::getValidFrom() const { - return validFrom; -} - -void Token::setValidFrom(qint64 validFrom) { - Token::validFrom = validFrom; -} - -qint64 Token::getValidTo() const { - return validTo; -} - -void Token::setValidTo(qint64 validTo) { - Token::validTo = validTo; -} - -int Token::getTimeToLive() const { - return timeToLive; -} - -void Token::setTimeToLive(int timeToLive) { - Token::timeToLive = timeToLive; -} - -int Token::getAuthErrors() const { - return authErrors; -} - -void Token::setAuthErrors(int authErrors) { - Token::authErrors = authErrors; -} - -const QSet &Token::getFlags() const { - return flags; -} - -void Token::setFlags(const QSet &flags) { - Token::flags = flags; -} - -const QUuid &Token::getSubjectId() const { - return subjectId; -} - -void Token::setSubjectId(const QUuid &subjectId) { - Token::subjectId = subjectId; -} +#include "token.h" + +#include + +void Token::fromJSON(const QJsonObject &json) { + Entity::fromJSON(json); + + tokenType = json.value("tokenType").toString(); + tokenBits = json.value("tokenBits").toInt(); + tokenData = json.value("tokenData").toString(); + validFrom = json.value("validFrom").toDouble(); + validTo = json.value("validTo").toDouble(); + timeToLive = json.value("timeToLive").toInt(); + authErrors = json["authErrors"].toInt(); + const auto &flagsArray = json["flags"].toArray(); + for(const auto &flag : flagsArray){ + flags.insert(flag.toString()); + } + subjectId = json.value("subjectId").toString(); +} + +QJsonObject Token::toJSON() const { + QJsonObject json = Entity::toJSON(); + + json.value("tokenType") = tokenType; + json.value("tokenBits") = tokenBits; + json.value("tokenData") = tokenData; + json.value("validFrom") = validFrom; + json.value("validTo") = validTo; + json.value("timeToLive") = timeToLive; + json.value("authErrors") = authErrors; + json.value("flags") = QJsonArray::fromStringList(flags.toList()); + json.value("subjectId") = subjectId.toString(); + + return json; +} + +const QString &Token::getTokenType() const { + return tokenType; +} + +void Token::setTokenType(const QString &tokenType) { + Token::tokenType = tokenType; +} + +int Token::getTokenBits() const { + return tokenBits; +} + +void Token::setTokenBits(int tokenBits) { + Token::tokenBits = tokenBits; +} + +const QString &Token::getTokenData() const { + return tokenData; +} + +void Token::setTokenData(const QString &tokenData) { + Token::tokenData = tokenData; +} + +qint64 Token::getValidFrom() const { + return validFrom; +} + +void Token::setValidFrom(qint64 validFrom) { + Token::validFrom = validFrom; +} + +qint64 Token::getValidTo() const { + return validTo; +} + +void Token::setValidTo(qint64 validTo) { + Token::validTo = validTo; +} + +int Token::getTimeToLive() const { + return timeToLive; +} + +void Token::setTimeToLive(int timeToLive) { + Token::timeToLive = timeToLive; +} + +int Token::getAuthErrors() const { + return authErrors; +} + +void Token::setAuthErrors(int authErrors) { + Token::authErrors = authErrors; +} + +const QSet &Token::getFlags() const { + return flags; +} + +void Token::setFlags(const QSet &flags) { + Token::flags = flags; +} + +const QUuid &Token::getSubjectId() const { + return subjectId; +} + +void Token::setSubjectId(const QUuid &subjectId) { + Token::subjectId = subjectId; +} From de7e64c4f594123b298ee1a585f590a32acbe16b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20Fischer?= Date: Thu, 3 Oct 2019 15:40:56 +0200 Subject: [PATCH 08/12] Add test for communication with DB --- src/colnod/databasemanager.cpp | 79 +++++++++++++++++++++------------- src/colnod/databasemanager.h | 72 ++++++++++++++++--------------- src/colnod/requestmanager.cpp | 8 ++-- test/unitTests/UnitTest.cpp | 14 +++--- 4 files changed, 100 insertions(+), 73 deletions(-) diff --git a/src/colnod/databasemanager.cpp b/src/colnod/databasemanager.cpp index 5fae9e4..1b8839d 100644 --- a/src/colnod/databasemanager.cpp +++ b/src/colnod/databasemanager.cpp @@ -1,29 +1,50 @@ -#include "databasemanager.h" - -DatabaseManager::DatabaseManager(QString host, QString dbName, QString user, QString password) -{ - - db = QSqlDatabase::addDatabase("QPSQL"); - - db.setDatabaseName(dbName); - db.setHostName(host); - db.setUserName(user); - db.setPassword(password); - opened = db.open(); - if (!opened) - { - qDebug() << "Opening error" + db.lastError().text(); - } - query = QSqlQuery("query", db); -} - -void DatabaseManager::saveSubject(Subject subject, QString table) -{ - //TODO -} - -void DatabaseManager::saveToken(Subject subject, QString table) -{ - //TODO -} - +#include "databasemanager.h" + +DatabaseManager::DatabaseManager(QString host, QString dbName, QString user, QString password) +{ + + db = QSqlDatabase::addDatabase("QPSQL"); + + db.setDatabaseName(dbName); + db.setHostName(host); + db.setUserName(user); + db.setPassword(password); + opened = db.open(); + if (!opened) + { + qDebug() << "Opening error" + db.lastError().text(); + } + query = QSqlQuery("query", db); +} + +void DatabaseManager::saveSubject(Subject subject, QString table) +{ + //TODO +} + +void DatabaseManager::saveToken(Subject subject, QString table) +{ + //TODO +} + +QString DatabaseManager::getTestMessage(int id) +{ + query.prepare("SELECT message FROM test WHERE id = :id"); + query.bindValue(":id", id); + query.exec(); + query.next(); + //qDebug() << query.value(0); + return query.value(0).toString(); +} + +void DatabaseManager::createTestRecord(QString msg) +{ + query.exec("SELECT MAX(id) FROM test"); + query.next(); + int id = query.value(0).toInt() + 1; + QString statement = QString("INSERT INTO test (id, message) VALUES (%1, '%2')").arg(id).arg(msg); + query.exec(statement); + query.next(); + qDebug() << "U inserted new row, id: " << id << "msg: " << getTestMessage(id); + +} diff --git a/src/colnod/databasemanager.h b/src/colnod/databasemanager.h index 3cc175c..1340673 100644 --- a/src/colnod/databasemanager.h +++ b/src/colnod/databasemanager.h @@ -1,34 +1,38 @@ -#ifndef DATABASEMANAGER_H -#define DATABASEMANAGER_H -#include -#include -#include -#include - -#include -#include -#include "subject.h" -#include "token.h" - - -class DatabaseManager : public QObject -{ - Q_OBJECT -public: - DatabaseManager(QString host, QString dbName, QString user, QString password); - - void saveSubject(Subject subject, QString table); - void saveToken(Subject subject, QString table); - - bool getOpened() {return opened;} - -private: - QSqlDatabase db; - QSqlQuery query; - - bool opened; - - -}; - -#endif // DATABASEMANAGER_H +#ifndef DATABASEMANAGER_H +#define DATABASEMANAGER_H +#include +#include +#include +#include + +#include +#include +#include "subject.h" +#include "token.h" + + +class DatabaseManager : public QObject +{ + Q_OBJECT +public: + DatabaseManager(QString host, QString dbName, QString user, QString password); + + void saveSubject(Subject subject, QString table); + void saveToken(Subject subject, QString table); + + QString getTestMessage(int id); + void createTestRecord(QString msg); + + + bool getOpened() {return opened;} + +private: + QSqlDatabase db; + QSqlQuery query; + + bool opened; + + +}; + +#endif // DATABASEMANAGER_H diff --git a/src/colnod/requestmanager.cpp b/src/colnod/requestmanager.cpp index 8b24aa5..8af919c 100644 --- a/src/colnod/requestmanager.cpp +++ b/src/colnod/requestmanager.cpp @@ -69,10 +69,10 @@ void RequestManager::getRequest(QString endpoint) request.setUrl(host + endpoint); qDebug() << authHeader; request.setRawHeader("Authorization", authHeader.toLocal8Bit()); - //request.setRawHeader("User-Agent", "curl/7.65.3"); - //request.setRawHeader("Accept", "*/*"); - //request.setRawHeader("Accept-Encoding", "*"); - // request.setRawHeader("Accept-Language", "*"); + request.setRawHeader("User-Agent", "curl/7.65.3"); + request.setRawHeader("Accept", "*/*"); + request.setRawHeader("Accept-Encoding", "*"); + request.setRawHeader("Accept-Language", "*"); QNetworkReply* reply = manager->post(request, QByteArray()); diff --git a/test/unitTests/UnitTest.cpp b/test/unitTests/UnitTest.cpp index 61dc3b5..dd4c31d 100644 --- a/test/unitTests/UnitTest.cpp +++ b/test/unitTests/UnitTest.cpp @@ -19,7 +19,6 @@ void UnitTest::loginSuccessfully() void UnitTest::getSubjects() { RequestManager* testAccess = new RequestManager(); - // testAccess->login(host, email, password); QSignalSpy spy(testAccess, SIGNAL(responseReady())); testAccess->getRequest("/SubjectManager/getSubjects"); spy.wait(); @@ -38,7 +37,6 @@ void UnitTest::getSubjects() void UnitTest::getTokens() { RequestManager* testAccess = new RequestManager(); - // testAccess->login(host, email, password); QSignalSpy spy(testAccess, SIGNAL(responseReady())); testAccess->getRequest("/TokenManager/getTokens"); QCOMPARE(spy.count(), 0); @@ -51,7 +49,6 @@ void UnitTest::getTokens() void UnitTest::getTokensOpenManager() { RequestManager* testAccess = new RequestManager(); - // testAccess->login(host, email, password); QSignalSpy spy(testAccess, SIGNAL(responseReady())); testAccess->getRequest("/OpenManager/getTokenSubject"); QCOMPARE(spy.count(), 0); @@ -78,9 +75,11 @@ void UnitTest::subjectJSONParser() QJsonObject obj = doc.object(); QJsonArray arr = obj["items"].toArray(); */ +QVERIFY(true); +return; + RequestManager* testAccess = new RequestManager(); - // testAccess->login(host, email, password); QSignalSpy spy(testAccess, SIGNAL(responseReady())); testAccess->getRequest("/SubjectManager/getSubjects"); spy.wait(); @@ -96,7 +95,6 @@ void UnitTest::subjectJSONParser() void UnitTest::tokenJSONParser() { RequestManager* testAccess = new RequestManager(); - // testAccess->login(host, email, password); QSignalSpy spy(testAccess, SIGNAL(responseReady())); testAccess->getRequest("/TokenManager/getTokens"); spy.wait(); @@ -117,8 +115,12 @@ void UnitTest::connectToDB() { DatabaseManager *db = new DatabaseManager("192.168.1.94", "deloitte", "postgres", "34rjkciea12"); QVERIFY(db->getOpened()); + qDebug() << db->getTestMessage(1); QVERIFY(true); - + QCOMPARE(db->getTestMessage(1), "Hello world"); + db->createTestRecord("Does it work?"); + QCOMPARE(db->getTestMessage(2), "Does it work?"); } + QTEST_MAIN(UnitTest) From 2f217962c49077f9d0e453f8fa605fbe9a158ecc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20Fischer?= Date: Thu, 3 Oct 2019 15:44:51 +0200 Subject: [PATCH 09/12] CURL response/request and Qt response --- http/Curl.txt | 37 +++++++++++++++++++++++++++++++++++++ http/Qt requests.txt | 24 ++++++++++++++++++++++++ 2 files changed, 61 insertions(+) create mode 100644 http/Curl.txt create mode 100644 http/Qt requests.txt diff --git a/http/Curl.txt b/http/Curl.txt new file mode 100644 index 0000000..541245c --- /dev/null +++ b/http/Curl.txt @@ -0,0 +1,37 @@ + +///SubjectManager/getSubjects +RESPONSE +HTTP/1.1 200 +X-Content-Type-Options: nosniff +X-XSS-Protection: 1; mode=block +Cache-Control: no-cache, no-store, max-age=0, must-revalidate +Pragma: no-cache +Expires: 0 +Strict-Transport-Security: max-age=31536000 ; includeSubDomains +X-Frame-Options: DENY +Set-Cookie: JSESSIONID=77278D21902AE1DE75E43204C2770545;path=/;Secure;HttpOnly +Content-Type: application/json;charset=UTF-8 +Transfer-Encoding: chunked +Date: Thu, 03 Oct 2019 11:12:03 GMT + +REQUEST +POST /SubjectManager/getSubjects HTTP/1.1 +Host: 192.168.1.3:8443 +Authorization: Basic ODkwZjllNmMtMDIxNi00ZThiLWI2MjgtMjViOGI2ZmFiNWM4Og== +User-Agent: curl/7.65.3 +Accept: */* + + + +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" +} diff --git a/http/Qt requests.txt b/http/Qt requests.txt new file mode 100644 index 0000000..5439388 --- /dev/null +++ b/http/Qt requests.txt @@ -0,0 +1,24 @@ +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" +} + + +//no data because cant get token +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 From 0903322e41e2921ba61ff7942e0c4be178dad377 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20Fischer?= Date: Thu, 3 Oct 2019 16:02:20 +0200 Subject: [PATCH 10/12] Request of insomnia --- http/Insomnia.txt | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 http/Insomnia.txt diff --git a/http/Insomnia.txt b/http/Insomnia.txt new file mode 100644 index 0000000..6d5a1ba --- /dev/null +++ b/http/Insomnia.txt @@ -0,0 +1,12 @@ +POST /OpenManager/getTokenSubject HTTP/1.1 +Host: localhost:8080 +Authorization: Basic c3BhY2V0aTpFN0ZFQTA3REJDODJGQjlCQTM0QjJFNDUzRTJFRkU4OUYwNTgzRTcxODc1NDM1MDdFRjExRTg0NzI2MDcxRkU0Mjg0NDUzNzJGMkU0NkI0NTVFQjBDNzk3NDdDNTFFMzYyRjQwM0NFMzk0NzNBMkE4QzJERkEwQ0U1Qzk4MjZDMA== +User-Agent: insomnia/7.0.0 +Content-Type: application/json +Accept: */* +Content-Length: 173 + +{ + "username": "spaceti", + "password": "E7FEA07DBC82FB9BA34B2E453E2EFE89F0583E7187543507EF11E84726071FE428445372F2E46B455EB0C79747C51E362F403CE39473A2A8C2DFA0CE5C9826C0" +} From cc9e9978ff7b5aeb12a5c25f82814018ccc03757 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20Fischer?= Date: Mon, 7 Oct 2019 12:00:04 +0200 Subject: [PATCH 11/12] test for debuging - ssl socket --- src/colnod/requestmanager.cpp | 9 ++++--- test/unitTests/UnitTest.cpp | 49 +++++++++++++++++++++++++++++++++++ test/unitTests/unittest.h | 3 +++ 3 files changed, 57 insertions(+), 4 deletions(-) diff --git a/src/colnod/requestmanager.cpp b/src/colnod/requestmanager.cpp index 8af919c..2c78589 100644 --- a/src/colnod/requestmanager.cpp +++ b/src/colnod/requestmanager.cpp @@ -56,13 +56,13 @@ void 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(); + // QEventLoop loop; + // QObject::connect(this, &RequestManager::successLogin, &loop, &QEventLoop::quit); + // loop.exec(); } // - host = config.object()["host"].toString(); + //host = config.object()["host"].toString(); // QNetworkRequest request; @@ -70,6 +70,7 @@ void RequestManager::getRequest(QString endpoint) qDebug() << authHeader; 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", "*"); diff --git a/test/unitTests/UnitTest.cpp b/test/unitTests/UnitTest.cpp index dd4c31d..70ff9d3 100644 --- a/test/unitTests/UnitTest.cpp +++ b/test/unitTests/UnitTest.cpp @@ -122,5 +122,54 @@ void UnitTest::connectToDB() QCOMPARE(db->getTestMessage(2), "Does it work?"); } +void UnitTest::debugConnection() +{ + QSslSocket ssl;// = new QSslSocket(); + ssl.connectToHostEncrypted("192.168.1.3", 8443); + ssl.ignoreSslErrors(); + if (!ssl.waitForEncrypted()) + { + 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\"}"; + /*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"}*/ + qDebug() << tmp.toUtf8(); + ssl.write(tmp.toUtf8()); + QString data; + while (ssl.waitForReadyRead() && data.isEmpty()) + { + data.append(ssl.readAll().data()); + } + qDebug() << data; + int index = data.lastIndexOf("id"); + QString tkn = data.mid( index + 5, 36); + tkn = tkn + ":"; + qDebug() << "parsed token : " <getConfig(); + QSignalSpy spy(testAccess, SIGNAL(successLogin())); + testAccess->login(host, email, password); + spy.wait(); + + 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()); + while (ssl.waitForReadyRead()) + qDebug() << ssl.readAll().data(); + + QVERIFY(true); +} + QTEST_MAIN(UnitTest) diff --git a/test/unitTests/unittest.h b/test/unitTests/unittest.h index f890afb..a1eafea 100644 --- a/test/unitTests/unittest.h +++ b/test/unitTests/unittest.h @@ -1,3 +1,4 @@ + #pragma once #include @@ -5,6 +6,7 @@ #include #include "subject.h" #include "databasemanager.h" +#include class UnitTest : public QObject @@ -20,6 +22,7 @@ private slots: void subjectJSONParser(); void tokenJSONParser(); void connectToDB(); + void debugConnection(); private: //QString host = "http://localhost:8080"; //colnod server (ssh -L 8080:192.168.254.11:8443 penta-master) From 8c3749b7991b7066e425769fd799c6347362b350 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20Fischer?= Date: Mon, 7 Oct 2019 12:45:02 +0200 Subject: [PATCH 12/12] SSL socket request --- http/sendingRequestBySSLSocket.txt | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 http/sendingRequestBySSLSocket.txt diff --git a/http/sendingRequestBySSLSocket.txt b/http/sendingRequestBySSLSocket.txt new file mode 100644 index 0000000..f65dec2 --- /dev/null +++ b/http/sendingRequestBySSLSocket.txt @@ -0,0 +1,5 @@ +POST /SubjectManager/getSubjects HTTP/1.1 +Host: 192.168.1.3:8443 +Authorization: Basic " + tkn.toUtf8().toBase64() + " +User-Agent: curl/7.65.3 +Accept: */*