Merge remote-tracking branch 'origin/feat/chmod' into dev
This commit is contained in:
@@ -190,6 +190,22 @@ class TestExecutability:
|
||||
assert received_mode & 0o077 == 0o011
|
||||
|
||||
|
||||
class TestChmod:
|
||||
def test_chmod_applies_to_transferred_files(self, shared_server):
|
||||
clean_dir(DEST_DIR)
|
||||
source_file = os.path.join(SOURCE_DIR, "small.txt")
|
||||
os.chmod(source_file, 0o777)
|
||||
result, dur = run_client(
|
||||
SOURCE_DIR, DEST_DIR,
|
||||
flags=["--chmod=u=rw,go=r"],
|
||||
port=shared_server.port,
|
||||
)
|
||||
if result.returncode != 0:
|
||||
pytest.fail(f"Exit {result.returncode}: {(result.stderr or result.stdout)[:200]}")
|
||||
received = get_dest_received_dir(DEST_DIR, SOURCE_DIR)
|
||||
assert (os.stat(os.path.join(received, "small.txt")).st_mode & 0o777) == 0o644
|
||||
|
||||
|
||||
class TestExclude:
|
||||
def test_exclude_single(self, shared_server):
|
||||
clean_dir(DEST_DIR)
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
#include "test_client_cli.h"
|
||||
#include "client_validation.h"
|
||||
#include "chmod.h"
|
||||
#include "config.h"
|
||||
#include "log.h"
|
||||
#include "test_utils.h"
|
||||
@@ -250,6 +251,40 @@ static void test_parse_args_executability() {
|
||||
config_delete(cfg);
|
||||
}
|
||||
|
||||
static void test_parse_args_chmod() {
|
||||
Config* cfg = config_create();
|
||||
char* argv[] = {"fastsync", "--chmod=u=rw,go=r", "/src", "/dst"};
|
||||
int positional_args[2];
|
||||
int positional_count = 0;
|
||||
EXPECT_EQ_INT(parse_args(cfg, 4, argv, positional_args, &positional_count), 0);
|
||||
EXPECT_EQ_STR(cfg->chmod_spec, "u=rw,go=r");
|
||||
EXPECT_TRUE(cfg->use_metadata);
|
||||
mode_t result;
|
||||
EXPECT_TRUE(chmod_apply(0777, cfg->chmod_spec, &result));
|
||||
EXPECT_EQ_INT(result, 0644);
|
||||
config_delete(cfg);
|
||||
}
|
||||
|
||||
static void test_parse_args_numeric_chmod() {
|
||||
Config* cfg = config_create();
|
||||
char* argv[] = {"fastsync", "--chmod", "7777", "/src", "/dst"};
|
||||
int positional_args[2];
|
||||
int positional_count = 0;
|
||||
EXPECT_EQ_INT(parse_args(cfg, 5, argv, positional_args, &positional_count), 0);
|
||||
EXPECT_EQ_STR(cfg->chmod_spec, "7777");
|
||||
EXPECT_TRUE(cfg->use_metadata);
|
||||
config_delete(cfg);
|
||||
}
|
||||
|
||||
static void test_parse_args_rejects_invalid_chmod() {
|
||||
Config* cfg = config_create();
|
||||
char* argv[] = {"fastsync", "--chmod=a+X", "/src", "/dst"};
|
||||
int positional_args[2];
|
||||
int positional_count = 0;
|
||||
EXPECT_EQ_INT(parse_args(cfg, 4, argv, positional_args, &positional_count), -1);
|
||||
config_delete(cfg);
|
||||
}
|
||||
|
||||
/* Test parse_args rejects port > 65535 */
|
||||
static void test_parse_args_invalid_port() {
|
||||
Config* cfg = config_create();
|
||||
@@ -671,6 +706,9 @@ void test_client_cli() {
|
||||
test_parse_args_size_only();
|
||||
test_parse_args_ignore_existing();
|
||||
test_parse_args_executability();
|
||||
test_parse_args_chmod();
|
||||
test_parse_args_numeric_chmod();
|
||||
test_parse_args_rejects_invalid_chmod();
|
||||
test_parse_args_invalid_port();
|
||||
test_parse_args_non_numeric_port();
|
||||
test_parse_args_invalid_server_port();
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
#include "test_metadata.h"
|
||||
#include "chmod.h"
|
||||
#include "metadata.h"
|
||||
#include "protocol.h"
|
||||
#include "test_utils.h"
|
||||
@@ -185,6 +186,27 @@ static void test_directory_restore_executability_only() {
|
||||
rmdir(path);
|
||||
}
|
||||
|
||||
static void test_chmod_changes() {
|
||||
mode_t result;
|
||||
EXPECT_TRUE(chmod_apply(0777, "u=rw,go=r", &result));
|
||||
EXPECT_EQ_INT(result, 0644);
|
||||
EXPECT_TRUE(chmod_apply(0644, "a+x", &result));
|
||||
EXPECT_EQ_INT(result, 0755);
|
||||
result = 0777;
|
||||
EXPECT_TRUE(chmod_apply(0777, "0000", &result));
|
||||
EXPECT_EQ_INT(result, 0000);
|
||||
result = 0777;
|
||||
EXPECT_TRUE(chmod_apply(0777, "7777", &result));
|
||||
EXPECT_EQ_INT(result, 07777);
|
||||
result = 0777;
|
||||
EXPECT_TRUE(chmod_apply(0777, "755", &result));
|
||||
EXPECT_EQ_INT(result, 0755);
|
||||
EXPECT_FALSE(chmod_apply(0777, "888", &result));
|
||||
EXPECT_FALSE(chmod_apply(0777, "10000", &result));
|
||||
EXPECT_FALSE(chmod_apply(0777, "a+X", &result));
|
||||
EXPECT_FALSE(chmod_apply(0777, "a+r,", &result));
|
||||
}
|
||||
|
||||
void test_metadata() {
|
||||
test_metadata_to_from_buf_roundtrip();
|
||||
test_metadata_to_buf_null();
|
||||
@@ -196,4 +218,5 @@ void test_metadata() {
|
||||
test_file_restore_metadata();
|
||||
test_file_restore_executability_only();
|
||||
test_directory_restore_executability_only();
|
||||
test_chmod_changes();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user