1
0
Fork 0
mirror of https://github.com/SunRed/haste-server.git synced 2025-09-04 04:50:14 +02:00

Rewrote key generator tests, fixed vowels

-Tests were not brought up to date with some updates that were done to key generator modules.
-Apparently original creator had no idea that 'y' is a vowel; fixed this issue and reflected changes in actual files.
This commit is contained in:
zneix 2020-09-23 01:07:32 +02:00
parent d2c5641886
commit 7808ccf009
WARNING! Although there is a key with this ID in the database it does not verify this commit! This commit is SUSPICIOUS.
GPG key ID: 911916E0523B22F6
7 changed files with 55 additions and 65 deletions

View file

@ -0,0 +1,28 @@
/* global describe, it */
const fs = require('fs');
const assert = require('assert');
const Generator = require('../../lib/key_generators/dictionary');
const tmpPath = '/tmp/haste-server-test-dictionary';
describe('KeyGenerator', () => {
describe('dictionary', () => {
it('should throw an error if given no path', () => {
assert.throws(() => { new Generator(); });
});
it('should throw an error if given invalid path', () => {
if (fs.existsSync(tmpPath)) fs.unlinkSync(tmpPath);
assert.throws(() => { new Generator({path: tmpPath}); });
});
it('should return a key of the proper number of words from the given dictionary', () => {
const words = ['xd'];
fs.writeFileSync(tmpPath, words.join('\n'));
const gen = new Generator({path: tmpPath});
assert.strictEqual('xdxdxd', gen.createKey(3));
});
});
});

View file

@ -1,33 +0,0 @@
/* global describe, it */
const assert = require('assert');
const fs = require('fs');
const Generator = require('../../lib/key_generators/dictionary');
describe('RandomKeyGenerator', function(){
describe('randomKey', function(){
it('should throw an error if given no options', () => {
assert.throws(() => {
new Generator();
}, Error);
});
it('should throw an error if given no path', () => {
assert.throws(() => {
new Generator({});
}, Error);
});
it('should return a key of the proper number of words from the given dictionary', () => {
const path = '/tmp/haste-server-test-dictionary';
const words = ['cat'];
fs.writeFileSync(path, words.join('\n'));
const gen = new Generator({path}, () => {
assert.equal('catcatcat', gen.createKey(3));
});
});
});
});

View file

@ -1,27 +1,23 @@
/* global describe, it */
const assert = require('assert');
const Generator = require('../../lib/key_generators/phonetic');
const vowels = 'aeiou';
const consonants = 'bcdfghjklmnpqrstvwxyz';
describe('RandomKeyGenerator', () => {
describe('randomKey', () => {
describe('KeyGenerator', () => {
describe('phonetic', () => {
it('should return a key of the proper length', () => {
const gen = new Generator();
assert.equal(6, gen.createKey(6).length);
assert.strictEqual(6, gen.createKey(6).length);
});
it('should alternate consonants and vowels', () => {
const gen = new Generator();
const vowels = 'aeiouy';
const key = gen.createKey(3);
assert.ok(consonants.includes(key[0]));
assert.ok(consonants.includes(key[2]));
assert.ok(vowels.includes(key[1]));
if (vowels.includes(key[0])) assert.ok(vowels.includes(key[2]));
else assert.ok(vowels.includes(key[1]));
});
});
});

View file

@ -1,19 +1,18 @@
/* global describe, it */
const assert = require('assert');
const Generator = require('../../lib/key_generators/random');
describe('RandomKeyGenerator', () => {
describe('randomKey', () => {
describe('KeyGenerator', () => {
describe('random', () => {
it('should return a key of the proper length', () => {
const gen = new Generator();
assert.equal(6, gen.createKey(6).length);
assert.strictEqual(6, gen.createKey(6).length);
});
it('should use a key from the given keyset if given', () => {
const gen = new Generator({keyspace: 'A'});
assert.equal('AAAAAA', gen.createKey(6));
assert.strictEqual('AAAAAA', gen.createKey(6));
});
});
});