2
0

test_porcelain.py 3.1 KB

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