Skip to content

Commit

Permalink
upgrade deps and dont show alert when no input given
Browse files Browse the repository at this point in the history
  • Loading branch information
florian42 committed Jun 19, 2022
1 parent 2d97989 commit 6ddac04
Show file tree
Hide file tree
Showing 8 changed files with 4,445 additions and 1,127 deletions.
5,370 changes: 4,353 additions & 1,017 deletions package-lock.json

Large diffs are not rendered by default.

138 changes: 72 additions & 66 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,67 +1,73 @@
{
"name": "jwt",
"displayName": "jwt decode",
"description": "Decode JWT",
"repository": {
"type": "git",
"url": "https://github.com/florian42/jwt"
},
"bugs": {
"url": "https://github.com/florian42/jwt/issues"
},
"version": "0.0.1",
"publisher": "florian",
"keywords": [
"jwt"
],
"engines": {
"vscode": "^1.53.0"
},
"categories": [
"Other"
],
"activationEvents": [
"onCommand:jwt.decode"
],
"main": "./dist/extension.js",
"contributes": {
"commands": [
{
"command": "jwt.decode",
"title": "JWT Decode"
}
]
},
"scripts": {
"vscode:prepublish": "webpack --mode production",
"webpack": "webpack --mode development",
"webpack-dev": "webpack --mode development --watch",
"compile": "tsc -p ./",
"watch": "tsc -watch -p ./",
"pretest": "npm run compile && npm run lint",
"lint": "eslint src --ext ts",
"test": "node ./out/test/runTest.js"
},
"devDependencies": {
"@types/glob": "^7.1.3",
"@types/mocha": "^8.0.4",
"@types/node": "^12.11.7",
"@types/sinon": "^9.0.10",
"@types/vscode": "^1.53.0",
"@typescript-eslint/eslint-plugin": "^4.14.1",
"@typescript-eslint/parser": "^4.14.1",
"eslint": "^7.19.0",
"glob": "^7.1.6",
"mocha": "^8.2.1",
"ts-loader": "^8.0.17",
"typescript": "^4.1.3",
"vscode-test": "^1.5.0",
"webpack": "^5.23.0",
"webpack-cli": "^4.5.0"
},
"dependencies": {
"jose": "^3.6.2",
"sinon": "^9.2.4"
},
"license": "Apache 2.0"
}
"name": "jwt",
"displayName": "JWT Decode",
"description": "Decode JWT",
"repository": {
"type": "git",
"url": "https://github.com/florian42/jwt"
},
"bugs": {
"url": "https://github.com/florian42/jwt/issues"
},
"version": "0.0.2",
"publisher": "florian",
"keywords": [
"jwt"
],
"engines": {
"vscode": "^1.68.0"
},
"categories": [
"Other"
],
"activationEvents": [
"onCommand:jwt.decode"
],
"main": "./dist/extension.js",
"contributes": {
"commands": [
{
"command": "jwt.decode",
"title": "JWT Decode"
}
]
},
"scripts": {
"vscode:prepublish": "webpack --mode production",
"webpack": "webpack --mode development",
"webpack-dev": "webpack --mode development --watch",
"compile": "tsc -p ./",
"watch": "tsc -watch -p ./",
"pretest": "npm run compile && npm run lint",
"lint": "eslint src --ext ts",
"test": "node ./dist/test/runTest.js"
},
"devDependencies": {
"@types/glob": "^7.2.0",
"@types/mocha": "^9.1.1",
"@types/node": "^18.0.0",
"@types/sinon": "^10.0.11",
"@types/vscode": "^1.68.0",
"@typescript-eslint/eslint-plugin": "^5.28.0",
"@typescript-eslint/parser": "^5.28.0",
"eslint": "^8.18.0",
"glob": "^8.0.3",
"mocha": "^10.0.0",
"ts-loader": "^9.3.0",
"typescript": "^4.7.4",
"@vscode/test-electron": "^2.1.4",
"webpack": "^5.73.0",
"webpack-cli": "^4.10.0"
},
"dependencies": {
"jose": "^4.8.1",
"sinon": "^14.0.0"
},
"license": "Apache 2.0",
"__metadata": {
"id": "3a8e2455-6a2e-4006-a99b-a14a4d2fcec3",
"publisherDisplayName": "Florian",
"publisherId": "bd443fac-0c42-40d0-a8f3-747c28ec3be7",
"isPreReleaseVersion": false
}
}
12 changes: 0 additions & 12 deletions src/exceptions.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,3 @@
export class InputCannotBeEmptyError extends Error {
constructor(message: string) {
super();
if (Error.captureStackTrace) {
Error.captureStackTrace(this, InputCannotBeEmptyError);
}

this.name = "InputCannotBeEmpty";
this.message = message;
}
}

export class InvalidInputError extends Error {
constructor(message: string) {
super();
Expand Down
4 changes: 2 additions & 2 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@ export function activate(context: vscode.ExtensionContext) {
try {
const input = await vscode.window.showInputBox();
const jwt = Jwt.getJwt(input);
const copyToClipboard = await vscode.window.showInformationMessage(
const copyToClipboard = jwt && await vscode.window.showInformationMessage(
JSON.stringify(jwt),
"Copy To Clipboard"
);
if (copyToClipboard) {
vscode.env.clipboard.writeText(JSON.stringify(jwt));
}
} catch (error) {
} catch (error: any) {
vscode.window.showErrorMessage(error.message);
}
});
Expand Down
10 changes: 5 additions & 5 deletions src/jwt.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { decode } from "jose/util/base64url";
import { base64url } from "jose";
import { TextDecoder } from "util";
import { InputCannotBeEmptyError, InvalidInputError } from "./exceptions";
import { InvalidInputError } from "./exceptions";

class Jwt {
header: string;
Expand All @@ -11,17 +11,17 @@ class Jwt {
this.payload = JSON.parse(payload);
}

public static getJwt(jwt: string | null | undefined): Jwt {
public static getJwt(jwt: string | null | undefined): Jwt | null {
if (!jwt) {
throw new InputCannotBeEmptyError("Forgot to paste your JWT?");
return null;
}
const textDecoder = new TextDecoder();
const parts = jwt.split(".");
if (parts.length < 2) {
throw new InvalidInputError("Make sure your JWT has a valid format");
}
const [header, payload] = parts.map((part) =>
textDecoder.decode(decode(part))
textDecoder.decode(base64url.decode(part))
);
return new Jwt(header, payload);
}
Expand Down
23 changes: 10 additions & 13 deletions src/test/runTest.ts
Original file line number Diff line number Diff line change
@@ -1,27 +1,24 @@
import * as path from "path";
import * as path from 'path';

import { downloadAndUnzipVSCode, runTests } from "vscode-test";
import { runTests } from '@vscode/test-electron';

async function main() {
try {
// The folder containing the Extension Manifest package.json
// Passed to `--extensionDevelopmentPath`
const extensionDevelopmentPath = path.resolve(__dirname, "../../");
const extensionDevelopmentPath = path.resolve(__dirname, '../../');

// The path to test runner
// The path to the extension test runner script
// Passed to --extensionTestsPath
const extensionTestsPath = path.resolve(__dirname, "./suite/index");
const extensionTestsPath = path.resolve(__dirname, './suite/index');

const vscodeExecutablePath = await downloadAndUnzipVSCode("1.53.1"); // Download VS Code, unzip it and run the integration test
await runTests({
extensionDevelopmentPath,
vscodeExecutablePath,
extensionTestsPath,
});
// Download VS Code, unzip it and run the integration test
await runTests({ extensionDevelopmentPath, extensionTestsPath });
} catch (err) {
console.error("Failed to run tests");
console.error(err);
console.error('Failed to run tests');
process.exit(1);
}
}

main();
main();
13 changes: 2 additions & 11 deletions src/test/suite/extension.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,6 @@ suite("Extension Test Suite", () => {
sinon.restore();
});

test("starts extension @integration", async () => {
await vscode.commands.executeCommand("jwt.decode");
const started = vscode.extensions.getExtension("florian.jwt")?.isActive;
assert.strictEqual(started, true);
});

test("decodes valid jwt input", async () => {
const showInputBox = sinon.stub(vscode.window, "showInputBox");
const showInformationMessage = sinon.stub(
Expand All @@ -45,18 +39,15 @@ suite("Extension Test Suite", () => {
sinon.assert.calledWith(showInformationMessage, expectedMessage);
});

test("shows error message when no input given", async () => {
test("does not show message when no input given", async () => {
const showInputBox = sinon.stub(vscode.window, "showInputBox");
const showErrorMessage = sinon.stub(vscode.window, "showErrorMessage");
showInputBox.resolves(undefined);

await vscode.commands.executeCommand("jwt.decode");

assert(showInputBox.calledOnce);
assert(showErrorMessage.calledOnce);
console.log(showErrorMessage.firstCall.lastArg);
//@ts-ignore
sinon.assert.calledWith(showErrorMessage, "Forgot to paste your JWT?");
assert(showErrorMessage.notCalled);
});

test("shows error message when input is invalid", async () => {
Expand Down
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"compilerOptions": {
"module": "commonjs",
"target": "es6",
"outDir": "out",
"outDir": "dist",
"lib": [
"es6"
],
Expand Down

0 comments on commit 6ddac04

Please sign in to comment.