mirror of
https://github.com/chenx-dust/EZ4Connect.git
synced 2026-09-20 02:13:32 +08:00
chore: 让 easyconnect 专属的参数不给进去
This commit is contained in:
@@ -73,6 +73,7 @@ QString CoreCommand::loggableCommandLine() const
|
||||
CoreCommand CoreCommandBuilder::build(const ConnectionProfile &profile, const CoreRuntimePaths &runtimePaths)
|
||||
{
|
||||
QStringList arguments;
|
||||
QStringList credentials;
|
||||
|
||||
appendOption(arguments, "-protocol", profile.endpoint.protocol);
|
||||
|
||||
@@ -91,6 +92,24 @@ CoreCommand CoreCommandBuilder::build(const ConnectionProfile &profile, const Co
|
||||
arguments << "-update-best-nodes-interval" << QString::number(profile.behavior.updateBestNodesInterval);
|
||||
}
|
||||
}
|
||||
else if (profile.endpoint.protocol == "easyconnect")
|
||||
{
|
||||
if (profile.behavior.disableMultiLine)
|
||||
{
|
||||
arguments << "-disable-multi-line";
|
||||
}
|
||||
if (profile.behavior.disableZjuConfig)
|
||||
{
|
||||
arguments << "-disable-zju-config";
|
||||
}
|
||||
if (profile.behavior.skipDomainResource)
|
||||
{
|
||||
arguments << "-skip-domain-resource";
|
||||
}
|
||||
appendOption(arguments, "-custom-proxy-domain", profile.proxy.customDomains);
|
||||
appendOption(credentials, "-cert-file", profile.credentials.certFile);
|
||||
appendOption(credentials, "-cert-password", profile.credentials.certPassword);
|
||||
}
|
||||
|
||||
appendOption(arguments, "-server", profile.endpoint.server);
|
||||
if (profile.endpoint.port != 0)
|
||||
@@ -108,10 +127,6 @@ CoreCommand CoreCommandBuilder::build(const ConnectionProfile &profile, const Co
|
||||
}
|
||||
appendOption(arguments, "-secondary-dns-server", profile.dns.secondary);
|
||||
|
||||
if (profile.behavior.disableMultiLine)
|
||||
{
|
||||
arguments << "-disable-multi-line";
|
||||
}
|
||||
if (profile.behavior.disableKeepAlive)
|
||||
{
|
||||
arguments << "-disable-keep-alive";
|
||||
@@ -122,10 +137,6 @@ CoreCommand CoreCommandBuilder::build(const ConnectionProfile &profile, const Co
|
||||
{
|
||||
arguments << "-auto-detect-interface";
|
||||
}
|
||||
if (profile.behavior.disableZjuConfig)
|
||||
{
|
||||
arguments << "-disable-zju-config";
|
||||
}
|
||||
if (profile.dns.disableZjuDns)
|
||||
{
|
||||
arguments << "-disable-zju-dns";
|
||||
@@ -138,11 +149,6 @@ CoreCommand CoreCommandBuilder::build(const ConnectionProfile &profile, const Co
|
||||
{
|
||||
arguments << "-proxy-all";
|
||||
}
|
||||
if (profile.behavior.skipDomainResource)
|
||||
{
|
||||
arguments << "-skip-domain-resource";
|
||||
}
|
||||
|
||||
if (profile.tunnel.tunMode)
|
||||
{
|
||||
arguments << "-tun-mode";
|
||||
@@ -171,7 +177,6 @@ CoreCommand CoreCommandBuilder::build(const ConnectionProfile &profile, const Co
|
||||
appendOption(arguments, "-tcp-port-forwarding", profile.tunnel.tcpPortForwarding);
|
||||
appendOption(arguments, "-udp-port-forwarding", profile.tunnel.udpPortForwarding);
|
||||
appendOption(arguments, "-custom-dns", profile.dns.custom);
|
||||
appendOption(arguments, "-custom-proxy-domain", profile.proxy.customDomains);
|
||||
if (!profile.extraArguments.isEmpty())
|
||||
{
|
||||
arguments.append(profile.extraArguments.split(" "));
|
||||
@@ -180,13 +185,10 @@ CoreCommand CoreCommandBuilder::build(const ConnectionProfile &profile, const Co
|
||||
CoreCommand command;
|
||||
command.loggableArguments = arguments;
|
||||
|
||||
QStringList credentials;
|
||||
appendOption(credentials, "-username", profile.credentials.username);
|
||||
appendOption(credentials, "-password", profile.credentials.password);
|
||||
appendOption(credentials, "-totp-secret", profile.credentials.totpSecret);
|
||||
|
||||
appendOption(arguments, "-cert-file", profile.credentials.certFile);
|
||||
appendOption(arguments, "-cert-password", profile.credentials.certPassword);
|
||||
command.arguments = credentials + arguments;
|
||||
return command;
|
||||
}
|
||||
|
||||
@@ -16,6 +16,11 @@ void DeviceTrust::set(
|
||||
bool trusted
|
||||
)
|
||||
{
|
||||
if (protocol != "atrust")
|
||||
{
|
||||
throw std::runtime_error("授信设备功能仅支持 aTrust");
|
||||
}
|
||||
|
||||
QStringList arguments;
|
||||
if (!protocol.isEmpty())
|
||||
{
|
||||
|
||||
@@ -215,7 +215,8 @@ void ZjuConnectProcess::start(const ConnectionProfile &profile)
|
||||
{
|
||||
qInfo().noquote() << "使用了 TOTP";
|
||||
}
|
||||
if (!profile.credentials.certFile.isEmpty())
|
||||
if (profile.endpoint.protocol == "easyconnect"
|
||||
&& !profile.credentials.certFile.isEmpty())
|
||||
{
|
||||
qInfo().noquote() << "使用了证书文件";
|
||||
}
|
||||
|
||||
@@ -16,8 +16,8 @@ ConnectionProfile SettingsProfileLoader::load(
|
||||
: "certificate"
|
||||
).toString();
|
||||
const bool useCertificate =
|
||||
settings.value("ZJUConnect/Protocol").toString() != "easyconnect"
|
||||
|| easyconnectAuthType == "certificate";
|
||||
settings.value("ZJUConnect/Protocol").toString() == "easyconnect"
|
||||
&& easyconnectAuthType == "certificate";
|
||||
profile.credentials = {
|
||||
username,
|
||||
password,
|
||||
|
||||
@@ -89,16 +89,13 @@ bool buildsCompleteCommandInCompatibleOrder()
|
||||
"-zju-dns-server", "10.0.0.1",
|
||||
"-dns-ttl", "60",
|
||||
"-secondary-dns-server", "10.0.0.2",
|
||||
"-disable-multi-line",
|
||||
"-disable-keep-alive",
|
||||
"-keep-alive-url", "https://keepalive",
|
||||
"-bind-interface", "en0",
|
||||
"-auto-detect-interface",
|
||||
"-disable-zju-config",
|
||||
"-disable-zju-dns",
|
||||
"-disable-server-config",
|
||||
"-proxy-all",
|
||||
"-skip-domain-resource",
|
||||
"-tun-mode",
|
||||
"-dns-hijack",
|
||||
"-fake-ip",
|
||||
@@ -111,14 +108,74 @@ bool buildsCompleteCommandInCompatibleOrder()
|
||||
"-tcp-port-forwarding", "127.0.0.1:80/10.0.0.1:80",
|
||||
"-udp-port-forwarding", "127.0.0.1:53/10.0.0.1:53",
|
||||
"-custom-dns", "example.org=1.1.1.1",
|
||||
"-custom-proxy-domain", "example.org",
|
||||
"-foo", "bar",
|
||||
"-cert-file", "/tmp/client.p12",
|
||||
"-cert-password", "cert-secret"
|
||||
"-foo", "bar"
|
||||
};
|
||||
return expectEqual(command.arguments, expected, "buildsCompleteCommandInCompatibleOrder");
|
||||
}
|
||||
|
||||
bool keepsEasyConnectOnlyOptionsOutOfATrustCommand()
|
||||
{
|
||||
ConnectionProfile profile;
|
||||
profile.endpoint.protocol = "atrust";
|
||||
profile.credentials.certFile = "/tmp/client.p12";
|
||||
profile.credentials.certPassword = "cert-secret";
|
||||
profile.proxy.customDomains = "example.org";
|
||||
profile.behavior.disableMultiLine = true;
|
||||
profile.behavior.disableZjuConfig = true;
|
||||
profile.behavior.skipDomainResource = true;
|
||||
|
||||
const CoreCommand command = CoreCommandBuilder::build(profile);
|
||||
return expectEqual(
|
||||
command.arguments,
|
||||
{"-protocol", "atrust"},
|
||||
"keepsEasyConnectOnlyOptionsOutOfATrustCommand"
|
||||
);
|
||||
}
|
||||
|
||||
bool addsEasyConnectOnlyOptionsForEasyConnect()
|
||||
{
|
||||
ConnectionProfile profile;
|
||||
profile.endpoint.protocol = "easyconnect";
|
||||
profile.credentials.username = "alice";
|
||||
profile.credentials.certFile = "/tmp/client.p12";
|
||||
profile.credentials.certPassword = "cert-secret";
|
||||
profile.proxy.customDomains = "example.org";
|
||||
profile.behavior.disableMultiLine = true;
|
||||
profile.behavior.disableZjuConfig = true;
|
||||
profile.behavior.skipDomainResource = true;
|
||||
|
||||
const CoreCommand command = CoreCommandBuilder::build(profile);
|
||||
return expectEqual(
|
||||
command.arguments,
|
||||
{
|
||||
"-cert-file", "/tmp/client.p12",
|
||||
"-cert-password", "cert-secret",
|
||||
"-username", "alice",
|
||||
"-protocol", "easyconnect",
|
||||
"-disable-multi-line",
|
||||
"-disable-zju-config",
|
||||
"-skip-domain-resource",
|
||||
"-custom-proxy-domain", "example.org"
|
||||
},
|
||||
"addsEasyConnectOnlyOptionsForEasyConnect"
|
||||
);
|
||||
}
|
||||
|
||||
bool keepsATrustOnlyOptionsOutOfEasyConnectCommand()
|
||||
{
|
||||
ConnectionProfile profile;
|
||||
profile.endpoint = {"easyconnect", "cas", "domain", "86-123", QString(), 0};
|
||||
profile.behavior.updateBestNodesInterval = 30;
|
||||
|
||||
const CoreRuntimePaths runtimePaths{QString(), "/tmp/structured-client-data.json"};
|
||||
const CoreCommand command = CoreCommandBuilder::build(profile, runtimePaths);
|
||||
return expectEqual(
|
||||
command.arguments,
|
||||
{"-protocol", "easyconnect"},
|
||||
"keepsATrustOnlyOptionsOutOfEasyConnectCommand"
|
||||
);
|
||||
}
|
||||
|
||||
bool excludesCredentialsFromLoggableArguments()
|
||||
{
|
||||
ConnectionProfile profile;
|
||||
@@ -171,6 +228,9 @@ int main(int argc, char *argv[])
|
||||
const bool passed = buildsMinimalCommand()
|
||||
&& addsGraphCaptchaFileForEasyConnect()
|
||||
&& buildsCompleteCommandInCompatibleOrder()
|
||||
&& keepsEasyConnectOnlyOptionsOutOfATrustCommand()
|
||||
&& addsEasyConnectOnlyOptionsForEasyConnect()
|
||||
&& keepsATrustOnlyOptionsOutOfEasyConnectCommand()
|
||||
&& excludesCredentialsFromLoggableArguments()
|
||||
&& quotesLoggableArgumentsWithoutChangingArguments();
|
||||
return passed ? 0 : 1;
|
||||
|
||||
@@ -69,8 +69,8 @@ bool loadsSettingsIntoTypedProfile()
|
||||
&& profile.credentials.username == "alice"
|
||||
&& profile.credentials.password == "secret"
|
||||
&& profile.credentials.totpSecret == "totp"
|
||||
&& profile.credentials.certFile == "/tmp/client.p12"
|
||||
&& profile.credentials.certPassword == "cert-password"
|
||||
&& profile.credentials.certFile.isEmpty()
|
||||
&& profile.credentials.certPassword.isEmpty()
|
||||
&& profile.endpoint.protocol == "atrust"
|
||||
&& profile.endpoint.authType == "cas"
|
||||
&& profile.endpoint.loginDomain == "domain"
|
||||
|
||||
Reference in New Issue
Block a user