incubator-allura-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tvansteenbu...@apache.org
Subject git commit: [#6894] Sanitize trailing slashes on base_url when generating hook
Date Fri, 10 Jan 2014 15:48:47 GMT
Updated Branches:
  refs/heads/master 162309771 -> abd53ba5d


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

Signed-off-by: Cory Johns <cjohns@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/abd53ba5
Tree: http://git-wip-us.apache.org/repos/asf/incubator-allura/tree/abd53ba5
Diff: http://git-wip-us.apache.org/repos/asf/incubator-allura/diff/abd53ba5

Branch: refs/heads/master
Commit: abd53ba5de52245da3c159fe242b55189f96ec7a
Parents: 1623097
Author: Cory Johns <cjohns@slashdotmedia.com>
Authored: Thu Jan 9 23:52:09 2014 +0000
Committer: Tim Van Steenburgh <tvansteenburgh@gmail.com>
Committed: Fri Jan 10 15:48:04 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/abd53ba5/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/abd53ba5/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/abd53ba5/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/abd53ba5/ForgeSVN/forgesvn/model/svn.py
----------------------------------------------------------------------
diff --git a/ForgeSVN/forgesvn/model/svn.py b/ForgeSVN/forgesvn/model/svn.py
index f4d0ac0..a547913 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._repo.refresh_url())
         fn = os.path.join(self._repo.fs_path, self._repo.name, 'hooks', 'post-commit')
         with open(fn, 'wb') as fp:
             fp.write(text)


Mime
View raw message