test_porcelain.py 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. # test_porcelain .py -- Tests for dulwich.porcelain/CGit compatibility
  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 for dulwich.porcelain."""
  21. import os
  22. import platform
  23. import sys
  24. from unittest import skipIf
  25. from dulwich import porcelain
  26. from dulwich.tests.utils import (
  27. build_commit_graph,
  28. )
  29. from dulwich.tests.compat.utils import (
  30. run_git_or_fail,
  31. CompatTestCase,
  32. )
  33. from dulwich.tests.test_porcelain import (
  34. PorcelainGpgTestCase,
  35. )
  36. @skipIf(platform.python_implementation() == "PyPy" or sys.platform == "win32", "gpgme not easily available or supported on Windows and PyPy")
  37. class TagCreateSignTestCase(PorcelainGpgTestCase, CompatTestCase):
  38. def setUp(self):
  39. super().setUp()
  40. def test_sign(self):
  41. # Test that dulwich signatures can be verified by CGit
  42. c1, c2, c3 = build_commit_graph(
  43. self.repo.object_store, [[1], [2, 1], [3, 1, 2]]
  44. )
  45. self.repo.refs[b"HEAD"] = c3.id
  46. cfg = self.repo.get_config()
  47. cfg.set(("user",), "signingKey", PorcelainGpgTestCase.DEFAULT_KEY_ID)
  48. self.import_default_key()
  49. porcelain.tag_create(
  50. self.repo.path,
  51. b"tryme",
  52. b"foo <foo@bar.com>",
  53. b"bar",
  54. annotated=True,
  55. sign=True,
  56. )
  57. run_git_or_fail(
  58. [
  59. f"--git-dir={self.repo.controldir()}",
  60. "tag",
  61. "-v",
  62. "tryme"
  63. ],
  64. env={'GNUPGHOME': os.environ['GNUPGHOME']},
  65. )
  66. def test_verify(self):
  67. # Test that CGit signatures can be verified by dulwich
  68. c1, c2, c3 = build_commit_graph(
  69. self.repo.object_store, [[1], [2, 1], [3, 1, 2]]
  70. )
  71. self.repo.refs[b"HEAD"] = c3.id
  72. self.import_default_key()
  73. run_git_or_fail(
  74. [
  75. f"--git-dir={self.repo.controldir()}",
  76. "tag",
  77. "-u",
  78. PorcelainGpgTestCase.DEFAULT_KEY_ID,
  79. "-m",
  80. "foo",
  81. "verifyme",
  82. ],
  83. env={
  84. 'GNUPGHOME': os.environ['GNUPGHOME'],
  85. 'GIT_COMMITTER_NAME': 'Joe Example',
  86. 'GIT_COMMITTER_EMAIL': 'joe@example.com',
  87. },
  88. )
  89. tag = self.repo[b"refs/tags/verifyme"]
  90. self.assertNotEqual(tag.signature, None)
  91. tag.verify()