Skip to content

Commit df4c1a5

Browse files
committed
add man and tests for removing write permission from template result
Signed-off-by: Tin Lai <[email protected]>
1 parent d7669f2 commit df4c1a5

File tree

5 files changed

+35
-2
lines changed

5 files changed

+35
-2
lines changed

test/conftest.py

+1
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,7 @@ def supported_configs():
157157
"yadm.openssl-old",
158158
"yadm.openssl-program",
159159
"yadm.ssh-perms",
160+
"yadm.template-read-only",
160161
]
161162

162163

test/test_alt.py

+22
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,28 @@ def test_ensure_alt_path(runner, paths, style):
292292
assert run.out == ""
293293
assert paths.work.join(filename).read().strip() == "test-data"
294294

295+
@pytest.mark.usefixtures("ds1_repo_copy")
296+
@pytest.mark.parametrize("readonly", [None, "true", "false"])
297+
def test_template_readonly(runner, yadm_cmd, paths, tst_sys, readonly):
298+
"""Remove write permission for template result file.
299+
300+
If the `yadm.template-read-only` configuration is not set to false,
301+
the resulting file from processing a template should has no write permission.
302+
"""
303+
# set the value of template read-only
304+
if readonly:
305+
runner(yadm_cmd("config", "yadm.template-read-only", readonly))
306+
307+
utils.create_alt_files(paths, f"##template.default")
308+
run = runner(yadm_cmd("alt"))
309+
310+
for stale_path in [utils.ALT_FILE1, utils.ALT_FILE2]:
311+
write_perm_mask = os.stat(paths.work.join(stale_path)).st_mode & 0o222
312+
if readonly == "false":
313+
assert write_perm_mask > 0
314+
else:
315+
assert write_perm_mask == 0
316+
295317

296318
def setup_standard_yadm_dir(paths):
297319
"""Configure a yadm home within the work tree"""

yadm

+2-1
Original file line numberDiff line numberDiff line change
@@ -540,7 +540,7 @@ function move_file() {
540540

541541
mv -f "$temp_file" "$output"
542542
copy_perms "$input" "$output"
543-
[ "$(config --bool yadm.template-read-only)" == "true" ] && chmod a-w "$output"
543+
[ "$(config --bool yadm.template-read-only)" != "false" ] && chmod a-w "$output"
544544
}
545545

546546
# ****** yadm Commands ******
@@ -1267,6 +1267,7 @@ yadm.openssl-ciphername
12671267
yadm.openssl-old
12681268
yadm.openssl-program
12691269
yadm.ssh-perms
1270+
yadm.template-read-only
12701271
EOF
12711272
printf '%s' "$msg"
12721273
}

yadm.1

+7
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,9 @@ unnecessary to run this command, as yadm automatically processes alternates by
108108
default. This automatic behavior can be disabled by setting the configuration
109109
.I yadm.auto-alt
110110
to "false".
111+
The resulting file's write permission can be controlled with the
112+
.I yadm.template-read-only
113+
configuration.
111114
.TP
112115
.B bootstrap
113116
Execute
@@ -425,6 +428,10 @@ By default, the first "openssl" found in $PATH is used.
425428
Disable the permission changes to
426429
.IR $HOME/.ssh/* .
427430
This feature is enabled by default.
431+
.TP
432+
.B yadm.template-read-only
433+
Remove write permissions from the resulting template file.
434+
This feature is enabled by default.
428435

429436
.RE
430437
The following five "local" configurations are not stored in the

yadm.md

+3-1
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,9 @@
6767
TEMPLATES sections. It is usually unnecessary to run this com‐
6868
mand, as yadm automatically processes alternates by default.
6969
This automatic behavior can be disabled by setting the configu‐
70-
ration yadm.auto-alt to "false".
70+
ration yadm.auto-alt to "false". The resulting file's write
71+
permission can be controlled with the yadm.template-read-only
72+
configuration.
7173

7274
bootstrap
7375
Execute $HOME/.config/yadm/bootstrap if it exists.

0 commit comments

Comments
 (0)