Bugzilla – Attachment 103102 Details for
Bug 23816
Allow to have different password strength and length settings for different patron categories
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 23816: Add tests
Bug-23816-Add-tests.patch (text/plain), 7.10 KB, created by
Agustín Moyano
on 2020-04-16 21:16:00 UTC
(
hide
)
Description:
Bug 23816: Add tests
Filename:
MIME Type:
Creator:
Agustín Moyano
Created:
2020-04-16 21:16:00 UTC
Size:
7.10 KB
patch
obsolete
>From 44be09334b80e3e64e72d5dd9a1f02cd02c31b57 Mon Sep 17 00:00:00 2001 >From: Agustin Moyano <agustinmoyano@theke.io> >Date: Wed, 15 Apr 2020 17:13:16 -0300 >Subject: [PATCH] Bug 23816: Add tests > >--- > t/db_dependent/AuthUtils.t | 114 ++++++++++++++++++++++++++ > t/db_dependent/Koha/Patron/Category.t | 38 ++++++++- > 2 files changed, 151 insertions(+), 1 deletion(-) > create mode 100644 t/db_dependent/AuthUtils.t > >diff --git a/t/db_dependent/AuthUtils.t b/t/db_dependent/AuthUtils.t >new file mode 100644 >index 0000000000..5fe62957ae >--- /dev/null >+++ b/t/db_dependent/AuthUtils.t >@@ -0,0 +1,114 @@ >+#!/usr/bin/perl >+ >+# This file is part of Koha. >+# >+# Koha is free software; you can redistribute it and/or modify it >+# under the terms of the GNU General Public License as published by >+# the Free Software Foundation; either version 3 of the License, or >+# (at your option) any later version. >+# >+# Koha 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 >+# along with Koha; if not, see <http://www.gnu.org/licenses>. >+ >+use Modern::Perl; >+ >+use Test::More tests => 2; >+use Test::MockModule; >+use t::lib::Mocks; >+use t::lib::TestBuilder; >+use Koha::AuthUtils; >+ >+my $schema = Koha::Database->schema; >+my $builder = t::lib::TestBuilder->new; >+ >+$schema->storage->txn_begin; >+ >+my $category1 = $builder->build_object({class=>'Koha::Patron::Categories', value=>{min_password_length => 15, require_strong_password => 1}}); >+my $category2 = $builder->build_object({class=>'Koha::Patron::Categories', value=>{min_password_length => 5, require_strong_password => undef}}); >+my $category3 = $builder->build_object({class=>'Koha::Patron::Categories', value=>{min_password_length => undef, require_strong_password => 1}}); >+my $category4 = $builder->build_object({class=>'Koha::Patron::Categories', value=>{min_password_length => undef, require_strong_password => undef}}); >+ >+my $p_3l_weak = '123'; >+my $p_3l_strong = '1Ab'; >+my $p_5l_weak = 'abcde'; >+my $p_15l_weak = '0123456789abcdf'; >+my $p_5l_strong = 'Abc12'; >+my $p_15l_strong = '0123456789AbCdF'; >+ >+subtest 'is_password_valid for category' => sub { >+ plan tests => 12; >+ >+ my ( $is_valid, $error ); >+ >+ t::lib::Mocks::mock_preference('RequireStrongPassword', 0); >+ t::lib::Mocks::mock_preference('minPasswordLength', 3); >+ >+ #Category 1 - override=>1, length=>15, strong=>1 >+ ( $is_valid, $error ) = Koha::AuthUtils::is_password_valid( $p_5l_strong, $category1 ); >+ is($is_valid, 0, 'min password length for this category is 15'); >+ is($error, 'too_short', 'min password length for this category is 15'); >+ >+ ( $is_valid, $error ) = Koha::AuthUtils::is_password_valid( $p_15l_weak, $category1 ); >+ is($is_valid, 0, 'password should be strong for this category'); >+ is($error, 'too_weak', 'password should be strong for this category'); >+ >+ ( $is_valid, $error ) = Koha::AuthUtils::is_password_valid( $p_15l_strong, $category1 ); >+ is($is_valid, 1, 'password should be ok for this category'); >+ >+ #Category 2 - override=>1, length=>5, strong=>0 >+ ( $is_valid, $error ) = Koha::AuthUtils::is_password_valid( $p_3l_strong, $category2 ); >+ is($is_valid, 0, 'min password length for this category is 5'); >+ is($error, 'too_short', 'min password length for this category is 5'); >+ >+ ( $is_valid, $error ) = Koha::AuthUtils::is_password_valid( $p_5l_weak, $category2 ); >+ is($is_valid, 1, 'password should be ok for this category'); >+ >+ #Category 3 - override=>0, length=>20, strong=>0 >+ ( $is_valid, $error ) = Koha::AuthUtils::is_password_valid( $p_3l_weak, $category3 ); >+ is($is_valid, 0, 'password should be strong'); >+ is($error, 'too_weak', 'password should be strong'); >+ >+ ( $is_valid, $error ) = Koha::AuthUtils::is_password_valid( $p_3l_strong, $category3 ); >+ is($is_valid, 1, 'password should be ok'); >+ >+ #Category 4 - default settings - override=>undef, length=>undef, strong=>undef >+ ( $is_valid, $error ) = Koha::AuthUtils::is_password_valid( $p_3l_weak, $category4 ); >+ is($is_valid, 1, 'password should be ok'); >+}; >+ >+subtest 'generate_password for category' => sub { >+ plan tests => 4; >+ >+ my ( $is_valid, $error ); >+ >+ t::lib::Mocks::mock_preference('RequireStrongPassword', 0); >+ t::lib::Mocks::mock_preference('minPasswordLength', 3); >+ >+ #Category 4 >+ my $password = Koha::AuthUtils::generate_password($category4); >+ ( $is_valid, $error ) = Koha::AuthUtils::is_password_valid( $password, $category4 ); >+ is($is_valid, 1, 'password should be ok'); >+ >+ #Category 3 >+ $password = Koha::AuthUtils::generate_password($category3); >+ ( $is_valid, $error ) = Koha::AuthUtils::is_password_valid( $password, $category3 ); >+ is($is_valid, 1, 'password should be ok'); >+ >+ #Category 2 >+ $password = Koha::AuthUtils::generate_password($category2); >+ ( $is_valid, $error ) = Koha::AuthUtils::is_password_valid( $password, $category2 ); >+ is($is_valid, 1, 'password should be ok'); >+ >+ #Category 1 >+ $password = Koha::AuthUtils::generate_password($category1); >+ ( $is_valid, $error ) = Koha::AuthUtils::is_password_valid( $password, $category1 ); >+ is($is_valid, 1, 'password should be ok'); >+ >+}; >+ >+$schema->storage->txn_rollback; >\ No newline at end of file >diff --git a/t/db_dependent/Koha/Patron/Category.t b/t/db_dependent/Koha/Patron/Category.t >index 7f8e779802..93711d7c95 100644 >--- a/t/db_dependent/Koha/Patron/Category.t >+++ b/t/db_dependent/Koha/Patron/Category.t >@@ -19,7 +19,7 @@ > > use Modern::Perl; > >-use Test::More tests => 3; >+use Test::More tests => 5; > > use t::lib::TestBuilder; > use t::lib::Mocks; >@@ -166,3 +166,39 @@ subtest 'override_hidden_items() tests' => sub { > > $schema->storage->txn_rollback; > }; >+ >+subtest 'effective_min_password_length' => sub { >+ plan tests => 2; >+ >+ $schema->storage->txn_begin; >+ >+ t::lib::Mocks::mock_preference('minPasswordLength', 3); >+ >+ my $category = $builder->build_object({class => 'Koha::Patron::Categories', value => {min_password_length => undef}}); >+ >+ is($category->effective_min_password_length, 3, 'Patron should have minimum password length from preference'); >+ >+ $category->min_password_length(10)->store; >+ >+ is($category->effective_min_password_length, 10, 'Patron should have minimum password length from category'); >+ >+ $schema->storage->txn_rollback; >+}; >+ >+subtest 'effective_require_strong_password' => sub { >+ plan tests => 2; >+ >+ $schema->storage->txn_begin; >+ >+ t::lib::Mocks::mock_preference('RequireStrongPassword', 0); >+ >+ my $category = $builder->build_object({class => 'Koha::Patron::Categories', value => {require_strong_password => undef}}); >+ >+ is($category->effective_require_strong_password, 0, 'Patron should be required strong password from preference'); >+ >+ $category->require_strong_password(1)->store; >+ >+ is($category->effective_require_strong_password, 1, 'Patron should be required strong password from category'); >+ >+ $schema->storage->txn_rollback; >+}; >\ No newline at end of file >-- >2.25.0
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 23816
:
103099
|
103100
|
103101
|
103102
|
103103
|
103104
|
103108
|
103109
|
103110
|
103111
|
103112
|
103113
|
103805
|
103806
|
103807
|
103808
|
103809
|
103810
|
107158
|
107159
|
107160
|
107161
|
107162
|
107163
|
108554
|
108555
|
108556
|
108557
|
108558
|
108559
|
108571
|
108572
|
109243
|
109244
|
109245
|
109249
|
109250
|
109251
|
109252
|
109253
|
109254
|
109255
|
109256
|
109257
|
109520
|
109521
|
109522
|
109523
|
109524
|
109525
|
109526
|
109527
|
109528
|
109833
|
109834