Skip to content

Commit

Permalink
Reorganize old auth tests
Browse files Browse the repository at this point in the history
Moved them into the test-auth.js test and reformated things a little bit to
be in sync with the projects overall style.
  • Loading branch information
felixge committed Sep 2, 2010
1 parent 41b0091 commit a303d9b
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 83 deletions.
14 changes: 7 additions & 7 deletions lib/mysql/auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,13 +115,13 @@ exports.fmt32 = function(x){
var a = x[0].toString(16);
var b = x[1].toString(16);

if (a.length == 1) a = "000"+a;
if (a.length == 2) a = "00"+a;
if (a.length == 3) a = "0"+a;
if (b.length == 1) b = "000"+b;
if (b.length == 2) b = "00"+b;
if (b.length == 3) b = "0"+b;
return "" + a + '/' + b;
if (a.length == 1) a = '000'+a;
if (a.length == 2) a = '00'+a;
if (a.length == 3) a = '0'+a;
if (b.length == 1) b = '000'+b;
if (b.length == 2) b = '00'+b;
if (b.length == 3) b = '0'+b;
return '' + a + '/' + b;
}

exports.xor32 = function(a,b){
Expand Down
76 changes: 0 additions & 76 deletions test/simple/test-auth-old.js

This file was deleted.

71 changes: 71 additions & 0 deletions test/simple/test-auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,74 @@ test(function token() {
assert.deepEqual(auth.token(null, SCRAMBLE), new Buffer(0));
})();
});

test(function hashPassword() {
function verify(password, bytes){
var expected = new Buffer(bytes);
var actual = auth.hashPassword(password);

assert.deepEqual(actual, expected);
}

verify('root', [0x67, 0x45, 0x7E, 0x22, 0x6a, 0x1a, 0x15, 0xbd]);
verify('long password test', [0x6c, 0x24, 0x68, 0x41, 0x2c, 0xa6, 0x86, 0x56]);
verify('saf789yasfbsd89f', [0x6c, 0x9b, 0x2f, 0x07, 0x17, 0xeb, 0x95, 0xc6]);
});


test(function randomInit() {
function verify(in1, in2, out1, out2){
var r = auth.randomInit(in1, in2);
assert.equal(out1, r.seed1);
assert.equal(out2, r.seed2);
}

verify(0x00000000, 0x00000000, 0x00000000, 0x00000000);
verify(0x0000FFFF, 0x0000FFFF, 0x0000ffff, 0x0000ffff);
verify(0x50000000, 0x50000000, 0x10000001, 0x10000001);
verify(0xFFFFFFFF, 0xFFFFFFFF, 0x00000003, 0x00000003);
verify(3252345, 7149734, 0x0031a079, 0x006d18a6);
});

test(function myRnd() {
function verifySequence(seed1, seed2, expected){
var r = auth.randomInit(seed1, seed2);
for (var i = 0; i < expected.length; i++){
var n = auth.myRnd(r);

// we will test to 14 digits, since
// we only ever use this function mutliplied
// by small numbers anyway

var a = ':'+n;
var b = ':'+expected[i];

assert.equal(a.substr(1, 16), b.substr(1, 16));
}
}

verifySequence(3252345, 7149734, [
0.0157456556481734,
0.0696413620092360,
0.3009698738353047,
0.2959253138824602,
0.5767169786400320,
0.9958089822864243,
0.2488940062456708,
0.2570431151027261,
0.5385335875102631,
0.9215386229767824,
]);
});

test(function scramble323() {
function verify(message, password, bytes){
var expected = new Buffer(bytes);
var actual = auth.scramble323(new Buffer(message), password);

assert.deepEqual(actual, expected);
}

verify('8bytesofstuff', 'root', [0x5a, 0x4d, 0x46, 0x47, 0x43, 0x53, 0x58, 0x5f]);
verify('e8cf00cec9ec825af22', 'saf789yasfbsd', [0x4d, 0x54, 0x5b, 0x47, 0x5f, 0x52, 0x4d, 0x45]);
});

0 comments on commit a303d9b

Please sign in to comment.