Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow ~user in universal ID if it's the current user #4730

Merged
merged 1 commit into from
Mar 4, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions cylc/flow/id_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
UserInputError,
WorkflowFilesError,
)
from cylc.flow.hostuserutil import get_user
from cylc.flow.id import (
Tokens,
contains_multiple_workflows,
Expand All @@ -47,6 +48,7 @@
validate_workflow_name,
)


FN_CHARS = re.compile(r'[\*\?\[\]\!]')


Expand Down Expand Up @@ -380,9 +382,9 @@ def _validate_constraint(*tokens_list, constraint=None):

def _validate_workflow_ids(*tokens_list, src_path):
for ind, tokens in enumerate(tokens_list):
if tokens['user']:
if tokens['user'] and (tokens['user'] != get_user()):
raise UserInputError(
"Operating on others users' workflows is not supported"
"Operating on other users' workflows is not supported"
)
if not src_path:
validate_workflow_name(tokens['workflow'])
Expand Down
13 changes: 11 additions & 2 deletions tests/unit/test_id_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -370,12 +370,15 @@ async def test_parse_ids_src_path(src_dir):
),
(
['~alice/foo'],
"Operating on others users' workflows is not supported",
"Operating on other users' workflows is not supported",
),
]
)
async def test_parse_ids_invalid_ids(ids_in, error_msg):
async def test_parse_ids_invalid_ids(
ids_in, error_msg, monkeypatch: pytest.MonkeyPatch
):
"""It should error for invalid IDs."""
monkeypatch.setattr('cylc.flow.id_cli.get_user', lambda: 'rincewind')
with pytest.raises(Exception) as exc_ctx:
await parse_ids_async(
*ids_in,
Expand All @@ -384,6 +387,12 @@ async def test_parse_ids_invalid_ids(ids_in, error_msg):
assert error_msg in str(exc_ctx.value)


async def test_parse_ids_current_user(monkeypatch: pytest.MonkeyPatch):
"""It should work if the user in the ID is the current user."""
monkeypatch.setattr('cylc.flow.id_cli.get_user', lambda: 'rincewind')
await parse_ids_async('~rincewind/luggage', constraint='workflows')


async def test_parse_ids_file(tmp_run_dir):
"""It should reject IDs that are paths to files."""
tmp_path = tmp_run_dir('x')
Expand Down