mirror of
https://github.com/awatertrevi/infisical.git
synced 2026-10-14 11:29:42 +00:00
Add eslint rule and fix as many issues as possible
This commit is contained in:
@@ -1,78 +1,78 @@
|
||||
import { describe, test, expect } from '@jest/globals';
|
||||
import { describe, expect, test } from "@jest/globals";
|
||||
import {
|
||||
decryptAsymmetric,
|
||||
encryptAsymmetric,
|
||||
} from '../../../src/utils/crypto';
|
||||
} from "../../../src/utils/crypto";
|
||||
|
||||
describe('Crypto', () => {
|
||||
describe('encryptAsymmetric', () => {
|
||||
describe('given all valid publicKey, privateKey and plaintext', () => {
|
||||
const publicKey = '6U5m6S5jlyazJ+R4z7Yf/Ah4th4JwKxDN8Wn7+upvzw=';
|
||||
const privateKey = 'Z8W53YV+2ddjJCrFwzptjK96y2QsQI9oXuvfcx+qxz0=';
|
||||
const plaintext = 'secret-message';
|
||||
describe("Crypto", () => {
|
||||
describe("encryptAsymmetric", () => {
|
||||
describe("given all valid publicKey, privateKey and plaintext", () => {
|
||||
const publicKey = "6U5m6S5jlyazJ+R4z7Yf/Ah4th4JwKxDN8Wn7+upvzw=";
|
||||
const privateKey = "Z8W53YV+2ddjJCrFwzptjK96y2QsQI9oXuvfcx+qxz0=";
|
||||
const plaintext = "secret-message";
|
||||
|
||||
test('should encrypt plain text', () => {
|
||||
test("should encrypt plain text", () => {
|
||||
const result = encryptAsymmetric({ plaintext, publicKey, privateKey });
|
||||
expect(result.ciphertext).toBeDefined();
|
||||
expect(result.nonce).toBeDefined();
|
||||
});
|
||||
});
|
||||
|
||||
describe('given empty/undefined publicKey', () => {
|
||||
describe("given empty/undefined publicKey", () => {
|
||||
let publicKey: string;
|
||||
const privateKey = 'Z8W53YV+2ddjJCrFwzptjK96y2QsQI9oXuvfcx+qxz0=';
|
||||
const plaintext = 'secret-message';
|
||||
const privateKey = "Z8W53YV+2ddjJCrFwzptjK96y2QsQI9oXuvfcx+qxz0=";
|
||||
const plaintext = "secret-message";
|
||||
|
||||
test('should throw error if publicKey is undefined', () => {
|
||||
test("should throw error if publicKey is undefined", () => {
|
||||
expect(() => {
|
||||
encryptAsymmetric({ plaintext, publicKey, privateKey });
|
||||
}).toThrowError('invalid encoding');
|
||||
}).toThrowError("invalid encoding");
|
||||
});
|
||||
|
||||
test('should throw error if publicKey is empty string', () => {
|
||||
publicKey = '';
|
||||
test("should throw error if publicKey is empty string", () => {
|
||||
publicKey = "";
|
||||
expect(() => {
|
||||
encryptAsymmetric({ plaintext, publicKey, privateKey });
|
||||
}).toThrowError('bad public key size');
|
||||
}).toThrowError("bad public key size");
|
||||
});
|
||||
});
|
||||
|
||||
describe('given empty/undefined privateKey', () => {
|
||||
const publicKey = '6U5m6S5jlyazJ+R4z7Yf/Ah4th4JwKxDN8Wn7+upvzw=';
|
||||
describe("given empty/undefined privateKey", () => {
|
||||
const publicKey = "6U5m6S5jlyazJ+R4z7Yf/Ah4th4JwKxDN8Wn7+upvzw=";
|
||||
let privateKey: string;
|
||||
const plaintext = 'secret-message';
|
||||
const plaintext = "secret-message";
|
||||
|
||||
test('should throw error if privateKey is undefined', () => {
|
||||
test("should throw error if privateKey is undefined", () => {
|
||||
expect(() => {
|
||||
encryptAsymmetric({ plaintext, publicKey, privateKey });
|
||||
}).toThrowError('invalid encoding');
|
||||
}).toThrowError("invalid encoding");
|
||||
});
|
||||
|
||||
test('should throw error if privateKey is empty string', () => {
|
||||
privateKey = '';
|
||||
test("should throw error if privateKey is empty string", () => {
|
||||
privateKey = "";
|
||||
expect(() => {
|
||||
encryptAsymmetric({ plaintext, publicKey, privateKey });
|
||||
}).toThrowError('bad secret key size');
|
||||
}).toThrowError("bad secret key size");
|
||||
});
|
||||
});
|
||||
|
||||
describe('given undefined/invalid plaint text', () => {
|
||||
const publicKey = '6U5m6S5jlyazJ+R4z7Yf/Ah4th4JwKxDN8Wn7+upvzw=';
|
||||
const privateKey = 'Z8W53YV+2ddjJCrFwzptjK96y2QsQI9oXuvfcx+qxz0=';
|
||||
describe("given undefined/invalid plaint text", () => {
|
||||
const publicKey = "6U5m6S5jlyazJ+R4z7Yf/Ah4th4JwKxDN8Wn7+upvzw=";
|
||||
const privateKey = "Z8W53YV+2ddjJCrFwzptjK96y2QsQI9oXuvfcx+qxz0=";
|
||||
let plaintext: string;
|
||||
|
||||
test('should throw error if plaintext is undefined', () => {
|
||||
test("should throw error if plaintext is undefined", () => {
|
||||
expect(() => {
|
||||
encryptAsymmetric({ plaintext, publicKey, privateKey });
|
||||
}).toThrowError('expected string');
|
||||
}).toThrowError("expected string");
|
||||
});
|
||||
|
||||
test('should encrypt plaintext containing special characters', () => {
|
||||
plaintext = '131@#$%235!@#&*(&123sadfkjadjf';
|
||||
test("should encrypt plaintext containing special characters", () => {
|
||||
plaintext = "131@#$%235!@#&*(&123sadfkjadjf";
|
||||
const result = encryptAsymmetric({
|
||||
plaintext,
|
||||
publicKey,
|
||||
privateKey
|
||||
privateKey,
|
||||
});
|
||||
expect(result.ciphertext).toBeDefined();
|
||||
expect(result.nonce).toBeDefined();
|
||||
@@ -80,17 +80,17 @@ describe('Crypto', () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe('decryptAsymmetric', () => {
|
||||
describe('given all valid publicKey, privateKey and plaintext', () => {
|
||||
const publicKey = '6U5m6S5jlyazJ+R4z7Yf/Ah4th4JwKxDN8Wn7+upvzw=';
|
||||
const privateKey = 'Z8W53YV+2ddjJCrFwzptjK96y2QsQI9oXuvfcx+qxz0=';
|
||||
const plaintext = 'secret-message';
|
||||
describe("decryptAsymmetric", () => {
|
||||
describe("given all valid publicKey, privateKey and plaintext", () => {
|
||||
const publicKey = "6U5m6S5jlyazJ+R4z7Yf/Ah4th4JwKxDN8Wn7+upvzw=";
|
||||
const privateKey = "Z8W53YV+2ddjJCrFwzptjK96y2QsQI9oXuvfcx+qxz0=";
|
||||
const plaintext = "secret-message";
|
||||
|
||||
test('should decrypt the encrypted plaintext', () => {
|
||||
test("should decrypt the encrypted plaintext", () => {
|
||||
const encryptedResult = encryptAsymmetric({
|
||||
plaintext,
|
||||
publicKey,
|
||||
privateKey
|
||||
privateKey,
|
||||
});
|
||||
const ciphertext = encryptedResult.ciphertext;
|
||||
const nonce = encryptedResult.nonce;
|
||||
@@ -99,7 +99,7 @@ describe('Crypto', () => {
|
||||
ciphertext,
|
||||
nonce,
|
||||
publicKey,
|
||||
privateKey
|
||||
privateKey,
|
||||
});
|
||||
|
||||
expect(decryptedResult).toBeDefined();
|
||||
@@ -107,18 +107,18 @@ describe('Crypto', () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe('given ciphertext or nonce is modified before decrypt', () => {
|
||||
const publicKey = '6U5m6S5jlyazJ+R4z7Yf/Ah4th4JwKxDN8Wn7+upvzw=';
|
||||
const privateKey = 'Z8W53YV+2ddjJCrFwzptjK96y2QsQI9oXuvfcx+qxz0=';
|
||||
const plaintext = 'secret-message';
|
||||
describe("given ciphertext or nonce is modified before decrypt", () => {
|
||||
const publicKey = "6U5m6S5jlyazJ+R4z7Yf/Ah4th4JwKxDN8Wn7+upvzw=";
|
||||
const privateKey = "Z8W53YV+2ddjJCrFwzptjK96y2QsQI9oXuvfcx+qxz0=";
|
||||
const plaintext = "secret-message";
|
||||
|
||||
test('should throw error if ciphertext is modified', () => {
|
||||
test("should throw error if ciphertext is modified", () => {
|
||||
const encryptedResult = encryptAsymmetric({
|
||||
plaintext,
|
||||
publicKey,
|
||||
privateKey
|
||||
privateKey,
|
||||
});
|
||||
const ciphertext = '=12adfJ@#52af1231=123'; // modified
|
||||
const ciphertext = "=12adfJ@#52af1231=123"; // modified
|
||||
const nonce = encryptedResult.nonce;
|
||||
|
||||
expect(() => {
|
||||
@@ -126,28 +126,28 @@ describe('Crypto', () => {
|
||||
ciphertext,
|
||||
nonce,
|
||||
publicKey,
|
||||
privateKey
|
||||
privateKey,
|
||||
});
|
||||
}).toThrowError('invalid encoding');
|
||||
}).toThrowError("invalid encoding");
|
||||
});
|
||||
|
||||
test('should throw error if nonce is modified', () => {
|
||||
test("should throw error if nonce is modified", () => {
|
||||
const encryptedResult = encryptAsymmetric({
|
||||
plaintext,
|
||||
publicKey,
|
||||
privateKey
|
||||
privateKey,
|
||||
});
|
||||
const ciphertext = encryptedResult.ciphertext;
|
||||
const nonce = '=12adfJ@#52af1231=123'; // modified
|
||||
const nonce = "=12adfJ@#52af1231=123"; // modified
|
||||
|
||||
expect(() => {
|
||||
decryptAsymmetric({
|
||||
ciphertext,
|
||||
nonce,
|
||||
publicKey,
|
||||
privateKey
|
||||
privateKey,
|
||||
});
|
||||
}).toThrowError('invalid encoding');
|
||||
}).toThrowError("invalid encoding");
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,29 +1,29 @@
|
||||
import { describe, test, expect } from '@jest/globals';
|
||||
import { getChannelFromUserAgent } from '../../../src/utils/posthog';
|
||||
import { describe, expect, test } from "@jest/globals";
|
||||
import { getChannelFromUserAgent } from "../../../src/utils/posthog";
|
||||
|
||||
describe('posthog getChannelFromUserAgent', () => {
|
||||
describe("posthog getChannelFromUserAgent", () => {
|
||||
test("should return 'web' when userAgent includes 'mozilla'", () => {
|
||||
const userAgent =
|
||||
'Mozilla/5.0 (Linux; Android 10) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/111.0.5563.115 Mobile Safari/537.36';
|
||||
"Mozilla/5.0 (Linux; Android 10) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/111.0.5563.115 Mobile Safari/537.36";
|
||||
const channel = getChannelFromUserAgent(userAgent);
|
||||
expect(channel).toBe('web');
|
||||
expect(channel).toBe("web");
|
||||
});
|
||||
|
||||
test("should return 'cli'", () => {
|
||||
const userAgent = 'cli';
|
||||
const userAgent = "cli";
|
||||
const channel = getChannelFromUserAgent(userAgent);
|
||||
expect(channel).toBe('cli');
|
||||
expect(channel).toBe("cli");
|
||||
});
|
||||
|
||||
test("should return 'k8-operator'", () => {
|
||||
const userAgent = 'k8-operator';
|
||||
const userAgent = "k8-operator";
|
||||
const channel = getChannelFromUserAgent(userAgent);
|
||||
expect(channel).toBe('k8-operator');
|
||||
expect(channel).toBe("k8-operator");
|
||||
});
|
||||
|
||||
test('should return undefined if no userAgent', () => {
|
||||
test("should return undefined if no userAgent", () => {
|
||||
const userAgent = undefined;
|
||||
const channel = getChannelFromUserAgent(userAgent);
|
||||
expect(channel).toBe('other');
|
||||
expect(channel).toBe("other");
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user