1 #include <gtest/gtest.h> 6 #include <boost/process.hpp> 8 #include "authenticate.h" 9 #include "server_credentials.h" 10 #include "test_utils.h" 11 #include "treehub_server.h" 12 #include "utilities/utils.h" 14 boost::filesystem::path certs_dir;
18 TEST(authenticate, good_zip) {
20 boost::filesystem::path filepath =
"tests/sota_tools/auth_test_good.zip";
22 EXPECT_EQ(creds.GetMethod(), AuthMethod::kOauth2);
24 int r = authenticate(
"", creds, treehub);
30 TEST(authenticate, good_cert_zip) {
32 boost::filesystem::path filepath = certs_dir /
"good.zip";
34 EXPECT_EQ(creds.GetMethod(), AuthMethod::kTls);
36 int r = authenticate(
"tests/fake_http_server/server.crt", creds, treehub);
39 curlEasySetoptWrapper(curl_handle.get(), CURLOPT_VERBOSE, 1);
40 treehub.InjectIntoCurl(
"test.txt", curl_handle.get());
41 CURLcode rc = curl_easy_perform(curl_handle.get());
42 EXPECT_EQ(CURLE_OK, rc);
48 TEST(authenticate, good_cert_noauth_zip) {
50 boost::filesystem::path filepath =
"tests/sota_tools/auth_test_noauth_good.zip";
52 EXPECT_EQ(creds.GetMethod(), AuthMethod::kNone);
54 int r = authenticate(
"tests/fake_http_server/server.crt", creds, treehub);
57 curlEasySetoptWrapper(curl_handle.get(), CURLOPT_VERBOSE, 1);
58 treehub.InjectIntoCurl(
"test.txt", curl_handle.get());
59 CURLcode rc = curl_easy_perform(curl_handle.get());
61 EXPECT_EQ(CURLE_OK, rc);
64 TEST(authenticate, bad_cert_zip) {
68 boost::filesystem::path filepath = certs_dir /
"bad.zip";
70 EXPECT_EQ(creds.GetMethod(), AuthMethod::kTls);
72 int r = authenticate(
"", creds, treehub);
75 curlEasySetoptWrapper(curl_handle.get(), CURLOPT_VERBOSE, 1);
76 treehub.InjectIntoCurl(
"test.txt", curl_handle.get());
77 CURLcode rc = curl_easy_perform(curl_handle.get());
79 EXPECT_NE(CURLE_OK, rc);
83 TEST(authenticate, bad_zip) {
84 boost::filesystem::path filepath =
"tests/sota_tools/auth_test_bad.zip";
91 TEST(authenticate, no_json_zip) {
92 boost::filesystem::path filepath =
"tests/sota_tools/auth_test_no_json.zip";
97 TEST(authenticate, good_json) {
99 boost::filesystem::path filepath =
"tests/sota_tools/auth_test_good.json";
106 TEST(authenticate, bad_json) {
107 boost::filesystem::path filepath =
"tests/sota_tools/auth_test_bad.json";
114 TEST(authenticate, invalid_file) {
115 boost::filesystem::path filepath =
"tests/sota_tools/auth_test.cc";
120 TEST(authenticate, offline_sign_creds) {
123 boost::filesystem::path auth_offline =
"tests/sota_tools/auth_test_good_offline.zip";
125 EXPECT_TRUE(creds_offline.CanSignOffline());
129 TEST(authenticate, online_sign_creds) {
131 boost::filesystem::path auth_online = certs_dir /
"good.zip";
133 EXPECT_FALSE(creds_online.CanSignOffline());
137 int main(
int argc,
char **argv) {
138 ::testing::InitGoogleTest(&argc, argv);
140 std::cerr <<
"Error: " << argv[0] <<
" requires the path to the directory with generated certificates.\n";
145 boost::process::child server_process(
"tests/fake_http_server/tls_server.py");
146 boost::process::child server_noauth_process(
"tests/fake_http_server/tls_noauth_server.py");
151 TestUtils::waitForServer(
"https://localhost:2443/");
152 return RUN_ALL_TESTS();