Files
noVNC/tests/test.base64.js
T

34 lines
1.2 KiB
JavaScript
Raw Normal View History

2018-05-24 00:27:09 +03:00
const expect = chai.expect;
2014-05-06 15:11:31 -04:00
2017-02-05 12:34:47 -05:00
import Base64 from '../core/base64.js';
2018-09-06 17:34:15 +02:00
describe('Base64 Tools', function () {
2014-05-06 15:11:31 -04:00
"use strict";
2018-05-24 00:27:09 +03:00
const BIN_ARR = new Array(256);
for (let i = 0; i < 256; i++) {
2014-05-06 15:11:31 -04:00
BIN_ARR[i] = i;
}
2017-05-13 01:45:23 +02:00
2018-05-24 00:27:09 +03:00
const B64_STR = "AAECAwQFBgcICQoLDA0ODxAREhMUFRYXGBkaGxwdHh8gISIjJCUmJygpKissLS4vMDEyMzQ1Njc4OTo7PD0+P0BBQkNERUZHSElKS0xNTk9QUVJTVFVWV1hZWltcXV5fYGFiY2RlZmdoaWprbG1ub3BxcnN0dXZ3eHl6e3x9fn+AgYKDhIWGh4iJiouMjY6PkJGSk5SVlpeYmZqbnJ2en6ChoqOkpaanqKmqq6ytrq+wsbKztLW2t7i5uru8vb6/wMHCw8TFxsfIycrLzM3Oz9DR0tPU1dbX2Nna29zd3t/g4eLj5OXm5+jp6uvs7e7v8PHy8/T19vf4+fr7/P3+/w==";
2014-05-06 15:11:31 -04:00
2018-09-06 17:34:15 +02:00
describe('encode', function () {
it('should encode a binary string into Base64', function () {
2018-05-24 00:27:09 +03:00
const encoded = Base64.encode(BIN_ARR);
2014-05-06 15:11:31 -04:00
expect(encoded).to.equal(B64_STR);
});
});
2018-09-06 17:34:15 +02:00
describe('decode', function () {
it('should decode a Base64 string into a normal string', function () {
2018-05-24 00:27:09 +03:00
const decoded = Base64.decode(B64_STR);
2014-05-06 15:11:31 -04:00
expect(decoded).to.deep.equal(BIN_ARR);
});
2018-09-06 17:34:15 +02:00
it('should throw an error if we have extra characters at the end of the string', function () {
expect(() => Base64.decode(B64_STR+'abcdef')).to.throw(Error);
2014-05-06 15:11:31 -04:00
});
});
});