Skip to content

Commit 8c49947

Browse files
committed
IAM | IAM Unit test
Signed-off-by: Naveen Paul <[email protected]>
1 parent a8b71fe commit 8c49947

File tree

15 files changed

+82
-38
lines changed

15 files changed

+82
-38
lines changed

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());

src/test/integration_tests/api/iam/test_nc_iam_basic_integration.js renamed to src/test/integration_tests/api/iam/test_iam_basic_integration.js

Lines changed: 32 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,10 @@ const path = require('path');
77
const _ = require('lodash');
88
const mocha = require('mocha');
99
const assert = require('assert');
10+
const SensitiveString = require('../../../../util/sensitive_string');
1011
const fs_utils = require('../../../../util/fs_utils');
1112
const { TMP_PATH, generate_nsfs_account, get_new_buckets_path_by_test_env, generate_iam_client,
12-
require_coretest } = require('../../../system_tests/test_utils');
13+
require_coretest, is_nc_coretest } = require('../../../system_tests/test_utils');
1314
const { ListUsersCommand, CreateUserCommand, GetUserCommand, UpdateUserCommand, DeleteUserCommand,
1415
ListAccessKeysCommand, CreateAccessKeyCommand, GetAccessKeyLastUsedCommand,
1516
UpdateAccessKeyCommand, DeleteAccessKeyCommand,
@@ -28,37 +29,47 @@ const IamError = require('../../../../endpoint/iam/iam_errors').IamError;
2829

2930

3031
const coretest = require_coretest();
31-
const setup_options = { should_run_iam: true, https_port_iam: 7005, debug: 5 };
32+
let setup_options;
33+
if (is_nc_coretest) {
34+
setup_options = { should_run_iam: true, https_port_iam: 7005, debug: 5 };
35+
}
3236
coretest.setup(setup_options);
3337
const { rpc_client, EMAIL, get_current_setup_options, stop_nsfs_process, start_nsfs_process } = coretest;
3438

35-
const CORETEST_ENDPOINT_IAM = coretest.get_iam_https_address();
36-
37-
const config_root = path.join(TMP_PATH, 'test_nc_iam');
38-
// on NC - new_buckets_path is full absolute path
39-
// on Containerized - new_buckets_path is the directory
40-
const new_bucket_path_param = get_new_buckets_path_by_test_env(config_root, '/');
41-
4239
let iam_account;
40+
let account_res;
41+
let config_root;
4342

4443
mocha.describe('IAM basic integration tests - happy path', async function() {
4544
this.timeout(50000); // eslint-disable-line no-invalid-this
4645

4746
mocha.before(async () => {
4847
// we want to make sure that we run this test with a couple of forks (by default setup it is 0)
49-
const current_setup_options = get_current_setup_options();
50-
const same_setup = _.isEqual(current_setup_options, setup_options);
51-
if (!same_setup) {
52-
console.log('current_setup_options', current_setup_options, 'same_setup', same_setup);
53-
await stop_nsfs_process();
54-
await start_nsfs_process(setup_options);
48+
if (is_nc_coretest) {
49+
config_root = path.join(TMP_PATH, 'test_nc_iam');
50+
// on NC - new_buckets_path is full absolute path
51+
// on Containerized - new_buckets_path is the directory
52+
const new_bucket_path_param = get_new_buckets_path_by_test_env(config_root, '/');
53+
54+
const current_setup_options = get_current_setup_options();
55+
const same_setup = _.isEqual(current_setup_options, setup_options);
56+
if (!same_setup) {
57+
console.log('current_setup_options', current_setup_options, 'same_setup', same_setup);
58+
await stop_nsfs_process();
59+
await start_nsfs_process(setup_options);
60+
}
61+
await fs_utils.create_fresh_path(new_bucket_path_param);
62+
await fs_utils.file_must_exist(new_bucket_path_param);
63+
account_res = await generate_nsfs_account(rpc_client, EMAIL, new_bucket_path_param, { admin: true });
64+
} else {
65+
account_res = (await rpc_client.account.read_account({ email: EMAIL })).access_keys[0];
5566
}
5667

5768
// needed details for creating the account (and then the client)
58-
await fs_utils.create_fresh_path(new_bucket_path_param);
59-
await fs_utils.file_must_exist(new_bucket_path_param);
60-
const res = await generate_nsfs_account(rpc_client, EMAIL, new_bucket_path_param, { admin: true });
61-
iam_account = generate_iam_client(res.access_key, res.secret_key, CORETEST_ENDPOINT_IAM);
69+
const coretest_endpoint_iam = coretest.get_https_address_iam();
70+
const access_key = account_res.access_key instanceof SensitiveString ? account_res.access_key.unwrap() : account_res.access_key;
71+
const secret_key = account_res.secret_key instanceof SensitiveString ? account_res.secret_key.unwrap() : account_res.secret_key;
72+
iam_account = generate_iam_client(access_key, secret_key, coretest_endpoint_iam);
6273
});
6374

6475
mocha.after(async () => {
@@ -196,6 +207,8 @@ mocha.describe('IAM basic integration tests - happy path', async function() {
196207
});
197208

198209
mocha.it('get access key (last used)', async function() {
210+
// Skipping for containerized noobaa
211+
if (!is_nc_coretest) this.skip(); // eslint-disable-line no-invalid-this
199212
const input = {
200213
AccessKeyId: access_key_id
201214
};

0 commit comments

Comments
 (0)