@@ -10,29 +10,32 @@ const execa = require('execa');
10
10
const rimraf = require ( 'rimraf' ) ;
11
11
12
12
const {
13
+ exe,
13
14
getLocalPublicKey,
14
15
getUsernames,
15
16
listKnownPublicKeys,
16
17
lookupPublicKey,
18
+ parseListing,
17
19
parsePublicKeys,
18
20
} = require ( './gpg' ) ;
19
21
20
22
describe ( 'gpg' , ( ) => {
21
23
let tempDir ;
22
24
23
- afterEach ( async ( ) => {
25
+ afterAll ( async ( ) => {
24
26
if ( tempDir ) {
25
27
await promisify ( rimraf ) ( tempDir ) ;
26
28
}
27
29
delete process . env . GNUPGHOME ;
28
30
} ) ;
29
31
30
- beforeEach ( async ( ) => {
32
+ beforeAll ( async ( ) => {
31
33
tempDir = await promisify ( mkdtemp ) (
32
34
joinPath ( tmpdir ( ) , 'git-crypt-test--gpg-' ) ,
33
35
) ;
36
+ process . env . DEBUG = 'gpg' ;
34
37
process . env . GNUPGHOME = tempDir ;
35
- await execa ( 'gpg' , [ '--generate -key' , '--batch' ] , {
38
+ await execa ( await exe ( ) , [ '--gen -key' , '--batch' ] , {
36
39
input : [
37
40
'Key-Type: default' ,
38
41
'Subkey-Type: default' ,
@@ -42,7 +45,7 @@ describe('gpg', () => {
42
45
'%commit' ,
43
46
] . join ( '\n' ) ,
44
47
} ) ;
45
- await execa ( 'gpg' , [ '--generate -key' , '--batch' ] , {
48
+ await execa ( await exe ( ) , [ '--gen -key' , '--batch' ] , {
46
49
input : [
47
50
'Key-Type: default' ,
48
51
'Subkey-Type: default' ,
@@ -52,6 +55,10 @@ describe('gpg', () => {
52
55
'%commit' ,
53
56
] . join ( '\n' ) ,
54
57
} ) ;
58
+
59
+ // eslint-disable-next-line no-console
60
+ console . log ( 'listing keys in test keyring:' ) ;
61
+ await execa ( await exe ( ) , [ '-K' ] , { stderr : 'inherit' , stdout : 'inherit' } ) ;
55
62
} ) ;
56
63
57
64
describe ( 'getLocalPublicKey()' , ( ) => {
@@ -93,6 +100,7 @@ describe('gpg', () => {
93
100
94
101
describe ( 'lookupPublicKey()' , ( ) => {
95
102
it ( 'finds the public key for Hashicorp' , async ( ) => {
103
+ jest . setTimeout ( 30 * 1000 ) ;
96
104
try {
97
105
const got = await lookupPublicKey (
98
106
'91A6E7F85D05C65630BEF18951852D87348FFC4C' ,
@@ -107,6 +115,56 @@ describe('gpg', () => {
107
115
} ) ;
108
116
} ) ;
109
117
118
+ describe ( 'parseListing()' , ( ) => {
119
+ it ( 'parses output from gpg 2.1.11' , ( ) => {
120
+ const listing = `/tmp/git-crypt-test--gpg-KHPaVv/pubring.kbx
121
+ -------------------------------------------
122
+ pub rsa2048/589EF98F 2019-07-21 [SC]
123
+ Key fingerprint = 1D5F 7BFE 54E5 C2E9 78AF 88FF 6BC3 D9B3 589E F98F
124
+ uid [ultimate] Alice <alice@example.local>
125
+ sub rsa2048/73AF806B 2019-07-21 [E]
126
+ pub rsa2048/CC38658E 2019-07-21 [SC]
127
+ Key fingerprint = 9A21 8AA0 BBB0 E64E B6AA 7731 7282 FA72 CC38 658E
128
+ uid [ultimate] Bob <bob@example.local>
129
+ sub rsa2048/568A60C0 2019-07-21 [E]
130
+ ` ;
131
+ const got = parseListing ( listing ) ;
132
+ expect ( got ) . toContainEqual ( {
133
+ email : 'alice@example.local' ,
134
+ fingerprint : '1D5F7BFE54E5C2E978AF88FF6BC3D9B3589EF98F' ,
135
+ } ) ;
136
+ expect ( got ) . toContainEqual ( {
137
+ email : 'bob@example.local' ,
138
+ fingerprint : '9A218AA0BBB0E64EB6AA77317282FA72CC38658E' ,
139
+ } ) ;
140
+ } ) ;
141
+
142
+ it ( 'parses output from gpg 2.2.16' , ( ) => {
143
+ const listing = `/tmp/git-crypt-test--gpg-zr7rYT/pubring.kbx
144
+ -------------------------------------------
145
+ sec rsa2048 2019-07-21 [SC]
146
+ 8E82A43990918AE0BC5AF076438FBEFBB18785ED
147
+ uid [ultimate] Alice <alice@example.local>
148
+ ssb rsa2048 2019-07-21 [E]
149
+
150
+ sec rsa2048 2019-07-21 [SC]
151
+ 1CC8653C86167701289AB6D398402AEC113CE2BB
152
+ uid [ultimate] Bob <bob@example.local>
153
+ ssb rsa2048 2019-07-21 [E]
154
+
155
+ ` ;
156
+ const got = parseListing ( listing ) ;
157
+ expect ( got ) . toContainEqual ( {
158
+ email : 'alice@example.local' ,
159
+ fingerprint : '8E82A43990918AE0BC5AF076438FBEFBB18785ED' ,
160
+ } ) ;
161
+ expect ( got ) . toContainEqual ( {
162
+ email : 'bob@example.local' ,
163
+ fingerprint : '1CC8653C86167701289AB6D398402AEC113CE2BB' ,
164
+ } ) ;
165
+ } ) ;
166
+ } ) ;
167
+
110
168
describe ( 'parsePublicKeys()' , ( ) => {
111
169
it ( 'parses ASCII Armor for Alice or Bob' , async ( ) => {
112
170
const keyIds = await listKnownPublicKeys ( ) ;
0 commit comments