-
Notifications
You must be signed in to change notification settings - Fork 90
IAM | CreateUser, UpdateUser - UserName, NewUserName Check #9323
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
f90aef4
0098e6d
b0c05ca
990cfe3
e837a5d
49d8434
ece7b42
e911245
bc65ecf
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -676,6 +676,9 @@ module.exports = { | |
| iam_path: { | ||
| type: 'string', | ||
| }, | ||
| username: { | ||
| type: 'string', | ||
| }, | ||
| } | ||
| }, | ||
| reply: { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -927,6 +927,141 @@ mocha.describe('IAM basic integration tests - happy path', async function() { | |
| }); | ||
| }); | ||
|
|
||
| mocha.describe('IAM advanced integration tests', async function() { | ||
| mocha.describe('IAM User API', async function() { | ||
| const username = 'Mateo'; | ||
| const username_lowercase = username.toLowerCase(); | ||
| const username_uppercase = username.toUpperCase(); | ||
|
|
||
| mocha.describe('IAM CreateUser API', async function() { | ||
| mocha.before(async () => { | ||
| // create a user | ||
| const input = { | ||
| UserName: username | ||
| }; | ||
| const command = new CreateUserCommand(input); | ||
| const response = await iam_account.send(command); | ||
| _check_status_code_ok(response); | ||
| }); | ||
|
|
||
| mocha.after(async () => { | ||
| // delete a user | ||
| const input = { | ||
| UserName: username | ||
| }; | ||
| const command = new DeleteUserCommand(input); | ||
| const response = await iam_account.send(command); | ||
| _check_status_code_ok(response); | ||
| }); | ||
|
|
||
| mocha.it('create a user with username that already exists should fail', async function() { | ||
| try { | ||
| const input = { | ||
| UserName: username | ||
| }; | ||
| const command = new CreateUserCommand(input); | ||
| await iam_account.send(command); | ||
| assert.fail('create user with existing username - should throw an error'); | ||
| } catch (err) { | ||
| const err_code = err.Error.Code; | ||
| assert.equal(err_code, IamError.EntityAlreadyExists.code); | ||
| } | ||
| }); | ||
|
|
||
| mocha.it('create a user with username that already exists (lower case) should fail', async function() { | ||
| try { | ||
| const input = { | ||
| UserName: username_lowercase | ||
| }; | ||
| const command = new CreateUserCommand(input); | ||
| await iam_account.send(command); | ||
| assert.fail('create user with existing username (lower case) - should throw an error'); | ||
| } catch (err) { | ||
| const err_code = err.Error.Code; | ||
| assert.equal(err_code, IamError.EntityAlreadyExists.code); | ||
| } | ||
| }); | ||
|
|
||
| mocha.it('create a user with username that already exists (upper case) should fail', async function() { | ||
| try { | ||
| const input = { | ||
| UserName: username_uppercase | ||
| }; | ||
| const command = new CreateUserCommand(input); | ||
| await iam_account.send(command); | ||
| assert.fail('create user with existing username (upper case) - should throw an error'); | ||
| } catch (err) { | ||
| const err_code = err.Error.Code; | ||
| assert.equal(err_code, IamError.EntityAlreadyExists.code); | ||
| } | ||
| }); | ||
| }); | ||
|
|
||
| mocha.describe('IAM UpdateUser API', async function() { | ||
| mocha.before(async () => { | ||
| // create a user | ||
| const input = { | ||
| UserName: username | ||
| }; | ||
| const command = new CreateUserCommand(input); | ||
| const response = await iam_account.send(command); | ||
| _check_status_code_ok(response); | ||
| }); | ||
|
|
||
| mocha.after(async () => { | ||
| // delete a user | ||
| const input = { | ||
| UserName: username | ||
| }; | ||
| const command = new DeleteUserCommand(input); | ||
| const response = await iam_account.send(command); | ||
| _check_status_code_ok(response); | ||
| }); | ||
|
|
||
| mocha.it('update a user with same username', async function() { | ||
| const input = { | ||
| UserName: username, | ||
| NewUserName: username, | ||
| }; | ||
| const command = new UpdateUserCommand(input); | ||
| const response = await iam_account.send(command); | ||
| _check_status_code_ok(response); | ||
| }); | ||
|
|
||
| mocha.it('update a user with new username that already exists (lower case) should fail', async function() { | ||
| try { | ||
| const input = { | ||
| UserName: username, | ||
| NewUserName: username_lowercase, | ||
| }; | ||
| const command = new UpdateUserCommand(input); | ||
| await iam_account.send(command); | ||
| assert.fail('update user with existing username (lower case) - should throw an error'); | ||
| } catch (err) { | ||
| const err_code = err.Error.Code; | ||
| assert.equal(err_code, IamError.EntityAlreadyExists.code); | ||
| } | ||
| }); | ||
|
|
||
| mocha.it('update a user with new username that already exists (upper case) should fail', async function() { | ||
| try { | ||
| const input = { | ||
| UserName: username, | ||
| NewUserName: username_uppercase, | ||
| }; | ||
| const command = new UpdateUserCommand(input); | ||
| await iam_account.send(command); | ||
| assert.fail('update user with existing username (upper case) - should throw an error'); | ||
| } catch (err) { | ||
| const err_code = err.Error.Code; | ||
| assert.equal(err_code, IamError.EntityAlreadyExists.code); | ||
| } | ||
| }); | ||
| }); | ||
|
Comment on lines
+1000
to
+1060
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. UpdateUser “duplicate username” tests don’t actually create a conflicting user In the
attempt to set To actually exercise case-insensitive uniqueness on update, you should create a second, conflicting user and then try to rename the first user to that name (in different casings). For example: mocha.describe('IAM UpdateUser API', async function() {
+ const conflicting_username = `${username}_conflict`;
+ const conflicting_username_lowercase = conflicting_username.toLowerCase();
+ const conflicting_username_uppercase = conflicting_username.toUpperCase();
+
mocha.before(async () => {
- // create a user
- const input = {
- UserName: username
- };
- const command = new CreateUserCommand(input);
- const response = await iam_account.send(command);
- _check_status_code_ok(response);
+ // create two users so we can test collisions on update
+ for (const name of [username, conflicting_username]) {
+ const input = { UserName: name };
+ const command = new CreateUserCommand(input);
+ const response = await iam_account.send(command);
+ _check_status_code_ok(response);
+ }
});
mocha.after(async () => {
- // delete a user
- const input = {
- UserName: username
- };
- const command = new DeleteUserCommand(input);
- const response = await iam_account.send(command);
- _check_status_code_ok(response);
+ // delete both users
+ for (const name of [username, conflicting_username]) {
+ const input = { UserName: name };
+ const command = new DeleteUserCommand(input);
+ const response = await iam_account.send(command);
+ _check_status_code_ok(response);
+ }
});
@@
mocha.it('update a user with new username that already exists (lower case) should fail', async function() {
try {
const input = {
UserName: username,
- NewUserName: username_lowercase,
+ NewUserName: conflicting_username_lowercase,
};
@@
mocha.it('update a user with new username that already exists (upper case) should fail', async function() {
try {
const input = {
UserName: username,
- NewUserName: username_uppercase,
+ NewUserName: conflicting_username_uppercase,
};This way you test that updating one user to a name already used by another user (in any casing) correctly yields 🤖 Prompt for AI Agents |
||
|
|
||
| }); | ||
| }); | ||
|
|
||
| /** | ||
| * _check_status_code_ok is an helper function to check that we got an response from the server | ||
| * @param {{ $metadata: { httpStatusCode: number; }; }} response | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.