X-Git-Url: http://git.freeside.biz/gitweb/?a=blobdiff_plain;f=rt%2Ft%2Fapi%2Fpassword-types.t;h=3278b488de1c5978d46070dccd4bcc870cae1b8e;hb=da820d8c8837dce295e7cbd61accc22c4c019e14;hp=267a6ede472e3fb52ad7812029407bdee5b0d9cb;hpb=0fb307c305e4bc2c9c27dc25a3308beae3a4d33c;p=freeside.git diff --git a/rt/t/api/password-types.t b/rt/t/api/password-types.t index 267a6ede4..3278b488d 100644 --- a/rt/t/api/password-types.t +++ b/rt/t/api/password-types.t @@ -1,31 +1,62 @@ -#!/usr/bin/perl -w use strict; use warnings; use RT::Test; use Digest::MD5; +my $default = "bcrypt"; + my $root = RT::User->new(RT->SystemUser); $root->Load("root"); -# Salted truncated SHA-256 +# bcrypt (default) my $old = $root->__Value("Password"); -is(length($old), 40, "Stored as truncated salted SHA-256"); +like($old, qr/^\!$default\!/, "Stored as salted $default"); ok($root->IsPassword("password")); is($root->__Value("Password"), $old, "Unchanged after password check"); +# bcrypt (smaller number of rounds) +my $rounds = RT->Config->Get("BcryptCost"); +my $salt = Crypt::Eksblowfish::Bcrypt::en_base64("a"x16); +$root->_Set( Field => "Password", Value => RT::User->_GeneratePassword_bcrypt("smaller", 6, $salt) ); +like($root->__Value("Password"), qr/^\!$default\!06\!/, "Stored with a smaller number of rounds"); +ok($root->IsPassword("smaller"), "Smaller number of bcrypt rounds works"); +like($root->__Value("Password"), qr/^\!$default\!$rounds\!/, "And is now upgraded to $rounds rounds"); + +# Salted SHA-512, one round +$root->_Set( Field => "Password", Value => RT::User->_GeneratePassword_sha512("other", "salt") ); +ok($root->IsPassword("other"), "SHA-512 password works"); +like($root->__Value("Password"), qr/^\!$default\!/, "And is now upgraded to salted $default"); + # Crypt $root->_Set( Field => "Password", Value => crypt("something", "salt")); ok($root->IsPassword("something"), "crypt()ed password works"); -is(length($root->__Value("Password")), 40, "And is now upgraded to truncated salted SHA-256"); +like($root->__Value("Password"), qr/^\!$default\!/, "And is now upgraded to salted $default"); # MD5, hex $root->_Set( Field => "Password", Value => Digest::MD5::md5_hex("changed")); ok($root->IsPassword("changed"), "Unsalted MD5 hex works"); -is(length($root->__Value("Password")), 40, "And is now upgraded to truncated salted SHA-256"); +like($root->__Value("Password"), qr/^\!$default\!/, "And is now upgraded to salted $default"); # MD5, base64 $root->_Set( Field => "Password", Value => Digest::MD5::md5_base64("new")); ok($root->IsPassword("new"), "Unsalted MD5 base64 works"); -is(length($root->__Value("Password")), 40, "And is now upgraded to truncated salted SHA-256"); +like($root->__Value("Password"), qr/^\!$default\!/, "And is now upgraded to salted $default"); + +# Salted truncated SHA-256 +my $trunc = MIME::Base64::encode_base64( + "salt" . substr(Digest::SHA::sha256("salt".Digest::MD5::md5("secret")),0,26), + "" +); +$root->_Set( Field => "Password", Value => $trunc); +ok($root->IsPassword("secret"), "Unsalted MD5 base64 works"); +like($root->__Value("Password"), qr/^\!$default\!/, "And is now upgraded to salted $default"); +# Non-ASCII salted truncated SHA-256 +my $non_ascii_trunc = MIME::Base64::encode_base64( + "salt" . substr(Digest::SHA::sha256("salt".Digest::MD5::md5("áěšý")),0,26), + "" +); +$root->_Set( Field => "Password", Value => $non_ascii_trunc); +ok($root->IsPassword(Encode::decode("UTF-8", "áěšý")), "Unsalted MD5 base64 works"); +like($root->__Value("Password"), qr/^\!$default\!/, "And is now upgraded to salted $default");