Skip to content

Commit

Permalink
added utilities for validating service urls
Browse files Browse the repository at this point in the history
  • Loading branch information
rkoval committed Aug 5, 2021
1 parent b0b3422 commit 38f11f5
Show file tree
Hide file tree
Showing 10 changed files with 210 additions and 0 deletions.
1 change: 1 addition & 0 deletions aws-url-validator/.nvmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
v12.16.1
3 changes: 3 additions & 0 deletions aws-url-validator/.prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
*node_modules*
.git/
package.json
10 changes: 10 additions & 0 deletions aws-url-validator/.prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"printWidth": 100,
"singleQuote": true,
"trailingComma": "es5",
"bracketSpacing": false,
"jsxBracketSameLine": false,
"semi": true,
"requirePragma": false,
"arrowParens": "avoid"
}
9 changes: 9 additions & 0 deletions aws-url-validator/README.md
Original file line number Diff line number Diff line change
@@ -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
29 changes: 29 additions & 0 deletions aws-url-validator/diff-urls-with-last-opened-urls-json.js
Original file line number Diff line number Diff line change
@@ -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();
20 changes: 20 additions & 0 deletions aws-url-validator/getAwsUrlsFromPage.js
Original file line number Diff line number Diff line change
@@ -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);
}
Binary file added aws-url-validator/lz4jsoncat
Binary file not shown.
6 changes: 6 additions & 0 deletions aws-url-validator/main.sh
Original file line number Diff line number Diff line change
@@ -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
123 changes: 123 additions & 0 deletions aws-url-validator/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions aws-url-validator/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"dependencies": {
"assert-diff": "^3.0.2",
"chalk": "^4.1.2",
"diff": "^5.0.0",
"prettier": "^2.3.2"
},
"devDependencies": {}
}

0 comments on commit 38f11f5

Please sign in to comment.