From 7ed3cbc0d03eb10f33fe1dadc33aecd7225a605a Mon Sep 17 00:00:00 2001 From: Toshimitsu Takahashi Date: Tue, 24 Oct 2023 22:07:51 +0900 Subject: [PATCH] Fix single and complex linkage was reversed --- src/js/lib/target_profiles.js | 6 +++--- src/test/find_target_profiles.test.js | 18 +++++++++--------- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/js/lib/target_profiles.js b/src/js/lib/target_profiles.js index 23a6972..72e56e2 100644 --- a/src/js/lib/target_profiles.js +++ b/src/js/lib/target_profiles.js @@ -7,6 +7,9 @@ export async function findTargetProfiles(ctx) { const results = []; await dbManager.transaction('profiles', async dbTable => { + const singles = await dbTable.query(`[SINGLE];`); + results.push(...singles) + const complexSrcItems = await dbTable.query('[COMPLEX];'); const matchedComplexSrc = complexSrcItems.find(it => matchSourceProfile(it, baseAccount, loginRole)); if (matchedComplexSrc) { @@ -17,9 +20,6 @@ export async function findTargetProfiles(ctx) { } results.push(...targets) } - - const singles = await dbTable.query(`[SINGLE];`); - results.push(...singles) }, 'readonly'); await dbManager.close(); diff --git a/src/test/find_target_profiles.test.js b/src/test/find_target_profiles.test.js index 481b4c5..17ab996 100644 --- a/src/test/find_target_profiles.test.js +++ b/src/test/find_target_profiles.test.js @@ -24,56 +24,56 @@ export async function findTargetProfilesTest() { // matching aws_account_id const resultsA1 = await findTargetProfiles({ baseAccount: '111100000000', loginRole: 'a-user' }); assert(resultsA1, [ + { profilePath: '[SINGLE];000012', name: 'test', aws_account_id: '999900000000', role_name: 'entry-user', image: 'https://example.com/t.png' }, + { profilePath: '[SINGLE];000013', name: 'SandBox', aws_account_id: '999900001111', role_name: 'user' }, // not applying target_region to region because region is specified { profilePath: 'a-company;000005', name: 'saas-stg', aws_account_id: '111100001111', role_name: 'developer', color: '112233', region: 'us-west-2' }, // applying target_region to region { profilePath: 'a-company;000006', name: 'saas-prd', aws_account_id: '111100002222', role_name: 'developer', color: '4455FF', region: 'ap-northeast-1' }, { profilePath: 'a-company;000007', name: 'saas-prd-admin', aws_account_id: '111100003333', role_name: 'admin', image: 'https://example.com/s.png', region: 'ap-northeast-1' }, - { profilePath: '[SINGLE];000012', name: 'test', aws_account_id: '999900000000', role_name: 'entry-user', image: 'https://example.com/t.png' }, - { profilePath: '[SINGLE];000013', name: 'SandBox', aws_account_id: '999900001111', role_name: 'user' }, ]); // showOnlyMatchingRoles is true const resultsA2 = await findTargetProfiles({ baseAccount: '111100000000', loginRole: 'a-user', filterByTargetRole: 'developer' }); assert(resultsA2, [ + { profilePath: '[SINGLE];000012', name: 'test', aws_account_id: '999900000000', role_name: 'entry-user', image: 'https://example.com/t.png' }, + { profilePath: '[SINGLE];000013', name: 'SandBox', aws_account_id: '999900001111', role_name: 'user' }, // narrow down to only profiles with the same role_name { profilePath: 'a-company;000005', name: 'saas-stg', aws_account_id: '111100001111', role_name: 'developer', color: '112233', region: 'us-west-2' }, { profilePath: 'a-company;000006', name: 'saas-prd', aws_account_id: '111100002222', role_name: 'developer', color: '4455FF', region: 'ap-northeast-1' }, - { profilePath: '[SINGLE];000012', name: 'test', aws_account_id: '999900000000', role_name: 'entry-user', image: 'https://example.com/t.png' }, - { profilePath: '[SINGLE];000013', name: 'SandBox', aws_account_id: '999900001111', role_name: 'user' }, ]); const resultsB1 = await findTargetProfiles({ baseAccount: '222200000000', loginRole: 'b-user' }); assert(resultsB1, [ - { profilePath: 'b-company;000008', name: 'project1', aws_account_id: '222200001111', role_name: 'manager' }, { profilePath: '[SINGLE];000012', name: 'test', aws_account_id: '999900000000', role_name: 'entry-user', image: 'https://example.com/t.png' }, { profilePath: '[SINGLE];000013', name: 'SandBox', aws_account_id: '999900001111', role_name: 'user' }, + { profilePath: 'b-company;000008', name: 'project1', aws_account_id: '222200001111', role_name: 'manager' }, ]); // matching aws_account_alias const resultsB2 = await findTargetProfiles({ baseAccount: 'bc', loginRole: 'b-user' }); assert(resultsB2, [ - { profilePath: 'b-company;000008', name: 'project1', aws_account_id: '222200001111', role_name: 'manager' }, { profilePath: '[SINGLE];000012', name: 'test', aws_account_id: '999900000000', role_name: 'entry-user', image: 'https://example.com/t.png' }, { profilePath: '[SINGLE];000013', name: 'SandBox', aws_account_id: '999900001111', role_name: 'user' }, + { profilePath: 'b-company;000008', name: 'project1', aws_account_id: '222200001111', role_name: 'manager' }, ]); const resultsC = await findTargetProfiles({ baseAccount: '333300000000', loginRole: 'c-user' }); assert(resultsC, [ + { profilePath: '[SINGLE];000012', name: 'test', aws_account_id: '999900000000', role_name: 'entry-user', image: 'https://example.com/t.png' }, + { profilePath: '[SINGLE];000013', name: 'SandBox', aws_account_id: '999900001111', role_name: 'user' }, // target_role_name is ignored when role_name is specified { profilePath: 'c-company;000009', name: 'service/prd', aws_account_id: '333300001111', role_name: 'maintainer' }, // applying target_role_name to role_name { profilePath: 'c-company;000010', name: 'service/dev', aws_account_id: '333300002222', role_name: 'c-member' }, - { profilePath: '[SINGLE];000012', name: 'test', aws_account_id: '999900000000', role_name: 'entry-user', image: 'https://example.com/t.png' }, - { profilePath: '[SINGLE];000013', name: 'SandBox', aws_account_id: '999900001111', role_name: 'user' }, ]); // matching aws_account_* and role_name const resultsD1 = await findTargetProfiles({ baseAccount: '444400000000', loginRole: 'd-user' }); assert(resultsD1, [ - { profilePath: 'd-company;000011', name: 'proj-D', aws_account_id: '444400001111', role_name: 'd-admin' }, { profilePath: '[SINGLE];000012', name: 'test', aws_account_id: '999900000000', role_name: 'entry-user', image: 'https://example.com/t.png' }, { profilePath: '[SINGLE];000013', name: 'SandBox', aws_account_id: '999900001111', role_name: 'user' }, + { profilePath: 'd-company;000011', name: 'proj-D', aws_account_id: '444400001111', role_name: 'd-admin' }, ]); // no matching aws_account_* and role_name