Skip to content

Linux + iPhone Continuity / iMessage / SMS

fix: tests on nixos

Zack Bartel90855cb1fd13
diff --git a/nix/package.nix b/nix/package.nix
index 2171bd9..97f0aa6 100644
--- a/nix/package.nix
+++ b/nix/package.nix
@@ -117,8 +117,6 @@ stdenv.mkDerivation (finalAttrs: {
'';
doCheck = true;
- # Crypto tests share a temporary HOME and must not run concurrently.
- enableParallelChecking = false;
postCheck = ''
(cd .. && npm test --prefix extension)
diff --git a/test/test_bluetooth_monitor.cpp b/test/test_bluetooth_monitor.cpp
index 4188651..f40153a 100644
--- a/test/test_bluetooth_monitor.cpp
+++ b/test/test_bluetooth_monitor.cpp
@@ -20,7 +20,7 @@ namespace {
explicit FakeBtmgmt(const std::string& body) {
const char* path = std::getenv("PATH");
old_path_ = path ? path : "";
- dir_ = std::filesystem::path("/var/tmp") / ("tether-monitor-test-" + std::to_string(getpid()));
+ dir_ = std::filesystem::temp_directory_path() / ("tether-monitor-test-" + std::to_string(getpid()));
std::filesystem::remove_all(dir_);
std::filesystem::create_directories(dir_);
@@ -32,7 +32,7 @@ namespace {
std::filesystem::perms::owner_read | std::filesystem::perms::owner_write |
std::filesystem::perms::owner_exec,
std::filesystem::perm_options::replace);
- setenv("PATH", dir_.c_str(), 1);
+ setenv("PATH", (dir_.string() + ":" + old_path_).c_str(), 1);
}
~FakeBtmgmt() {
@@ -66,7 +66,7 @@ TEST(SecureConnectionsProbe, ParsesEnabledAndDisabledSettings) {
}
TEST(SecureConnectionsProbe, TimesOutAndTerminatesTheExactChild) {
- FakeBtmgmt fake("exec /bin/sleep 5\n");
+ FakeBtmgmt fake("exec sleep 5\n");
const auto started = std::chrono::steady_clock::now();
const auto result = probe_secure_connections("hci0", 50ms);
const auto elapsed = std::chrono::steady_clock::now() - started;
diff --git a/test/test_crypto.cpp b/test/test_crypto.cpp
index 0a58f76..3b763b7 100644
--- a/test/test_crypto.cpp
+++ b/test/test_crypto.cpp
@@ -4,26 +4,30 @@
#include <cstdlib>
#include <fstream>
#include <iostream>
+#include <unistd.h>
class CryptoTest : public ::testing::Test {
protected:
void SetUp() override {
- setenv("HOME", "/tmp/tether_tests", 1);
- std::filesystem::remove_all("/tmp/tether_tests");
- std::filesystem::create_directories("/tmp/tether_tests");
+ setenv("HOME", home_.c_str(), 1);
+ std::filesystem::remove_all(home_);
+ std::filesystem::create_directories(home_);
}
void TearDown() override {
- std::filesystem::remove_all("/tmp/tether_tests");
+ std::filesystem::remove_all(home_);
}
+
+ const std::filesystem::path home_ =
+ std::filesystem::temp_directory_path() / ("tether-tests-" + std::to_string(getpid()));
};
TEST_F(CryptoTest, CompleteCryptographicLifecycle) {
EXPECT_TRUE(tether::Crypto::instance().init());
- EXPECT_TRUE(std::filesystem::exists("/tmp/tether_tests/.config/tether/key.pem"));
- EXPECT_TRUE(std::filesystem::exists("/tmp/tether_tests/.config/tether/cert.pem"));
- EXPECT_TRUE(std::filesystem::exists("/tmp/tether_tests/.config/tether/known_hosts.json"));
+ EXPECT_TRUE(std::filesystem::exists(home_ / ".config/tether/key.pem"));
+ EXPECT_TRUE(std::filesystem::exists(home_ / ".config/tether/cert.pem"));
+ EXPECT_TRUE(std::filesystem::exists(home_ / ".config/tether/known_hosts.json"));
EXPECT_NE(tether::Crypto::instance().get_server_context(), nullptr);
EXPECT_NE(tether::Crypto::instance().get_client_context(), nullptr);
diff --git a/test/test_file_transfer.cpp b/test/test_file_transfer.cpp
index fe80cd3..3fd607c 100644
--- a/test/test_file_transfer.cpp
+++ b/test/test_file_transfer.cpp
@@ -4,18 +4,22 @@
#include <filesystem>
#include <fstream>
#include <string>
+#include <unistd.h>
class FileTransferTest : public ::testing::Test {
protected:
void SetUp() override {
- setenv("HOME", "/tmp/tether_tests", 1);
- std::filesystem::remove_all("/tmp/tether_tests");
- std::filesystem::create_directories("/tmp/tether_tests/Downloads");
+ setenv("HOME", home_.c_str(), 1);
+ std::filesystem::remove_all(home_);
+ std::filesystem::create_directories(home_ / "Downloads");
}
void TearDown() override {
- std::filesystem::remove_all("/tmp/tether_tests");
+ std::filesystem::remove_all(home_);
}
+
+ const std::filesystem::path home_ =
+ std::filesystem::temp_directory_path() / ("tether-tests-" + std::to_string(getpid()));
};
TEST_F(FileTransferTest, SingleChunkTransfer) {
@@ -31,9 +35,9 @@ TEST_F(FileTransferTest, SingleChunkTransfer) {
EXPECT_TRUE(mgr.handle_end(t_id));
// Ensure output matches native directory targeting logic
- EXPECT_TRUE(std::filesystem::exists("/tmp/tether_tests/Downloads/hello.txt"));
+ EXPECT_TRUE(std::filesystem::exists(home_ / "Downloads/hello.txt"));
- std::ifstream iff("/tmp/tether_tests/Downloads/hello.txt");
+ std::ifstream iff(home_ / "Downloads/hello.txt");
std::string res;
std::getline(iff, res);
EXPECT_EQ(res, "hello world");
@@ -54,11 +58,11 @@ TEST_F(FileTransferTest, NameDeduplicatorAppendsCounterGracefully) {
mgr.handle_chunk(t_id2, 0, tether::base64_encode((const unsigned char*)"DEF", 3));
mgr.handle_end(t_id2);
- EXPECT_TRUE(std::filesystem::exists("/tmp/tether_tests/Downloads/image.png"));
- EXPECT_TRUE(std::filesystem::exists("/tmp/tether_tests/Downloads/image(1).png"));
+ EXPECT_TRUE(std::filesystem::exists(home_ / "Downloads/image.png"));
+ EXPECT_TRUE(std::filesystem::exists(home_ / "Downloads/image(1).png"));
// Verify isolated integrity natively
- std::ifstream i2("/tmp/tether_tests/Downloads/image(1).png");
+ std::ifstream i2(home_ / "Downloads/image(1).png");
std::string r2;
std::getline(i2, r2);
EXPECT_EQ(r2, "DEF");
@@ -73,7 +77,7 @@ TEST_F(FileTransferTest, MultiChunkTransferConcatenates) {
EXPECT_TRUE(mgr.handle_chunk(t_id, 1, tether::base64_encode((const unsigned char*)"def", 3)));
EXPECT_TRUE(mgr.handle_end(t_id));
- std::ifstream iff("/tmp/tether_tests/Downloads/parts.txt");
+ std::ifstream iff(home_ / "Downloads/parts.txt");
std::string res;
std::getline(iff, res);
EXPECT_EQ(res, "abcdef");
@@ -88,7 +92,7 @@ TEST_F(FileTransferTest, RejectsChunkPastDeclaredSize) {
// Peer declared 3 bytes but streams 8. The extra must not be written.
EXPECT_FALSE(mgr.handle_chunk(t_id, 0, tether::base64_encode((const unsigned char*)"AAAABBBB", 8)));
EXPECT_FALSE(mgr.handle_end(t_id)) << "aborted transfer must not report success";
- EXPECT_FALSE(std::filesystem::exists("/tmp/tether_tests/Downloads/small.bin"));
+ EXPECT_FALSE(std::filesystem::exists(home_ / "Downloads/small.bin"));
}
TEST_F(FileTransferTest, TruncatedTransferIsNotReportedAsSuccess) {
@@ -100,7 +104,7 @@ TEST_F(FileTransferTest, TruncatedTransferIsNotReportedAsSuccess) {
// Only 3 of 10 bytes arrived; this used to return true and leave a partial file.
EXPECT_FALSE(mgr.handle_end(t_id));
- EXPECT_FALSE(std::filesystem::exists("/tmp/tether_tests/Downloads/short.bin"));
+ EXPECT_FALSE(std::filesystem::exists(home_ / "Downloads/short.bin"));
}
TEST_F(FileTransferTest, DuplicateTransferIdIsRejected) {
@@ -124,6 +128,6 @@ TEST_F(FileTransferTest, PathTraversalInFilenameStaysInDownloads) {
ASSERT_TRUE(mgr.handle_chunk("trav", 0, tether::base64_encode((const unsigned char*)"xyz", 3)));
ASSERT_TRUE(mgr.handle_end("trav"));
- EXPECT_TRUE(std::filesystem::exists("/tmp/tether_tests/Downloads/tether_pwned"));
- EXPECT_FALSE(std::filesystem::exists("/tmp/tether_tests/etc/tether_pwned"));
+ EXPECT_TRUE(std::filesystem::exists(home_ / "Downloads/tether_pwned"));
+ EXPECT_FALSE(std::filesystem::exists(home_ / "etc/tether_pwned"));
}