1717const fs = require ( `fs` ) ;
1818const path = require ( `path` ) ;
1919const { assert} = require ( 'chai' ) ;
20- const execa = require ( 'execa ' ) ;
20+ const { execSync } = require ( 'child_process ' ) ;
2121const uuid = require ( `uuid` ) ;
2222const { promisify} = require ( 'util' ) ;
2323const unlink = promisify ( fs . unlink ) ;
2424
25- const cwd = path . join ( __dirname , `..` ) ;
2625const keyRingName = `test-ring-${ uuid . v4 ( ) } ` ;
2726const keyNameOne = `test-key-${ uuid . v4 ( ) } ` ;
2827const member = `allAuthenticatedUsers` ;
@@ -36,14 +35,6 @@ const unspecifiedKeyRingName = `projects/${projectId}/locations/global/keyRings/
3635const formattedKeyRingName = `projects/${ projectId } /locations/global/keyRings/${ keyRingName } ` ;
3736const formattedKeyName = `${ formattedKeyRingName } /cryptoKeys/${ keyNameOne } ` ;
3837
39- const exec = async cmd => {
40- const result = await execa . shell ( cmd , { cwd} ) ;
41- if ( result . stderr ) {
42- throw new Error ( result . stderr ) ;
43- }
44- return result . stdout ;
45- } ;
46-
4738describe ( 'kms sample tests' , ( ) => {
4839 before ( async ( ) => {
4940 try {
@@ -64,13 +55,13 @@ describe('kms sample tests', () => {
6455 } ) ;
6556
6657 it ( 'should list key rings' , async ( ) => {
67- const output = await exec ( `node quickstart.js "${ projectId } "` ) ;
58+ const output = execSync ( `node quickstart.js "${ projectId } "` ) ;
6859 assert . match ( output , / K e y r i n g s : / ) ;
6960 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 \/ / ) ;
7061 } ) ;
7162
7263 it ( `should create a key ring` , async ( ) => {
73- const output = await exec (
64+ const output = execSync (
7465 `node createKeyring.js "${ projectId } " "${ keyRingName } "`
7566 ) ;
7667 if ( ! output . includes ( `KeyRing ${ formattedKeyRingName } already exists` ) ) {
@@ -82,18 +73,18 @@ describe('kms sample tests', () => {
8273 } ) ;
8374
8475 it ( `should list key rings` , async ( ) => {
85- const output = await exec ( `node listKeyrings.js ${ projectId } ` ) ;
76+ const output = execSync ( `node listKeyrings.js ${ projectId } ` ) ;
8677 assert . match ( output , new RegExp ( unspecifiedKeyRingName ) ) ;
8778 } ) ;
8879
8980 it ( `should get a key ring` , async ( ) => {
90- const output = await exec ( `node getKeyring ${ projectId } ${ keyRingName } ` ) ;
81+ const output = execSync ( `node getKeyring ${ projectId } ${ keyRingName } ` ) ;
9182 assert . match ( output , new RegExp ( `Name: ${ formattedKeyRingName } ` ) ) ;
92- assert . ok ( output . match ( new RegExp ( ` Created: ` ) ) ) ;
83+ assert . match ( output , / C r e a t e d : / ) ;
9384 } ) ;
9485
9586 it ( `should get a key ring's empty IAM policy` , async ( ) => {
96- const output = await exec (
87+ const output = execSync (
9788 `node getKeyringIamPolicy.js ${ projectId } ${ keyRingName } `
9889 ) ;
9990 assert . match (
@@ -103,7 +94,7 @@ describe('kms sample tests', () => {
10394 } ) ;
10495
10596 it ( `should grant access to a key ring` , async ( ) => {
106- const output = await exec (
97+ const output = execSync (
10798 `node addMemberToKeyRingPolicy.js ${ projectId } ${ keyRingName } ${ member } ${ role } `
10899 ) ;
109100 assert . match (
@@ -115,15 +106,15 @@ describe('kms sample tests', () => {
115106 } ) ;
116107
117108 it ( `should get a key ring's updated IAM policy` , async ( ) => {
118- const output = await exec (
109+ const output = execSync (
119110 `node getKeyringIamPolicy.js ${ projectId } ${ keyRingName } `
120111 ) ;
121112 assert . match ( output , new RegExp ( `${ role } :` ) ) ;
122113 assert . match ( output , new RegExp ( ` ${ member } ` ) ) ;
123114 } ) ;
124115
125116 it ( `should revoke access to a key ring` , async ( ) => {
126- const output = await exec (
117+ const output = execSync (
127118 `node removeMemberFromKeyRingPolicy.js ${ projectId } ${ keyRingName } ${ member } ${ role } `
128119 ) ;
129120 assert . match (
@@ -135,7 +126,7 @@ describe('kms sample tests', () => {
135126 } ) ;
136127
137128 it ( `should create a key` , async ( ) => {
138- const output = await exec (
129+ const output = execSync (
139130 `node createCryptoKey.js ${ projectId } ${ keyRingName } ${ keyNameOne } `
140131 ) ;
141132 if ( ! output . includes ( `CryptoKey ${ formattedKeyName } already exists` ) ) {
@@ -144,22 +135,22 @@ describe('kms sample tests', () => {
144135 } ) ;
145136
146137 it ( `should list keys` , async ( ) => {
147- const output = await exec (
138+ const output = execSync (
148139 `node listCryptoKeys.js ${ projectId } ${ keyRingName } `
149140 ) ;
150141 assert . match ( output , new RegExp ( formattedKeyName ) ) ;
151142 } ) ;
152143
153144 it ( `should get a key` , async ( ) => {
154- const output = await exec (
145+ const output = execSync (
155146 `node getCryptoKey.js ${ projectId } ${ keyRingName } ${ keyNameOne } `
156147 ) ;
157148 assert . match ( output , new RegExp ( `Name: ${ formattedKeyName } ` ) ) ;
158149 assert . match ( output , new RegExp ( `Created: ` ) ) ;
159150 } ) ;
160151
161152 it ( `should set a crypto key's primary version` , async ( ) => {
162- const output = await exec (
153+ const output = execSync (
163154 `node setPrimaryCryptoKeyVersion.js ${ projectId } ${ keyRingName } ${ keyNameOne } 1`
164155 ) ;
165156 assert . match (
@@ -169,7 +160,7 @@ describe('kms sample tests', () => {
169160 } ) ;
170161
171162 it ( `should encrypt a file` , async ( ) => {
172- const output = await exec (
163+ const output = execSync (
173164 `node encrypt.js ${ projectId } ${ keyRingName } ${ keyNameOne } "${ plaintext } " "${ ciphertext } "`
174165 ) ;
175166 assert . match (
@@ -182,7 +173,7 @@ describe('kms sample tests', () => {
182173 } ) ;
183174
184175 it ( `should decrypt a file` , async ( ) => {
185- const output = await exec (
176+ const output = execSync (
186177 `node decrypt.js ${ projectId } "${ keyRingName } " "${ keyNameOne } " "${ ciphertext } " "${ decrypted } "`
187178 ) ;
188179 assert . match (
@@ -197,7 +188,7 @@ describe('kms sample tests', () => {
197188 } ) ;
198189
199190 it ( `should create a crypto key version` , async ( ) => {
200- const output = await exec (
191+ const output = execSync (
201192 `node createCryptoKeyVersion ${ projectId } "${ keyRingName } " "${ keyNameOne } "`
202193 ) ;
203194 assert . match (
@@ -208,14 +199,14 @@ describe('kms sample tests', () => {
208199 } ) ;
209200
210201 it ( `should list crypto key versions` , async ( ) => {
211- const output = await exec (
202+ const output = execSync (
212203 `node listCryptoKeyVersions.js ${ projectId } "${ keyRingName } " "${ keyNameOne } "`
213204 ) ;
214205 assert . match ( output , new RegExp ( `${ formattedKeyName } /cryptoKeyVersions/1` ) ) ;
215206 } ) ;
216207
217208 it ( `should destroy a crypto key version` , async ( ) => {
218- const output = await exec (
209+ const output = execSync (
219210 `node destroyCryptoKeyVersion ${ projectId } "${ keyRingName } " "${ keyNameOne } " 2`
220211 ) ;
221212 assert . match (
@@ -227,7 +218,7 @@ describe('kms sample tests', () => {
227218 } ) ;
228219
229220 it ( `should restore a crypto key version` , async ( ) => {
230- const output = await exec (
221+ const output = execSync (
231222 `node restoreCryptoKeyVersion ${ projectId } "${ keyRingName } " "${ keyNameOne } " 2`
232223 ) ;
233224 assert . match (
@@ -239,7 +230,7 @@ describe('kms sample tests', () => {
239230 } ) ;
240231
241232 it ( `should enable a crypto key version` , async ( ) => {
242- const output = await exec (
233+ const output = execSync (
243234 `node enableCryptoKeyVersion ${ projectId } "${ keyRingName } " "${ keyNameOne } " 2`
244235 ) ;
245236 assert . match (
@@ -251,7 +242,7 @@ describe('kms sample tests', () => {
251242 } ) ;
252243
253244 it ( `should disable a crypto key version` , async ( ) => {
254- const output = await exec (
245+ const output = execSync (
255246 `node disableCryptoKeyVersion ${ projectId } "${ keyRingName } " "${ keyNameOne } " 2`
256247 ) ;
257248 assert . match (
@@ -263,7 +254,7 @@ describe('kms sample tests', () => {
263254 } ) ;
264255
265256 it ( `should get a crypto key's empty IAM policy` , async ( ) => {
266- const output = await exec (
257+ const output = execSync (
267258 `node getCryptoKeyIamPolicy ${ projectId } "${ keyRingName } " "${ keyNameOne } "`
268259 ) ;
269260 assert . match (
@@ -273,7 +264,7 @@ describe('kms sample tests', () => {
273264 } ) ;
274265
275266 it ( `should grant access to a crypto key` , async ( ) => {
276- const output = await exec (
267+ const output = execSync (
277268 `node addMemberToCryptoKeyPolicy ${ projectId } "${ keyRingName } " "${ keyNameOne } " "${ member } " "${ role } "`
278269 ) ;
279270 assert . match (
@@ -285,15 +276,15 @@ describe('kms sample tests', () => {
285276 } ) ;
286277
287278 it ( `should get a crypto key's updated IAM policy` , async ( ) => {
288- const output = await exec (
279+ const output = execSync (
289280 `node getCryptoKeyIamPolicy ${ projectId } "${ keyRingName } " "${ keyNameOne } "`
290281 ) ;
291282 assert . match ( output , new RegExp ( `${ role } :` ) ) ;
292283 assert . match ( output , new RegExp ( ` ${ member } ` ) ) ;
293284 } ) ;
294285
295286 it ( `should revoke access to a crypto key` , async ( ) => {
296- const output = await exec (
287+ const output = execSync (
297288 `node removeMemberCryptoKeyPolicy ${ projectId } "${ keyRingName } " "${ keyNameOne } " ${ member } ${ role } `
298289 ) ;
299290 assert . match (
0 commit comments