Skip to content

Commit

Permalink
fixtures and test for randomInit
Browse files Browse the repository at this point in the history
  • Loading branch information
iamcal authored and felixge committed Sep 2, 2010
1 parent 8ab6841 commit 274280b
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 6 deletions.
12 changes: 6 additions & 6 deletions lib/mysql/auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,13 +66,13 @@ exports.hashPassword = function(password) {
return result;
};

exports.randomInit = function(rand_struct, seed1, seed2) {
exports.randomInit = function(seed1, seed2) {

rand_struct = {
max_value : 0x3FFFFFFFL,
max_value_dbl : 0x3FFFFFFFL,
seed1 : seed1 % 0x3FFFFFFFL,
seed2 : seed1 % 0x3FFFFFFFL,
return {
max_value : 0x3FFFFFFF,
max_value_dbl : 0x3FFFFFFF,
seed1 : seed1 % 0x3FFFFFFF,
seed2 : seed2 % 0x3FFFFFFF,
};
};

Expand Down
17 changes: 17 additions & 0 deletions test/fixture/libmysql_password.c
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,9 @@ int main() {
const char password2[] = "long password test";
const char password3[] = "saf789yasfbsd89f";
ulong result[2];
struct rand_struct rand_st;

// test hash_password
hash_password((ulong*)result, password1, strlen(password1));
printf("hash_password(\"%s\") = %08x%08x\n", password1, result[0], result[1]);

Expand All @@ -86,6 +88,21 @@ int main() {
hash_password((ulong*)result, password3, strlen(password3));
printf("hash_password(\"%s\") = %08x%08x\n", password3, result[0], result[1]);


// test randominit
randominit(&rand_st, 0, 0);
printf("randominit(0x00000000,0x00000000) = %08x, %08x\n", rand_st.seed1, rand_st.seed2);

randominit(&rand_st, 0xFFFF, 0xFFFF);
printf("randominit(0x0000FFFF,0x0000FFFF) = %08x, %08x\n", rand_st.seed1, rand_st.seed2);

randominit(&rand_st, 0x50000000, 0x50000000);
printf("randominit(0x50000000,0x50000000) = %08x, %08x\n", rand_st.seed1, rand_st.seed2);

randominit(&rand_st, 0xFFFFFFFF, 0xFFFFFFFF);
printf("randominit(0xFFFFFFFF,0xFFFFFFFF) = %08x, %08x\n", rand_st.seed1, rand_st.seed2);


return 23;
}

15 changes: 15 additions & 0 deletions test/simple/test-auth-old.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,21 @@ function test_hash_password(password, bytes){
sys.print('ok\n');
}

function test_randominit(in1, in2, out1, out2){
var r = auth.randomInit(in1, in2);
sys.print('randomInit('+in1+','+in2+')...');
assert.equal(out1, r.seed1);
assert.equal(out2, r.seed2);
sys.print('ok\n');
}

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


test_randominit(0x00000000, 0x00000000, 0x00000000, 0x00000000);
test_randominit(0x0000FFFF, 0x0000FFFF, 0x0000ffff, 0x0000ffff);
test_randominit(0x50000000, 0x50000000, 0x10000001, 0x10000001);
test_randominit(0xFFFFFFFF, 0xFFFFFFFF, 0x00000003, 0x00000003);

0 comments on commit 274280b

Please sign in to comment.