Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix single and complex linkage was reversed #315

Merged
merged 1 commit into from
Oct 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/js/lib/target_profiles.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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();
Expand Down
18 changes: 9 additions & 9 deletions src/test/find_target_profiles.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down