test_web.py 7.1 KB

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