test_server.py 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. # test_server.py -- Compatibility tests for git server.
  2. # Copyright (C) 2010 Google, Inc.
  3. #
  4. # SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later
  5. # Dulwich is dual-licensed under the Apache License, Version 2.0 and the GNU
  6. # General Public License as public by the Free Software Foundation; version 2.0
  7. # or (at your option) any later version. You can redistribute it and/or
  8. # modify it under the terms of either of these two licenses.
  9. #
  10. # Unless required by applicable law or agreed to in writing, software
  11. # distributed under the License is distributed on an "AS IS" BASIS,
  12. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. # See the License for the specific language governing permissions and
  14. # limitations under the License.
  15. #
  16. # You should have received a copy of the licenses; if not, see
  17. # <http://www.gnu.org/licenses/> for a copy of the GNU General Public License
  18. # and <http://www.apache.org/licenses/LICENSE-2.0> for a copy of the Apache
  19. # License, Version 2.0.
  20. #
  21. """Compatibility tests between Dulwich and the cgit server.
  22. Warning: these tests should be fairly stable, but when writing/debugging new
  23. tests, deadlocks may freeze the test process such that it cannot be
  24. Ctrl-C'ed. On POSIX systems, you can kill the tests with Ctrl-Z, "kill %".
  25. """
  26. import os
  27. import sys
  28. import threading
  29. from dulwich.server import DictBackend, TCPGitServer
  30. from .. import skipIf
  31. from .server_utils import NoSideBand64kReceivePackHandler, ServerTests
  32. from .utils import CompatTestCase, require_git_version
  33. @skipIf(sys.platform == "win32", "Broken on windows, with very long fail time.")
  34. class GitServerTestCase(ServerTests, CompatTestCase):
  35. """Tests for client/server compatibility.
  36. This server test case does not use side-band-64k in git-receive-pack.
  37. """
  38. protocol = "git"
  39. def _handlers(self):
  40. return {b"git-receive-pack": NoSideBand64kReceivePackHandler}
  41. def _check_server(self, dul_server) -> None:
  42. receive_pack_handler_cls = dul_server.handlers[b"git-receive-pack"]
  43. caps = receive_pack_handler_cls.capabilities()
  44. self.assertNotIn(b"side-band-64k", caps)
  45. def _start_server(self, repo):
  46. backend = DictBackend({b"/": repo})
  47. dul_server = TCPGitServer(backend, b"localhost", 0, handlers=self._handlers())
  48. self._check_server(dul_server)
  49. self.addCleanup(dul_server.shutdown)
  50. self.addCleanup(dul_server.server_close)
  51. threading.Thread(target=dul_server.serve).start()
  52. self._server = dul_server
  53. _, port = self._server.socket.getsockname()
  54. return port
  55. @skipIf(sys.platform == "win32", "Broken on windows, with very long fail time.")
  56. class GitServerSideBand64kTestCase(GitServerTestCase):
  57. """Tests for client/server compatibility with side-band-64k support."""
  58. # side-band-64k in git-receive-pack was introduced in git 1.7.0.2
  59. min_git_version = (1, 7, 0, 2)
  60. def setUp(self) -> None:
  61. super().setUp()
  62. # side-band-64k is broken in the windows client.
  63. # https://github.com/msysgit/git/issues/101
  64. # Fix has landed for the 1.9.3 release.
  65. if os.name == "nt":
  66. require_git_version((1, 9, 3))
  67. def _handlers(self) -> None:
  68. return None # default handlers include side-band-64k
  69. def _check_server(self, server) -> None:
  70. receive_pack_handler_cls = server.handlers[b"git-receive-pack"]
  71. caps = receive_pack_handler_cls.capabilities()
  72. self.assertIn(b"side-band-64k", caps)