Unit test fixes
This commit is contained in:
@@ -15,6 +15,8 @@ test(`connect fails when error occurs during createConnection`, async () => {
|
||||
test(`socket receive data fails when decryption fails`, async () => {
|
||||
let cbl = {};
|
||||
const socket = {
|
||||
setNoDelay: () => {},
|
||||
setKeepAlive: () => {},
|
||||
on: (name, cb) => {
|
||||
cbl[name] = cb;
|
||||
},
|
||||
@@ -40,6 +42,8 @@ test(`socket receive data fails when decryption fails`, async () => {
|
||||
|
||||
test(`disconnect succeeds if an error is thrown`, async () => {
|
||||
const socket = {
|
||||
setNoDelay: () => {},
|
||||
setKeepAlive: () => {},
|
||||
destroy: () => {
|
||||
throw new Error('mock destroy error');
|
||||
},
|
||||
@@ -53,6 +57,8 @@ test(`disconnect succeeds if an error is thrown`, async () => {
|
||||
test(`send fails on socket error`, async () => {
|
||||
let cbl = {};
|
||||
const socket = {
|
||||
setNoDelay: () => {},
|
||||
setKeepAlive: () => {},
|
||||
on: (name, cb) => {
|
||||
cbl[name] = cb;
|
||||
},
|
||||
@@ -70,6 +76,8 @@ test(`send fails on socket error`, async () => {
|
||||
test(`error is thrown when socket is closed`, async () => {
|
||||
let cbl = {};
|
||||
const socket = {
|
||||
setNoDelay: () => {},
|
||||
setKeepAlive: () => {},
|
||||
on: (name, cb) => {
|
||||
cbl[name] = cb;
|
||||
},
|
||||
@@ -87,6 +95,8 @@ test(`error is thrown when socket is closed`, async () => {
|
||||
test(`send fails when write error occurs`, async () => {
|
||||
let cbl = {};
|
||||
const socket = {
|
||||
setNoDelay: () => {},
|
||||
setKeepAlive: () => {},
|
||||
on: (name, cb) => {
|
||||
cbl[name] = cb;
|
||||
},
|
||||
|
||||
@@ -24,7 +24,7 @@ export default class packet {
|
||||
this.token = token;
|
||||
}
|
||||
|
||||
buffer = null;
|
||||
buffer = new Uint8Array(0);
|
||||
decode_offset = 0;
|
||||
token;
|
||||
|
||||
@@ -180,9 +180,11 @@ export default class packet {
|
||||
...this.buffer.slice(nonce.length + mac.length),
|
||||
...this.buffer.slice(nonce.length, nonce.length + mac.length),
|
||||
]);
|
||||
this.buffer = Buffer.from(
|
||||
new XChaCha20Poly1305(key).open(nonce, this.buffer, aad)
|
||||
);
|
||||
const result = new XChaCha20Poly1305(key).open(nonce, this.buffer, aad);
|
||||
if (!result) {
|
||||
throw new Error('decryption failed');
|
||||
}
|
||||
this.buffer = Buffer.from(result);
|
||||
}
|
||||
|
||||
this.buffer = new Uint8Array(this.buffer);
|
||||
|
||||
Reference in New Issue
Block a user