forked from loafle/openapi-generator-original
[QT][C++]fixed integration test for Oauth (#10921)
* fixed missing package, fixed namespace issues * using older function to check if token is valid * using time.h to check if token is valid
This commit is contained in:
parent
eb224db540
commit
8fbd11073a
@ -12,7 +12,8 @@ else ()
|
||||
endif ()
|
||||
|
||||
find_package(Qt5Core REQUIRED)
|
||||
find_package(Qt5Network REQUIRED){{#contentCompression}}
|
||||
find_package(Qt5Network REQUIRED){{#authMethods}}{{#isOAuth}}
|
||||
find_package(Qt5Gui REQUIRED){{/isOAuth}}{{/authMethods}}{{#contentCompression}}
|
||||
find_package(ZLIB REQUIRED){{/contentCompression}}
|
||||
|
||||
add_library(${PROJECT_NAME}
|
||||
@ -31,9 +32,9 @@ add_library(${PROJECT_NAME}
|
||||
{{prefix}}Helpers.cpp
|
||||
{{prefix}}HttpRequest.cpp
|
||||
{{prefix}}HttpFileElement.cpp
|
||||
{{prefix}}Oauth.cpp
|
||||
)
|
||||
target_link_libraries(${PROJECT_NAME} PRIVATE Qt5::Core Qt5::Network {{#contentCompression}} ${ZLIB_LIBRARIES}{{/contentCompression}})
|
||||
|
||||
target_link_libraries(${PROJECT_NAME} PRIVATE Qt5::Core Qt5::Network{{#authMethods}}{{#isOAuth}} Qt5::Gui{{/isOAuth}}{{/authMethods}}{{#contentCompression}} ${ZLIB_LIBRARIES}{{/contentCompression}})
|
||||
if(NOT APPLE)
|
||||
target_link_libraries(${PROJECT_NAME} PRIVATE ssl crypto)
|
||||
endif()
|
||||
|
@ -1,6 +1,8 @@
|
||||
#include "{{prefix}}Oauth.h"
|
||||
|
||||
namespace OpenAPI {
|
||||
{{#cppNamespaceDeclarations}}
|
||||
namespace {{this}} {
|
||||
{{/cppNamespaceDeclarations}}
|
||||
|
||||
/*
|
||||
* Base class to perform oauth2 flows
|
||||
@ -343,5 +345,6 @@ void ReplyServer::read()
|
||||
emit dataReceived(queryParams);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
{{#cppNamespaceDeclarations}}
|
||||
} // namespace {{this}}
|
||||
{{/cppNamespaceDeclarations}}
|
@ -21,8 +21,7 @@
|
||||
#include <QUrl>
|
||||
#include <QUrlQuery>
|
||||
#include <QDateTime>
|
||||
|
||||
|
||||
#include <time.h>
|
||||
|
||||
{{#cppNamespaceDeclarations}}
|
||||
namespace {{this}} {
|
||||
@ -32,19 +31,19 @@ class oauthToken
|
||||
{
|
||||
public:
|
||||
oauthToken(QString token, int expiresIn, QString scope, QString tokenType) : m_token(token), m_scope(scope), m_type(tokenType){
|
||||
m_validUntil = QDateTime::fromSecsSinceEpoch(QDateTime::currentSecsSinceEpoch() + expiresIn);
|
||||
m_validUntil = time(0) + expiresIn;
|
||||
}
|
||||
oauthToken(){
|
||||
m_validUntil = QDateTime::fromSecsSinceEpoch(QDateTime::currentSecsSinceEpoch() -1);
|
||||
m_validUntil = time(0) - 1;
|
||||
}
|
||||
QString getToken(){return m_token;};
|
||||
QString getScope(){return m_scope;};
|
||||
QString getType(){return m_type;};
|
||||
bool isValid(){return QDateTime::currentDateTime() < m_validUntil;};
|
||||
bool isValid(){return time(0) < m_validUntil;};
|
||||
|
||||
private:
|
||||
QString m_token;
|
||||
QDateTime m_validUntil;
|
||||
time_t m_validUntil;
|
||||
QString m_scope;
|
||||
QString m_type;
|
||||
};
|
||||
|
@ -10,6 +10,7 @@ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC -Wall -Wno-unused-variable")
|
||||
find_package(Qt5Core REQUIRED)
|
||||
find_package(Qt5Network REQUIRED)
|
||||
find_package(Qt5Test REQUIRED)
|
||||
find_package(Qt5Gui REQUIRED)
|
||||
|
||||
include_directories(
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/client
|
||||
@ -23,7 +24,7 @@ add_executable(${PROJECT_NAME}
|
||||
PetStore/UserApiTests.cpp
|
||||
)
|
||||
target_link_libraries(${PROJECT_NAME} PRIVATE client)
|
||||
target_link_libraries(${PROJECT_NAME} PRIVATE Qt5::Core Qt5::Network Qt5::Test)
|
||||
target_link_libraries(${PROJECT_NAME} PRIVATE Qt5::Core Qt5::Network Qt5::Test Qt5::Gui)
|
||||
set_property(TARGET ${PROJECT_NAME} PROPERTY CXX_STANDARD 14)
|
||||
set_property(TARGET ${PROJECT_NAME} PROPERTY CXX_STANDARD_REQUIRED ON)
|
||||
set_property(TARGET ${PROJECT_NAME} PROPERTY CXX_EXTENSIONS OFF)
|
||||
|
@ -13,6 +13,7 @@ endif ()
|
||||
|
||||
find_package(Qt5Core REQUIRED)
|
||||
find_package(Qt5Network REQUIRED)
|
||||
find_package(Qt5Gui REQUIRED)
|
||||
|
||||
add_library(${PROJECT_NAME}
|
||||
PFXApiResponse.cpp
|
||||
@ -27,9 +28,9 @@ add_library(${PROJECT_NAME}
|
||||
PFXHelpers.cpp
|
||||
PFXHttpRequest.cpp
|
||||
PFXHttpFileElement.cpp
|
||||
PFXOauth.cpp
|
||||
)
|
||||
target_link_libraries(${PROJECT_NAME} PRIVATE Qt5::Core Qt5::Network )
|
||||
|
||||
target_link_libraries(${PROJECT_NAME} PRIVATE Qt5::Core Qt5::Network Qt5::Gui)
|
||||
if(NOT APPLE)
|
||||
target_link_libraries(${PROJECT_NAME} PRIVATE ssl crypto)
|
||||
endif()
|
||||
|
@ -1,6 +1,6 @@
|
||||
#include "PFXOauth.h"
|
||||
|
||||
namespace OpenAPI {
|
||||
namespace test_namespace {
|
||||
|
||||
/*
|
||||
* Base class to perform oauth2 flows
|
||||
@ -343,5 +343,4 @@ void ReplyServer::read()
|
||||
emit dataReceived(queryParams);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
} // namespace test_namespace
|
||||
|
@ -31,8 +31,7 @@
|
||||
#include <QUrl>
|
||||
#include <QUrlQuery>
|
||||
#include <QDateTime>
|
||||
|
||||
|
||||
#include <time.h>
|
||||
|
||||
namespace test_namespace {
|
||||
|
||||
@ -40,19 +39,19 @@ class oauthToken
|
||||
{
|
||||
public:
|
||||
oauthToken(QString token, int expiresIn, QString scope, QString tokenType) : m_token(token), m_scope(scope), m_type(tokenType){
|
||||
m_validUntil = QDateTime::fromSecsSinceEpoch(QDateTime::currentSecsSinceEpoch() + expiresIn);
|
||||
m_validUntil = time(0) + expiresIn;
|
||||
}
|
||||
oauthToken(){
|
||||
m_validUntil = QDateTime::fromSecsSinceEpoch(QDateTime::currentSecsSinceEpoch() -1);
|
||||
m_validUntil = time(0) - 1;
|
||||
}
|
||||
QString getToken(){return m_token;};
|
||||
QString getScope(){return m_scope;};
|
||||
QString getType(){return m_type;};
|
||||
bool isValid(){return QDateTime::currentDateTime() < m_validUntil;};
|
||||
bool isValid(){return time(0) < m_validUntil;};
|
||||
|
||||
private:
|
||||
QString m_token;
|
||||
QDateTime m_validUntil;
|
||||
time_t m_validUntil;
|
||||
QString m_scope;
|
||||
QString m_type;
|
||||
};
|
||||
|
Loading…
x
Reference in New Issue
Block a user