Skip to content
This repository has been archived by the owner on May 21, 2024. It is now read-only.

Commit

Permalink
Merge pull request #1254 from advancedtelematic/fix/OTA-2851/test-tre…
Browse files Browse the repository at this point in the history
…ehub-improvment

OTA-2851: Support ostree refs posting by the test treehub server
  • Loading branch information
pattivacek authored Jul 19, 2019
2 parents 17c3713 + 1e0fdcd commit 383dfc3
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 3 deletions.
14 changes: 12 additions & 2 deletions src/sota_tools/deploy_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,25 @@ TEST(deploy, UploadToTreehub) {
OSTreeRepo::ptr src_repo = std::make_shared<OSTreeDirRepo>("tests/sota_tools/repo");
boost::filesystem::path filepath = (temp_dir.Path() / "auth.json").string();
boost::filesystem::path cert_path = "tests/fake_http_server/client.crt";
auto server_creds = ServerCredentials(filepath);
auto run_mode = RunMode::kDefault;
auto test_ref = src_repo->GetRef("master");

const uint8_t hash[32] = {0x16, 0xef, 0x2f, 0x26, 0x29, 0xdc, 0x92, 0x63, 0xfd, 0xf3, 0xc0,
0xf0, 0x32, 0x56, 0x3a, 0x2d, 0x75, 0x76, 0x23, 0xbb, 0xc1, 0x1c,
0xf9, 0x9d, 0xf2, 0x5c, 0x3c, 0x3f, 0x25, 0x8d, 0xcc, 0xbe};
UploadToTreehub(src_repo, ServerCredentials(filepath), OSTreeHash(hash), cert_path.string(), RunMode::kDefault, 2);
UploadToTreehub(src_repo, server_creds, OSTreeHash(hash), cert_path.string(), run_mode, 2);

int result = system(
(std::string("diff -r ") + (temp_dir.Path() / "objects/").string() + " tests/sota_tools/repo/objects/").c_str());
EXPECT_EQ(result, 0) << "Diff between source and destination repos is nonzero.";
EXPECT_EQ(result, 0) << "Diff between the source repo objects and the destination repo objects is nonzero.";

bool push_root_ref_res = PushRootRef(server_creds, test_ref, cert_path.string(), run_mode);
EXPECT_TRUE(push_root_ref_res);

result =
system((std::string("diff -r ") + (temp_dir.Path() / "refs/").string() + " tests/sota_tools/repo/refs/").c_str());
EXPECT_EQ(result, 0) << "Diff between the source repo refs and the destination repos refs is nonzero.";
}

#ifndef __NO_MAIN__
Expand Down
2 changes: 1 addition & 1 deletion src/sota_tools/server_credentials.cc
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ bool ServerCredentials::CanSignOffline() const {
archive_read_data_skip(a);
}
}
(void)archive_read_free(a);
}
(void)archive_read_free(a);
return (found_root && found_targets_pub && found_targets_sec && found_tufrepo_url);
}
15 changes: 15 additions & 0 deletions tests/sota_tools/treehub_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ def do_GET(self):
def do_POST(self):
print("POST: %s\n" % self.path)
ctype, pdict = cgi.parse_header(self.headers['Content-Type'])
print("Upload type: {}".format(ctype))
if ctype == 'multipart/form-data':
pdict['boundary'] = bytes(pdict['boundary'], 'utf-8')
fields = cgi.parse_multipart(self.rfile, pdict)
Expand All @@ -65,6 +66,20 @@ def do_POST(self):
self.send_response_only(200)
self.end_headers()
return
elif ctype == 'application/x-www-form-urlencoded':
length = int(self.headers['content-length'])
postvars = cgi.parse_qs(self.rfile.read(length), keep_blank_values=1)
full_path = os.path.join(repo_path, self.path[1:])
os.makedirs(os.path.dirname(full_path), exist_ok=True)
with open(full_path, "wb") as f:
for key in postvars:
print(key)
f.write(key)
f.write(b'\n') # refs is represented as a string in the source repo and has a trailing newline byte
self.send_response_only(200)
self.end_headers()
return

self.send_response_only(400)
self.end_headers()

Expand Down

0 comments on commit 383dfc3

Please sign in to comment.