2007-03-05 01:36:41 +03:00
/*
Unix SMB / CIFS implementation .
local testing of random data routines .
Copyright ( C ) Jelmer Vernooij < jelmer @ samba . org >
This program is free software ; you can redistribute it and / or modify
it under the terms of the GNU General Public License as published by
2007-07-10 06:07:03 +04:00
the Free Software Foundation ; either version 3 of the License , or
2007-03-05 01:36:41 +03:00
( at your option ) any later version .
This program is distributed in the hope that it will be useful ,
but WITHOUT ANY WARRANTY ; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
GNU General Public License for more details .
You should have received a copy of the GNU General Public License
2007-07-10 06:07:03 +04:00
along with this program . If not , see < http : //www.gnu.org/licenses/>.
2007-03-05 01:36:41 +03:00
*/
# include "includes.h"
# include "torture/torture.h"
2014-02-27 12:08:17 +04:00
# include "torture/local/proto.h"
2007-03-05 01:36:41 +03:00
static bool test_check_password_quality ( struct torture_context * tctx )
{
torture_assert ( tctx , ! check_password_quality ( " " ) , " empty password " ) ;
torture_assert ( tctx , ! check_password_quality ( " a " ) , " one char password " ) ;
torture_assert ( tctx , ! check_password_quality ( " aaaaaaaaaaaa " ) , " same char password " ) ;
torture_assert ( tctx , ! check_password_quality ( " BLA " ) , " multiple upcases password " ) ;
torture_assert ( tctx , ! check_password_quality ( " 123 " ) , " digits only " ) ;
2009-07-11 17:57:35 +04:00
torture_assert ( tctx , ! check_password_quality ( " matthiéu " ) , " not enough high symbols " ) ;
2013-02-04 11:45:48 +04:00
torture_assert ( tctx , ! check_password_quality ( " abcdééàçè " ) , " only lower case " ) ;
torture_assert ( tctx , ! check_password_quality ( " abcdééàçè+ " ) , " only lower and symbols " ) ;
torture_assert ( tctx , check_password_quality ( " abcdééàçè+ढ " ) , " valid " ) ;
torture_assert ( tctx , check_password_quality ( " ç+ढ " ) , " valid " ) ;
2007-03-05 01:36:41 +03:00
torture_assert ( tctx , check_password_quality ( " A2e " ) , " valid " ) ;
torture_assert ( tctx , check_password_quality ( " BA2eLi443 " ) , " valid " ) ;
return true ;
}
static bool test_generate_random_str ( struct torture_context * tctx )
{
TALLOC_CTX * mem_ctx = talloc_init ( __FUNCTION__ ) ;
char * r = generate_random_str ( mem_ctx , 10 ) ;
torture_assert_int_equal ( tctx , strlen ( r ) , 10 , " right length generated " ) ;
r = generate_random_str ( mem_ctx , 5 ) ;
torture_assert_int_equal ( tctx , strlen ( r ) , 5 , " right length generated " ) ;
return true ;
}
struct torture_suite * torture_local_genrand ( TALLOC_CTX * mem_ctx )
{
2010-12-11 05:26:31 +03:00
struct torture_suite * suite = torture_suite_create ( mem_ctx , " genrand " ) ;
2007-03-05 01:36:41 +03:00
torture_suite_add_simple_test ( suite , " check_password_quality " , test_check_password_quality ) ;
torture_suite_add_simple_test ( suite , " generate_random_str " , test_generate_random_str ) ;
return suite ;
}