You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@allura.apache.org by jo...@apache.org on 2014/01/10 00:52:21 UTC

git commit: [#6894] Sanitize trailing slashes on base_url when generating hook

Updated Branches:
  refs/heads/cj/6894 [created] da4e3a55d


[#6894] Sanitize trailing slashes on base_url when generating hook

Signed-off-by: Cory Johns <cj...@slashdotmedia.com>


Project: http://git-wip-us.apache.org/repos/asf/incubator-allura/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-allura/commit/da4e3a55
Tree: http://git-wip-us.apache.org/repos/asf/incubator-allura/tree/da4e3a55
Diff: http://git-wip-us.apache.org/repos/asf/incubator-allura/diff/da4e3a55

Branch: refs/heads/cj/6894
Commit: da4e3a55d57164eb04bd34cc2da6bd3d9ed1dff1
Parents: 86fca2f
Author: Cory Johns <cj...@slashdotmedia.com>
Authored: Thu Jan 9 23:52:09 2014 +0000
Committer: Cory Johns <cj...@slashdotmedia.com>
Committed: Thu Jan 9 23:52:09 2014 +0000

----------------------------------------------------------------------
 Allura/allura/model/repository.py      |  7 +++++++
 Allura/allura/tests/model/test_repo.py | 30 +++++++++++++++++++++++++++++
 ForgeGit/forgegit/model/git_repo.py    |  3 +--
 ForgeSVN/forgesvn/model/svn.py         |  3 +--
 4 files changed, 39 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/da4e3a55/Allura/allura/model/repository.py
----------------------------------------------------------------------
diff --git a/Allura/allura/model/repository.py b/Allura/allura/model/repository.py
index 252210e..b0f567e 100644
--- a/Allura/allura/model/repository.py
+++ b/Allura/allura/model/repository.py
@@ -498,6 +498,13 @@ class Repository(Artifact, ActivityObject):
     def url(self):
         return self.app_config.url()
 
+    def refresh_url(self):
+        return '/'.join([
+                tg.config.get('base_url', 'http://localhost:8080').rstrip('/'),
+                'auth/refresh_repo',
+                self.url().lstrip('/'),
+            ])
+
     def shorthand_id(self):
         return self.name
 

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/da4e3a55/Allura/allura/tests/model/test_repo.py
----------------------------------------------------------------------
diff --git a/Allura/allura/tests/model/test_repo.py b/Allura/allura/tests/model/test_repo.py
index a2a66ff..f0bf936 100644
--- a/Allura/allura/tests/model/test_repo.py
+++ b/Allura/allura/tests/model/test_repo.py
@@ -95,6 +95,36 @@ class RepoImplTestBase(object):
         self.assertEqual(run.parent_commit_ids, [])
 
 
+class RepoTestBase(unittest.TestCase):
+    def setUp(self):
+        setup_basic_test()
+
+    @mock.patch('allura.model.repository.Repository.url')
+    def test_refresh_url(self, url):
+        url.return_value = '/p/test/repo'
+        c.app = mock.Mock(**{'config._id': 'deadbeef'})
+        repo = M.repository.Repository()
+        cases = [
+            [
+                None,
+                'http://localhost:8080/auth/refresh_repo/p/test/repo',
+            ],
+            [
+                'https://somewhere.com',
+                'https://somewhere.com/auth/refresh_repo/p/test/repo',
+            ],
+            [
+                'http://somewhere.com/',
+                'http://somewhere.com/auth/refresh_repo/p/test/repo',
+            ]]
+        for base_url, result in cases:
+            values = {}
+            if base_url:
+                values['base_url'] = base_url
+            with mock.patch.dict(config, values, clear=True):
+                self.assertEqual(result, repo.refresh_url())
+
+
 class TestLastCommit(unittest.TestCase):
     def setUp(self):
         setup_basic_test()

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/da4e3a55/ForgeGit/forgegit/model/git_repo.py
----------------------------------------------------------------------
diff --git a/ForgeGit/forgegit/model/git_repo.py b/ForgeGit/forgegit/model/git_repo.py
index ae9f63e..9debcc9 100644
--- a/ForgeGit/forgegit/model/git_repo.py
+++ b/ForgeGit/forgegit/model/git_repo.py
@@ -417,8 +417,7 @@ class GitImplementation(M.RepositoryImplementation):
     def _setup_hooks(self, source_path=None):
         'Set up the git post-commit hook'
         text = self.post_receive_template.substitute(
-            url=tg.config.get('base_url', 'http://localhost:8080')
-            + '/auth/refresh_repo' + self._repo.url())
+            url=self._repo.refresh_url())
         fn = os.path.join(self._repo.fs_path, self._repo.name, 'hooks', 'post-receive')
         with open(fn, 'w') as fp:
             fp.write(text)

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/da4e3a55/ForgeSVN/forgesvn/model/svn.py
----------------------------------------------------------------------
diff --git a/ForgeSVN/forgesvn/model/svn.py b/ForgeSVN/forgesvn/model/svn.py
index f4d0ac0..954179b 100644
--- a/ForgeSVN/forgesvn/model/svn.py
+++ b/ForgeSVN/forgesvn/model/svn.py
@@ -630,8 +630,7 @@ class SVNImplementation(M.RepositoryImplementation):
         # setup a post-commit hook to notify Allura of changes to the repo
         # the hook should also call the user-defined post-commit-user hook
         text = self.post_receive_template.substitute(
-            url=tg.config.get('base_url', 'http://localhost:8080')
-            + '/auth/refresh_repo' + self._repo.url())
+            url=self.refresh_repo.url())
         fn = os.path.join(self._repo.fs_path, self._repo.name, 'hooks', 'post-commit')
         with open(fn, 'wb') as fp:
             fp.write(text)