You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

GpgConfigTest.java 2.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. /*
  2. * Copyright (C) 2018, Salesforce. and others
  3. *
  4. * This program and the accompanying materials are made available under the
  5. * terms of the Eclipse Distribution License v. 1.0 which is available at
  6. * https://www.eclipse.org/org/documents/edl-v10.php.
  7. *
  8. * SPDX-License-Identifier: BSD-3-Clause
  9. */
  10. package org.eclipse.jgit.lib;
  11. import static org.junit.Assert.assertEquals;
  12. import static org.junit.Assert.assertFalse;
  13. import static org.junit.Assert.assertNull;
  14. import static org.junit.Assert.assertTrue;
  15. import static org.junit.Assert.fail;
  16. import org.eclipse.jgit.errors.ConfigInvalidException;
  17. import org.junit.Test;
  18. public class GpgConfigTest {
  19. private static Config parse(String content) throws ConfigInvalidException {
  20. final Config c = new Config(null);
  21. c.fromText(content);
  22. return c;
  23. }
  24. @Test
  25. public void isSignCommits_defaultIsFalse() throws Exception {
  26. Config c = parse("");
  27. assertFalse(new GpgConfig(c).isSignCommits());
  28. }
  29. @Test
  30. public void isSignCommits_false() throws Exception {
  31. Config c = parse("" //
  32. + "[gpg]\n" //
  33. + " format = x509\n" //
  34. + "[commit]\n" //
  35. + " gpgSign = false\n" //
  36. );
  37. assertFalse(new GpgConfig(c).isSignCommits());
  38. }
  39. @Test
  40. public void isSignCommits_true() throws Exception {
  41. Config c = parse("" //
  42. + "[commit]\n" //
  43. + " gpgSign = true\n" //
  44. );
  45. assertTrue(new GpgConfig(c).isSignCommits());
  46. }
  47. @Test
  48. public void testGetKeyFormat_defaultsToOpenpgp() throws Exception {
  49. Config c = parse("");
  50. assertEquals(GpgConfig.GpgFormat.OPENPGP,
  51. new GpgConfig(c).getKeyFormat());
  52. }
  53. @Test(expected = IllegalArgumentException.class)
  54. public void testGetKeyFormat_failsForInvalidValue() throws Exception {
  55. Config c = parse("" //
  56. + "[gpg]\n" //
  57. + " format = invalid\n" //
  58. );
  59. new GpgConfig(c).getKeyFormat();
  60. fail("Call should not have succeeded!");
  61. }
  62. @Test
  63. public void testGetKeyFormat_openpgp() throws Exception {
  64. Config c = parse("" //
  65. + "[gpg]\n" //
  66. + " format = openpgp\n" //
  67. );
  68. assertEquals(GpgConfig.GpgFormat.OPENPGP,
  69. new GpgConfig(c).getKeyFormat());
  70. }
  71. @Test
  72. public void testGetKeyFormat_x509() throws Exception {
  73. Config c = parse("" //
  74. + "[gpg]\n" //
  75. + " format = x509\n" //
  76. );
  77. assertEquals(GpgConfig.GpgFormat.X509, new GpgConfig(c).getKeyFormat());
  78. }
  79. @Test
  80. public void testGetSigningKey() throws Exception {
  81. Config c = parse("" //
  82. + "[user]\n" //
  83. + " signingKey = 0x2345\n" //
  84. );
  85. assertEquals("0x2345", new GpgConfig(c).getSigningKey());
  86. }
  87. @Test
  88. public void testGetSigningKey_defaultToNull() throws Exception {
  89. Config c = parse("");
  90. assertNull(new GpgConfig(c).getSigningKey());
  91. }
  92. }