46 lines
1.4 KiB
C++
46 lines
1.4 KiB
C++
// net 层端到端登录连通测试(真实站点)。
|
||
// 复刻已实测通过的流程:getImageCode -> verifyCodeCheck -> RSA -> login2,
|
||
// 关键在 ApiClient 内单一 QNetworkAccessManager 共享 JSESSIONID 会话。
|
||
// 需要 QCoreApplication 提供事件循环(ApiClient 用 QEventLoop 同步等待)。
|
||
// 网络不可达时本用例会失败(属环境问题,非逻辑问题)。
|
||
|
||
#include <gtest/gtest.h>
|
||
|
||
#include <QCoreApplication>
|
||
#include <fstream>
|
||
#include <sstream>
|
||
#include <string>
|
||
|
||
#include "ApiClient.hpp"
|
||
#include "AuthService.hpp"
|
||
|
||
namespace {
|
||
|
||
// 读取整个文件内容(PEM 公钥)。
|
||
std::string slurp(const char* path) {
|
||
std::ifstream f(path);
|
||
std::stringstream s;
|
||
s << f.rdbuf();
|
||
return s.str();
|
||
}
|
||
|
||
} // namespace
|
||
|
||
TEST(AuthLiveTest, FullLoginFlowReturnsToken) {
|
||
int argc = 0;
|
||
char** argv = nullptr;
|
||
QCoreApplication app(argc, argv);
|
||
|
||
geopro::net::ApiClient api("http://tenant.geomative.cn/pop-api");
|
||
geopro::net::AuthService auth(
|
||
api, slurp("D:/Git/lanbingtech/geopro/resources/rsa_public_key.pem"));
|
||
|
||
auto cap = auth.fetchCaptcha();
|
||
ASSERT_FALSE(cap.codeId.isEmpty());
|
||
ASSERT_FALSE(cap.code.isEmpty());
|
||
|
||
auto r = auth.login("sydk", "123456", cap.code, cap.codeId);
|
||
EXPECT_TRUE(r.ok) << r.error.toStdString();
|
||
EXPECT_TRUE(r.token.startsWith("Geomative ")) << r.token.toStdString();
|
||
}
|