swdc-tracker
Advanced tools
Comparing version 1.2.5 to 1.3.0
@@ -54,16 +54,16 @@ "use strict"; | ||
return __awaiter(this, void 0, void 0, function () { | ||
var hashedName, hashedPath; | ||
var hashedValues; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: return [4 /*yield*/, hash_1.hashValue(this.file_name.replace(/\\/g, "/"), "file_name", jwt)]; | ||
case 0: return [4 /*yield*/, hash_1.hashValues([ | ||
{ value: this.file_name.replace(/\\/g, "/"), dataType: "file_name" }, | ||
{ value: this.file_path, dataType: "file_path" } | ||
], jwt)]; | ||
case 1: | ||
hashedName = _a.sent(); | ||
return [4 /*yield*/, hash_1.hashValue(this.file_path, "file_path", jwt)]; | ||
case 2: | ||
hashedPath = _a.sent(); | ||
hashedValues = _a.sent(); | ||
return [2 /*return*/, { | ||
schema: "iglu:com.software/file/jsonschema/1-0-1", | ||
data: { | ||
file_name: hashedName, | ||
file_path: hashedPath, | ||
file_name: hashedValues.file_name, | ||
file_path: hashedValues.file_path, | ||
syntax: this.syntax, | ||
@@ -70,0 +70,0 @@ line_count: this.line_count, |
@@ -51,16 +51,16 @@ "use strict"; | ||
return __awaiter(this, void 0, void 0, function () { | ||
var hashedName, hashedDirectory; | ||
var hashedValues; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: return [4 /*yield*/, hash_1.hashValue(this.project_name, "project_name", jwt)]; | ||
case 0: return [4 /*yield*/, hash_1.hashValues([ | ||
{ value: this.project_name, dataType: "project_name" }, | ||
{ value: this.project_directory, dataType: "project_directory" } | ||
], jwt)]; | ||
case 1: | ||
hashedName = _a.sent(); | ||
return [4 /*yield*/, hash_1.hashValue(this.project_directory, "project_directory", jwt)]; | ||
case 2: | ||
hashedDirectory = _a.sent(); | ||
hashedValues = _a.sent(); | ||
return [2 /*return*/, { | ||
schema: "iglu:com.software/project/jsonschema/1-0-0", | ||
data: { | ||
project_name: hashedName, | ||
project_directory: hashedDirectory | ||
project_name: hashedValues.project_name, | ||
project_directory: hashedValues.project_directory | ||
} | ||
@@ -67,0 +67,0 @@ }]; |
@@ -54,28 +54,22 @@ "use strict"; | ||
return __awaiter(this, void 0, void 0, function () { | ||
var hashedName, hashedIdentifier, hashedOwnerId, hashedGitBranch, hashedGitTag; | ||
var hashedValues; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: return [4 /*yield*/, hash_1.hashValue(this.repo_name, "repo_name", jwt)]; | ||
case 0: return [4 /*yield*/, hash_1.hashValues([ | ||
{ value: this.repo_name, dataType: "repo_name" }, | ||
{ value: this.repo_identifier, dataType: "repo_identifer" }, | ||
{ value: this.owner_id, dataType: "owner_id" }, | ||
{ value: this.git_branch, dataType: "git_branch" }, | ||
{ value: this.git_tag, dataType: "git_tag" }, | ||
], jwt)]; | ||
case 1: | ||
hashedName = _a.sent(); | ||
return [4 /*yield*/, hash_1.hashValue(this.repo_identifier, "repo_identifier", jwt)]; | ||
case 2: | ||
hashedIdentifier = _a.sent(); | ||
return [4 /*yield*/, hash_1.hashValue(this.owner_id, "owner_id", jwt)]; | ||
case 3: | ||
hashedOwnerId = _a.sent(); | ||
return [4 /*yield*/, hash_1.hashValue(this.git_branch, "git_branch", jwt)]; | ||
case 4: | ||
hashedGitBranch = _a.sent(); | ||
return [4 /*yield*/, hash_1.hashValue(this.git_tag, "git_tag", jwt)]; | ||
case 5: | ||
hashedGitTag = _a.sent(); | ||
hashedValues = _a.sent(); | ||
return [2 /*return*/, { | ||
schema: "iglu:com.software/repo/jsonschema/1-0-0", | ||
data: { | ||
repo_identifier: hashedIdentifier, | ||
repo_name: hashedName, | ||
owner_id: hashedOwnerId, | ||
git_branch: hashedGitBranch, | ||
git_tag: hashedGitTag | ||
repo_identifier: hashedValues.repo_identifer, | ||
repo_name: hashedValues.repo_name, | ||
owner_id: hashedValues.owner_id, | ||
git_branch: hashedValues.git_branch, | ||
git_tag: hashedValues.git_tag | ||
} | ||
@@ -82,0 +76,0 @@ }]; |
@@ -1,1 +0,3 @@ | ||
export declare function hashValue(value: string, dataType: string, jwt?: string): Promise<any>; | ||
export declare function hashValues(payload: any, jwt: string): Promise<any>; | ||
export declare function hasHashValueInCache(dataType: string, hashedValue: string): Promise<any>; | ||
export declare function setUserHashedValues(jwt: string): Promise<void>; |
@@ -39,32 +39,58 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.hashValue = void 0; | ||
exports.setUserHashedValues = exports.hasHashValueInCache = exports.hashValues = void 0; | ||
var http_1 = require("./http"); | ||
var file_1 = require("../utils/file"); | ||
var _sodium = require('libsodium-wrappers'); | ||
var sodium; | ||
var userHashedValues = {}; | ||
function hashValue(value, dataType, jwt) { | ||
var lastJwt = ""; | ||
function hashValues(payload, jwt) { | ||
var _a; | ||
return __awaiter(this, void 0, void 0, function () { | ||
var hashedValue; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
var result, _i, payload_1, hashPayload, hashedValue, alreadyEncrypted; | ||
return __generator(this, function (_b) { | ||
switch (_b.label) { | ||
case 0: | ||
if (!jwt) { | ||
return [2 /*return*/, ""]; | ||
} | ||
if (!value) { | ||
return [2 /*return*/, value]; | ||
} | ||
if (!(sodium === undefined)) return [3 /*break*/, 2]; | ||
return [4 /*yield*/, Promise.all([setUserHashedValues(jwt), _sodium.ready]).then(function () { | ||
return [4 /*yield*/, Promise.resolve(_sodium.ready).then(function () { | ||
sodium = _sodium; | ||
})]; | ||
case 1: | ||
_a.sent(); | ||
_a.label = 2; | ||
_b.sent(); | ||
_b.label = 2; | ||
case 2: | ||
hashedValue = sodium.to_hex(sodium.crypto_generichash(64, value)); | ||
return [4 /*yield*/, encryptValue(value, hashedValue, dataType, jwt)]; | ||
if (!(lastJwt !== jwt)) return [3 /*break*/, 4]; | ||
return [4 /*yield*/, setUserHashedValues(jwt)]; | ||
case 3: | ||
_a.sent(); | ||
return [2 /*return*/, hashedValue]; | ||
_b.sent(); | ||
lastJwt = jwt; | ||
_b.label = 4; | ||
case 4: | ||
result = {}; | ||
_i = 0, payload_1 = payload; | ||
_b.label = 5; | ||
case 5: | ||
if (!(_i < payload_1.length)) return [3 /*break*/, 11]; | ||
hashPayload = payload_1[_i]; | ||
if (!((_a = hashPayload.value) === null || _a === void 0 ? void 0 : _a.length)) return [3 /*break*/, 9]; | ||
hashedValue = sodium.to_hex(sodium.crypto_generichash(64, hashPayload.value)); | ||
return [4 /*yield*/, hasHashValueInCache(hashPayload.dataType, hashedValue)]; | ||
case 6: | ||
alreadyEncrypted = _b.sent(); | ||
if (!!alreadyEncrypted) return [3 /*break*/, 8]; | ||
return [4 /*yield*/, encryptValue(hashPayload.value, hashedValue, hashPayload.dataType, jwt)]; | ||
case 7: | ||
_b.sent(); | ||
_b.label = 8; | ||
case 8: | ||
result[hashPayload.dataType] = hashedValue; | ||
return [3 /*break*/, 10]; | ||
case 9: | ||
result[hashPayload.dataType] = hashPayload.value; | ||
_b.label = 10; | ||
case 10: | ||
_i++; | ||
return [3 /*break*/, 5]; | ||
case 11: | ||
; | ||
return [2 /*return*/, result]; | ||
} | ||
@@ -74,14 +100,30 @@ }); | ||
} | ||
exports.hashValue = hashValue; | ||
exports.hashValues = hashValues; | ||
function hasHashValueInCache(dataType, hashedValue) { | ||
return __awaiter(this, void 0, void 0, function () { | ||
var userHashedValues, hasValue; | ||
return __generator(this, function (_a) { | ||
userHashedValues = file_1.getStoredHashedValues(); | ||
// add dataType to userHashedValues cache if it doesn't already exist | ||
if (!userHashedValues[dataType]) { | ||
userHashedValues[dataType] = []; | ||
} | ||
hasValue = userHashedValues[dataType].includes(hashedValue); | ||
// if it does not have the value, add it | ||
if (!hasValue) { | ||
userHashedValues[dataType].push(hashedValue); | ||
file_1.storeHashedValues(userHashedValues); | ||
} | ||
// return the result of hasValue | ||
return [2 /*return*/, hasValue]; | ||
}); | ||
}); | ||
} | ||
exports.hasHashValueInCache = hasHashValueInCache; | ||
function encryptValue(value, hashedValue, dataType, jwt) { | ||
return __awaiter(this, void 0, void 0, function () { | ||
var hashValueAlreadyExists, params, response; | ||
var params; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: | ||
if (!jwt) { | ||
return [2 /*return*/, ""]; | ||
} | ||
hashValueAlreadyExists = !!userHashedValues[dataType] && userHashedValues[dataType].includes(hashedValue); | ||
if (!!hashValueAlreadyExists) return [3 /*break*/, 2]; | ||
params = { | ||
@@ -94,15 +136,4 @@ value: value, | ||
case 1: | ||
response = _a.sent(); | ||
if (response.status == 201) { | ||
// update the local userHashedValues so that we don't re-encrypt it | ||
if (userHashedValues[dataType]) { | ||
userHashedValues[dataType].push(hashedValue); | ||
} | ||
else { | ||
userHashedValues[dataType] = [hashedValue]; | ||
} | ||
} | ||
setUserHashedValues(jwt); | ||
_a.label = 2; | ||
case 2: return [2 /*return*/]; | ||
_a.sent(); | ||
return [2 /*return*/]; | ||
} | ||
@@ -114,3 +145,3 @@ }); | ||
return __awaiter(this, void 0, void 0, function () { | ||
var response; | ||
var response, hashed_values; | ||
return __generator(this, function (_a) { | ||
@@ -121,3 +152,6 @@ switch (_a.label) { | ||
response = _a.sent(); | ||
userHashedValues = response.data; | ||
hashed_values = response.data; | ||
return [4 /*yield*/, file_1.storeHashedValues(hashed_values)]; | ||
case 2: | ||
_a.sent(); | ||
return [2 /*return*/]; | ||
@@ -128,1 +162,2 @@ } | ||
} | ||
exports.setUserHashedValues = setUserHashedValues; |
{ | ||
"name": "swdc-tracker", | ||
"version": "1.2.5", | ||
"version": "1.3.0", | ||
"description": "swdc event tracker", | ||
@@ -28,2 +28,3 @@ "main": "dist", | ||
"axios": "^0.19.2", | ||
"file-it": "^1.0.24", | ||
"libsodium": "^0.7.6", | ||
@@ -30,0 +31,0 @@ "libsodium-wrappers": "^0.7.6", |
@@ -1,2 +0,2 @@ | ||
import { hashValue } from "../utils/hash"; | ||
import { hashValues } from "../utils/hash"; | ||
@@ -32,4 +32,6 @@ // The file entity | ||
async buildPayload(jwt: string) { | ||
const hashedName = await hashValue(this.file_name.replace(/\\/g, "/"), "file_name", jwt); | ||
const hashedPath = await hashValue(this.file_path, "file_path", jwt); | ||
const hashedValues = await hashValues([ | ||
{ value: this.file_name.replace(/\\/g, "/"), dataType: "file_name" }, | ||
{ value: this.file_path, dataType: "file_path" } | ||
], jwt) | ||
@@ -39,4 +41,4 @@ return { | ||
data: { | ||
file_name: hashedName, | ||
file_path: hashedPath, | ||
file_name: hashedValues.file_name, | ||
file_path: hashedValues.file_path, | ||
syntax: this.syntax, | ||
@@ -43,0 +45,0 @@ line_count: this.line_count, |
@@ -1,2 +0,2 @@ | ||
import { hashValue } from "../utils/hash"; | ||
import { hashValues } from "../utils/hash"; | ||
@@ -23,11 +23,12 @@ // The project entity | ||
async buildPayload(jwt: string) { | ||
const hashedValues = await hashValues([ | ||
{ value: this.project_name, dataType: "project_name" }, | ||
{ value: this.project_directory, dataType: "project_directory" } | ||
], jwt) | ||
const hashedName = await hashValue(this.project_name, "project_name", jwt); | ||
const hashedDirectory = await hashValue(this.project_directory, "project_directory", jwt); | ||
return { | ||
schema: "iglu:com.software/project/jsonschema/1-0-0", | ||
data: { | ||
project_name: hashedName, | ||
project_directory: hashedDirectory | ||
project_name: hashedValues.project_name, | ||
project_directory: hashedValues.project_directory | ||
} | ||
@@ -34,0 +35,0 @@ } |
@@ -1,2 +0,2 @@ | ||
import { hashValue } from "../utils/hash"; | ||
import { hashValues } from "../utils/hash"; | ||
@@ -32,17 +32,18 @@ // The repo entity | ||
async buildPayload(jwt: string) { | ||
const hashedValues = await hashValues([ | ||
{ value: this.repo_name, dataType: "repo_name"}, | ||
{ value: this.repo_identifier, dataType: "repo_identifer"}, | ||
{ value: this.owner_id, dataType: "owner_id" }, | ||
{ value: this.git_branch, dataType: "git_branch" }, | ||
{ value: this.git_tag, dataType: "git_tag" }, | ||
], jwt) | ||
const hashedName = await hashValue(this.repo_name, "repo_name", jwt); | ||
const hashedIdentifier = await hashValue(this.repo_identifier, "repo_identifier", jwt); | ||
const hashedOwnerId = await hashValue(this.owner_id, "owner_id", jwt); | ||
const hashedGitBranch = await hashValue(this.git_branch, "git_branch", jwt); | ||
const hashedGitTag = await hashValue(this.git_tag, "git_tag", jwt); | ||
return { | ||
schema: "iglu:com.software/repo/jsonschema/1-0-0", | ||
data: { | ||
repo_identifier: hashedIdentifier, | ||
repo_name: hashedName, | ||
owner_id: hashedOwnerId, | ||
git_branch: hashedGitBranch, | ||
git_tag: hashedGitTag | ||
repo_identifier: hashedValues.repo_identifer, | ||
repo_name: hashedValues.repo_name, | ||
owner_id: hashedValues.owner_id, | ||
git_branch: hashedValues.git_branch, | ||
git_tag:hashedValues.git_tag | ||
} | ||
@@ -49,0 +50,0 @@ } |
@@ -10,3 +10,2 @@ import { setBaseUrl, get } from "./utils/http"; | ||
const snowplow = require("snowplow-tracker"); | ||
const emitter = snowplow.emitter; | ||
@@ -36,3 +35,2 @@ const tracker = snowplow.tracker; | ||
if (isTestMode()) { | ||
@@ -39,0 +37,0 @@ console.log('swdc-tracker test mode on. set env ENABLE_SWDC_TRACKER to "true" to send events'); |
@@ -8,3 +8,2 @@ import { CodeTime } from "../events/codetime"; | ||
import { Plugin } from "../entities/plugin"; | ||
import { UIInteraction } from "../events/ui_interaction"; | ||
import { UIElement } from "../entities/ui_element"; | ||
@@ -11,0 +10,0 @@ |
import { get, post } from "./http"; | ||
import { storeHashedValues, getStoredHashedValues } from "../utils/file"; | ||
@@ -6,15 +7,7 @@ const _sodium = require('libsodium-wrappers'); | ||
let userHashedValues: any = {}; | ||
let lastJwt: string = ""; | ||
export async function hashValue(value: string, dataType: string, jwt?: string) { | ||
if (!jwt) { | ||
return "" | ||
} | ||
if (!value) { | ||
return value; | ||
} | ||
export async function hashValues(payload: any, jwt: string) { | ||
if (sodium === undefined) { | ||
await Promise.all([setUserHashedValues(jwt), _sodium.ready]).then(() => { | ||
await Promise.resolve(_sodium.ready).then(() => { | ||
sodium = _sodium; | ||
@@ -24,41 +17,63 @@ }); | ||
const hashedValue = sodium.to_hex(sodium.crypto_generichash(64, value)); | ||
// if the jwt is different from the last fetch (different user, or initializing tracker) | ||
// fetch the hashed values and store them in ~/.software/hashed_values.json | ||
if(lastJwt !== jwt) { | ||
await setUserHashedValues(jwt); | ||
lastJwt = jwt; | ||
} | ||
await encryptValue(value, hashedValue, dataType, jwt); | ||
let result: any = {} | ||
return hashedValue; | ||
for (const hashPayload of payload) { | ||
if(hashPayload.value?.length) { | ||
const hashedValue = sodium.to_hex(sodium.crypto_generichash(64, hashPayload.value)); | ||
const alreadyEncrypted = await hasHashValueInCache(hashPayload.dataType, hashedValue); | ||
if(!alreadyEncrypted) { | ||
await encryptValue(hashPayload.value, hashedValue, hashPayload.dataType, jwt) | ||
} | ||
result[hashPayload.dataType] = hashedValue; | ||
} else { | ||
result[hashPayload.dataType] = hashPayload.value; | ||
} | ||
}; | ||
return result; | ||
} | ||
async function encryptValue(value: string, hashedValue: string, dataType: string, jwt?: string) { | ||
if (!jwt) { | ||
return "" | ||
export async function hasHashValueInCache(dataType: string, hashedValue: string) { | ||
let userHashedValues = getStoredHashedValues(); | ||
// add dataType to userHashedValues cache if it doesn't already exist | ||
if(!userHashedValues[dataType]) { | ||
userHashedValues[dataType] = [] | ||
} | ||
const hashValueAlreadyExists = !!userHashedValues[dataType] && userHashedValues[dataType].includes(hashedValue); | ||
const hasValue = userHashedValues[dataType].includes(hashedValue); | ||
if(!hashValueAlreadyExists) { | ||
const params = { | ||
value: value, | ||
hashed_value: hashedValue, | ||
data_type: dataType | ||
} | ||
// if it does not have the value, add it | ||
if(!hasValue) { | ||
userHashedValues[dataType].push(hashedValue) | ||
storeHashedValues(userHashedValues); | ||
} | ||
const response = await post("/user_encrypted_data", params, jwt); | ||
// return the result of hasValue | ||
return hasValue | ||
} | ||
if(response.status == 201) { | ||
// update the local userHashedValues so that we don't re-encrypt it | ||
if(userHashedValues[dataType]) { | ||
userHashedValues[dataType].push(hashedValue); | ||
} else { | ||
userHashedValues[dataType] = [hashedValue] | ||
} | ||
} | ||
async function encryptValue(value: string, hashedValue: string, dataType: string, jwt: string) { | ||
const params = { | ||
value: value, | ||
hashed_value: hashedValue, | ||
data_type: dataType | ||
} | ||
setUserHashedValues(jwt); | ||
} | ||
await post("/user_encrypted_data", params, jwt); | ||
} | ||
async function setUserHashedValues(jwt: string) { | ||
export async function setUserHashedValues(jwt: string) { | ||
const response = await get("/hashed_values", jwt); | ||
userHashedValues = response.data; | ||
const hashed_values = response.data; | ||
await storeHashedValues(hashed_values); | ||
} |
@@ -1,2 +0,5 @@ | ||
import { hashValue } from "../../src/utils/hash"; | ||
import { | ||
hashValues, | ||
hasHashValueInCache, | ||
} from "../../src/utils/hash"; | ||
import { expect } from 'chai' | ||
@@ -7,121 +10,47 @@ | ||
describe("Hash Utility", function () { | ||
describe("hashedValues", function () { | ||
const sandbox = sinon.createSandbox(); | ||
context("when the JWT is not supplied", async function () { | ||
beforeEach(function () { | ||
// return any api since we're not really trying to call out | ||
sandbox.stub(http, "get").callsFake(function () { | ||
return { data: {} } | ||
}); | ||
sandbox.stub(http, "post").callsFake(function () { | ||
return { status: 201 } | ||
}) | ||
beforeEach(function () { | ||
sandbox.stub(http, "get").callsFake(function () { | ||
return { data: {} } | ||
}); | ||
afterEach(function () { | ||
sandbox.restore(); | ||
sandbox.stub(http, "post").callsFake(function () { | ||
return { status: 201 } | ||
}); | ||
let string_param = "something"; | ||
it("returns empty string", async function () { | ||
expect(await hashValue(string_param, "test-data-type")).to.equal(""); | ||
}); | ||
it("does NOT encrypt the value", async function () { | ||
await hashValue(string_param, "test-data-type") | ||
expect(http.post.callCount).to.eq(0) | ||
}); | ||
it("does not get hashed_values", async function () { | ||
await hashValue(string_param, "test-data-type") | ||
expect(http.get.callCount).to.eq(0) | ||
}); | ||
}); | ||
context("when the parameter is empty string", async function () { | ||
let string_param = ""; | ||
it("returns empty string", async function () { | ||
expect(await hashValue(string_param, "test-data-type", "test-jwt")).to.equal(""); | ||
}); | ||
afterEach(function () { | ||
sandbox.restore(); | ||
}); | ||
context("when the parameter is a string", async function () { | ||
// the first hashed value in file_name = "alreadyexists" | ||
let hashedValueThatAlreadyExists = "b6462a82e047f8fd12103ddeace50a4024f88cbcaf01c8705ff6a741408d3df1d70c57e65f80409d1098797b3dd428812443eef566e4dcbab2168734bacdc501" | ||
let userHashedValues = { | ||
"file_name": [hashedValueThatAlreadyExists, "fasdfsda", "asdfasdfsdew"], | ||
"project_name": ["bbaljbl", "fjsfiejwil", "faksdjfjsad"] | ||
}; | ||
let string_param = "secret_message"; | ||
let expectedHashedValue = '998504e62163ab1030d14ec90ba2d4e4dd87707f2591fcdcb6473e6f6c260778cdaed8b9e913b3965b9ab331553eedcbfb877b3268c3fa414a4cb09a5b30ee05' | ||
it("returns the expected map of values", async function() { | ||
const payload = [ | ||
{ value: "/Users/bob/test_app/", dataType: "file_path" }, | ||
{ value: "/Users/bob/test_app/path.js", dataType: "file_name" }, | ||
{ value: "", dataType: "empty_string" }, | ||
{ value: null, dataType: "null_value" } | ||
] | ||
beforeEach(function() { | ||
// return any api since we're not really trying to call out | ||
sandbox.stub(http, "get").callsFake(function () { | ||
return { data: userHashedValues } | ||
}); | ||
const result = await hashValues(payload, 'jwt-token'); | ||
expect(result.file_path).to.eql("e318cb72390f272c992c878c8f3e712b6dbbd5cf3b94b304eb7529f466c8bcded0312445c0af17ee5f7e48b816b9fe1c43fd7e10a46e7c35272a56bd33ddc149") | ||
expect(result.file_name).to.eql("4a3bede4a465f6d4e95019a6a6c90fbf972e96b4c10eef3f08a576f22e83f69f7876946f1fb0effdab730ec4d6cd10cd71ba8da195e4e3967e4d25ee8df39576") | ||
expect(result.null_value).to.eql(null) | ||
expect(result.empty_string).to.eql("") | ||
}); | ||
sandbox.stub(http, "post").callsFake().callsFake(function () { | ||
return { status: 201 } | ||
}) | ||
describe("hasHashValueInCache", function() { | ||
it("returns false if the hash value does not exist", async function() { | ||
const result = await hasHashValueInCache("file_path", "12345"); | ||
expect(result).to.eq(false); | ||
}); | ||
afterEach(function() { | ||
sandbox.restore(); | ||
it("adds the value if it does not exist", async function() { | ||
await hasHashValueInCache("foobar", "54321"); | ||
const result = await hasHashValueInCache("foobar", "54321"); | ||
expect(result).to.eq(true); | ||
}); | ||
it("returns a hashed string with 128 character length", async function () { | ||
let result = await hashValue(string_param, "project_name", 'test-jwt'); | ||
expect(result).to.be.a('string') | ||
.that.matches(/^[a-f0-9]{128}$/) | ||
.and.equal(expectedHashedValue); | ||
}); | ||
it("gets the user's hashed values", async function () { | ||
await hashValue(string_param, "test-data-type", "test-jwt"); | ||
expect(http.get.calledWith("/hashed_values", "test-jwt")).to.eq(true) | ||
}); | ||
context("when user hashed value does not exist", function() { | ||
it("encrypts the value", async function() { | ||
await hashValue("wow", "test-data-type", "test-jwt"); | ||
expect(http.post.calledWith( | ||
"/user_encrypted_data", | ||
{ | ||
value: "wow", | ||
hashed_value: "ec52cc2cca29bc83f1d1f6916b885a52ac694d386ea8d1a9798f01aafc75d3bffc94f4d6ef21d354a4992ecbaa784a1d226347a043beac323ce7d500577290f7", | ||
data_type: "test-data-type" | ||
}, | ||
"test-jwt" | ||
)).to.eq(true) | ||
}) | ||
it("gets the hashedValue list for the user", async function() { | ||
await hashValue("cool", "test-data-type", "test-jwt"); | ||
expect(http.get.callCount).to.eq(1) | ||
}) | ||
}); | ||
context("when the user hashed value already exists", function() { | ||
it("does NOT encrypt the value", async function() { | ||
await hashValue("alreadyexists", "file_name", "test-jwt"); | ||
expect(http.post.callCount).to.eq(0) | ||
}); | ||
it("does NOT GET the hashedValue list for the user", async function() { | ||
await hashValue("alreadyexists", "file_name", "test-jwt"); | ||
expect(http.get.callCount).to.eq(0) | ||
}) | ||
it("returns a hashed string with 128 character length", async function () { | ||
const result = await hashValue("alreadyexists", "file_name", "test-jwt"); | ||
expect(result).to.be.a('string') | ||
.that.matches(/^[a-f0-9]{128}$/) | ||
.and.equal(hashedValueThatAlreadyExists); | ||
}); | ||
}) | ||
}); | ||
}); | ||
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
127983
61
2723
7
3
+ Addedfile-it@^1.0.24
+ Added@types/universalify@1.0.3(transitive)
+ Addedfile-it@1.1.5(transitive)
+ Addeduniversalify@2.0.1(transitive)