From 7bf12636a05a0bcc53f0c947994b6a376e5cc778 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lubom=C3=ADr=20Sedl=C3=A1=C5=99?= Date: Mon, 26 Sep 2016 15:50:49 +0200 Subject: [PATCH] Translate paths without double slash MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit If the path in `translate_paths` config ends with a slash, we would create public path with double slash. Fixes: https://pagure.io/pungi/issue/408 Signed-off-by: Lubomír Sedlář --- pungi/paths.py | 2 ++ tests/test_notifier.py | 28 ++++++++++++++++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/pungi/paths.py b/pungi/paths.py index b688fb29..41c8a107 100644 --- a/pungi/paths.py +++ b/pungi/paths.py @@ -36,6 +36,8 @@ def translate_path(compose, path): for prefix, newvalue in mapping: prefix = os.path.normpath(prefix) + # Strip trailing slashes: the prefix has them stripped by `normpath`. + newvalue = newvalue.rstrip('/') if normpath.startswith(prefix): # We can't call os.path.normpath on result since it is not actually # a path - http:// would get changed to http:/ and so on. diff --git a/tests/test_notifier.py b/tests/test_notifier.py index 8c079f7d..8077e1cb 100755 --- a/tests/test_notifier.py +++ b/tests/test_notifier.py @@ -39,6 +39,34 @@ class TestNotifier(unittest.TestCase): stdin_data=json.dumps(data), can_fail=True, return_stdout=False, workdir='/a/b') + @mock.patch('kobo.shortcuts.run') + def test_translates_path(self, run): + compose = mock.Mock( + compose_id='COMPOSE_ID', + paths=mock.Mock( + compose=mock.Mock( + topdir=mock.Mock(return_value='/root/a/b') + ) + ), + conf={ + "translate_paths": [("/root/", "http://example.com/compose/")], + } + ) + + run.return_value = (0, None) + + n = PungiNotifier('run-notify') + n.compose = compose + data = {'foo': 'bar', 'baz': 'quux'} + n.send('cmd', **data) + + data['compose_id'] = 'COMPOSE_ID' + data['location'] = 'http://example.com/compose/a/b' + run.assert_called_once_with(('run-notify', 'cmd'), + stdin_data=json.dumps(data), + can_fail=True, return_stdout=False, + workdir='/root/a/b') + @mock.patch('kobo.shortcuts.run') def test_does_not_run_without_config(self, run): n = PungiNotifier(None)