Skip to content

Commit

Permalink
Merge pull request #4730 from MetRonnie/user-bug
Browse files Browse the repository at this point in the history
Allow `~user` in universal ID if it's the current user
  • Loading branch information
hjoliver authored Mar 4, 2022
2 parents 098a4fd + 44bd0dc commit 5ff1f0f
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
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

0 comments on commit 5ff1f0f

Please sign in to comment.