File tree Expand file tree Collapse file tree 2 files changed +41
-5
lines changed
Expand file tree Collapse file tree 2 files changed +41
-5
lines changed Original file line number Diff line number Diff line change @@ -73,11 +73,21 @@ class VaultsSecretsRemove extends DuplexHandler<
7373 success : true ,
7474 } ;
7575 } catch ( e ) {
76- yield {
77- type : 'error' ,
78- code : e . code ,
79- reason : secretName ,
80- } ;
76+ if (
77+ e . code === 'ENOENT' ||
78+ e . code === 'ENOTEMPTY' ||
79+ e . code === 'EINVAL'
80+ ) {
81+ // INVAL can be triggered if removing the root of the
82+ // vault is attempted.
83+ yield {
84+ type : 'error' ,
85+ code : e . code ,
86+ reason : secretName ,
87+ } ;
88+ } else {
89+ throw e ;
90+ }
8191 }
8292 }
8393 } ,
Original file line number Diff line number Diff line change @@ -2382,6 +2382,32 @@ describe('vaultsSecretsRemove', () => {
23822382 vaultsErrors . ErrorVaultsVaultUndefined ,
23832383 ) ;
23842384 } ) ;
2385+ test ( 'fails deleting vault root' , async ( ) => {
2386+ // Create secrets
2387+ const secretName = 'test-secret1' ;
2388+ const vaultId = await vaultManager . createVault ( 'test-vault' ) ;
2389+ const vaultIdEncoded = vaultsUtils . encodeVaultId ( vaultId ) ;
2390+ await vaultManager . withVaults ( [ vaultId ] , async ( vault ) => {
2391+ await vault . writeF ( async ( efs ) => {
2392+ await efs . writeFile ( secretName , secretName ) ;
2393+ } ) ;
2394+ } ) ;
2395+ // Delete secrets
2396+ const response = await rpcClient . methods . vaultsSecretsRemove ( ) ;
2397+ const writer = response . writable . getWriter ( ) ;
2398+ await writer . write ( { nameOrId : vaultIdEncoded , secretName : '/' } ) ;
2399+ await writer . close ( ) ;
2400+ for await ( const data of response . readable ) {
2401+ expect ( data . type ) . toStrictEqual ( 'error' ) ;
2402+ console . log ( data )
2403+ }
2404+ // Check
2405+ await vaultManager . withVaults ( [ vaultId ] , async ( vault ) => {
2406+ await vault . readF ( async ( efs ) => {
2407+ expect ( await efs . exists ( secretName ) ) . toBeTruthy ( ) ;
2408+ } ) ;
2409+ } ) ;
2410+ } ) ;
23852411 test ( 'deletes multiple secrets' , async ( ) => {
23862412 // Create secrets
23872413 const secretName1 = 'test-secret1' ;
You can’t perform that action at this time.
0 commit comments