Skip to content

Commit

Permalink
[test] Update tests to test returned encodings and remove generate_ke…
Browse files Browse the repository at this point in the history
…y_ascii tests
  • Loading branch information
markbao committed Jan 23, 2016
1 parent 461263e commit 14cb7e9
Showing 1 changed file with 7 additions and 12 deletions.
19 changes: 7 additions & 12 deletions test/generate.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

var chai = require('chai');
var assert = chai.assert;
var base32 = require('base32.js');
var speakeasy = require('..');

// These tests use the information from RFC 4226's Appendix D: Test Values.
Expand All @@ -14,11 +15,17 @@ describe('Generator tests', function () {
it('Normal generation with defaults', function () {
var secret = speakeasy.generate_key();
assert.equal(secret.ascii.length, 32, 'Should return the correct length');

// check returned fields
assert.isDefined(secret.google_auth_url, 'Google Auth URL should be returned')
assert.isUndefined(secret.qr_code_ascii, 'QR Code ASCII should not be returned')
assert.isUndefined(secret.qr_code_hex, 'QR Code Hex should not be returned')
assert.isUndefined(secret.qr_code_base32, 'QR Code Base 32 should not be returned')
assert.isUndefined(secret.google_auth_qr, 'Google Auth QR should not be returned')

// check encodings
assert.equal(Buffer(secret.hex, 'hex').toString('ascii'), secret.ascii, 'Should have encoded correct hex string');
assert.equal(base32.decode(secret.base32).toString('ascii'), secret.ascii, 'Should have encoded correct base32 string');
});

it('Generation with custom key length', function () {
Expand Down Expand Up @@ -48,16 +55,4 @@ describe('Generator tests', function () {
assert.isDefined(secret.google_auth_qr, 'Google Auth QR should be returned')
});

it('Testing generate_key_ascii with defaults', function () {
var secret = speakeasy.generate_key_ascii();
assert.equal(secret.length, 32, 'Should return the correct length');
assert.ok(/^[a-z0-9]+$/i.test(secret.ascii), 'Should return an alphanumeric key');
});

it('Testing generate_key_ascii with custom length', function () {
var secret = speakeasy.generate_key_ascii(20);
assert.equal(secret.length, 20, 'Should return the correct length');
assert.ok(/^[a-z0-9]+$/i.test(secret.ascii), 'Should return an alphanumeric key');
});

});

0 comments on commit 14cb7e9

Please sign in to comment.