@@ -10,29 +10,32 @@ const execa = require('execa');
1010const rimraf = require ( 'rimraf' ) ;
1111
1212const {
13+ exe,
1314 getLocalPublicKey,
1415 getUsernames,
1516 listKnownPublicKeys,
1617 lookupPublicKey,
18+ parseListing,
1719 parsePublicKeys,
1820} = require ( './gpg' ) ;
1921
2022describe ( 'gpg' , ( ) => {
2123 let tempDir ;
2224
23- afterEach ( async ( ) => {
25+ afterAll ( async ( ) => {
2426 if ( tempDir ) {
2527 await promisify ( rimraf ) ( tempDir ) ;
2628 }
2729 delete process . env . GNUPGHOME ;
2830 } ) ;
2931
30- beforeEach ( async ( ) => {
32+ beforeAll ( async ( ) => {
3133 tempDir = await promisify ( mkdtemp ) (
3234 joinPath ( tmpdir ( ) , 'git-crypt-test--gpg-' ) ,
3335 ) ;
36+ process . env . DEBUG = 'gpg' ;
3437 process . env . GNUPGHOME = tempDir ;
35- await execa ( 'gpg' , [ '--generate -key' , '--batch' ] , {
38+ await execa ( await exe ( ) , [ '--gen -key' , '--batch' ] , {
3639 input : [
3740 'Key-Type: default' ,
3841 'Subkey-Type: default' ,
@@ -42,7 +45,7 @@ describe('gpg', () => {
4245 '%commit' ,
4346 ] . join ( '\n' ) ,
4447 } ) ;
45- await execa ( 'gpg' , [ '--generate -key' , '--batch' ] , {
48+ await execa ( await exe ( ) , [ '--gen -key' , '--batch' ] , {
4649 input : [
4750 'Key-Type: default' ,
4851 'Subkey-Type: default' ,
@@ -52,6 +55,10 @@ describe('gpg', () => {
5255 '%commit' ,
5356 ] . join ( '\n' ) ,
5457 } ) ;
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' } ) ;
5562 } ) ;
5663
5764 describe ( 'getLocalPublicKey()' , ( ) => {
@@ -93,6 +100,7 @@ describe('gpg', () => {
93100
94101 describe ( 'lookupPublicKey()' , ( ) => {
95102 it ( 'finds the public key for Hashicorp' , async ( ) => {
103+ jest . setTimeout ( 30 * 1000 ) ;
96104 try {
97105 const got = await lookupPublicKey (
98106 '91A6E7F85D05C65630BEF18951852D87348FFC4C' ,
@@ -107,6 +115,56 @@ describe('gpg', () => {
107115 } ) ;
108116 } ) ;
109117
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+
110168 describe ( 'parsePublicKeys()' , ( ) => {
111169 it ( 'parses ASCII Armor for Alice or Bob' , async ( ) => {
112170 const keyIds = await listKnownPublicKeys ( ) ;
0 commit comments