@@ -65,9 +65,10 @@ const cross_test_store = {};
6565let user_a_account_details ;
6666let user_b_account_details ;
6767
68+ let user_a_account_id ;
69+ let user_b_account_id ;
70+
6871let admin_info ;
69- let account_info_a ;
70- let account_info_b ;
7172
7273let a_principal ;
7374let b_principal ;
@@ -123,14 +124,14 @@ async function setup() {
123124 account . name = user_a ;
124125 account . email = user_a ;
125126 user_a_account_details = await rpc_client . account . create_account ( account ) ;
126- account_info_a = user_a_account_details . _id ? user_a_account_details : await rpc_client . account . read_account ( { email : user_a } ) ;
127- console . log ( 'user_a_account_details' , account_info_a ) ;
127+ console . log ( 'user_a_account_details' , user_a_account_details ) ;
128128 const user_a_keys = user_a_account_details . access_keys ;
129+ user_a_account_id = is_nc_coretest ? user_a_account_details . _id : user_a_account_details . id ;
129130 account . name = user_b ;
130131 account . email = user_b ;
131132 user_b_account_details = await rpc_client . account . create_account ( account ) ;
132- account_info_b = user_b_account_details . _id ? user_b_account_details : await rpc_client . account . read_account ( { email : user_b } ) ;
133- console . log ( ' user_b_account_details' , account_info_b ) ;
133+ console . log ( ' user_b_account_details' , user_b_account_details ) ;
134+ user_b_account_id = is_nc_coretest ? user_b_account_details . _id : user_b_account_details . id ;
134135 const user_b_keys = user_b_account_details . access_keys ;
135136 s3_creds . credentials = {
136137 accessKeyId : user_a_keys [ 0 ] . access_key . unwrap ( ) ,
@@ -149,11 +150,11 @@ async function setup() {
149150 } ;
150151 /*
151152 For coretest nc, principal will have account name and
152- + for containerized deployment principal is ARN
153+ for containerized deployment principal is ARN
153154 */
154155 admin_principal = is_nc_coretest ? EMAIL : s3_bucket_policy_utils . create_arn_for_root ( admin_info . _id . toString ( ) ) ;
155- a_principal = is_nc_coretest ? user_a : s3_bucket_policy_utils . create_arn_for_root ( account_info_a . _id . toString ( ) ) ;
156- b_principal = is_nc_coretest ? user_b : s3_bucket_policy_utils . create_arn_for_root ( account_info_b . _id . toString ( ) ) ;
156+ a_principal = is_nc_coretest ? user_a : s3_bucket_policy_utils . create_arn_for_root ( user_a_account_details . id . toString ( ) ) ;
157+ b_principal = is_nc_coretest ? user_b : s3_bucket_policy_utils . create_arn_for_root ( user_b_account_details . id . toString ( ) ) ;
157158
158159 s3_owner = new S3 ( s3_creds ) ;
159160 await s3_owner . createBucket ( { Bucket : BKT } ) ;
@@ -312,12 +313,11 @@ mocha.describe('s3_bucket_policy', function() {
312313 } ) ;
313314
314315 mocha . it ( 'should put/get bucket policy - principal by account ID' , async function ( ) {
315- if ( ! is_nc_coretest ) this . skip ( ) ; // eslint-disable-line no-invalid-this
316316 const policy = {
317317 Statement : [ {
318- Sid : `Allow all s3 actions on bucket ${ BKT } to principal (by ID) ${ user_a_account_details . _id } ` ,
318+ Sid : `Allow all s3 actions on bucket ${ BKT } to principal (by ID) ${ user_a_account_id } ` ,
319319 Effect : 'Allow' ,
320- Principal : { AWS : user_a_account_details . _id } ,
320+ Principal : { AWS : user_a_account_id } ,
321321 Action : [ 's3:*' ] ,
322322 Resource : [ `arn:aws:s3:::${ BKT } ` , `arn:aws:s3:::${ BKT } /*` ]
323323 } ]
@@ -335,12 +335,11 @@ mocha.describe('s3_bucket_policy', function() {
335335 } ) ;
336336
337337 mocha . it ( 'should put object to permitted account (bucket policy - principal by account ID' , async function ( ) {
338- if ( ! is_nc_coretest ) this . skip ( ) ; // eslint-disable-line no-invalid-this
339338 const policy = {
340339 Statement : [ {
341- Sid : `Allow all s3 actions on bucket ${ BKT } to principal (by ID) ${ user_a_account_details . _id } ` ,
340+ Sid : `Allow all s3 actions on bucket ${ BKT } to principal (by ID) ${ user_a_account_id } ` ,
342341 Effect : 'Allow' ,
343- Principal : { AWS : user_a_account_details . _id } ,
342+ Principal : { AWS : user_a_account_id } ,
344343 Action : [ 's3:*' ] ,
345344 Resource : [ `arn:aws:s3:::${ BKT } ` , `arn:aws:s3:::${ BKT } /*` ]
346345 } ]
@@ -395,7 +394,7 @@ mocha.describe('s3_bucket_policy', function() {
395394 } ;
396395 }
397396 // Losing this value in-between, assigning it again
398- a_principal = is_nc_coretest ? user_a : s3_bucket_policy_utils . create_arn_for_root ( account_info_a . _id . toString ( ) ) ;
397+ a_principal = is_nc_coretest ? user_a : s3_bucket_policy_utils . create_arn_for_root ( user_b_account_id . toString ( ) ) ;
399398 const deny_account_by_name_all_s3_actions_statement = {
400399 Sid : `Do not allow user ${ user_a } any s3 action` ,
401400 Effect : 'Deny' ,
@@ -407,9 +406,8 @@ mocha.describe('s3_bucket_policy', function() {
407406 mocha . it ( 'should not allow principal get object bucket policy with 2 statements: ' +
408407 '(1) DENY principal by account ID (2) ALLOW all principals as *' , async function ( ) {
409408 // in NC we allow principal to be also IDs
410- if ( ! is_nc_coretest ) this . skip ( ) ; // eslint-disable-line no-invalid-this
411409 const deny_account_by_id_all_s3_actions_statement =
412- get_deny_account_by_id_all_s3_actions_statement ( user_a_account_details . _id ) ;
410+ get_deny_account_by_id_all_s3_actions_statement ( user_a_account_id ) ;
413411 const policy = {
414412 Statement : [
415413 allow_all_principals_all_s3_actions_statement ,
@@ -481,9 +479,9 @@ mocha.describe('s3_bucket_policy', function() {
481479 mocha . it ( 'should not allow principal get object bucket policy with 2 statements: ' +
482480 '(1) DENY principal by account ID (2) ALLOW by account name' , async function ( ) {
483481 // in NC we allow principal to be also IDs
484- if ( ! is_nc_coretest ) this . skip ( ) ; // eslint-disable-line no-invalid-this
482+ // if (!is_nc_coretest) this.skip(); // eslint-disable-line no-invalid-this
485483 const deny_account_by_id_all_s3_actions_statement =
486- get_deny_account_by_id_all_s3_actions_statement ( user_a_account_details . _id ) ;
484+ get_deny_account_by_id_all_s3_actions_statement ( user_a_account_id ) ;
487485 const allow_account_by_name_all_s3_actions_statement = _ . cloneDeep ( deny_account_by_name_all_s3_actions_statement ) ;
488486 allow_account_by_name_all_s3_actions_statement . Effect = 'Allow' ;
489487 allow_account_by_name_all_s3_actions_statement . Sid = `Allow user ${ user_a } any s3 action` ;
@@ -516,12 +514,12 @@ mocha.describe('s3_bucket_policy', function() {
516514 mocha . it ( 'should not allow principal get object bucket policy with 2 statements: ' +
517515 '(1) DENY principal by account name (2) ALLOW by account ID' , async function ( ) {
518516 // in NC we allow principal to be also IDs
519- if ( ! is_nc_coretest ) this . skip ( ) ; // eslint-disable-line no-invalid-this
517+ // if (!is_nc_coretest) this.skip(); // eslint-disable-line no-invalid-this
520518 const deny_account_by_id_all_s3_actions_statement =
521- get_deny_account_by_id_all_s3_actions_statement ( user_a_account_details . _id ) ;
519+ get_deny_account_by_id_all_s3_actions_statement ( user_a_account_id ) ;
522520 const allow_account_by_id_all_s3_actions_statement = _ . cloneDeep ( deny_account_by_id_all_s3_actions_statement ) ;
523521 allow_account_by_id_all_s3_actions_statement . Effect = 'Allow' ;
524- allow_account_by_id_all_s3_actions_statement . Sid = `Allow user ${ user_a_account_details . _id } any s3 action` ;
522+ allow_account_by_id_all_s3_actions_statement . Sid = `Allow user ${ user_a_account_id } any s3 action` ;
525523 const policy = {
526524 Statement : [
527525 deny_account_by_name_all_s3_actions_statement ,
@@ -582,12 +580,12 @@ mocha.describe('s3_bucket_policy', function() {
582580 mocha . it ( 'should not allow principal get object bucket policy with 2 statements: ' +
583581 '(1) ALLOW principal by account ID (2) DENY all principals as * (specific action only)' , async function ( ) {
584582 // in NC we allow principal to be also IDs
585- if ( ! is_nc_coretest ) this . skip ( ) ; // eslint-disable-line no-invalid-this
583+ // if (!is_nc_coretest) this.skip(); // eslint-disable-line no-invalid-this
586584 const deny_account_by_id_all_s3_actions_statement =
587- get_deny_account_by_id_all_s3_actions_statement ( user_a_account_details . _id ) ;
585+ get_deny_account_by_id_all_s3_actions_statement ( user_a_account_id ) ;
588586 const allow_account_by_id_all_s3_actions_statement = _ . cloneDeep ( deny_account_by_id_all_s3_actions_statement ) ;
589587 allow_account_by_id_all_s3_actions_statement . Effect = 'Allow' ;
590- allow_account_by_id_all_s3_actions_statement . Sid = `Allow user ${ user_a_account_details . _id } any s3 action` ;
588+ allow_account_by_id_all_s3_actions_statement . Sid = `Allow user ${ user_a_account_id } any s3 action` ;
591589 const policy = {
592590 Statement : [
593591 allow_account_by_id_all_s3_actions_statement ,
0 commit comments