From 97c29e6e2f7d435aed83d3e680df75a7d9af9c17 Mon Sep 17 00:00:00 2001 From: Timothy William Cleaver Date: Wed, 30 Jan 2019 08:44:59 +1000 Subject: [PATCH 01/21] Add images to each profile --- src/lib/content.js | 52 +++++++++++++++++++++++++++++++++------------- 1 file changed, 37 insertions(+), 15 deletions(-) diff --git a/src/lib/content.js b/src/lib/content.js index 0a1cb345..c737509f 100644 --- a/src/lib/content.js +++ b/src/lib/content.js @@ -122,20 +122,38 @@ function loadProfiles(profile, list, csrf, hidesHistory, hidesAccountId) { if (recentNames.indexOf(name) !== -1) return true; var color = item.color || 'aaaaaa'; - list.insertAdjacentHTML('beforeend', Sanitizer.escapeHTML`
  • -
    - - - - - - - - - -
    -
  • `); + if (!item.image) { + list.insertAdjacentHTML('beforeend', Sanitizer.escapeHTML`
  • +
    + + + + + + + + + +
    +
  • `); + } else { + list.insertAdjacentHTML('beforeend', Sanitizer.escapeHTML`
  • +
    + + + + + + + + + +
    +
  • `); + + } }); Array.from(list.querySelectorAll('form')).forEach(form => { @@ -200,9 +218,13 @@ function attachColorLine(profiles) { const found = profiles.find(item => { return item.profile === profileName }); const color = found && found.color || null; + var label = usernameMenu.querySelector('.nav-elt-label'); + if (found.image) { + label.insertAdjacentHTML('beforebegin', Sanitizer.escapeHTML(``)); + } + if (color) { if (needsInvertForeColorByBack(color)) { - var label = usernameMenu.querySelector('.nav-elt-label'); label.style = 'color: #eee'; } From 8f5133331fbe7efc3e5e1258ddadd2284bd7d76d Mon Sep 17 00:00:00 2001 From: "timcleaver@hotmail.com" Date: Fri, 1 Feb 2019 09:35:29 +1000 Subject: [PATCH 02/21] Guard against unmatched profile --- src/lib/content.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lib/content.js b/src/lib/content.js index c737509f..f30494cf 100644 --- a/src/lib/content.js +++ b/src/lib/content.js @@ -219,7 +219,7 @@ function attachColorLine(profiles) { const color = found && found.color || null; var label = usernameMenu.querySelector('.nav-elt-label'); - if (found.image) { + if (found && found.image) { label.insertAdjacentHTML('beforebegin', Sanitizer.escapeHTML(``)); } From 4e6d39a047dcde3b832cc066ab2e741b762605ff Mon Sep 17 00:00:00 2001 From: "timcleaver@hotmail.com" Date: Fri, 1 Feb 2019 09:57:42 +1000 Subject: [PATCH 03/21] Add element id and tests --- src/lib/content.js | 2 +- test/content_attach_color_line.test.js | 32 ++++++++++++++++++++++++++ test/fixtures/data.json | 2 ++ 3 files changed, 35 insertions(+), 1 deletion(-) diff --git a/src/lib/content.js b/src/lib/content.js index f30494cf..53fe8fd2 100644 --- a/src/lib/content.js +++ b/src/lib/content.js @@ -220,7 +220,7 @@ function attachColorLine(profiles) { var label = usernameMenu.querySelector('.nav-elt-label'); if (found && found.image) { - label.insertAdjacentHTML('beforebegin', Sanitizer.escapeHTML(``)); + label.insertAdjacentHTML('beforebegin', Sanitizer.escapeHTML(``)); } if (color) { diff --git a/test/content_attach_color_line.test.js b/test/content_attach_color_line.test.js index 070ecd3c..a2cc4a3f 100644 --- a/test/content_attach_color_line.test.js +++ b/test/content_attach_color_line.test.js @@ -8,6 +8,13 @@ describe('ContentScripts', () => { expect(document.getElementById('AESW_ColorLine')).to.exist; }) + it('attaches image', () => { + loadFixtures('awsmc-iam-switched', 'data'); + document.querySelector('#nav-usernameMenu .nav-elt-label').textContent = 'a-stg-image'; + extendIAMFormList(); + expect(document.getElementById('AESW_Image')).to.exist; + }) + context('color not defined', () => { it('does not attach color line', () => { loadFixtures('awsmc-iam-switched', 'data'); @@ -55,6 +62,13 @@ describe('ContentScripts', () => { expect(document.getElementById('AESW_ColorLine')).to.exist; }) + it('attaches image', () => { + loadFixtures('awsmc-federated-switched', 'data'); + document.querySelector('#nav-usernameMenu .nav-elt-label').textContent = 'b-prod-image'; + extendIAMFormList(); + expect(document.getElementById('AESW_Image')).to.exist; + }) + context('color not defined', () => { it('does not attach color line', () => { loadFixtures('awsmc-federated-switched', 'data'); @@ -63,6 +77,15 @@ describe('ContentScripts', () => { expect(document.getElementById('AESW_ColorLine')).to.be.null; }) }) + + context('image not defined', () => { + it('does not attach image', () => { + loadFixtures('awsmc-federated-switched', 'data'); + document.querySelector('#nav-usernameMenu .nav-elt-label').textContent = 'b-renpou'; + extendIAMFormList(); + expect(document.getElementById('AESW_Image')).to.be.null; + }) + }) }) context('does not hide account id', () => { @@ -91,5 +114,14 @@ describe('ContentScripts', () => { expect(document.getElementById('AESW_ColorLine')).to.be.null; }) }) + + context('profile not found', () => { + it('does not attach icon', () => { + loadFixtures('awsmc-federated-switched', 'data'); + document.querySelector('#nav-usernameMenu .nav-elt-label').textContent = 'other | 000000000000'; + extendIAMFormList(); + expect(document.getElementById('AESW_Image')).to.be.null; + }) + }) }) }) diff --git a/test/fixtures/data.json b/test/fixtures/data.json index b8922662..d9ecdfc4 100644 --- a/test/fixtures/data.json +++ b/test/fixtures/data.json @@ -4,10 +4,12 @@ { "profile": "history-contained", "aws_account_id": "111122224444", "role_name": "contained_history_role" }, { "profile": "base-a", "aws_account_id": "555511112222" }, { "profile": "a-stg", "aws_account_id": "555511113333", "role_name": "stg-role", "source_profile": "base-a", "color": "00ddff" }, + { "profile": "a-stg-image", "aws_account_id": "555511113333", "role_name": "stg-role", "source_profile": "base-a", "image": "not-found.png" }, { "profile": "a-prod", "aws_account_id": "555511114444", "role_name": "prod-role", "source_profile": "base-a", "region": "ap-northwest-1" }, { "profile": "base-b", "aws_account_id": "666611112222" }, { "profile": "b-stg", "aws_account_id": "666611113333", "role_name": "stg-role", "source_profile": "base-b" }, { "profile": "b-prod", "aws_account_id": "666611114444", "role_name": "prod-role", "source_profile": "base-b", "color": "ffcc333" }, + { "profile": "b-prod-image", "aws_account_id": "666611114444", "role_name": "prod-role", "source_profile": "base-b", "image": "not-found.png" }, { "profile": "b-renpou", "aws_account_id": "666611115555", "role_name": "renpou", "source_profile": "base-b" } ] } From 13cf65e1ea37e4bd27a58154e7a0d3e3a3e4daaf Mon Sep 17 00:00:00 2001 From: "timcleaver@hotmail.com" Date: Fri, 1 Feb 2019 10:02:22 +1000 Subject: [PATCH 04/21] Change order of profiles since the indexes are hard-coded in tests --- test/fixtures/data.json | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/test/fixtures/data.json b/test/fixtures/data.json index d9ecdfc4..3bb36daf 100644 --- a/test/fixtures/data.json +++ b/test/fixtures/data.json @@ -4,12 +4,12 @@ { "profile": "history-contained", "aws_account_id": "111122224444", "role_name": "contained_history_role" }, { "profile": "base-a", "aws_account_id": "555511112222" }, { "profile": "a-stg", "aws_account_id": "555511113333", "role_name": "stg-role", "source_profile": "base-a", "color": "00ddff" }, - { "profile": "a-stg-image", "aws_account_id": "555511113333", "role_name": "stg-role", "source_profile": "base-a", "image": "not-found.png" }, { "profile": "a-prod", "aws_account_id": "555511114444", "role_name": "prod-role", "source_profile": "base-a", "region": "ap-northwest-1" }, { "profile": "base-b", "aws_account_id": "666611112222" }, { "profile": "b-stg", "aws_account_id": "666611113333", "role_name": "stg-role", "source_profile": "base-b" }, { "profile": "b-prod", "aws_account_id": "666611114444", "role_name": "prod-role", "source_profile": "base-b", "color": "ffcc333" }, - { "profile": "b-prod-image", "aws_account_id": "666611114444", "role_name": "prod-role", "source_profile": "base-b", "image": "not-found.png" }, - { "profile": "b-renpou", "aws_account_id": "666611115555", "role_name": "renpou", "source_profile": "base-b" } + { "profile": "b-renpou", "aws_account_id": "666611115555", "role_name": "renpou", "source_profile": "base-b" }, + { "profile": "a-stg-image", "aws_account_id": "555511113333", "role_name": "stg-role", "source_profile": "base-a", "image": "not-found.png" }, + { "profile": "b-prod-image", "aws_account_id": "666611114444", "role_name": "prod-role", "source_profile": "base-b", "image": "not-found.png" } ] } From 3cafd31da8945cabf3e3b55040dda5e5e87d7745 Mon Sep 17 00:00:00 2001 From: "timcleaver@hotmail.com" Date: Fri, 1 Feb 2019 10:20:40 +1000 Subject: [PATCH 05/21] Fix role count --- test/content_redirect_uri.test.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/content_redirect_uri.test.js b/test/content_redirect_uri.test.js index cc4f6403..d420daa3 100644 --- a/test/content_redirect_uri.test.js +++ b/test/content_redirect_uri.test.js @@ -21,7 +21,7 @@ describe('Reset the region of redirect_uri on content script', () => { expect(document.body.className.includes('user-type-federated')).to.be.false; const roles = Array.from(document.querySelectorAll('#awsc-username-menu-recent-roles li')) - expect(roles.length).to.eq(4); + expect(roles.length).to.eq(5); expect(roles[3].querySelector('input[name="roleName"]').value).to.eq('prod-role'); expect(roles[3].querySelector('input[type="submit"]').value).to.eq('a-prod | 555511114444'); @@ -39,7 +39,7 @@ describe('Reset the region of redirect_uri on content script', () => { expect(document.body.className.includes('user-type-federated')).to.be.false; const roles = Array.from(document.querySelectorAll('#awsc-username-menu-recent-roles li')) - expect(roles.length).to.eq(4); + expect(roles.length).to.eq(5); expect(roles[2].querySelector('input[name="roleName"]').value).to.eq('stg-role'); expect(roles[2].querySelector('input[type="submit"]').value).to.eq('a-stg | 555511113333'); From 4ed88a685f8c545bb20f459bc0568dc573b83325 Mon Sep 17 00:00:00 2001 From: "timcleaver@hotmail.com" Date: Fri, 1 Feb 2019 10:20:59 +1000 Subject: [PATCH 06/21] Fix role counts --- test/content_reset_region.test.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/content_reset_region.test.js b/test/content_reset_region.test.js index afedae78..350af981 100644 --- a/test/content_reset_region.test.js +++ b/test/content_reset_region.test.js @@ -21,7 +21,7 @@ describe('Content redirect_uri', () => { expect(document.body.className.includes('user-type-federated')).to.be.false; const roles = Array.from(document.querySelectorAll('#awsc-username-menu-recent-roles li')) - expect(roles.length).to.eq(4); + expect(roles.length).to.eq(5); expect(roles[3].querySelector('input[name="roleName"]').value).to.eq('prod-role'); expect(roles[3].querySelector('input[type="submit"]').value).to.eq('a-prod | 555511114444'); @@ -39,7 +39,7 @@ describe('Content redirect_uri', () => { expect(document.body.className.includes('user-type-federated')).to.be.false; const roles = Array.from(document.querySelectorAll('#awsc-username-menu-recent-roles li')) - expect(roles.length).to.eq(4); + expect(roles.length).to.eq(5); expect(roles[2].querySelector('input[name="roleName"]').value).to.eq('stg-role'); expect(roles[2].querySelector('input[type="submit"]').value).to.eq('a-stg | 555511113333'); From 7e578ac5ed543859ca3c262bc0982541b2bac692 Mon Sep 17 00:00:00 2001 From: "timcleaver@hotmail.com" Date: Fri, 1 Feb 2019 10:21:29 +1000 Subject: [PATCH 07/21] Fix role counts and test new inputs --- test/content_scripts.test.js | 28 +++++++++++++++++++++------- 1 file changed, 21 insertions(+), 7 deletions(-) diff --git a/test/content_scripts.test.js b/test/content_scripts.test.js index c6bbadd5..af722e31 100644 --- a/test/content_scripts.test.js +++ b/test/content_scripts.test.js @@ -72,13 +72,15 @@ describe('ContentScripts', () => { expect(document.body.className.includes('user-type-federated')).to.be.false; const roles = Array.from(document.querySelectorAll('#awsc-username-menu-recent-roles li')) - expect(roles.length).to.eq(4); + expect(roles.length).to.eq(5); expect(roles[0].querySelector('input[name="roleName"]').value).to.eq('independence_role'); expect(roles[1].querySelector('input[name="roleName"]').value).to.eq('contained_history_role'); expect(roles[2].querySelector('input[name="roleName"]').value).to.eq('stg-role'); expect(roles[2].querySelector('input[type="submit"]').value).to.eq('a-stg | 555511113333'); expect(roles[3].querySelector('input[name="roleName"]').value).to.eq('prod-role'); expect(roles[3].querySelector('input[type="submit"]').value).to.eq('a-prod | 555511114444'); + expect(roles[4].querySelector('input[name="roleName"]').value).to.eq('stg-role-image'); + expect(roles[4].querySelector('input[type="submit"]').value).to.eq('a-stg-image | 555511113333'); }) }) @@ -93,7 +95,7 @@ describe('ContentScripts', () => { expect(document.body.className.includes('user-type-federated')).to.be.false; const roles = Array.from(document.querySelectorAll('#awsc-username-menu-recent-roles li')) - expect(roles.length).to.eq(5); + expect(roles.length).to.eq(6); expect(roles[0].querySelector('input[name="roleName"]').value).to.eq('independence_role'); expect(roles[1].querySelector('input[name="roleName"]').value).to.eq('contained_history_role'); expect(roles[2].querySelector('input[name="roleName"]').value).to.eq('stg-role'); @@ -102,6 +104,8 @@ describe('ContentScripts', () => { expect(roles[3].querySelector('input[type="submit"]').value).to.eq('b-prod | 666611114444'); expect(roles[4].querySelector('input[name="roleName"]').value).to.eq('renpou'); expect(roles[4].querySelector('input[type="submit"]').value).to.eq('b-renpou | 666611115555'); + expect(roles[5].querySelector('input[name="roleName"]').value).to.eq('prod-role'); + expect(roles[5].querySelector('input[type="submit"]').value).to.eq('b-prod-image | 666611114444'); }) }) }) @@ -119,7 +123,7 @@ describe('ContentScripts', () => { expect(document.body.className.includes('user-type-federated')).to.be.false; const roles = Array.from(document.querySelectorAll('#awsc-username-menu-recent-roles li')) - expect(roles.length).to.eq(5); + expect(roles.length).to.eq(6); expect(roles[0].querySelector('input[name="roleName"]').value).to.eq('independence_role'); expect(roles[0].querySelector('input[type="submit"]').value).to.eq('independence'); expect(roles[1].querySelector('input[name="roleName"]').value).to.eq('contained_history_role'); @@ -130,6 +134,8 @@ describe('ContentScripts', () => { expect(roles[3].querySelector('input[type="submit"]').value).to.eq('b-prod'); expect(roles[4].querySelector('input[name="roleName"]').value).to.eq('renpou'); expect(roles[4].querySelector('input[type="submit"]').value).to.eq('b-renpou'); + expect(roles[5].querySelector('input[name="roleName"]').value).to.eq('prod-role'); + expect(roles[5].querySelector('input[type="submit"]').value).to.eq('b-prod-image'); }) }) }) @@ -145,7 +151,7 @@ describe('ContentScripts', () => { expect(document.body.className.includes('user-type-federated')).to.be.false; const roles = Array.from(document.querySelectorAll('#awsc-username-menu-recent-roles li')) - expect(roles.length).to.eq(9); + expect(roles.length).to.eq(10); expect(roles[3].querySelector('input[name="roleName"]').value).to.eq('contained_history_role'); expect(roles[5].querySelector('input[name="roleName"]').value).to.eq('independence_role'); expect(roles[6].querySelector('input[name="roleName"]').value).to.eq('stg-role'); @@ -154,6 +160,8 @@ describe('ContentScripts', () => { expect(roles[7].querySelector('input[type="submit"]').value).to.eq('b-prod | 666611114444'); expect(roles[8].querySelector('input[name="roleName"]').value).to.eq('renpou'); expect(roles[8].querySelector('input[type="submit"]').value).to.eq('b-renpou | 666611115555'); + expect(roles[9].querySelector('input[name="roleName"]').value).to.eq('prod-role'); + expect(roles[9].querySelector('input[type="submit"]').value).to.eq('b-prod-image | 666611114444'); }) }) @@ -169,7 +177,7 @@ describe('ContentScripts', () => { expect(document.body.className.includes('user-type-federated')).to.be.false; const roles = Array.from(document.querySelectorAll('#awsc-username-menu-recent-roles li')) - expect(roles.length).to.eq(5); + expect(roles.length).to.eq(6); expect(roles[0].querySelector('input[name="roleName"]').value).to.eq('independence_role'); expect(roles[1].querySelector('input[name="roleName"]').value).to.eq('contained_history_role'); expect(roles[2].querySelector('input[name="roleName"]').value).to.eq('stg-role'); @@ -178,6 +186,8 @@ describe('ContentScripts', () => { expect(roles[3].querySelector('input[type="submit"]').value).to.eq('b-prod | 666611114444'); expect(roles[4].querySelector('input[name="roleName"]').value).to.eq('renpou'); expect(roles[4].querySelector('input[type="submit"]').value).to.eq('b-renpou | 666611115555'); + expect(roles[5].querySelector('input[name="roleName"]').value).to.eq('prod-role'); + expect(roles[5].querySelector('input[type="submit"]').value).to.eq('b-prod-image | 666611114444'); }) }) }) @@ -237,13 +247,15 @@ describe('ContentScripts', () => { expect(document.body.className.includes('user-type-iam')).to.be.false; const roles = Array.from(document.querySelectorAll('#awsc-username-menu-recent-roles li')) - expect(roles.length).to.eq(4); + expect(roles.length).to.eq(5); expect(roles[0].querySelector('input[name="roleName"]').value).to.eq('independence_role'); expect(roles[1].querySelector('input[name="roleName"]').value).to.eq('contained_history_role'); expect(roles[2].querySelector('input[name="roleName"]').value).to.eq('stg-role'); expect(roles[2].querySelector('input[type="submit"]').value).to.eq('a-stg | 555511113333'); expect(roles[3].querySelector('input[name="roleName"]').value).to.eq('prod-role'); expect(roles[3].querySelector('input[type="submit"]').value).to.eq('a-prod | 555511114444'); + expect(roles[4].querySelector('input[name="roleName"]').value).to.eq('stg-role-image'); + expect(roles[4].querySelector('input[type="submit"]').value).to.eq('a-stg-image | 555511113333'); }) }) @@ -258,7 +270,7 @@ describe('ContentScripts', () => { expect(document.body.className.includes('user-type-iam')).to.be.false; const roles = Array.from(document.querySelectorAll('#awsc-username-menu-recent-roles li')) - expect(roles.length).to.eq(5); + expect(roles.length).to.eq(6); expect(roles[0].querySelector('input[name="roleName"]').value).to.eq('independence_role'); expect(roles[1].querySelector('input[name="roleName"]').value).to.eq('contained_history_role'); expect(roles[2].querySelector('input[name="roleName"]').value).to.eq('stg-role'); @@ -267,6 +279,8 @@ describe('ContentScripts', () => { expect(roles[3].querySelector('input[type="submit"]').value).to.eq('b-prod | 666611114444'); expect(roles[4].querySelector('input[name="roleName"]').value).to.eq('renpou'); expect(roles[4].querySelector('input[type="submit"]').value).to.eq('b-renpou | 666611115555'); + expect(roles[5].querySelector('input[name="roleName"]').value).to.eq('prod-role'); + expect(roles[5].querySelector('input[type="submit"]').value).to.eq('b-prod-image | 666611114444'); }) }) }) From e2743c619f37e891bbe6fd53cf282911fa340a5f Mon Sep 17 00:00:00 2001 From: "timcleaver@hotmail.com" Date: Fri, 1 Feb 2019 10:34:32 +1000 Subject: [PATCH 08/21] Update role names and fix some counts in tests --- test/content_switched.test.js | 6 ++++-- test/fixtures/data.json | 4 ++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/test/content_switched.test.js b/test/content_switched.test.js index f5bce369..6ccc37fc 100644 --- a/test/content_switched.test.js +++ b/test/content_switched.test.js @@ -20,7 +20,7 @@ describe('ContentScripts', () => { expect(document.body.className.includes('user-type-iam')).to.be.false; const roles = Array.from(document.querySelectorAll('#awsc-username-menu-recent-roles li')) - expect(roles.length).to.eq(7); + expect(roles.length).to.eq(8); expect(roles[0].querySelector('input[name="roleName"]').value).to.eq('stg-role'); expect(roles[0].querySelector('input[type="submit"]').value).to.eq('a-stg | 555511113333'); expect(roles[3].querySelector('input[name="roleName"]').value).to.eq('contained_history_role'); @@ -63,7 +63,7 @@ describe('ContentScripts', () => { expect(document.body.className.includes('user-type-iam')).to.be.false; const roles = Array.from(document.querySelectorAll('#awsc-username-menu-recent-roles li')) - expect(roles.length).to.eq(5); + expect(roles.length).to.eq(6); expect(roles[0].querySelector('input[name="roleName"]').value).to.eq('independence_role'); expect(roles[1].querySelector('input[name="roleName"]').value).to.eq('contained_history_role'); expect(roles[2].querySelector('input[name="roleName"]').value).to.eq('stg-role'); @@ -72,6 +72,8 @@ describe('ContentScripts', () => { expect(roles[3].querySelector('input[type="submit"]').value).to.eq('b-prod | 666611114444'); expect(roles[4].querySelector('input[name="roleName"]').value).to.eq('renpou'); expect(roles[4].querySelector('input[type="submit"]').value).to.eq('b-renpou | 666611115555'); + expect(roles[5].querySelector('input[name="roleName"]').value).to.eq('prod-role-image'); + expect(roles[5].querySelector('input[type="submit"]').value).to.eq('b-prod-image | 666611114444'); }) }) }) diff --git a/test/fixtures/data.json b/test/fixtures/data.json index 3bb36daf..1c6ec4cc 100644 --- a/test/fixtures/data.json +++ b/test/fixtures/data.json @@ -9,7 +9,7 @@ { "profile": "b-stg", "aws_account_id": "666611113333", "role_name": "stg-role", "source_profile": "base-b" }, { "profile": "b-prod", "aws_account_id": "666611114444", "role_name": "prod-role", "source_profile": "base-b", "color": "ffcc333" }, { "profile": "b-renpou", "aws_account_id": "666611115555", "role_name": "renpou", "source_profile": "base-b" }, - { "profile": "a-stg-image", "aws_account_id": "555511113333", "role_name": "stg-role", "source_profile": "base-a", "image": "not-found.png" }, - { "profile": "b-prod-image", "aws_account_id": "666611114444", "role_name": "prod-role", "source_profile": "base-b", "image": "not-found.png" } + { "profile": "a-stg-image", "aws_account_id": "555511113333", "role_name": "stg-role-image", "source_profile": "base-a", "image": "not-found.png" }, + { "profile": "b-prod-image", "aws_account_id": "666611114444", "role_name": "prod-role-image", "source_profile": "base-b", "image": "not-found.png" } ] } From cc475b117c788b31bee7d19989c63f899537ed4c Mon Sep 17 00:00:00 2001 From: "timcleaver@hotmail.com" Date: Fri, 1 Feb 2019 10:42:56 +1000 Subject: [PATCH 09/21] Fix rolenames --- test/content_scripts.test.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/test/content_scripts.test.js b/test/content_scripts.test.js index af722e31..6de98bde 100644 --- a/test/content_scripts.test.js +++ b/test/content_scripts.test.js @@ -104,7 +104,7 @@ describe('ContentScripts', () => { expect(roles[3].querySelector('input[type="submit"]').value).to.eq('b-prod | 666611114444'); expect(roles[4].querySelector('input[name="roleName"]').value).to.eq('renpou'); expect(roles[4].querySelector('input[type="submit"]').value).to.eq('b-renpou | 666611115555'); - expect(roles[5].querySelector('input[name="roleName"]').value).to.eq('prod-role'); + expect(roles[5].querySelector('input[name="roleName"]').value).to.eq('prod-role-image'); expect(roles[5].querySelector('input[type="submit"]').value).to.eq('b-prod-image | 666611114444'); }) }) @@ -160,7 +160,7 @@ describe('ContentScripts', () => { expect(roles[7].querySelector('input[type="submit"]').value).to.eq('b-prod | 666611114444'); expect(roles[8].querySelector('input[name="roleName"]').value).to.eq('renpou'); expect(roles[8].querySelector('input[type="submit"]').value).to.eq('b-renpou | 666611115555'); - expect(roles[9].querySelector('input[name="roleName"]').value).to.eq('prod-role'); + expect(roles[9].querySelector('input[name="roleName"]').value).to.eq('prod-role-image'); expect(roles[9].querySelector('input[type="submit"]').value).to.eq('b-prod-image | 666611114444'); }) }) @@ -186,7 +186,7 @@ describe('ContentScripts', () => { expect(roles[3].querySelector('input[type="submit"]').value).to.eq('b-prod | 666611114444'); expect(roles[4].querySelector('input[name="roleName"]').value).to.eq('renpou'); expect(roles[4].querySelector('input[type="submit"]').value).to.eq('b-renpou | 666611115555'); - expect(roles[5].querySelector('input[name="roleName"]').value).to.eq('prod-role'); + expect(roles[5].querySelector('input[name="roleName"]').value).to.eq('prod-role-image'); expect(roles[5].querySelector('input[type="submit"]').value).to.eq('b-prod-image | 666611114444'); }) }) @@ -279,7 +279,7 @@ describe('ContentScripts', () => { expect(roles[3].querySelector('input[type="submit"]').value).to.eq('b-prod | 666611114444'); expect(roles[4].querySelector('input[name="roleName"]').value).to.eq('renpou'); expect(roles[4].querySelector('input[type="submit"]').value).to.eq('b-renpou | 666611115555'); - expect(roles[5].querySelector('input[name="roleName"]').value).to.eq('prod-role'); + expect(roles[5].querySelector('input[name="roleName"]').value).to.eq('prod-role-image'); expect(roles[5].querySelector('input[type="submit"]').value).to.eq('b-prod-image | 666611114444'); }) }) From 48b2d6a98db5c4ed291e8be9a50d3457ed5005fd Mon Sep 17 00:00:00 2001 From: "timcleaver@hotmail.com" Date: Fri, 1 Feb 2019 10:43:20 +1000 Subject: [PATCH 10/21] Fix counts and test for new roles --- test/content_switched.test.js | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/test/content_switched.test.js b/test/content_switched.test.js index 6ccc37fc..59b65cf1 100644 --- a/test/content_switched.test.js +++ b/test/content_switched.test.js @@ -91,7 +91,7 @@ describe('ContentScripts', () => { expect(document.body.className.includes('user-type-iam')).to.be.false; const roles = Array.from(document.querySelectorAll('#awsc-username-menu-recent-roles li')) - expect(roles.length).to.eq(5); + expect(roles.length).to.eq(6); expect(roles[0].querySelector('input[name="roleName"]').value).to.eq('independence_role'); expect(roles[0].querySelector('input[type="submit"]').value).to.eq('independence'); expect(roles[1].querySelector('input[name="roleName"]').value).to.eq('contained_history_role'); @@ -102,6 +102,8 @@ describe('ContentScripts', () => { expect(roles[3].querySelector('input[type="submit"]').value).to.eq('b-prod'); expect(roles[4].querySelector('input[name="roleName"]').value).to.eq('renpou'); expect(roles[4].querySelector('input[type="submit"]').value).to.eq('b-renpou'); + expect(roles[5].querySelector('input[name="roleName"]').value).to.eq('prod-role-image'); + expect(roles[5].querySelector('input[type="submit"]').value).to.eq('b-prod-image'); }) }) }) @@ -168,7 +170,7 @@ describe('ContentScripts', () => { expect(document.body.className.includes('user-type-iam')).to.be.false; const roles = Array.from(document.querySelectorAll('#awsc-username-menu-recent-roles li')) - expect(roles.length).to.eq(5); + expect(roles.length).to.eq(6); expect(roles[0].querySelector('input[name="roleName"]').value).to.eq('independence_role'); expect(roles[1].querySelector('input[name="roleName"]').value).to.eq('contained_history_role'); expect(roles[2].querySelector('input[name="roleName"]').value).to.eq('stg-role'); @@ -177,6 +179,8 @@ describe('ContentScripts', () => { expect(roles[3].querySelector('input[type="submit"]').value).to.eq('b-prod | 666611114444'); expect(roles[4].querySelector('input[name="roleName"]').value).to.eq('renpou'); expect(roles[4].querySelector('input[type="submit"]').value).to.eq('b-renpou | 666611115555'); + expect(roles[5].querySelector('input[name="roleName"]').value).to.eq('prod-role-image'); + expect(roles[5].querySelector('input[type="submit"]').value).to.eq('b-prod-image | 666611114444'); }) }) }) @@ -193,7 +197,7 @@ describe('ContentScripts', () => { expect(document.body.className.includes('user-type-iam')).to.be.false; const roles = Array.from(document.querySelectorAll('#awsc-username-menu-recent-roles li')) - expect(roles.length).to.eq(5); + expect(roles.length).to.eq(6); expect(roles[0].querySelector('input[name="roleName"]').value).to.eq('independence_role'); expect(roles[1].querySelector('input[name="roleName"]').value).to.eq('contained_history_role'); expect(roles[2].querySelector('input[name="roleName"]').value).to.eq('stg-role'); @@ -202,6 +206,8 @@ describe('ContentScripts', () => { expect(roles[3].querySelector('input[type="submit"]').value).to.eq('b-prod | 666611114444'); expect(roles[4].querySelector('input[name="roleName"]').value).to.eq('renpou'); expect(roles[4].querySelector('input[type="submit"]').value).to.eq('b-renpou | 666611115555'); + expect(roles[5].querySelector('input[name="roleName"]').value).to.eq('prod-role-image'); + expect(roles[5].querySelector('input[type="submit"]').value).to.eq('b-prod-image | 666611114444'); }) }) }) From 28631037dd11897f6fa7d0362622c2601749baa9 Mon Sep 17 00:00:00 2001 From: "timcleaver@hotmail.com" Date: Fri, 1 Feb 2019 11:12:27 +1000 Subject: [PATCH 11/21] Missed one rolename change --- test/content_scripts.test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/content_scripts.test.js b/test/content_scripts.test.js index 6de98bde..fd2e0e01 100644 --- a/test/content_scripts.test.js +++ b/test/content_scripts.test.js @@ -134,7 +134,7 @@ describe('ContentScripts', () => { expect(roles[3].querySelector('input[type="submit"]').value).to.eq('b-prod'); expect(roles[4].querySelector('input[name="roleName"]').value).to.eq('renpou'); expect(roles[4].querySelector('input[type="submit"]').value).to.eq('b-renpou'); - expect(roles[5].querySelector('input[name="roleName"]').value).to.eq('prod-role'); + expect(roles[5].querySelector('input[name="roleName"]').value).to.eq('prod-role-image'); expect(roles[5].querySelector('input[type="submit"]').value).to.eq('b-prod-image'); }) }) From 3fa74443adf76347e6d632b5d5f92fcfe9ff50b3 Mon Sep 17 00:00:00 2001 From: "timcleaver@hotmail.com" Date: Mon, 4 Feb 2019 17:22:07 +1000 Subject: [PATCH 12/21] Use ems for image sizes. Use 14em based on no scrollbars in both chrome and firefox on my machine --- src/lib/content.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/lib/content.js b/src/lib/content.js index 53fe8fd2..daf7fb39 100644 --- a/src/lib/content.js +++ b/src/lib/content.js @@ -148,7 +148,7 @@ function loadProfiles(profile, list, csrf, hidesHistory, hidesAccountId) { - + `); @@ -220,7 +220,7 @@ function attachColorLine(profiles) { var label = usernameMenu.querySelector('.nav-elt-label'); if (found && found.image) { - label.insertAdjacentHTML('beforebegin', Sanitizer.escapeHTML(``)); + label.insertAdjacentHTML('beforebegin', Sanitizer.escapeHTML(``)); } if (color) { From dfaf925126a2c5800ecccd7f5135170525f3c670 Mon Sep 17 00:00:00 2001 From: "timcleaver@hotmail.com" Date: Tue, 5 Feb 2019 09:57:31 +1000 Subject: [PATCH 13/21] Use style attribute so ems work correctly --- src/lib/content.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/lib/content.js b/src/lib/content.js index daf7fb39..da99776b 100644 --- a/src/lib/content.js +++ b/src/lib/content.js @@ -148,7 +148,7 @@ function loadProfiles(profile, list, csrf, hidesHistory, hidesAccountId) { - + `); @@ -220,7 +220,7 @@ function attachColorLine(profiles) { var label = usernameMenu.querySelector('.nav-elt-label'); if (found && found.image) { - label.insertAdjacentHTML('beforebegin', Sanitizer.escapeHTML(``)); + label.insertAdjacentHTML('beforebegin', Sanitizer.escapeHTML(``)); } if (color) { From 5bbf633db5099362e2e12fe106cb2198db89f856 Mon Sep 17 00:00:00 2001 From: "timcleaver@hotmail.com" Date: Mon, 11 Feb 2019 18:43:46 +1000 Subject: [PATCH 14/21] Describe optional image parameter in README.md --- README.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/README.md b/README.md index f9356959..23770c0f 100644 --- a/README.md +++ b/README.md @@ -32,6 +32,7 @@ The simplest configuration is for multiple **target roles** when you always inte * A 'color' parameter can be used to specify an RGB hex value without prefix '#'. * A 'region' parameter can be used to change the region whenever switching the role. +* An 'image' parameter can be used to specify the uri of an image to use on top of any color attribute supplied. The color and image are not mutually exclusive. ``` [profile marketingadmin] @@ -42,6 +43,11 @@ color = ffaaee aws_account_id = 987654321987 role_name = anotherrole region=ap-northeast-1 + +[athirdaccount] +aws_account_id = 987654321988 +role_name = athirdrole +image = "https://via.placeholder.com/150" ``` ### Complex Configuration From 5e34df5f82600756473fb7cee360da807b5a6918 Mon Sep 17 00:00:00 2001 From: "timcleaver@hotmail.com" Date: Fri, 30 Aug 2019 21:04:09 +1000 Subject: [PATCH 15/21] Fix for bug #111 --- src/lib/content.js | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/lib/content.js b/src/lib/content.js index 7b91348a..cdcd9f5c 100644 --- a/src/lib/content.js +++ b/src/lib/content.js @@ -102,6 +102,17 @@ function loadProfiles(profileSet, list, csrf, hidesHistory, hidesAccountId) { input = li.querySelector('input[type="submit"]'); let name = input.value; name = name.replace(/\s+\|\s+\d+$/, ''); + let profile = profileSet.destProfiles.find(function (profile) { + return profile.profile === name; + }); + console.log(profile); + console.log(profile.image); + console.log(li); + if (profile.image) { + li.querySelector('label.awsc-role-color').innerHTML = Sanitizer.escapeHTML` + + `; + } if (profileSet.excludedNames.includes(name)) { const nextLi = li.nextElementSibling; list.removeChild(li); From 4698807bf6ec89c573d57ff2e85ad207219fbbdc Mon Sep 17 00:00:00 2001 From: "timcleaver@hotmail.com" Date: Fri, 30 Aug 2019 21:08:25 +1000 Subject: [PATCH 16/21] Remove debug --- src/lib/content.js | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/lib/content.js b/src/lib/content.js index cdcd9f5c..3cc38142 100644 --- a/src/lib/content.js +++ b/src/lib/content.js @@ -105,9 +105,6 @@ function loadProfiles(profileSet, list, csrf, hidesHistory, hidesAccountId) { let profile = profileSet.destProfiles.find(function (profile) { return profile.profile === name; }); - console.log(profile); - console.log(profile.image); - console.log(li); if (profile.image) { li.querySelector('label.awsc-role-color').innerHTML = Sanitizer.escapeHTML` From fed80178665436712caf42d6bc3d1aaf307a2a2b Mon Sep 17 00:00:00 2001 From: "timcleaver@hotmail.com" Date: Fri, 30 Aug 2019 21:17:21 +1000 Subject: [PATCH 17/21] Check that we find a matching profile --- src/lib/content.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lib/content.js b/src/lib/content.js index 3cc38142..c9eb800d 100644 --- a/src/lib/content.js +++ b/src/lib/content.js @@ -105,7 +105,7 @@ function loadProfiles(profileSet, list, csrf, hidesHistory, hidesAccountId) { let profile = profileSet.destProfiles.find(function (profile) { return profile.profile === name; }); - if (profile.image) { + if (profile && profile.image) { li.querySelector('label.awsc-role-color').innerHTML = Sanitizer.escapeHTML` `; From 8924b3c745f0f0513467aec08ec0fe7e6f05960c Mon Sep 17 00:00:00 2001 From: "timcleaver@hotmail.com" Date: Fri, 30 Aug 2019 23:06:53 +1000 Subject: [PATCH 18/21] Create imagedata uris in options (or allow users to set them manually) and use the data uris instead of the original img urls --- src/lib/content.js | 12 ++-- src/options.js | 138 +++++++++++++++++++++++++++++++++++++-------- 2 files changed, 119 insertions(+), 31 deletions(-) diff --git a/src/lib/content.js b/src/lib/content.js index c9eb800d..d251fd12 100644 --- a/src/lib/content.js +++ b/src/lib/content.js @@ -105,9 +105,9 @@ function loadProfiles(profileSet, list, csrf, hidesHistory, hidesAccountId) { let profile = profileSet.destProfiles.find(function (profile) { return profile.profile === name; }); - if (profile && profile.image) { + if (profile && profile.imagedata) { li.querySelector('label.awsc-role-color').innerHTML = Sanitizer.escapeHTML` - + `; } if (profileSet.excludedNames.includes(name)) { @@ -132,7 +132,7 @@ function loadProfiles(profileSet, list, csrf, hidesHistory, hidesAccountId) { var color = item.color || 'aaaaaa'; var actionHost = window.location.host.endsWith('.amazonaws-us-gov.com') ? 'signin.amazonaws-us-gov.com' : 'signin.aws.amazon.com'; - if (!item.image) { + if (!item.imagedata) { list.insertAdjacentHTML('beforeend', Sanitizer.escapeHTML`
  • @@ -158,7 +158,7 @@ function loadProfiles(profileSet, list, csrf, hidesHistory, hidesAccountId) { - +
  • `); @@ -229,8 +229,8 @@ function attachColorLine(profiles) { const color = found && found.color || null; var label = usernameMenu.querySelector('.nav-elt-label'); - if (found && found.image) { - label.insertAdjacentHTML('beforebegin', Sanitizer.escapeHTML``); + if (found && found.imagedata) { + label.insertAdjacentHTML('beforebegin', Sanitizer.escapeHTML``); } if (color) { diff --git a/src/options.js b/src/options.js index 42f4b01f..8b1920a8 100644 --- a/src/options.js +++ b/src/options.js @@ -1,19 +1,48 @@ -function elById(id) { +function elById (id) { return document.getElementById(id); } -window.onload = function() { +// taken from: https://davidwalsh.name/convert-image-data-uri-javascript +// converted to return a promise +function getDataUri (profile) { + return new Promise(function (resolve, reject) { + var image = new Image(); + image.setAttribute('crossOrigin', 'anonymous'); + + image.onload = function () { + var canvas = document.createElement('canvas'); + canvas.width = 64; // or 'width' if you want a special/scaled size + canvas.height = 64; // or 'height' if you want a special/scaled size + + canvas.getContext('2d').drawImage(this, 0, 0, 64, 64); + + // get as Data URI + profile.imagedata = canvas.toDataURL('image/png') + console.log(`Got data uri for: ${profile.image}: ${profile.imagedata}`); + resolve(profile); + }; + image.onerror = function () { + console.error(`Failed to load image: ${profile.image}`); + reject(profile) + } + + console.log(`Getting data uri for: ${profile.image}`); + image.src = profile.image.replace(/"/g, ''); + }) +} + +window.onload = function () { var colorPicker = new ColorPicker(document); var selection = []; var textArea = elById('awsConfigTextArea'); - textArea.onselect = function() { + textArea.onselect = function () { var str = this.value.substring(this.selectionStart, this.selectionEnd); var r = str.match(/^([0-9a-fA-F]{6})$/); if (r !== null) { colorPicker.setColor(r[1]); selection = [this.selectionStart, this.selectionEnd]; - colorPicker.onpick = function(newColor) { + colorPicker.onpick = function (newColor) { str = textArea.value; textArea.value = str.substring(0, selection[0]) + newColor + str.substring(selection[1]); } @@ -25,7 +54,7 @@ window.onload = function() { var msgSpan = elById('msgSpan'); var saveButton = elById('saveButton'); - saveButton.onclick = function() { + saveButton.onclick = function () { var rawstr = textArea.value; try { @@ -34,26 +63,85 @@ window.onload = function() { msgSpan.innerHTML = 'Failed to save bacause the number of profiles exceeded maximum 200!'; return; } + // map the profiles to promises. if there is an image specification but no + // imagedata attribute then generate the data-uri otherwise resolve to the + // original profile + Promise.all(profiles.map(function (profile) { + if (profile.image && !profile.imagedata) { + return getDataUri(profile) + } + return new Promise(function (resolve, reject) { + resolve(profile) + }); + })).then(values => { + // parse the rawstr into a list of lines or profiles (where each profile + // is a list of lines) preserving comments and formatting so that we can + // just add the imagedata lines. NOTE: the data parser turns comments + // and empty lines into profile separators + const lines = rawstr.split('\n'); + const profileLines = []; + let output = ""; + let currentProfile = undefined; + lines.forEach(function (line) { + if (r = line.match(/^\[(.+)\]$/)) { + var pname = r[1].trim(); + pname = pname.replace(/^profile\s+/i, ''); + currentProfile = { + profile: pname, + lines: [line] + }; + profileLines.push(currentProfile); + } else { + if (currentProfile) { + currentProfile.lines.push(line); + } else { + output += line; + } + } + }); - localStorage['rawdata'] = rawstr; + // re-render the profiles as string to update the UI and local storage + output += profileLines.map(function (profile) { + let match = values.find(function (value) { + return value.profile === profile.profile + }); + // only add an imagedata line if there isn't one + if (!profile.lines.find(function (line) { return line.startsWith('imagedata'); })) { + console.log('no imagedata'); + // add it after the image line if there is one + const index = profile.lines.findIndex(function (line) { return line.startsWith('image'); }); + if (index > -1) { + profile.lines = profile.lines.slice(0, index + 1) + .concat([`imagedata = ${match.imagedata}`]) + .concat(profile.lines.slice(index + 1)); + } + } + return profile.lines.join('\n'); + }).join('\n'); - const dps = new DataProfilesSplitter(); - const dataSet = dps.profilesToDataSet(profiles); - dataSet.lztext = LZString.compressToUTF16(rawstr); + localStorage['rawdata'] = output; + textArea.value = output; - chrome.storage.sync.set(dataSet, - function() { - const { lastError } = chrome.runtime || browser.runtime; - if (lastError) { - msgSpan.innerHTML = Sanitizer.escapeHTML`${lastError.message}`; - return; - } + const dps = new DataProfilesSplitter(); + const dataSet = dps.profilesToDataSet(values); + dataSet.lztext = LZString.compressToUTF16(output); - msgSpan.innerHTML = 'Configuration has been updated!'; - setTimeout(function() { - msgSpan.innerHTML = ''; - }, 2500); - }); + chrome.storage.sync.set(dataSet, + function () { + const { lastError } = chrome.runtime || browser.runtime; + if (lastError) { + msgSpan.innerHTML = Sanitizer.escapeHTML`${lastError.message}`; + return; + } + + msgSpan.innerHTML = 'Configuration has been updated!'; + setTimeout(function () { + msgSpan.innerHTML = ''; + }, 2500); + }); + }).catch(error => { + console.log(error.message); + }); } catch (e) { msgSpan.innerHTML = 'Failed to save because of invalid format!'; } @@ -61,21 +149,21 @@ window.onload = function() { const booleanSettings = ['hidesHistory', 'hidesAccountId', 'showOnlyMatchingRoles', 'autoAssumeLastRole']; for (let key of booleanSettings) { - elById(`${key}CheckBox`).onchange = function() { + elById(`${key}CheckBox`).onchange = function () { chrome.storage.sync.set({ [key]: this.checked }); } } - elById('configSenderIdText').onchange = function() { + elById('configSenderIdText').onchange = function () { chrome.storage.sync.set({ configSenderId: this.value }); } - chrome.storage.sync.get(['lztext', 'configSenderId'].concat(booleanSettings), function(data) { + chrome.storage.sync.get(['lztext', 'configSenderId'].concat(booleanSettings), function (data) { let rawData = localStorage['rawdata']; if (data.lztext) { try { rawData = LZString.decompressFromUTF16(data.lztext); - } catch(err) { + } catch (err) { rawdata = ';; !!!WARNING!!!\n;; Latest setting is broken.\n;; !!!WARNING!!!\n'; } } From 1fcfdb41a8cb186f5de01970b345cc009d252e7a Mon Sep 17 00:00:00 2001 From: "timcleaver@hotmail.com" Date: Fri, 30 Aug 2019 23:10:56 +1000 Subject: [PATCH 19/21] No spaces before () --- src/options.js | 42 +++++++++++++++++++++--------------------- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/src/options.js b/src/options.js index 8b1920a8..7eac71c3 100644 --- a/src/options.js +++ b/src/options.js @@ -1,15 +1,15 @@ -function elById (id) { +function elById(id) { return document.getElementById(id); } // taken from: https://davidwalsh.name/convert-image-data-uri-javascript // converted to return a promise -function getDataUri (profile) { - return new Promise(function (resolve, reject) { +function getDataUri(profile) { + return new Promise(function(resolve, reject) { var image = new Image(); image.setAttribute('crossOrigin', 'anonymous'); - image.onload = function () { + image.onload = function() { var canvas = document.createElement('canvas'); canvas.width = 64; // or 'width' if you want a special/scaled size canvas.height = 64; // or 'height' if you want a special/scaled size @@ -21,7 +21,7 @@ function getDataUri (profile) { console.log(`Got data uri for: ${profile.image}: ${profile.imagedata}`); resolve(profile); }; - image.onerror = function () { + image.onerror = function() { console.error(`Failed to load image: ${profile.image}`); reject(profile) } @@ -31,18 +31,18 @@ function getDataUri (profile) { }) } -window.onload = function () { +window.onload = function() { var colorPicker = new ColorPicker(document); var selection = []; var textArea = elById('awsConfigTextArea'); - textArea.onselect = function () { + textArea.onselect = function() { var str = this.value.substring(this.selectionStart, this.selectionEnd); var r = str.match(/^([0-9a-fA-F]{6})$/); if (r !== null) { colorPicker.setColor(r[1]); selection = [this.selectionStart, this.selectionEnd]; - colorPicker.onpick = function (newColor) { + colorPicker.onpick = function(newColor) { str = textArea.value; textArea.value = str.substring(0, selection[0]) + newColor + str.substring(selection[1]); } @@ -54,7 +54,7 @@ window.onload = function () { var msgSpan = elById('msgSpan'); var saveButton = elById('saveButton'); - saveButton.onclick = function () { + saveButton.onclick = function() { var rawstr = textArea.value; try { @@ -66,11 +66,11 @@ window.onload = function () { // map the profiles to promises. if there is an image specification but no // imagedata attribute then generate the data-uri otherwise resolve to the // original profile - Promise.all(profiles.map(function (profile) { + Promise.all(profiles.map(function(profile) { if (profile.image && !profile.imagedata) { return getDataUri(profile) } - return new Promise(function (resolve, reject) { + return new Promise(function(resolve, reject) { resolve(profile) }); })).then(values => { @@ -82,7 +82,7 @@ window.onload = function () { const profileLines = []; let output = ""; let currentProfile = undefined; - lines.forEach(function (line) { + lines.forEach(function(line) { if (r = line.match(/^\[(.+)\]$/)) { var pname = r[1].trim(); pname = pname.replace(/^profile\s+/i, ''); @@ -101,15 +101,15 @@ window.onload = function () { }); // re-render the profiles as string to update the UI and local storage - output += profileLines.map(function (profile) { - let match = values.find(function (value) { + output += profileLines.map(function(profile) { + let match = values.find(function(value) { return value.profile === profile.profile }); // only add an imagedata line if there isn't one - if (!profile.lines.find(function (line) { return line.startsWith('imagedata'); })) { + if (!profile.lines.find(function(line) { return line.startsWith('imagedata'); })) { console.log('no imagedata'); // add it after the image line if there is one - const index = profile.lines.findIndex(function (line) { return line.startsWith('image'); }); + const index = profile.lines.findIndex(function(line) { return line.startsWith('image'); }); if (index > -1) { profile.lines = profile.lines.slice(0, index + 1) .concat([`imagedata = ${match.imagedata}`]) @@ -127,7 +127,7 @@ window.onload = function () { dataSet.lztext = LZString.compressToUTF16(output); chrome.storage.sync.set(dataSet, - function () { + function() { const { lastError } = chrome.runtime || browser.runtime; if (lastError) { msgSpan.innerHTML = Sanitizer.escapeHTML`${lastError.message}`; @@ -135,7 +135,7 @@ window.onload = function () { } msgSpan.innerHTML = 'Configuration has been updated!'; - setTimeout(function () { + setTimeout(function() { msgSpan.innerHTML = ''; }, 2500); }); @@ -149,16 +149,16 @@ window.onload = function () { const booleanSettings = ['hidesHistory', 'hidesAccountId', 'showOnlyMatchingRoles', 'autoAssumeLastRole']; for (let key of booleanSettings) { - elById(`${key}CheckBox`).onchange = function () { + elById(`${key}CheckBox`).onchange = function() { chrome.storage.sync.set({ [key]: this.checked }); } } - elById('configSenderIdText').onchange = function () { + elById('configSenderIdText').onchange = function() { chrome.storage.sync.set({ configSenderId: this.value }); } - chrome.storage.sync.get(['lztext', 'configSenderId'].concat(booleanSettings), function (data) { + chrome.storage.sync.get(['lztext', 'configSenderId'].concat(booleanSettings), function(data) { let rawData = localStorage['rawdata']; if (data.lztext) { try { From ea41d669e8eb56f92d1d507afe049853f98e4a91 Mon Sep 17 00:00:00 2001 From: "timcleaver@hotmail.com" Date: Fri, 30 Aug 2019 23:12:47 +1000 Subject: [PATCH 20/21] No spaces after catch --- src/options.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/options.js b/src/options.js index 7eac71c3..3485d79f 100644 --- a/src/options.js +++ b/src/options.js @@ -142,7 +142,7 @@ window.onload = function() { }).catch(error => { console.log(error.message); }); - } catch (e) { + } catch(e) { msgSpan.innerHTML = 'Failed to save because of invalid format!'; } } @@ -163,7 +163,7 @@ window.onload = function() { if (data.lztext) { try { rawData = LZString.decompressFromUTF16(data.lztext); - } catch (err) { + } catch(err) { rawdata = ';; !!!WARNING!!!\n;; Latest setting is broken.\n;; !!!WARNING!!!\n'; } } From e21b21d159574bcccddfbbc04f925cf468ea92de Mon Sep 17 00:00:00 2001 From: "timcleaver@hotmail.com" Date: Fri, 30 Aug 2019 23:32:51 +1000 Subject: [PATCH 21/21] Add imagedata attributes to the test configuration file --- test/fixtures/data.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/fixtures/data.json b/test/fixtures/data.json index 1c6ec4cc..73cbf59d 100644 --- a/test/fixtures/data.json +++ b/test/fixtures/data.json @@ -9,7 +9,7 @@ { "profile": "b-stg", "aws_account_id": "666611113333", "role_name": "stg-role", "source_profile": "base-b" }, { "profile": "b-prod", "aws_account_id": "666611114444", "role_name": "prod-role", "source_profile": "base-b", "color": "ffcc333" }, { "profile": "b-renpou", "aws_account_id": "666611115555", "role_name": "renpou", "source_profile": "base-b" }, - { "profile": "a-stg-image", "aws_account_id": "555511113333", "role_name": "stg-role-image", "source_profile": "base-a", "image": "not-found.png" }, - { "profile": "b-prod-image", "aws_account_id": "666611114444", "role_name": "prod-role-image", "source_profile": "base-b", "image": "not-found.png" } + { "profile": "a-stg-image", "aws_account_id": "555511113333", "role_name": "stg-role-image", "source_profile": "base-a", "image": "not-found.png", "imagedata": "imagedata" }, + { "profile": "b-prod-image", "aws_account_id": "666611114444", "role_name": "prod-role-image", "source_profile": "base-b", "image": "not-found.png", imagedata: "imagedata" } ] }