Skip to content

Commit

Permalink
feat: add --trust as a less scary alternative to --UNSAFE (copier…
Browse files Browse the repository at this point in the history
…-org#1179)

See rationale in copier-org#1137 (comment).

Co-authored-by: Sigurd Spieckermann <2206639+sisp@users.noreply.github.com>
  • Loading branch information
yajo and sisp authored Jun 28, 2023
1 parent 32f2a3a commit aaf6cf3
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 9 deletions.
2 changes: 1 addition & 1 deletion copier/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ class _Subcommand(cli.Application):
help="Use prereleases to compare template VCS tags.",
)
unsafe = cli.Flag(
["--UNSAFE"],
["--UNSAFE", "--trust"],
help=(
"Allow templates with unsafe features (Jinja extensions, migrations, tasks)"
),
Expand Down
4 changes: 2 additions & 2 deletions docs/configuring.md
Original file line number Diff line number Diff line change
Expand Up @@ -1317,7 +1317,7 @@ templates suffix is _not_ empty, Copier will abort and print an error message.
### `unsafe`

- Format: `bool`
- CLI flags: `--UNSAFE`
- CLI flags: `--UNSAFE`, `--trust`
- Default value: `False`

Copier templates can use dangerous features that allow arbitrary code execution:
Expand All @@ -1330,7 +1330,7 @@ Therefore, these features are disabled by default and Copier will raise an error
exit from the CLI with code `2`) when they are found in a template. In this case, please
verify that no malicious code gets executed by any of the used features. When you're
sufficiently confident or willing to take the risk, set `unsafe=True` or pass the CLI
switch `--UNSAFE`.
switch `--UNSAFE` or `--trust`.

!!! danger

Expand Down
13 changes: 7 additions & 6 deletions tests/test_unsafe.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from contextlib import nullcontext as does_not_raise
from typing import ContextManager
from typing import ContextManager, Union

import pytest
import yaml
Expand Down Expand Up @@ -314,13 +314,14 @@ def test_update(
run_update(dst, overwrite=True, unsafe=unsafe)


@pytest.mark.parametrize("unsafe", [False, True])
@pytest.mark.parametrize("unsafe", [False, "--trust", "--UNSAFE"])
def test_update_cli(
tmp_path_factory: pytest.TempPathFactory,
capsys: pytest.CaptureFixture[str],
unsafe: bool,
unsafe: Union[bool, str],
) -> None:
src, dst = map(tmp_path_factory.mktemp, ["src", "dst"])
unsafe_args = [unsafe] if unsafe else []

with local.cwd(src):
build_file_tree(
Expand All @@ -335,7 +336,7 @@ def test_update_cli(
git("tag", "v1")

_, retcode = CopierApp.run(
["copier", "copy", "--UNSAFE", str(src), str(dst)],
["copier", "copy", str(src), str(dst)] + unsafe_args,
exit=False,
)
assert retcode == 0
Expand All @@ -361,9 +362,9 @@ def test_update_cli(
[
"copier",
"update",
*(["--UNSAFE"] if unsafe else []),
str(dst),
],
]
+ unsafe_args,
exit=False,
)
if unsafe:
Expand Down

0 comments on commit aaf6cf3

Please sign in to comment.