yaml-crypt
Advanced tools
Comparing version 0.4.1 to 0.4.2
{ | ||
"name": "yaml-crypt", | ||
"version": "0.4.1", | ||
"version": "0.4.2", | ||
"description": "Encrypt and decrypt YAML documents", | ||
@@ -27,5 +27,5 @@ "license": "MIT", | ||
"argparse": "^1.0.7", | ||
"branca": "^0.2.0", | ||
"branca": "^0.3.0", | ||
"fernet": "^0.3.1", | ||
"js-yaml": "^3.12.0", | ||
"js-yaml": "^3.12.1", | ||
"pkginfo": "^0.4.1", | ||
@@ -40,5 +40,5 @@ "tmp": "^0.0.33", | ||
"mocha": "^5.1.0", | ||
"nyc": "^13.0.1", | ||
"nyc": "^13.2.0", | ||
"prettier": "^1.15.3" | ||
} | ||
} |
@@ -10,4 +10,5 @@ const fs = require("fs"); | ||
const crypto = require("../lib/crypto"); | ||
const { setupCrypto, decryptBranca } = require("./crypto-util"); | ||
require("./crypto-util").setupCrypto(); | ||
setupCrypto(); | ||
@@ -27,10 +28,6 @@ describe("crypto", () => { | ||
it("should return the encrypted content (branca)", () => { | ||
const result = crypto.encrypt( | ||
"branca", | ||
"aehae5Ui0Eechaeghau9Yoh9jufiep7H", | ||
"Hello, world!" | ||
); | ||
expect(result).to.equal( | ||
"XUvrtHkyXTh1VUW885Ta4V5eQ3hBMFQMC3S3QwEfWzKWVDt3A5TnVUNtVXubi0fsAA8eerahpobwC8" | ||
); | ||
const key = "aehae5Ui0Eechaeghau9Yoh9jufiep7H"; | ||
const result = crypto.encrypt("branca", key, "Hello, world!"); | ||
expect(result).to.be.not.empty; | ||
expect(decryptBranca(key, result)).to.equal("Hello, world!"); | ||
}); | ||
@@ -37,0 +34,0 @@ |
@@ -1,4 +0,3 @@ | ||
const crypto = require("../lib/crypto"); | ||
const fernet = require("fernet"); | ||
const branca = require("branca"); | ||
@@ -19,8 +18,10 @@ /** | ||
}; | ||
} | ||
// Branca: | ||
crypto.__brancaDefaults.ts = 1; | ||
crypto.__brancaDefaults.nonce = Buffer.alloc(24, 1); | ||
function decryptBranca(key, msg) { | ||
return branca(key) | ||
.decode(msg) | ||
.toString(); | ||
} | ||
module.exports.setupCrypto = setupCrypto; | ||
module.exports = { setupCrypto, decryptBranca }; |
@@ -125,3 +125,3 @@ const fs = require("fs"); | ||
const output = fs.readFileSync(input.name + "-crypt"); | ||
const expected = fs.readFileSync("./test/test-2a.yaml-crypt"); | ||
const expected = fs.readFileSync("./test/test-2.yaml-crypt"); | ||
expect(output.toString("utf8")).to.equal(expected.toString("utf8")); | ||
@@ -135,4 +135,3 @@ }); | ||
const output = fs.readFileSync(input.name + "-crypt"); | ||
const expected = fs.readFileSync("./test/test-2b.yaml-crypt"); | ||
expect(output.toString("utf8")).to.equal(expected.toString("utf8")); | ||
expect(output.toString("utf8")).to.not.be.empty; | ||
}); | ||
@@ -142,3 +141,3 @@ | ||
const input = tmp.fileSync({ postfix: ".yaml-crypt" }); | ||
fs.copyFileSync("./test/test-2a.yaml-crypt", input.name); | ||
fs.copyFileSync("./test/test-2.yaml-crypt", input.name); | ||
runWithKeyFile([input.name], {}, { stdout: new Out() }); | ||
@@ -154,4 +153,4 @@ const output = fs.readFileSync( | ||
const tmpdir = tmp.dirSync(); | ||
fs.copyFileSync("./test/test-2a.yaml-crypt", `${tmpdir.name}/1.yaml-crypt`); | ||
fs.copyFileSync("./test/test-2a.yaml-crypt", `${tmpdir.name}/2.yml-crypt`); | ||
fs.copyFileSync("./test/test-2.yaml-crypt", `${tmpdir.name}/1.yaml-crypt`); | ||
fs.copyFileSync("./test/test-2.yaml-crypt", `${tmpdir.name}/2.yml-crypt`); | ||
runWithKeyFile(["--dir", tmpdir.name], {}, { stdout: new Out() }); | ||
@@ -203,3 +202,3 @@ const expected = fs.readFileSync("./test/test-2.yaml"); | ||
const input = tmp.fileSync({ postfix: ".yaml-crypt" }); | ||
fs.copyFileSync("./test/test-2a.yaml-crypt", input.name); | ||
fs.copyFileSync("./test/test-2.yaml-crypt", input.name); | ||
const keyFile = tmp.fileSync(); | ||
@@ -224,3 +223,3 @@ fs.writeFileSync(keyFile.name, "aehae5Ui0Eechaeghau9Yoh9jufiep7H"); | ||
const input = tmp.fileSync({ postfix: ".yaml-crypt" }); | ||
fs.copyFileSync("./test/test-2a.yaml-crypt", input.name); | ||
fs.copyFileSync("./test/test-2.yaml-crypt", input.name); | ||
expect(() => | ||
@@ -269,3 +268,3 @@ yamlcryptcli.run( | ||
const options = { | ||
stdin: fs.readFileSync("./test/test-2a.yaml-crypt"), | ||
stdin: fs.readFileSync("./test/test-2.yaml-crypt"), | ||
stdout: new Out() | ||
@@ -318,3 +317,3 @@ }; | ||
const input = tmp.fileSync({ postfix: ".yaml-crypt" }); | ||
fs.copyFileSync("./test/test-2a.yaml-crypt", input.name); | ||
fs.copyFileSync("./test/test-2.yaml-crypt", input.name); | ||
@@ -328,5 +327,5 @@ yamlcryptcli.run( | ||
const output = fs.readFileSync(input.name); | ||
const expected = fs.readFileSync("./test/test-2a.yaml-crypt"); | ||
const expected = fs.readFileSync("./test/test-2.yaml-crypt"); | ||
expect(output.toString("utf8")).to.equal(expected.toString("utf8")); | ||
}); | ||
}); |
@@ -12,4 +12,5 @@ const fs = require("fs"); | ||
const { loadConfig, yamlcrypt } = require("../lib/yaml-crypt"); | ||
const { setupCrypto, decryptBranca } = require("./crypto-util"); | ||
require("./crypto-util").setupCrypto(); | ||
setupCrypto(); | ||
@@ -48,2 +49,9 @@ describe("yaml-crypt", () => { | ||
it("should return the default config file", () => { | ||
const home = tmp.dirSync(); | ||
const config = loadConfig({ home: home.name }); | ||
expect(config).to.not.be.null; | ||
expect(config.keys).to.be.undefined; | ||
}); | ||
it("should read the decrypted content", () => { | ||
@@ -84,13 +92,9 @@ const yaml = yamlcrypt({ keys: "aehae5Ui0Eechaeghau9Yoh9jufiep7H" }); | ||
it("should return the encrypted raw content", () => { | ||
const yaml = yamlcrypt({ | ||
encryptionKey: "aehae5Ui0Eechaeghau9Yoh9jufiep7H" | ||
}); | ||
const expected = fs | ||
.readFileSync("./test/test-7.yaml-crypt") | ||
.toString("utf8"); | ||
const key = "aehae5Ui0Eechaeghau9Yoh9jufiep7H"; | ||
const yaml = yamlcrypt({ encryptionKey: key }); | ||
const str = "Hello!"; | ||
const result1 = yaml.encrypt(str, { algorithm: "branca", raw: true }); | ||
const result2 = yaml.encryptAll(str, { algorithm: "branca", raw: true }); | ||
expect(result1).to.equal(expected.trim()); | ||
expect(result2).to.equal(expected.trim()); | ||
expect(decryptBranca(key, result1)).to.equal(str); | ||
expect(decryptBranca(key, result2)).to.equal(str); | ||
}); | ||
@@ -126,8 +130,7 @@ | ||
const yaml = yamlcrypt({ keys: "aehae5Ui0Eechaeghau9Yoh9jufiep7H" }); | ||
const content1 = fs.readFileSync("./test/test-6a.yaml-crypt"); | ||
const content2 = fs.readFileSync("./test/test-6b.yaml-crypt"); | ||
const content1 = fs.readFileSync("./test/test-6.yaml-crypt"); | ||
const transformed = yaml.transform(content1, str => | ||
str.replace("Hello!", "Hello, world!") | ||
); | ||
expect(transformed).to.equal(content2.toString()); | ||
expect(transformed).to.not.equal(content1.toString()); | ||
}); | ||
@@ -137,5 +140,5 @@ | ||
const yaml = yamlcrypt({ keys: "aehae5Ui0Eechaeghau9Yoh9jufiep7H" }); | ||
const expected = fs.readFileSync("./test/test-1b.yaml-crypt"); | ||
const expected = fs.readFileSync("./test/test-1a.yaml-crypt"); | ||
const newContent = | ||
"key1: !<!yaml-crypt/fernet> Hello, world!\nkey2: !<!yaml-crypt/branca> Hello, world!"; | ||
"key1: !<!yaml-crypt/fernet> Hello, world!\nkey2: !<!yaml-crypt/fernet> Hello, world!"; | ||
const transformed = yaml.transform("", () => newContent); | ||
@@ -158,5 +161,3 @@ expect(transformed).to.equal(expected.toString()); | ||
); | ||
expect(transformed).to.equal( | ||
"XUvrtHkyXTh1VUW885Ta4V5eQ3hBMFQMC3S3QwEfWzKWVDt3A5TnVUNtVXubi0fsAA8eerahpobwC8" | ||
); | ||
expect(transformed).to.not.equal(content); | ||
}); | ||
@@ -163,0 +164,0 @@ |
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
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
67797
25
1894
+ Addedbranca@0.3.0(transitive)
- Removedbranca@0.2.0(transitive)
Updatedbranca@^0.3.0
Updatedjs-yaml@^3.12.1