test_web.py 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  1. # test_web.py -- Compatibility tests for the git web server.
  2. # Copyright (C) 2010 Google, Inc.
  3. #
  4. # This program is free software; you can redistribute it and/or
  5. # modify it under the terms of the GNU General Public License
  6. # as published by the Free Software Foundation; version 2
  7. # of the License or (at your option) any later version of
  8. # the License.
  9. #
  10. # This program is distributed in the hope that it will be useful,
  11. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. # GNU General Public License for more details.
  14. #
  15. # You should have received a copy of the GNU General Public License
  16. # along with this program; if not, write to the Free Software
  17. # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
  18. # MA 02110-1301, USA.
  19. """Compatibility tests between Dulwich and the cgit HTTP server.
  20. warning: these tests should be fairly stable, but when writing/debugging new
  21. tests, deadlocks may freeze the test process such that it cannot be
  22. Ctrl-C'ed. On POSIX systems, you can kill the tests with Ctrl-Z, "kill %".
  23. """
  24. import threading
  25. from wsgiref import simple_server
  26. import sys
  27. from dulwich.server import (
  28. DictBackend,
  29. UploadPackHandler,
  30. ReceivePackHandler,
  31. )
  32. from dulwich.tests import (
  33. SkipTest,
  34. skipIf,
  35. )
  36. from dulwich.tests.utils import (
  37. skipIfPY3,
  38. )
  39. from dulwich.web import (
  40. make_wsgi_chain,
  41. HTTPGitApplication,
  42. WSGIRequestHandlerLogger,
  43. WSGIServerLogger,
  44. )
  45. from dulwich.tests.compat.server_utils import (
  46. ServerTests,
  47. NoSideBand64kReceivePackHandler,
  48. )
  49. from dulwich.tests.compat.utils import (
  50. CompatTestCase,
  51. )
  52. @skipIf(sys.platform == 'win32', 'Broken on windows, with very long fail time.')
  53. class WebTests(ServerTests):
  54. """Base tests for web server tests.
  55. Contains utility and setUp/tearDown methods, but does non inherit from
  56. TestCase so tests are not automatically run.
  57. """
  58. protocol = 'http'
  59. def _start_server(self, repo):
  60. backend = DictBackend({'/': repo})
  61. app = self._make_app(backend)
  62. dul_server = simple_server.make_server(
  63. 'localhost', 0, app, server_class=WSGIServerLogger,
  64. handler_class=WSGIRequestHandlerLogger)
  65. self.addCleanup(dul_server.shutdown)
  66. self.addCleanup(dul_server.server_close)
  67. threading.Thread(target=dul_server.serve_forever).start()
  68. self._server = dul_server
  69. _, port = dul_server.socket.getsockname()
  70. return port
  71. @skipIf(sys.platform == 'win32', 'Broken on windows, with very long fail time.')
  72. @skipIfPY3
  73. class SmartWebTestCase(WebTests, CompatTestCase):
  74. """Test cases for smart HTTP server.
  75. This server test case does not use side-band-64k in git-receive-pack.
  76. """
  77. min_git_version = (1, 6, 6)
  78. def _handlers(self):
  79. return {'git-receive-pack': NoSideBand64kReceivePackHandler}
  80. def _check_app(self, app):
  81. receive_pack_handler_cls = app.handlers[b'git-receive-pack']
  82. caps = receive_pack_handler_cls.capabilities()
  83. self.assertFalse(b'side-band-64k' in caps)
  84. def _make_app(self, backend):
  85. app = make_wsgi_chain(backend, handlers=self._handlers())
  86. to_check = app
  87. # peel back layers until we're at the base application
  88. while not issubclass(to_check.__class__, HTTPGitApplication):
  89. to_check = to_check.app
  90. self._check_app(to_check)
  91. return app
  92. def patch_capabilities(handler, caps_removed):
  93. # Patch a handler's capabilities by specifying a list of them to be
  94. # removed, and return the original classmethod for restoration.
  95. original_capabilities = handler.capabilities
  96. filtered_capabilities = tuple(
  97. i for i in original_capabilities() if i not in caps_removed)
  98. def capabilities(cls):
  99. return filtered_capabilities
  100. handler.capabilities = classmethod(capabilities)
  101. return original_capabilities
  102. @skipIf(sys.platform == 'win32', 'Broken on windows, with very long fail time.')
  103. @skipIfPY3
  104. class SmartWebSideBand64kTestCase(SmartWebTestCase):
  105. """Test cases for smart HTTP server with side-band-64k support."""
  106. # side-band-64k in git-receive-pack was introduced in git 1.7.0.2
  107. min_git_version = (1, 7, 0, 2)
  108. def setUp(self):
  109. self.o_uph_cap = patch_capabilities(UploadPackHandler, ("no-done",))
  110. self.o_rph_cap = patch_capabilities(ReceivePackHandler, ("no-done",))
  111. super(SmartWebSideBand64kTestCase, self).setUp()
  112. def tearDown(self):
  113. super(SmartWebSideBand64kTestCase, self).tearDown()
  114. UploadPackHandler.capabilities = self.o_uph_cap
  115. ReceivePackHandler.capabilities = self.o_rph_cap
  116. def _handlers(self):
  117. return None # default handlers include side-band-64k
  118. def _check_app(self, app):
  119. receive_pack_handler_cls = app.handlers[b'git-receive-pack']
  120. caps = receive_pack_handler_cls.capabilities()
  121. self.assertTrue(b'side-band-64k' in caps)
  122. self.assertFalse(b'no-done' in caps)
  123. class SmartWebSideBand64kNoDoneTestCase(SmartWebTestCase):
  124. """Test cases for smart HTTP server with side-band-64k and no-done
  125. support.
  126. """
  127. # no-done was introduced in git 1.7.4
  128. min_git_version = (1, 7, 4)
  129. def _handlers(self):
  130. return None # default handlers include side-band-64k
  131. def _check_app(self, app):
  132. receive_pack_handler_cls = app.handlers[b'git-receive-pack']
  133. caps = receive_pack_handler_cls.capabilities()
  134. self.assertTrue(b'side-band-64k' in caps)
  135. self.assertTrue(b'no-done' in caps)
  136. @skipIf(sys.platform == 'win32', 'Broken on windows, with very long fail time.')
  137. @skipIfPY3
  138. class DumbWebTestCase(WebTests, CompatTestCase):
  139. """Test cases for dumb HTTP server."""
  140. def _make_app(self, backend):
  141. return make_wsgi_chain(backend, dumb=True)
  142. def test_push_to_dulwich(self):
  143. # Note: remove this if dulwich implements dumb web pushing.
  144. raise SkipTest('Dumb web pushing not supported.')
  145. def test_push_to_dulwich_remove_branch(self):
  146. # Note: remove this if dumb pushing is supported
  147. raise SkipTest('Dumb web pushing not supported.')
  148. def test_new_shallow_clone_from_dulwich(self):
  149. # Note: remove this if C git and dulwich implement dumb web shallow
  150. # clones.
  151. raise SkipTest('Dumb web shallow cloning not supported.')
  152. def test_shallow_clone_from_git_is_identical(self):
  153. # Note: remove this if C git and dulwich implement dumb web shallow
  154. # clones.
  155. raise SkipTest('Dumb web shallow cloning not supported.')
  156. def test_fetch_same_depth_into_shallow_clone_from_dulwich(self):
  157. # Note: remove this if C git and dulwich implement dumb web shallow
  158. # clones.
  159. raise SkipTest('Dumb web shallow cloning not supported.')
  160. def test_fetch_full_depth_into_shallow_clone_from_dulwich(self):
  161. # Note: remove this if C git and dulwich implement dumb web shallow
  162. # clones.
  163. raise SkipTest('Dumb web shallow cloning not supported.')
  164. def test_push_to_dulwich_issue_88_standard(self):
  165. raise SkipTest('Dumb web pushing not supported.')