From 38f11f5ddcd751184a4f578eebad708dfac7ce50 Mon Sep 17 00:00:00 2001 From: Ryan Koval Date: Wed, 4 Aug 2021 23:19:16 -0500 Subject: [PATCH] added utilities for validating service urls --- aws-url-validator/.nvmrc | 1 + aws-url-validator/.prettierignore | 3 + aws-url-validator/.prettierrc | 10 ++ aws-url-validator/README.md | 9 ++ .../diff-urls-with-last-opened-urls-json.js | 29 +++++ aws-url-validator/getAwsUrlsFromPage.js | 20 +++ aws-url-validator/lz4jsoncat | Bin 0 -> 13808 bytes aws-url-validator/main.sh | 6 + aws-url-validator/package-lock.json | 123 ++++++++++++++++++ aws-url-validator/package.json | 9 ++ 10 files changed, 210 insertions(+) create mode 100644 aws-url-validator/.nvmrc create mode 100644 aws-url-validator/.prettierignore create mode 100644 aws-url-validator/.prettierrc create mode 100644 aws-url-validator/README.md create mode 100755 aws-url-validator/diff-urls-with-last-opened-urls-json.js create mode 100644 aws-url-validator/getAwsUrlsFromPage.js create mode 100755 aws-url-validator/lz4jsoncat create mode 100755 aws-url-validator/main.sh create mode 100644 aws-url-validator/package-lock.json create mode 100644 aws-url-validator/package.json diff --git a/aws-url-validator/.nvmrc b/aws-url-validator/.nvmrc new file mode 100644 index 00000000..25cf32f6 --- /dev/null +++ b/aws-url-validator/.nvmrc @@ -0,0 +1 @@ +v12.16.1 \ No newline at end of file diff --git a/aws-url-validator/.prettierignore b/aws-url-validator/.prettierignore new file mode 100644 index 00000000..2e165aa6 --- /dev/null +++ b/aws-url-validator/.prettierignore @@ -0,0 +1,3 @@ +*node_modules* +.git/ +package.json diff --git a/aws-url-validator/.prettierrc b/aws-url-validator/.prettierrc new file mode 100644 index 00000000..25677d6e --- /dev/null +++ b/aws-url-validator/.prettierrc @@ -0,0 +1,10 @@ +{ + "printWidth": 100, + "singleQuote": true, + "trailingComma": "es5", + "bracketSpacing": false, + "jsxBracketSameLine": false, + "semi": true, + "requirePragma": false, + "arrowParens": "avoid" +} \ No newline at end of file diff --git a/aws-url-validator/README.md b/aws-url-validator/README.md new file mode 100644 index 00000000..c8ff14ad --- /dev/null +++ b/aws-url-validator/README.md @@ -0,0 +1,9 @@ +This is used for testing URLs that are opened in the browser after using the `OPEN_ALL` command. This is useful for validating if the URLs redirect or error after opening. + +The `lz4jsoncat` was build on macOS 10.15.7 on a 2013 Macbook Pro. If it doesn't work, rebuild it from [its repo](https://github.com/andikleen/lz4json). + +This requires: + +- Firefox +- macOS 10.15.7 (or later?) +- nvm diff --git a/aws-url-validator/diff-urls-with-last-opened-urls-json.js b/aws-url-validator/diff-urls-with-last-opened-urls-json.js new file mode 100755 index 00000000..3b7d0c9b --- /dev/null +++ b/aws-url-validator/diff-urls-with-last-opened-urls-json.js @@ -0,0 +1,29 @@ +#!/usr/bin/env node +const fs = require('fs'); +const assert = require('assert-diff'); + +function main() { + const stdinBuffer = fs.readFileSync(0); + const rawSession = stdinBuffer.toString(); + const session = JSON.parse(rawSession); + const activeAwsUrls = []; + session.windows.forEach(window => { + window.tabs.forEach(tab => { + const currentEntry = tab.entries[tab.entries.length - 1]; + if (currentEntry.url.includes('console.aws.amazon.com')) { + activeAwsUrls.push(currentEntry.url); + } + }); + }); + + const lastOpenedUrlsBuffer = fs.readFileSync( + // TODO this will break with Alfred 4 + `${process.env.HOME}/Library/Caches/com.runningwithcrayons.Alfred-3/Workflow Data/com.ryankoval.awsconsoleservices/last-opened-urls.json` + ); + const lastOpenedUrls = JSON.parse(lastOpenedUrlsBuffer); + + assert.deepStrictEqual(activeAwsUrls, lastOpenedUrls); + console.log('✅ urls matches successfully!'); +} + +main(); diff --git a/aws-url-validator/getAwsUrlsFromPage.js b/aws-url-validator/getAwsUrlsFromPage.js new file mode 100644 index 00000000..c8c427e7 --- /dev/null +++ b/aws-url-validator/getAwsUrlsFromPage.js @@ -0,0 +1,20 @@ +// this is a helper to paste in the browser to pull out urls from aws side nav +function getAwsUrlsFromPage(className) { + return $$(`.${className} a`) + .map(element => { + let url; + try { + url = new URL(element.href); + url.searchParams.delete('region'); + url = url.pathname + url.search + url.hash; + } catch { + url = element.href; + } + return { + id: element.innerText.replaceAll(' ', '').replaceAll('-', '').toLowerCase(), + name: element.innerText, + url, + }; + }) + .filter(entry => !!entry.id); +} diff --git a/aws-url-validator/lz4jsoncat b/aws-url-validator/lz4jsoncat new file mode 100755 index 0000000000000000000000000000000000000000..8b4fbbfb9845580d31797efda9c8a728fba5efc3 GIT binary patch literal 13808 zcmeHOU2Ggz6}}rcVX;Fth6n=mXVTaZD)9O*l?_Glwl>UCH%V&;LP#>Ky|eKqyF1J5 zIJE;*P93*dEw21jg4Bmd{6!$4f(j~82~kPohDa^&fJ}u{Lj{>AMf|8rD;~Oh-<>;~ z-LcyTctO=%>D+U^d(S!d+;eyCuGeQ@{P*A9e3uZBCLzQcP%G%vS|R3y21$qyf^?8! z>`r`kXy4ESyExj|B8_lWL_bSVG>p-qy`zmP(tcy(m{1s@2%o577>+sR+|XU&Z#_1H z=_EJ927HqzdHqddrXCtb$(bB0)rNxpKDWX1=ZEZL-yo{|ty2S@KV!no6-^ssL4T)} zzbBMFu^*}&S`puP$+5GALpA@6`MWFT#dk!_6W6x}-~_W zyOk5-ppSb0Jl9jw&tPISVcfH8=ZKdooL|Ga`sb@SUvDJpaL6zYS#`$>yt+T%4UK5; zH|8IytTo2vf;>O9VIj0YT)?sg;_~-w7`c>Dn$C||Iiu*Ri7FN1dVgxT#%?^H!^xfZ4h<iwodEmtK!PbZGh<&OXV;V^AG1e^B zfhfyduKV~J##|o{_Bum9av^fnxb6VR-$&EC=_R6KvBp!mxK(uGxnsRDGDHWlqpJfU zX2+mO`@TB+NIHTO@a?e|sEtgQ95df>cg+a;9|1AGKIE6@@iB#&@34g#2s037Ak09R zf&VoFd-U>O5?@GsKCve;I-(zc^%NZHm4~AGTs3xL1K#VB<=2w47oxG-PROOYu6Lbx zNAQk5cRqIV6$~ZHi{(Xq{-=7iT6J$$6R%4zlV|kVH(O$l{S&CGdX{gTKW8^oeq*TX zk{f}tKKlmNxq`uD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}Xpb`WdMKML9gV&0hZ|JGi^FC|t!OL$=MEWPdhfosTnK;M1& literal 0 HcmV?d00001 diff --git a/aws-url-validator/main.sh b/aws-url-validator/main.sh new file mode 100755 index 00000000..3cd76a5e --- /dev/null +++ b/aws-url-validator/main.sh @@ -0,0 +1,6 @@ +#!/usr/bin/env bash +cd "$(dirname "$0")" + +# this holds session info in firefox like the currently opened tabs +./lz4jsoncat $HOME/Library/Application\ Support/Firefox/Profiles/*default*/sessionstore-backups/recovery.jsonlz4 \ + | ./diff-urls-with-last-opened-urls-json.js diff --git a/aws-url-validator/package-lock.json b/aws-url-validator/package-lock.json new file mode 100644 index 00000000..05eb0648 --- /dev/null +++ b/aws-url-validator/package-lock.json @@ -0,0 +1,123 @@ +{ + "name": "aws-url-redirect-tester", + "requires": true, + "lockfileVersion": 1, + "dependencies": { + "ansi-styles": { + "version": "4.3.0", + "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-4.3.0.tgz", + "integrity": "sha512-zbB9rCJAT1rbjiVDb2hqKFHNYLxgtk8NURxZ3IZwD3F6NtxbXZQCnnSi1Lkx+IDohdPlFp222wVALIheZJQSEg==", + "requires": { + "color-convert": "^2.0.1" + } + }, + "assert-diff": { + "version": "3.0.2", + "resolved": "https://registry.npmjs.org/assert-diff/-/assert-diff-3.0.2.tgz", + "integrity": "sha512-3FaXH0uQeMcFpVTcFjOsd6GQdiGgDoy7BYu/HEj/YZ+bjgZLC/i8nSIgerlUbY+iyoCKdEdjzYyNO9BUPcwUmA==", + "requires": { + "assert-plus": "1.0.0", + "json-diff": "0.5.4" + } + }, + "assert-plus": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/assert-plus/-/assert-plus-1.0.0.tgz", + "integrity": "sha1-8S4PPF13sLHN2RRpQuTpbB5N1SU=" + }, + "chalk": { + "version": "4.1.2", + "resolved": "https://registry.npmjs.org/chalk/-/chalk-4.1.2.tgz", + "integrity": "sha512-oKnbhFyRIXpUuez8iBMmyEa4nbj4IOQyuhc/wy9kY7/WVPcwIO9VA668Pu8RkO7+0G76SLROeyw9CpQ061i4mA==", + "requires": { + "ansi-styles": "^4.1.0", + "supports-color": "^7.1.0" + } + }, + "cli-color": { + "version": "0.1.7", + "resolved": "https://registry.npmjs.org/cli-color/-/cli-color-0.1.7.tgz", + "integrity": "sha1-rcMgD6RxzCEbDaf1ZrcemLnWc0c=", + "requires": { + "es5-ext": "0.8.x" + } + }, + "color-convert": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/color-convert/-/color-convert-2.0.1.tgz", + "integrity": "sha512-RRECPsj7iu/xb5oKYcsFHSppFNnsj/52OVTRKb4zP5onXwVF3zVmmToNcOfGC+CRDpfK/U584fMg38ZHCaElKQ==", + "requires": { + "color-name": "~1.1.4" + } + }, + "color-name": { + "version": "1.1.4", + "resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.4.tgz", + "integrity": "sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA==" + }, + "diff": { + "version": "5.0.0", + "resolved": "https://registry.npmjs.org/diff/-/diff-5.0.0.tgz", + "integrity": "sha512-/VTCrvm5Z0JGty/BWHljh+BAiw3IK+2j87NGMu8Nwc/f48WoDAC395uomO9ZD117ZOBaHmkX1oyLvkVM/aIT3w==" + }, + "difflib": { + "version": "0.2.4", + "resolved": "https://registry.npmjs.org/difflib/-/difflib-0.2.4.tgz", + "integrity": "sha1-teMDYabbAjF21WKJLbhZQKcY9H4=", + "requires": { + "heap": ">= 0.2.0" + } + }, + "dreamopt": { + "version": "0.6.0", + "resolved": "https://registry.npmjs.org/dreamopt/-/dreamopt-0.6.0.tgz", + "integrity": "sha1-2BPM2sjTnYrVJndVFKE92mZNa0s=", + "requires": { + "wordwrap": ">=0.0.2" + } + }, + "es5-ext": { + "version": "0.8.2", + "resolved": "https://registry.npmjs.org/es5-ext/-/es5-ext-0.8.2.tgz", + "integrity": "sha1-q6jZ4ZQ6iVrJaDemKjmz9V7NlKs=" + }, + "has-flag": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/has-flag/-/has-flag-4.0.0.tgz", + "integrity": "sha512-EykJT/Q1KjTWctppgIAgfSO0tKVuZUjhgMr17kqTumMl6Afv3EISleU7qZUzoXDFTAHTDC4NOoG/ZxU3EvlMPQ==" + }, + "heap": { + "version": "0.2.6", + "resolved": "https://registry.npmjs.org/heap/-/heap-0.2.6.tgz", + "integrity": "sha1-CH4fELBGky/IWU3Z5tN4r8nR5aw=" + }, + "json-diff": { + "version": "0.5.4", + "resolved": "https://registry.npmjs.org/json-diff/-/json-diff-0.5.4.tgz", + "integrity": "sha512-q5Xmx9QXNOzOzIlMoYtLrLiu4Jl/Ce2bn0CNcv54PhyH89CI4GWlGVDye8ei2Ijt9R3U+vsWPsXpLUNob8bs8Q==", + "requires": { + "cli-color": "~0.1.6", + "difflib": "~0.2.1", + "dreamopt": "~0.6.0" + } + }, + "prettier": { + "version": "2.3.2", + "resolved": "https://registry.npmjs.org/prettier/-/prettier-2.3.2.tgz", + "integrity": "sha512-lnJzDfJ66zkMy58OL5/NY5zp70S7Nz6KqcKkXYzn2tMVrNxvbqaBpg7H3qHaLxCJ5lNMsGuM8+ohS7cZrthdLQ==" + }, + "supports-color": { + "version": "7.2.0", + "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-7.2.0.tgz", + "integrity": "sha512-qpCAvRl9stuOHveKsn7HncJRvv501qIacKzQlO/+Lwxc9+0q2wLyv4Dfvt80/DPn2pqOBsJdDiogXGR9+OvwRw==", + "requires": { + "has-flag": "^4.0.0" + } + }, + "wordwrap": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/wordwrap/-/wordwrap-1.0.0.tgz", + "integrity": "sha1-J1hIEIkUVqQXHI0CJkQa3pDLyus=" + } + } +} diff --git a/aws-url-validator/package.json b/aws-url-validator/package.json new file mode 100644 index 00000000..b9900cbf --- /dev/null +++ b/aws-url-validator/package.json @@ -0,0 +1,9 @@ +{ + "dependencies": { + "assert-diff": "^3.0.2", + "chalk": "^4.1.2", + "diff": "^5.0.0", + "prettier": "^2.3.2" + }, + "devDependencies": {} +}