Skip to content

Commit

Permalink
CR 3
Browse files Browse the repository at this point in the history
  • Loading branch information
romayalon committed Jan 13, 2025
1 parent 1b98864 commit 0a01004
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 34 deletions.
2 changes: 1 addition & 1 deletion src/test/system_tests/test_utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -520,7 +520,7 @@ async function write_manual_config_file(type, config_fs, config_data, invalid_st
}

/**
* symlink_account_name symlinks the account's name path to the target link path
* symlink_account_name symlinks the account's name path to the target link path
* used for manual creation of the account name symlink
* @param {import('../../sdk/config_fs').ConfigFS} config_fs
* @param {String} account_name
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ const default_config_fs = new ConfigFS(DEFAULT_CONF_DIR_PATH, config_root_backen
const hidden_old_accounts_path = path.join(default_config_fs.config_root, `.backup_accounts_dir_${mock_old_version}/`);
const hidden_access_keys_backup_path = path.join(default_config_fs.config_root, `.backup_access_keys_dir_${mock_old_version}/`);
const root_dn = 'root';
// as mentioned in ResourcesLimitations.md - there is a soft limit of 5000 supported accounts
const accounts_soft_limit = 5000;
const mock_account_id = '1';
const mock_account_name = 'old_account' + mock_account_id;

// WARNING:
// The following test file will check the directory structure created using create_config_dirs_if_missing()
Expand Down Expand Up @@ -68,11 +72,11 @@ describe('move_old_accounts_dir', () => {
await assert_backup_dir({ [account_name]: account_data});
});

it('move_old_accounts_dir() - accounts/ dir contains 5000 accounts', async () => {
it('move_old_accounts_dir() - accounts/ dir contains accounts_soft_limit accounts', async () => {
await create_fresh_path(default_config_fs.old_accounts_dir_path);
const account_ids = Array.from({ length: 5000 }, (v, i) => Number(i + 1));
const account_ids = Array.from({ length: accounts_soft_limit }, (v, i) => Number(i + 1));
const account_names_obj = {};
await P.map_with_concurrency(5000, account_ids, async account_id => {
await P.map_with_concurrency(accounts_soft_limit, account_ids, async account_id => {
const account_data = { _id: String(account_id), name: 'old_account' + account_id, user: root_dn };
await write_manual_old_account_config_file(default_config_fs, account_data);
account_names_obj[account_data.name] = account_data;
Expand Down Expand Up @@ -125,7 +129,7 @@ describe('create_account_access_keys_index_if_missing', () => {
// in the following tests we test create_account_access_keys_index_if_missing()
// therefore we need to create the target symlink of the access keys, which is the identity file before we run the function
it('create_account_access_keys_index_if_missing() - single regular account', async () => {
const account_data = { _id: String(1), name: 'old_account' + 1, user: root_dn, access_keys: mock_access_keys };
const account_data = { _id: mock_account_id, name: mock_account_name, user: root_dn, access_keys: mock_access_keys };
await write_manual_old_account_config_file(default_config_fs, account_data, { symlink_access_key: true });
await write_manual_config_file(CONFIG_TYPES.ACCOUNT, default_config_fs, account_data, undefined,
{ symlink_access_key: false, symlink_name: false });
Expand All @@ -137,7 +141,7 @@ describe('create_account_access_keys_index_if_missing', () => {
});

it('create_account_access_keys_index_if_missing() - anonymous account', async () => {
const account_data = { _id: String(1), name: config.ANONYMOUS_ACCOUNT_NAME, user: root_dn };
const account_data = { _id: mock_account_id, name: config.ANONYMOUS_ACCOUNT_NAME, user: root_dn };
await write_manual_old_account_config_file(default_config_fs, account_data, { symlink_access_key: false });
await write_manual_config_file(CONFIG_TYPES.ACCOUNT, default_config_fs, account_data, undefined,
{ symlink_access_key: false, symlink_name: false });
Expand All @@ -148,7 +152,7 @@ describe('create_account_access_keys_index_if_missing', () => {
});

it('create_account_access_keys_index_if_missing() - new access key index already exists', async () => {
const account_data = { _id: String(1), name: 'old_account' + 1, user: root_dn, access_keys: mock_access_keys };
const account_data = { _id: mock_account_id, name: mock_account_name, user: root_dn, access_keys: mock_access_keys };
await write_manual_old_account_config_file(default_config_fs, account_data, { symlink_access_key: false });
await write_manual_config_file(CONFIG_TYPES.ACCOUNT, default_config_fs, account_data, undefined,
{ symlink_access_key: true, symlink_name: false });
Expand All @@ -159,7 +163,7 @@ describe('create_account_access_keys_index_if_missing', () => {
});

it('create_account_access_keys_index_if_missing() - new access key index already exists and points to a non existing location', async () => {
const account_data = { _id: String(1), name: 'old_account' + 1, user: root_dn, access_keys: mock_access_keys };
const account_data = { _id: mock_account_id, name: mock_account_name, user: root_dn, access_keys: mock_access_keys };
await write_manual_old_account_config_file(default_config_fs, account_data, { symlink_access_key: false });
await write_manual_config_file(CONFIG_TYPES.ACCOUNT, default_config_fs, account_data, undefined,
{ symlink_access_key: false, symlink_name: false });
Expand All @@ -171,8 +175,8 @@ describe('create_account_access_keys_index_if_missing', () => {
await assert_access_key_index_is_updated(account_data);
});

it('create_account_access_keys_index_if_missing() - new access key index already exists and points to a non wrong location', async () => {
const account_data = { _id: String(1), name: 'old_account' + 1, user: root_dn, access_keys: mock_access_keys };
it('create_account_access_keys_index_if_missing() - new access key index already exists and points to a wrong location', async () => {
const account_data = { _id: mock_account_id, name: mock_account_name, user: root_dn, access_keys: mock_access_keys };
await write_manual_old_account_config_file(default_config_fs, account_data, { symlink_access_key: false });
await write_manual_config_file(CONFIG_TYPES.ACCOUNT, default_config_fs, account_data, undefined,
{ symlink_access_key: false, symlink_name: false });
Expand All @@ -188,7 +192,7 @@ describe('create_account_access_keys_index_if_missing', () => {
});

it('create_account_access_keys_index_if_missing() - old access key index already deleted', async () => {
const account_data = { _id: String(1), name: 'old_account' + 1, user: root_dn, access_keys: mock_access_keys };
const account_data = { _id: mock_account_id, name: mock_account_name, user: root_dn, access_keys: mock_access_keys };
await write_manual_old_account_config_file(default_config_fs, account_data, { symlink_access_key: false });
await write_manual_config_file(CONFIG_TYPES.ACCOUNT, default_config_fs, account_data, undefined,
{ symlink_access_key: false, symlink_name: false });
Expand Down Expand Up @@ -217,7 +221,7 @@ describe('create_account_name_index_if_missing', () => {


it('create_account_name_index_if_missing() - single regular account', async () => {
const account_data = { _id: String(1), name: 'old_account' + 1, user: root_dn, access_keys: mock_access_keys };
const account_data = { _id: mock_account_id, name: mock_account_name, user: root_dn, access_keys: mock_access_keys };
await write_manual_old_account_config_file(default_config_fs, account_data, { symlink_access_key: false });
await write_manual_config_file(CONFIG_TYPES.ACCOUNT, default_config_fs, account_data, undefined,
{ symlink_access_key: false, symlink_name: false });
Expand All @@ -229,7 +233,7 @@ describe('create_account_name_index_if_missing', () => {
});

it('create_account_name_index_if_missing() - anonymous account', async () => {
const account_data = { _id: String(1), name: config.ANONYMOUS_ACCOUNT_NAME, user: root_dn };
const account_data = { _id: mock_account_id, name: config.ANONYMOUS_ACCOUNT_NAME, user: root_dn };
const symlink_options = { symlink_access_key: false };
await write_manual_old_account_config_file(default_config_fs, account_data, symlink_options);
await write_manual_config_file(CONFIG_TYPES.ACCOUNT, default_config_fs, account_data, undefined, symlink_options);
Expand All @@ -240,7 +244,7 @@ describe('create_account_name_index_if_missing', () => {
});

it('create_account_name_index_if_missing() - new name index already exists', async () => {
const account_data = { _id: String(1), name: 'old_account' + 1, user: root_dn, access_keys: mock_access_keys };
const account_data = { _id: mock_account_id, name: mock_account_name, user: root_dn, access_keys: mock_access_keys };
await write_manual_old_account_config_file(default_config_fs, account_data, { symlink_access_key: false });
await write_manual_config_file(CONFIG_TYPES.ACCOUNT, default_config_fs, account_data, undefined,
{ symlink_access_key: false, symlink_name: true });
Expand All @@ -251,7 +255,7 @@ describe('create_account_name_index_if_missing', () => {
});

it('create_account_name_index_if_missing() - new name index already exists and points to a non existing location', async () => {
const account_data = { _id: String(1), name: 'old_account' + 1, user: root_dn, access_keys: mock_access_keys };
const account_data = { _id: mock_account_id, name: mock_account_name, user: root_dn, access_keys: mock_access_keys };
await write_manual_old_account_config_file(default_config_fs, account_data, { symlink_access_key: false });
await write_manual_config_file(CONFIG_TYPES.ACCOUNT, default_config_fs, account_data, undefined,
{ symlink_access_key: false, symlink_name: false });
Expand All @@ -264,7 +268,7 @@ describe('create_account_name_index_if_missing', () => {
});

it('create_account_name_index_if_missing() - new name index already exists and points to wrong location', async () => {
const account_data = { _id: String(1), name: 'old_account' + 1, user: root_dn, access_keys: mock_access_keys };
const account_data = { _id: mock_account_id, name: mock_account_name, user: root_dn, access_keys: mock_access_keys };
await write_manual_old_account_config_file(default_config_fs, account_data, { symlink_access_key: false });
await write_manual_config_file(CONFIG_TYPES.ACCOUNT, default_config_fs, account_data, undefined,
{ symlink_access_key: false, symlink_name: false });
Expand All @@ -280,7 +284,7 @@ describe('create_account_name_index_if_missing', () => {
});

it('create_account_name_index_if_missing() - old name index already deleted', async () => {
const account_data = { _id: String(1), name: 'old_account' + 1, user: root_dn, access_keys: mock_access_keys };
const account_data = { _id: mock_account_id, name: mock_account_name, user: root_dn, access_keys: mock_access_keys };
await write_manual_old_account_config_file(default_config_fs, account_data, { symlink_access_key: false });
await write_manual_config_file(CONFIG_TYPES.ACCOUNT, default_config_fs, account_data, undefined,
{ symlink_access_key: false, symlink_name: false });
Expand Down Expand Up @@ -308,7 +312,7 @@ describe('create_identity_if_missing', () => {
}, TEST_TIMEOUT);

it('create_identity_if_missing() - identity does not exist', async () => {
const account_data = { _id: String(1), name: 'old_account' + 1, user: root_dn, access_keys: mock_access_keys };
const account_data = { _id: mock_account_id, name: mock_account_name, user: root_dn, access_keys: mock_access_keys };
await write_manual_old_account_config_file(default_config_fs, account_data);
const account_old_path = default_config_fs._get_old_account_path_by_name(account_data.name);
const account_old_path_stat = await nb_native().fs.stat(default_config_fs.fs_context, account_old_path);
Expand All @@ -324,7 +328,7 @@ describe('create_identity_if_missing', () => {
});

it('create_identity_if_missing() - identity file and dir already exists', async () => {
const account_data = { _id: String(1), name: 'old_account' + 1, user: root_dn, access_keys: mock_access_keys };
const account_data = { _id: mock_account_id, name: mock_account_name, user: root_dn, access_keys: mock_access_keys };
await write_manual_old_account_config_file(default_config_fs, account_data);
await write_manual_config_file(CONFIG_TYPES.ACCOUNT, default_config_fs, account_data, undefined);
const account_old_path = default_config_fs._get_old_account_path_by_name(account_data.name);
Expand All @@ -341,7 +345,7 @@ describe('create_identity_if_missing', () => {
});

it('create_identity_if_missing() - only dir exists but file doesn’t', async () => {
const account_data = { _id: String(1), name: 'old_account' + 1, user: root_dn, access_keys: mock_access_keys };
const account_data = { _id: mock_account_id, name: mock_account_name, user: root_dn, access_keys: mock_access_keys };
await write_manual_old_account_config_file(default_config_fs, account_data);
await create_identity_dir_if_missing(default_config_fs, account_data._id);
const account_old_path = default_config_fs._get_old_account_path_by_name(account_data.name);
Expand Down Expand Up @@ -375,7 +379,7 @@ describe('prepare_account_upgrade_params', () => {
}, TEST_TIMEOUT);

it('prepare_account_upgrade_params() - account name exists', async () => {
const account_data = { _id: String(1), name: 'old_account' + 1, user: root_dn, access_keys: mock_access_keys };
const account_data = { _id: mock_account_id, name: mock_account_name, user: root_dn, access_keys: mock_access_keys };
await write_manual_old_account_config_file(default_config_fs, account_data);
const account_old_path = default_config_fs._get_old_account_path_by_name(account_data.name);
const identity_path = default_config_fs.get_identity_path_by_id(account_data._id);
Expand Down Expand Up @@ -407,7 +411,7 @@ describe('prepare_account_upgrade_params', () => {
});

it('prepare_account_upgrade_params() - account name does not exist', async () => {
const account_data = { _id: String(1), name: 'old_account' + 1, user: root_dn, access_keys: mock_access_keys };
const account_data = { _id: mock_account_id, name: mock_account_name, user: root_dn, access_keys: mock_access_keys };
await expect(prepare_account_upgrade_params(default_config_fs, account_data.name)).rejects.toThrow('No such file or directory');
});
});
Expand All @@ -430,14 +434,14 @@ describe('upgrade_account_config_file', () => {
}, TEST_TIMEOUT);

it('upgrade_account_config_file() - account exists in accounts/', async () => {
const account_data = { _id: String(1), name: 'old_account' + 1, user: root_dn, access_keys: mock_access_keys };
const account_data = { _id: mock_account_id, name: mock_account_name, user: root_dn, access_keys: mock_access_keys };
await write_manual_old_account_config_file(default_config_fs, account_data, { symlink_access_key: true });
await upgrade_account_config_file(default_config_fs, account_data.name, hidden_access_keys_backup_path, dbg);
await assert_account_config_file_upgraded({[account_data.name]: account_data});
});

it('upgrade_account_config_file() - account was already upgraded', async () => {
const account_data = { _id: String(1), name: 'old_account' + 1, user: root_dn, access_keys: mock_access_keys };
const account_data = { _id: mock_account_id, name: mock_account_name, user: root_dn, access_keys: mock_access_keys };
await write_manual_old_account_config_file(default_config_fs, account_data, { symlink_access_key: false });
await write_manual_config_file(CONFIG_TYPES.ACCOUNT, default_config_fs, account_data, undefined,
{ symlink_access_key: false, symlink_name: false });
Expand All @@ -446,7 +450,7 @@ describe('upgrade_account_config_file', () => {
});

it('upgrade_account_config_file() - identity exists but indexes (symlinks) are not', async () => {
const account_data = { _id: String(1), name: 'old_account' + 1, user: root_dn, access_keys: mock_access_keys };
const account_data = { _id: mock_account_id, name: mock_account_name, user: root_dn, access_keys: mock_access_keys };
await write_manual_old_account_config_file(default_config_fs, account_data, { symlink_access_key: false });
await write_manual_config_file(CONFIG_TYPES.ACCOUNT, default_config_fs, account_data, undefined,
{ symlink_access_key: false, symlink_name: false });
Expand All @@ -455,7 +459,7 @@ describe('upgrade_account_config_file', () => {
});

it('upgrade_account_config_file() - identity exists, name index (symlink) exist, access keys index (symlink) does not', async () => {
const account_data = { _id: String(1), name: 'old_account' + 1, user: root_dn, access_keys: mock_access_keys };
const account_data = { _id: mock_account_id, name: mock_account_name, user: root_dn, access_keys: mock_access_keys };
await write_manual_old_account_config_file(default_config_fs, account_data, { symlink_access_key: false });
await write_manual_config_file(CONFIG_TYPES.ACCOUNT, default_config_fs, account_data, undefined,
{ symlink_access_key: false, symlink_name: true });
Expand All @@ -464,7 +468,7 @@ describe('upgrade_account_config_file', () => {
});

it('upgrade_account_config_file() - identity exists, access keys index exist, name index does not', async () => {
const account_data = { _id: String(1), name: 'old_account' + 1, user: root_dn, access_keys: mock_access_keys };
const account_data = { _id: mock_account_id, name: mock_account_name, user: root_dn, access_keys: mock_access_keys };
await write_manual_old_account_config_file(default_config_fs, account_data, { symlink_access_key: false });
await write_manual_config_file(CONFIG_TYPES.ACCOUNT, default_config_fs, account_data, undefined,
{ symlink_access_key: true, symlink_name: false });
Expand Down Expand Up @@ -498,8 +502,8 @@ describe('upgrade_accounts_config_files', () => {
await assert_dir_is_empty(default_config_fs.access_keys_dir_path);
});

it('upgrade_accounts_config_files() - accounts/ dir contains 5000 accounts', async () => {
const account_ids = Array.from({ length: 5000 }, (v, i) => Number(i + 1));
it('upgrade_accounts_config_files() - accounts/ dir contains accounts_soft_limit accounts', async () => {
const account_ids = Array.from({ length: accounts_soft_limit }, (v, i) => Number(i + 1));
const account_names_obj = {};
await P.map_with_concurrency(100, account_ids, async account_id => {
const access_keys = _.cloneDeep(mock_access_keys);
Expand Down Expand Up @@ -537,8 +541,8 @@ describe('run', () => {
await assert_backup_dir({});
});

it('run() - accounts/ dir contains 5000 accounts', async () => {
const account_ids = Array.from({ length: 5000 }, (v, i) => Number(i + 1));
it('run() - accounts/ dir contains accounts_soft_limit accounts', async () => {
const account_ids = Array.from({ length: accounts_soft_limit }, (v, i) => Number(i + 1));
const account_names_obj = {};
await P.map_with_concurrency(100, account_ids, async account_id => {
const access_keys = _.cloneDeep(mock_access_keys);
Expand All @@ -565,7 +569,8 @@ async function assert_old_account_dir_was_deleted() {

/**
* assert_backup_dir was created and contains the given accounts
* @param {Object} [expected_accounts]
* expected_accounts is an object that consisted of {account_name: account_data}
* @param {{[account_name: String]: Object}} [expected_accounts]
* @returns {Promise<Void>}
*/
async function assert_backup_dir(expected_accounts = {}) {
Expand Down
Loading

0 comments on commit 0a01004

Please sign in to comment.