14
14
15
15
'use strict' ;
16
16
17
- const fs = require ( `fs` ) ;
18
- const path = require ( ` path` ) ;
17
+ const fs = require ( 'fs' ) ;
18
+ const path = require ( ' path' ) ;
19
19
const { assert} = require ( 'chai' ) ;
20
20
const { describe, it, before, after} = require ( 'mocha' ) ;
21
21
const cp = require ( 'child_process' ) ;
22
22
const { promisify} = require ( 'util' ) ;
23
- const { v4} = require ( ` uuid` ) ;
23
+ const { v4} = require ( ' uuid' ) ;
24
24
const unlink = promisify ( fs . unlink ) ;
25
25
26
26
const execSync = cmd => cp . execSync ( cmd , { encoding : 'utf-8' } ) ;
27
27
28
28
const keyRingName = `test-ring-${ v4 ( ) } ` ;
29
29
const keyNameOne = `test-key-${ v4 ( ) } ` ;
30
- const member = ` allAuthenticatedUsers` ;
31
- const role = ` roles/viewer` ;
30
+ const member = ' allAuthenticatedUsers' ;
31
+ const role = ' roles/viewer' ;
32
32
const projectId = process . env . GCLOUD_PROJECT ;
33
- const plaintext = path . join ( __dirname , ` ../resources/plaintext.txt` ) ;
34
- const ciphertext = path . join ( __dirname , ` ../resources/plaintext.txt.encrypted` ) ;
35
- const decrypted = path . join ( __dirname , ` ../resources/plaintext.txt.decrypted` ) ;
33
+ const plaintext = path . join ( __dirname , ' ../resources/plaintext.txt' ) ;
34
+ const ciphertext = path . join ( __dirname , ' ../resources/plaintext.txt.encrypted' ) ;
35
+ const decrypted = path . join ( __dirname , ' ../resources/plaintext.txt.decrypted' ) ;
36
36
37
37
const unspecifiedKeyRingName = `projects/${ projectId } /locations/global/keyRings/` ;
38
38
const formattedKeyRingName = `projects/${ projectId } /locations/global/keyRings/${ keyRingName } ` ;
@@ -65,7 +65,7 @@ describe('kms sample tests', () => {
65
65
assert . match ( output , / \/ l o c a t i o n s \/ g l o b a l \/ k e y R i n g s \/ / ) ;
66
66
} ) ;
67
67
68
- it ( ` should create a key ring` , async ( ) => {
68
+ it ( ' should create a key ring' , async ( ) => {
69
69
const output = execSync (
70
70
`node createKeyring.js "${ projectId } " "${ keyRingName } "`
71
71
) ;
@@ -77,18 +77,18 @@ describe('kms sample tests', () => {
77
77
}
78
78
} ) ;
79
79
80
- it ( ` should list key rings` , async ( ) => {
80
+ it ( ' should list key rings' , async ( ) => {
81
81
const output = execSync ( `node listKeyrings.js ${ projectId } ` ) ;
82
82
assert . match ( output , new RegExp ( unspecifiedKeyRingName ) ) ;
83
83
} ) ;
84
84
85
- it ( ` should get a key ring` , async ( ) => {
85
+ it ( ' should get a key ring' , async ( ) => {
86
86
const output = execSync ( `node getKeyring ${ projectId } ${ keyRingName } ` ) ;
87
87
assert . match ( output , new RegExp ( `Name: ${ formattedKeyRingName } ` ) ) ;
88
88
assert . match ( output , / C r e a t e d : / ) ;
89
89
} ) ;
90
90
91
- it ( ` should get a key ring's empty IAM policy` , async ( ) => {
91
+ it ( " should get a key ring's empty IAM policy" , async ( ) => {
92
92
const output = execSync (
93
93
`node getKeyringIamPolicy.js ${ projectId } ${ keyRingName } `
94
94
) ;
@@ -98,7 +98,7 @@ describe('kms sample tests', () => {
98
98
) ;
99
99
} ) ;
100
100
101
- it ( ` should grant access to a key ring` , async ( ) => {
101
+ it ( ' should grant access to a key ring' , async ( ) => {
102
102
const output = execSync (
103
103
`node addMemberToKeyRingPolicy.js ${ projectId } ${ keyRingName } ${ member } ${ role } `
104
104
) ;
@@ -110,15 +110,15 @@ describe('kms sample tests', () => {
110
110
) ;
111
111
} ) ;
112
112
113
- it ( ` should get a key ring's updated IAM policy` , async ( ) => {
113
+ it ( " should get a key ring's updated IAM policy" , async ( ) => {
114
114
const output = execSync (
115
115
`node getKeyringIamPolicy.js ${ projectId } ${ keyRingName } `
116
116
) ;
117
117
assert . match ( output , new RegExp ( `${ role } :` ) ) ;
118
118
assert . match ( output , new RegExp ( ` ${ member } ` ) ) ;
119
119
} ) ;
120
120
121
- it ( ` should revoke access to a key ring` , async ( ) => {
121
+ it ( ' should revoke access to a key ring' , async ( ) => {
122
122
const output = execSync (
123
123
`node removeMemberFromKeyRingPolicy.js ${ projectId } ${ keyRingName } ${ member } ${ role } `
124
124
) ;
@@ -130,7 +130,7 @@ describe('kms sample tests', () => {
130
130
) ;
131
131
} ) ;
132
132
133
- it ( ` should create a key` , async ( ) => {
133
+ it ( ' should create a key' , async ( ) => {
134
134
const output = execSync (
135
135
`node createCryptoKey.js ${ projectId } ${ keyRingName } ${ keyNameOne } `
136
136
) ;
@@ -139,22 +139,22 @@ describe('kms sample tests', () => {
139
139
}
140
140
} ) ;
141
141
142
- it ( ` should list keys` , async ( ) => {
142
+ it ( ' should list keys' , async ( ) => {
143
143
const output = execSync (
144
144
`node listCryptoKeys.js ${ projectId } ${ keyRingName } `
145
145
) ;
146
146
assert . match ( output , new RegExp ( formattedKeyName ) ) ;
147
147
} ) ;
148
148
149
- it ( ` should get a key` , async ( ) => {
149
+ it ( ' should get a key' , async ( ) => {
150
150
const output = execSync (
151
151
`node getCryptoKey.js ${ projectId } ${ keyRingName } ${ keyNameOne } `
152
152
) ;
153
153
assert . match ( output , new RegExp ( `Name: ${ formattedKeyName } ` ) ) ;
154
- assert . match ( output , new RegExp ( ` Created: ` ) ) ;
154
+ assert . match ( output , new RegExp ( ' Created: ' ) ) ;
155
155
} ) ;
156
156
157
- it ( ` should set a crypto key's primary version` , async ( ) => {
157
+ it ( " should set a crypto key's primary version" , async ( ) => {
158
158
const output = execSync (
159
159
`node setPrimaryCryptoKeyVersion.js ${ projectId } ${ keyRingName } ${ keyNameOne } 1`
160
160
) ;
@@ -164,7 +164,7 @@ describe('kms sample tests', () => {
164
164
) ;
165
165
} ) ;
166
166
167
- it ( ` should encrypt a file` , async ( ) => {
167
+ it ( ' should encrypt a file' , async ( ) => {
168
168
const output = execSync (
169
169
`node encrypt.js ${ projectId } ${ keyRingName } ${ keyNameOne } "${ plaintext } " "${ ciphertext } "`
170
170
) ;
@@ -177,7 +177,7 @@ describe('kms sample tests', () => {
177
177
assert . match ( output , new RegExp ( `Result saved to ${ ciphertext } .` ) ) ;
178
178
} ) ;
179
179
180
- it ( ` should decrypt a file` , async ( ) => {
180
+ it ( ' should decrypt a file' , async ( ) => {
181
181
const output = execSync (
182
182
`node decrypt.js ${ projectId } "${ keyRingName } " "${ keyNameOne } " "${ ciphertext } " "${ decrypted } "`
183
183
) ;
@@ -192,25 +192,25 @@ describe('kms sample tests', () => {
192
192
) ;
193
193
} ) ;
194
194
195
- it ( ` should create a crypto key version` , async ( ) => {
195
+ it ( ' should create a crypto key version' , async ( ) => {
196
196
const output = execSync (
197
197
`node createCryptoKeyVersion ${ projectId } "${ keyRingName } " "${ keyNameOne } "`
198
198
) ;
199
199
assert . match (
200
200
output ,
201
201
new RegExp ( `Crypto key version ${ formattedKeyName } /cryptoKeyVersions/` )
202
202
) ;
203
- assert . match ( output , new RegExp ( ` created.` ) ) ;
203
+ assert . match ( output , new RegExp ( ' created.' ) ) ;
204
204
} ) ;
205
205
206
- it ( ` should list crypto key versions` , async ( ) => {
206
+ it ( ' should list crypto key versions' , async ( ) => {
207
207
const output = execSync (
208
208
`node listCryptoKeyVersions.js ${ projectId } "${ keyRingName } " "${ keyNameOne } "`
209
209
) ;
210
210
assert . match ( output , new RegExp ( `${ formattedKeyName } /cryptoKeyVersions/1` ) ) ;
211
211
} ) ;
212
212
213
- it ( ` should destroy a crypto key version` , async ( ) => {
213
+ it ( ' should destroy a crypto key version' , async ( ) => {
214
214
const output = execSync (
215
215
`node destroyCryptoKeyVersion ${ projectId } "${ keyRingName } " "${ keyNameOne } " 2`
216
216
) ;
@@ -222,7 +222,7 @@ describe('kms sample tests', () => {
222
222
) ;
223
223
} ) ;
224
224
225
- it ( ` should restore a crypto key version` , async ( ) => {
225
+ it ( ' should restore a crypto key version' , async ( ) => {
226
226
const output = execSync (
227
227
`node restoreCryptoKeyVersion ${ projectId } "${ keyRingName } " "${ keyNameOne } " 2`
228
228
) ;
@@ -234,7 +234,7 @@ describe('kms sample tests', () => {
234
234
) ;
235
235
} ) ;
236
236
237
- it ( ` should enable a crypto key version` , async ( ) => {
237
+ it ( ' should enable a crypto key version' , async ( ) => {
238
238
const output = execSync (
239
239
`node enableCryptoKeyVersion ${ projectId } "${ keyRingName } " "${ keyNameOne } " 2`
240
240
) ;
@@ -246,7 +246,7 @@ describe('kms sample tests', () => {
246
246
) ;
247
247
} ) ;
248
248
249
- it ( ` should disable a crypto key version` , async ( ) => {
249
+ it ( ' should disable a crypto key version' , async ( ) => {
250
250
const output = execSync (
251
251
`node disableCryptoKeyVersion ${ projectId } "${ keyRingName } " "${ keyNameOne } " 2`
252
252
) ;
@@ -258,7 +258,7 @@ describe('kms sample tests', () => {
258
258
) ;
259
259
} ) ;
260
260
261
- it ( ` should get a crypto key's empty IAM policy` , async ( ) => {
261
+ it ( " should get a crypto key's empty IAM policy" , async ( ) => {
262
262
const output = execSync (
263
263
`node getCryptoKeyIamPolicy ${ projectId } "${ keyRingName } " "${ keyNameOne } "`
264
264
) ;
@@ -268,7 +268,7 @@ describe('kms sample tests', () => {
268
268
) ;
269
269
} ) ;
270
270
271
- it ( ` should grant access to a crypto key` , async ( ) => {
271
+ it ( ' should grant access to a crypto key' , async ( ) => {
272
272
const output = execSync (
273
273
`node addMemberToCryptoKeyPolicy ${ projectId } "${ keyRingName } " "${ keyNameOne } " "${ member } " "${ role } "`
274
274
) ;
@@ -280,15 +280,15 @@ describe('kms sample tests', () => {
280
280
) ;
281
281
} ) ;
282
282
283
- it ( ` should get a crypto key's updated IAM policy` , async ( ) => {
283
+ it ( " should get a crypto key's updated IAM policy" , async ( ) => {
284
284
const output = execSync (
285
285
`node getCryptoKeyIamPolicy ${ projectId } "${ keyRingName } " "${ keyNameOne } "`
286
286
) ;
287
287
assert . match ( output , new RegExp ( `${ role } :` ) ) ;
288
288
assert . match ( output , new RegExp ( ` ${ member } ` ) ) ;
289
289
} ) ;
290
290
291
- it ( ` should revoke access to a crypto key` , async ( ) => {
291
+ it ( ' should revoke access to a crypto key' , async ( ) => {
292
292
const output = execSync (
293
293
`node removeMemberCryptoKeyPolicy ${ projectId } "${ keyRingName } " "${ keyNameOne } " ${ member } ${ role } `
294
294
) ;
@@ -304,7 +304,7 @@ describe('kms sample tests', () => {
304
304
const kms = require ( '@google-cloud/kms' ) ;
305
305
const client = new kms . KeyManagementServiceClient ( ) ;
306
306
307
- const locationId = ` global` ;
307
+ const locationId = ' global' ;
308
308
const keyRingId = `test-asymmetric-ring-${ v4 ( ) } ` ;
309
309
const keyAsymmetricDecryptName = `test-asymmetric-decrypt-${ v4 ( ) } ` ;
310
310
@@ -380,7 +380,7 @@ describe('kms sample tests', () => {
380
380
await client . destroyCryptoKeyVersion ( { name : signKeyVersionId } ) ;
381
381
} ) ;
382
382
383
- it ( ` should perform asymmetric encryption` , async function ( ) {
383
+ it ( ' should perform asymmetric encryption' , async function ( ) {
384
384
// Only run this test on Node 12+
385
385
if ( nodeMajorVersion < 12 ) {
386
386
this . skip ( ) ;
@@ -395,14 +395,14 @@ describe('kms sample tests', () => {
395
395
"${ dataToEncrypt } "
396
396
` ) ;
397
397
398
- const re = new RegExp ( ` Encrypted ciphertext: (.+)` ) ;
398
+ const re = new RegExp ( ' Encrypted ciphertext: (.+)' ) ;
399
399
assert . match ( out , re ) ;
400
400
401
401
const match = re . exec ( out ) ;
402
402
ciphertext = match [ 1 ] ;
403
403
} ) ;
404
404
405
- it ( ` should perform asymmetric decryption` , async function ( ) {
405
+ it ( ' should perform asymmetric decryption' , async function ( ) {
406
406
// Only run this test on Node 12+
407
407
if ( nodeMajorVersion < 12 ) {
408
408
this . skip ( ) ;
@@ -417,7 +417,7 @@ describe('kms sample tests', () => {
417
417
"${ ciphertext } "
418
418
` ) ;
419
419
420
- const re = new RegExp ( ` Decrypted plaintext: (.+)` ) ;
420
+ const re = new RegExp ( ' Decrypted plaintext: (.+)' ) ;
421
421
assert . match ( out , re ) ;
422
422
423
423
const match = re . exec ( out ) ;
@@ -426,7 +426,7 @@ describe('kms sample tests', () => {
426
426
assert . equal ( dataToEncrypt , plaintext ) ;
427
427
} ) ;
428
428
429
- it ( ` should perform asymmetric signing` , async function ( ) {
429
+ it ( ' should perform asymmetric signing' , async ( ) => {
430
430
const out = execSync ( `
431
431
node asymmetricSign.js \
432
432
"${ projectId } " \
@@ -436,14 +436,14 @@ describe('kms sample tests', () => {
436
436
"${ dataToSign } "
437
437
` ) ;
438
438
439
- const re = new RegExp ( ` Signature: (.+)` ) ;
439
+ const re = new RegExp ( ' Signature: (.+)' ) ;
440
440
assert . match ( out , re ) ;
441
441
442
442
const match = re . exec ( out ) ;
443
443
signature = match [ 1 ] ;
444
444
} ) ;
445
445
446
- it ( ` should perform asymmetric verification` , async function ( ) {
446
+ it ( ' should perform asymmetric verification' , async ( ) => {
447
447
const out = execSync ( `
448
448
node asymmetricVerify.js \
449
449
"${ projectId } " \
@@ -454,7 +454,7 @@ describe('kms sample tests', () => {
454
454
"${ signature } "
455
455
` ) ;
456
456
457
- const re = new RegExp ( ` Signature verified: (.+)` ) ;
457
+ const re = new RegExp ( ' Signature verified: (.+)' ) ;
458
458
assert . match ( out , re ) ;
459
459
460
460
const match = re . exec ( out ) ;
0 commit comments