Skip to content

Commit

Permalink
test_encryption namesapce resource target bucket fix, update_external…
Browse files Browse the repository at this point in the history
…_connection fix for node20 (noobaa#7654)

* test_encryption.js - add buckets

Signed-off-by: Amit Prinz Setter <[email protected]>

* test enc - prep add_external_connection() for node20

Signed-off-by: Amit Prinz Setter <[email protected]>

* test_encryption.js for node20 - remove logs

Signed-off-by: Amit Prinz Setter <[email protected]>

---------

Signed-off-by: Amit Prinz Setter <[email protected]>
  • Loading branch information
alphaprinz authored Dec 12, 2023
1 parent 13878f4 commit 6c34159
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 19 deletions.
4 changes: 2 additions & 2 deletions src/server/system_services/account_server.js
Original file line number Diff line number Diff line change
Expand Up @@ -848,7 +848,7 @@ async function update_external_connection(req) {
pool.cloud_pool_info &&
pool.cloud_pool_info.endpoint_type === connection.endpoint_type &&
pool.cloud_pool_info.endpoint === connection.endpoint &&
pool.cloud_pool_info.access_keys.account_id._id === req.account._id &&
pool.cloud_pool_info.access_keys.account_id._id.toString() === req.account._id.toString() &&
pool.cloud_pool_info.access_keys.access_key.unwrap() === connection.access_key.unwrap()
)
.map(pool => ({
Expand All @@ -862,7 +862,7 @@ async function update_external_connection(req) {
ns_resource.connection &&
ns_resource.connection.endpoint_type === connection.endpoint_type &&
ns_resource.connection.endpoint === connection.endpoint &&
ns_resource.account._id === req.account._id &&
ns_resource.account._id.toString() === req.account._id.toString() &&
ns_resource.connection.access_key.unwrap() === connection.access_key.unwrap()
)
.map(ns_resource => ({
Expand Down
37 changes: 20 additions & 17 deletions src/test/unit_tests/test_encryption.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,9 @@ mocha.describe('Encryption tests', function() {
await compare_master_keys({db_master_key_id: db_bucket.master_key_id,
father_master_key_id: db_system.master_key_id});
}
for (i = 0; i < 20; i++) {
await s3.createBucket({ Bucket: `${BKT}-${i}` });
}
await s3.createBucket({ Bucket: BKT });
});

Expand Down Expand Up @@ -137,7 +140,7 @@ mocha.describe('Encryption tests', function() {
for (i = 0; i < 20; i++) {
response_account = await rpc_client.account.create_account({...new_account_params,
email: `email${i}`, name: `name${i}`});
accounts.push({email: `email${i}`, create_account_result: response_account});
accounts.push({email: `email${i}`, create_account_result: response_account, index: i});
const db_account = await db_client.collection('accounts').findOne({ email: `email${i}` });
const system_store_account = account_by_name(system_store.data.accounts, `email${i}`);

Expand Down Expand Up @@ -189,17 +192,17 @@ mocha.describe('Encryption tests', function() {
this.timeout(600000); // eslint-disable-line no-invalid-this
await P.all(_.map(accounts.slice(10), async cur_account => {
const namespace_resource_name = `${cur_account.email}-namespace-resource`;
const target_bucket = BKT;
const target_bucket = `${BKT}-${cur_account.index}`;
await rpc_client.pool.create_namespace_resource({
name: namespace_resource_name,
connection: 'conn1',
target_bucket,
target_bucket
}, { auth_token: cur_account.create_account_result.token });
namespace_resources.push({name: namespace_resource_name,
auth_token: cur_account.create_account_result.token,
access_key: cur_account.create_account_result.access_keys[0].access_key.unwrap(),
secret_key: cur_account.create_account_result.access_keys[0].secret_key.unwrap(),
target_bucket });
target_bucket});
}));
await system_store.load();
await P.all(_.map(accounts.slice(10), async cur_account => {
Expand Down Expand Up @@ -530,7 +533,7 @@ mocha.describe('Rotation tests', function() {
await compare_secrets_disabled(secrets, system_store_account.master_key_id._id, original_secrets.system_store_secret);
await P.all(_.map(system_store.data.pools, async pool => {
if (!pool.cloud_pool_info) return;
if (pool.cloud_pool_info.target_bucket === BKT) return;
if (pool.cloud_pool_info.target_bucket.startsWith(BKT)) return;
const pools_secrets = await get_pools_secrets_from_system_store_and_db(pool);
if (is_connection_is_account_s3_creds(
pool, 'pool', system_store_account._id, system_store_account.access_keys[0])) {
Expand All @@ -539,7 +542,7 @@ mocha.describe('Rotation tests', function() {
}
}));
await P.all(_.map(system_store.data.namespace_resources, async ns_resource => {
if (!ns_resource.connection || ns_resource.connection.target_bucket === BKT) return;
if (!ns_resource.connection || ns_resource.connection.target_bucket.startsWith(BKT)) return;
const ns_resources_secrets = await get_ns_resources_secrets_from_system_store_and_db(ns_resource);
if (is_connection_is_account_s3_creds(
ns_resource, 'ns', system_store_account._id, system_store_account.access_keys[0])) {
Expand All @@ -559,7 +562,7 @@ mocha.describe('Rotation tests', function() {
compare_secrets(secrets, system_store_account.master_key_id._id);
await P.all(_.map(system_store.data.pools, async pool => {
if (!pool.cloud_pool_info) return;
if (pool.cloud_pool_info.target_bucket === BKT) return;
if (pool.cloud_pool_info.target_bucket.startsWith(BKT)) return;
if (is_connection_is_account_s3_creds(
pool, 'pool', system_store_account._id, system_store_account.access_keys[0])) {
const pools_secrets = await get_pools_secrets_from_system_store_and_db(pool);
Expand All @@ -568,7 +571,7 @@ mocha.describe('Rotation tests', function() {
}
}));
await P.all(_.map(system_store.data.namespace_resources, async ns_resource => {
if (!ns_resource.connection || ns_resource.connection.target_bucket === BKT) return;
if (!ns_resource.connection || ns_resource.connection.target_bucket.startsWith(BKT)) return;
const ns_resources_secrets = await get_ns_resources_secrets_from_system_store_and_db(ns_resource);
if (is_connection_is_account_s3_creds(
ns_resource, 'ns', system_store_account._id, system_store_account.access_keys[0])) {
Expand All @@ -589,7 +592,7 @@ mocha.describe('Rotation tests', function() {
const secrets = await get_account_secrets_from_system_store_and_db(accounts[0].email, 's3_creds');
await compare_secrets_disabled(secrets, system_store_account.master_key_id._id, original_secrets.system_store_secret);
await P.all(_.map(system_store.data.pools, async pool => {
if (!pool.cloud_pool_info || pool.cloud_pool_info.target_bucket === BKT) return;
if (!pool.cloud_pool_info || pool.cloud_pool_info.target_bucket.startsWith(BKT)) return;
const pools_secrets = await get_pools_secrets_from_system_store_and_db(pool);
if (is_pool_of_account(pool, 'pool', system_store_account._id)) {
await compare_secrets_disabled(pools_secrets.secrets, pools_secrets.owner_account_master_key_id);
Expand All @@ -612,7 +615,7 @@ mocha.describe('Rotation tests', function() {
const secrets = await get_account_secrets_from_system_store_and_db(accounts[2].email, 's3_creds');
await compare_secrets_disabled(secrets, system_store_account.master_key_id._id, original_secrets.system_store_secret);
await P.all(_.map(system_store.data.namespace_resources, async ns_resource => {
if (!ns_resource.connection || ns_resource.connection.target_bucket === BKT) return;
if (!ns_resource.connection || ns_resource.connection.target_bucket.startsWith(BKT)) return;
const ns_resources_secrets = await get_ns_resources_secrets_from_system_store_and_db(ns_resource);
if (is_pool_of_account(ns_resource, 'ns', system_store_account._id)) {
await compare_secrets_disabled(ns_resources_secrets.secrets, ns_resources_secrets.owner_account_master_key_id);
Expand Down Expand Up @@ -645,14 +648,14 @@ mocha.describe('Rotation tests', function() {
}));
await P.all(_.map(system_store.data.pools, async pool => {
if (pool.cloud_pool_info) {
if (pool.cloud_pool_info.target_bucket === BKT) return;
if (pool.cloud_pool_info.target_bucket.startsWith(BKT)) return;
const pools_secrets = await get_pools_secrets_from_system_store_and_db(pool);
await compare_secrets_disabled(pools_secrets.secrets, pools_secrets.owner_account_master_key_id);
}
}));

await P.all(_.map(system_store.data.namespace_resources, async ns_resource => {
if (!ns_resource.connection || ns_resource.connection.target_bucket === BKT) return;
if (!ns_resource.connection || ns_resource.connection.target_bucket.startsWith(BKT)) return;
const ns_resources_secrets = await get_ns_resources_secrets_from_system_store_and_db(ns_resource);
await compare_secrets_disabled(ns_resources_secrets.secrets, ns_resources_secrets.owner_account_master_key_id);
}));
Expand Down Expand Up @@ -717,7 +720,7 @@ mocha.describe('Rotation tests', function() {

await P.all(_.map(system_store.data.pools, async pool => {
if (pool.cloud_pool_info) {
if (pool.cloud_pool_info.target_bucket === BKT) return;
if (pool.cloud_pool_info.target_bucket.startsWith(BKT)) return;
const pools_secrets = await get_pools_secrets_from_system_store_and_db(pool);
await compare_secrets_disabled(pools_secrets.secrets, pools_secrets.owner_account_master_key_id);
}
Expand Down Expand Up @@ -754,7 +757,7 @@ mocha.describe('Rotation tests', function() {

await P.all(_.map(system_store.data.pools, async pool => {
if (!pool.cloud_pool_info) return;
if (pool.cloud_pool_info.target_bucket === BKT) return;
if (pool.cloud_pool_info.target_bucket.startsWith(BKT)) return;
const pools_secrets = await get_pools_secrets_from_system_store_and_db(pool);
if (is_connection_is_account_s3_creds(
pool, 'pool', system_store_account._id, system_store_account.access_keys[0])) {
Expand All @@ -778,7 +781,7 @@ mocha.describe('Rotation tests', function() {

await P.all(_.map(system_store.data.pools, async pool => {
if (!pool.cloud_pool_info) return;
if (pool.cloud_pool_info.target_bucket === BKT) return;
if (pool.cloud_pool_info.target_bucket.startsWith(BKT)) return;
if (is_connection_is_account_s3_creds(
pool, 'pool', system_store_account._id, system_store_account.access_keys[0])) {
const pools_secrets = await get_pools_secrets_from_system_store_and_db(pool);
Expand Down Expand Up @@ -812,7 +815,7 @@ mocha.describe('Rotation tests', function() {
}));
await P.all(_.map(system_store.data.pools, async pool => {
if (pool.cloud_pool_info) {
if (pool.cloud_pool_info.target_bucket === BKT) return;
if (pool.cloud_pool_info.target_bucket.startsWith(BKT)) return;
const sys_account = account_by_id(system_store.data.accounts, pool.cloud_pool_info.access_keys.account_id._id);
old_pools.push({pool_name: pool.pool_name, master_key: sys_account.master_key_id});
}
Expand Down Expand Up @@ -866,7 +869,7 @@ mocha.describe('Rotation tests', function() {
}));
await P.all(_.map(system_store.data.pools, async pool => {
if (pool.cloud_pool_info) {
if (pool.cloud_pool_info.target_bucket === BKT) return;
if (pool.cloud_pool_info.target_bucket.startsWith(BKT)) return;
const pools_secrets = await get_pools_secrets_from_system_store_and_db(pool);
await compare_secrets_disabled(pools_secrets.secrets, pools_secrets.owner_account_master_key_id);
}
Expand Down

0 comments on commit 6c34159

Please sign in to comment.