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