Skip to content

Commit 07940b2

Browse files
authored
Merge pull request #9023 from achouhan09/acc-del-fix
Added a validation for deletion of anonymous account with --name
2 parents 6cb56d3 + 9aec01f commit 07940b2

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

src/manage_nsfs/manage_nsfs_validations.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -350,6 +350,12 @@ function validate_flags_value_combination(type, action, input_options_with_data)
350350
throw_cli_error(ManageCLIError.InvalidAccountName, detail);
351351
}
352352
}
353+
if (action === ACTIONS.DELETE) {
354+
if (input_options_with_data.name === ANONYMOUS) {
355+
const detail = `Please use --${ANONYMOUS} flag to delete the ${ANONYMOUS} account`;
356+
throw_cli_error(ManageCLIError.InvalidAccountName, detail);
357+
}
358+
}
353359
}
354360
}
355361

src/test/unit_tests/jest_tests/test_nc_account_cli.test.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1705,6 +1705,24 @@ describe('manage nsfs cli account flow', () => {
17051705
expect(JSON.parse(res.stdout).error.code).toBe(ManageCLIError.AccountDeleteForbiddenHasIAMAccounts.code);
17061706
});
17071707

1708+
it('should fail when deleting anonymous account with option (name), and succeed with option (anonymous)', async function() {
1709+
const { type } = defaults;
1710+
const user = 'test-user';
1711+
const account_options1 = { user: user };
1712+
const command = create_command(type, ACTIONS.ADD, account_options1);
1713+
const flag = ANONYMOUS;
1714+
await exec_manage_cli_add_empty_option(command, flag);
1715+
1716+
const account_options2 = { name: ANONYMOUS };
1717+
const res = await exec_manage_cli(type, ACTIONS.DELETE, account_options2);
1718+
expect(JSON.parse(res.stdout).error.message).toBe(ManageCLIError.InvalidAccountName.message);
1719+
1720+
const command2 = create_command(type, ACTIONS.DELETE);
1721+
const res2 = await exec_manage_cli_add_empty_option(command2, flag);
1722+
const res_json = JSON.parse(res2.trim());
1723+
expect(res_json.response.code).toBe(ManageCLIResponse.AccountDeleted.code);
1724+
});
1725+
17081726
});
17091727

17101728
describe('cli status account', () => {

0 commit comments

Comments
 (0)