-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcrypto.test.js
33 lines (30 loc) · 1.08 KB
/
crypto.test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
const crypto = require("./crypto")
const c = require("crypto")
describe("crypto", ()=>{
it("should hash passwords to fixed length", ()=>{
const salt = c.randomBytes(16)
const hashed = crypto.hashPass("uh oh stinky", salt)
expect(hashed.length).equal(32)
})
it ("should hash passwords", ()=> {
const salt = c.randomBytes(16)
const hash1 = crypto.hashPass("pop", salt)
const hash2 = crypto.hashPass("poop", salt)
expect(hash1).to.not.equal(hash2)
})
it("should encrypt and decrypt text", ()=> {
const raw = JSON.stringify({
key1: "value1",
key2: "value2"
})
const password = "mypass"
const encrypted = crypto.encode(raw, password)
const decoded = crypto.decode(encrypted, password)
expect(decoded).equal(raw)
})
it("should decode wrong", ()=> {
const encrypted = crypto.encode("uh oh stinky", "passwordpassword")
let decrypted = crypto.decode(encrypted, "wrong pass")
expect(decrypted).to.not.equal("uh oh stinky")
})
})