Skip to content

Commit c0ac4c1

Browse files
authored
Merge pull request #9300 from naveenpaul1/iam_unit_test
IAM | IAM integration tests
2 parents a8b71fe + 6bdcf23 commit c0ac4c1

File tree

16 files changed

+93
-43
lines changed

16 files changed

+93
-43
lines changed

src/endpoint/iam/iam_utils.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -816,6 +816,20 @@ function validate_list_user_tags_params(params) {
816816
}
817817
}
818818

819+
/**
820+
* get_owner_account_id return owner account id
821+
* @param {object} user_account
822+
*/
823+
function get_owner_account_id(user_account) {
824+
let owner_account_id;
825+
if (typeof user_account.owner === 'object') {
826+
owner_account_id = String(user_account.owner._id);
827+
} else {
828+
owner_account_id = user_account.owner;
829+
}
830+
return owner_account_id;
831+
}
832+
819833
// EXPORTS
820834
exports.format_iam_xml_date = format_iam_xml_date;
821835
exports.create_arn_for_user = create_arn_for_user;
@@ -837,4 +851,5 @@ exports.parse_tag_keys_from_request_body = parse_tag_keys_from_request_body;
837851
exports.validate_tag_user_params = validate_tag_user_params;
838852
exports.validate_untag_user_params = validate_untag_user_params;
839853
exports.validate_list_user_tags_params = validate_list_user_tags_params;
854+
exports.get_owner_account_id = get_owner_account_id;
840855

src/endpoint/iam/ops/iam_list_attached_user_policies.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ async function list_attached_user_policies(req, res) {
2121

2222
dbg.log1('To check that we have the user we will run the IAM GET USER', params);
2323
iam_utils.validate_params(iam_constants.IAM_ACTIONS.GET_USER, params);
24-
await req.account_sdk.get_user(params);
24+
await req.account_sdk.get_user({ username: params.username });
2525

2626
dbg.log1('IAM LIST ATTACHED USER POLICIES (returns empty list on every request)', params);
2727

src/endpoint/iam/ops/iam_list_groups_for_user.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ async function list_groups_for_user(req, res) {
1717

1818
dbg.log1('To check that we have the user we will run the IAM GET USER', params);
1919
iam_utils.validate_params(iam_constants.IAM_ACTIONS.GET_USER, params);
20-
await req.account_sdk.get_user(params);
20+
await req.account_sdk.get_user({ username: params.username });
2121

2222
dbg.log1('IAM LIST GROUPS FOR USER (returns empty list on every request)', params);
2323

src/endpoint/iam/ops/iam_list_mfa_devices.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ async function list_mfa_devices(req, res) {
1818
if (params.username !== undefined) {
1919
dbg.log1('To check that we have the user we will run the IAM GET USER', params);
2020
iam_utils.validate_params(iam_constants.IAM_ACTIONS.GET_USER, params);
21-
await req.account_sdk.get_user(params);
21+
await req.account_sdk.get_user({ username: params.username });
2222
}
2323
dbg.log1('IAM LIST MFA DEVICES (returns empty list on every request)', params);
2424

src/endpoint/iam/ops/iam_list_service_specific_credentials.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ async function list_service_specific_credentials(req, res) {
1818
if (params.username !== undefined) {
1919
dbg.log1('To check that we have the user we will run the IAM GET USER', params);
2020
iam_utils.validate_params(iam_constants.IAM_ACTIONS.GET_USER, params);
21-
await req.account_sdk.get_user(params);
21+
await req.account_sdk.get_user({ username: params.username });
2222
}
2323
dbg.log1('IAM LIST SERVER SPECIFIC CREDENTIALS (returns empty list on every request)', params);
2424

src/endpoint/iam/ops/iam_list_signing_certificates.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ async function list_signing_certificates(req, res) {
2020
if (params.username !== undefined) {
2121
dbg.log1('To check that we have the user we will run the IAM GET USER', params);
2222
iam_utils.validate_params(iam_constants.IAM_ACTIONS.GET_USER, params);
23-
await req.account_sdk.get_user(params);
23+
await req.account_sdk.get_user({ username: params.username });
2424
}
2525
dbg.log1('IAM LIST SIGNING CERTIFICATES (returns empty list on every request)', params);
2626
const requesting_account_name = req.account_sdk.requesting_account.name instanceof SensitiveString ?

src/endpoint/iam/ops/iam_list_ssh_public_keys.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ async function list_ssh_public_keys(req, res) {
1919
if (params.username !== undefined) {
2020
dbg.log1('To check that we have the user we will run the IAM GET USER', params);
2121
iam_utils.validate_params(iam_constants.IAM_ACTIONS.GET_USER, params);
22-
await req.account_sdk.get_user(params);
22+
await req.account_sdk.get_user({ username: params.username });
2323
}
2424
dbg.log1('IAM LIST SSH PUBLIC KEYS (returns empty list on every request)', params);
2525

src/sdk/accountspace_nb.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,6 @@ class AccountSpaceNB {
6363
}
6464

6565
async get_user(params, account_sdk) {
66-
6766
const requesting_account = system_store.get_account_by_email(account_sdk.requesting_account.email);
6867
return await account_sdk.rpc_client.account.get_user(params, requesting_account);
6968
}

src/server/common_services/auth_server.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -316,7 +316,7 @@ function _authorize_signature_token(req) {
316316
const auth_token_obj = req.auth_token;
317317

318318
const account = _.find(system_store.data.accounts, function(acc) {
319-
return acc.access_keys &&
319+
return acc.access_keys && acc.access_keys.length > 0 &&
320320
acc.access_keys[0].access_key.unwrap() ===
321321
auth_token_obj.access_key;
322322
});

src/server/system_services/account_server.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1277,10 +1277,10 @@ async function list_users(req) {
12771277
const requesting_account = req.account;
12781278
account_util._check_if_requesting_account_is_root_account(action, requesting_account, { });
12791279
const is_truncated = false; // GAP - no pagination at this point
1280-
12811280
const requesting_account_iam_users = _.filter(system_store.data.accounts, function(account) {
1281+
const owner_account_id = account_util.get_owner_account_id(account);
12821282
// Check IAM user owner is same as requesting_account id
1283-
return account.owner?._id.toString() === requesting_account._id.toString();
1283+
return owner_account_id === requesting_account._id.toString();
12841284
});
12851285
let members = _.map(requesting_account_iam_users, function(iam_user) {
12861286
const iam_username = account_util.get_iam_username(iam_user.name.unwrap());

0 commit comments

Comments
 (0)