Lines 7-13
use CGI qw ( -utf8 );
Link Here
|
7 |
use Test::MockObject; |
7 |
use Test::MockObject; |
8 |
use Test::MockModule; |
8 |
use Test::MockModule; |
9 |
use List::MoreUtils qw/all any none/; |
9 |
use List::MoreUtils qw/all any none/; |
10 |
use Test::More tests => 18; |
10 |
use Test::More tests => 19; |
11 |
use Test::Warn; |
11 |
use Test::Warn; |
12 |
use t::lib::Mocks; |
12 |
use t::lib::Mocks; |
13 |
use t::lib::TestBuilder; |
13 |
use t::lib::TestBuilder; |
Lines 1086-1088
subtest 'get_cataloguing_page_permissions() tests' => sub {
Link Here
|
1086 |
|
1086 |
|
1087 |
$schema->storage->txn_rollback; |
1087 |
$schema->storage->txn_rollback; |
1088 |
}; |
1088 |
}; |
1089 |
- |
1089 |
|
|
|
1090 |
subtest 'checkpw() return values tests' => sub { |
1091 |
|
1092 |
plan tests => 3; |
1093 |
|
1094 |
subtest 'Internal check tests' => sub { |
1095 |
|
1096 |
plan tests => 25; |
1097 |
|
1098 |
$schema->storage->txn_begin; |
1099 |
|
1100 |
my $account_locked; |
1101 |
my $password_expired; |
1102 |
|
1103 |
my $mock_patron = Test::MockModule->new('Koha::Patron'); |
1104 |
$mock_patron->mock( 'account_locked', sub { return $account_locked; } ); |
1105 |
$mock_patron->mock( 'password_expired', sub { return $password_expired; } ); |
1106 |
|
1107 |
# Only interested here in regular login |
1108 |
t::lib::Mocks::mock_config( 'useshibboleth', undef ); |
1109 |
$C4::Auth::cas = 0; |
1110 |
$C4::Auth::ldap = 0; |
1111 |
|
1112 |
my $patron = $builder->build_object( { class => 'Koha::Patrons' } ); |
1113 |
my $password = 'thePassword123'; |
1114 |
$patron->set_password( { password => $password, skip_validation => 1 } ); |
1115 |
|
1116 |
my $patron_to_delete = $builder->build_object( { class => 'Koha::Patrons' } ); |
1117 |
my $unused_userid = $patron_to_delete->userid; |
1118 |
my $unused_cardnumber = $patron_to_delete->cardnumber; |
1119 |
$patron_to_delete->delete; |
1120 |
|
1121 |
$account_locked = 1; |
1122 |
my @return = checkpw( $patron->userid, $password, undef, ); |
1123 |
is_deeply( \@return, [], 'If the account is locked, empty list is returned' ); |
1124 |
|
1125 |
$account_locked = 0; |
1126 |
|
1127 |
my @matchpoints = qw(userid cardnumber); |
1128 |
foreach my $matchpoint (@matchpoints) { |
1129 |
|
1130 |
@return = checkpw( $patron->$matchpoint, $password, undef, ); |
1131 |
|
1132 |
is( $return[0], 1, "Password validation successful returns 1 ($matchpoint)" ); |
1133 |
is( $return[1], $patron->cardnumber, '`cardnumber` returned' ); |
1134 |
is( $return[2], $patron->userid, '`userid` returned' ); |
1135 |
is( ref( $return[3] ), 'Koha::Patron', 'Koha::Patron object reference returned' ); |
1136 |
is( $return[3]->id, $patron->id, 'Correct patron returned' ); |
1137 |
} |
1138 |
|
1139 |
@return = checkpw( $patron->userid, $password . 'hey', undef, ); |
1140 |
|
1141 |
is( scalar @return, 2, "Two results on invalid password scenario" ); |
1142 |
is( $return[0], 0, '0 returned on invalid password' ); |
1143 |
is( ref( $return[1] ), 'Koha::Patron' ); |
1144 |
is( $return[1]->id, $patron->id, 'Patron matched correctly' ); |
1145 |
|
1146 |
$password_expired = 1; |
1147 |
@return = checkpw( $patron->userid, $password, undef, ); |
1148 |
|
1149 |
is( scalar @return, 2, "Two results on expired password scenario" ); |
1150 |
is( $return[0], -2, '-2 returned' ); |
1151 |
is( ref( $return[1] ), 'Koha::Patron' ); |
1152 |
is( $return[1]->id, $patron->id, 'Patron matched correctly' ); |
1153 |
|
1154 |
@return = checkpw( $unused_userid, $password, undef, ); |
1155 |
|
1156 |
is( scalar @return, 2, "Two results on non-existing userid scenario" ); |
1157 |
is( $return[0], 0, '0 returned' ); |
1158 |
is( $return[1], undef, 'Undef returned, representing no match' ); |
1159 |
|
1160 |
@return = checkpw( $unused_cardnumber, $password, undef, ); |
1161 |
|
1162 |
is( scalar @return, 2, "Only one result on non-existing cardnumber scenario" ); |
1163 |
is( $return[0], 0, '0 returned' ); |
1164 |
is( $return[1], undef, 'Undef returned, representing no match' ); |
1165 |
|
1166 |
$schema->storage->txn_rollback; |
1167 |
}; |
1168 |
|
1169 |
subtest 'CAS check (mocked) tests' => sub { |
1170 |
|
1171 |
plan tests => 25; |
1172 |
|
1173 |
$schema->storage->txn_begin; |
1174 |
|
1175 |
my $account_locked; |
1176 |
my $password_expired; |
1177 |
|
1178 |
my $mock_patron = Test::MockModule->new('Koha::Patron'); |
1179 |
$mock_patron->mock( 'account_locked', sub { return $account_locked; } ); |
1180 |
$mock_patron->mock( 'password_expired', sub { return $password_expired; } ); |
1181 |
|
1182 |
# Only interested here in regular login |
1183 |
t::lib::Mocks::mock_config( 'useshibboleth', undef ); |
1184 |
$C4::Auth::cas = 1; |
1185 |
$C4::Auth::ldap = 0; |
1186 |
|
1187 |
my $patron = $builder->build_object( { class => 'Koha::Patrons' } ); |
1188 |
my $password = 'thePassword123'; |
1189 |
$patron->set_password( { password => $password, skip_validation => 1 } ); |
1190 |
|
1191 |
my $patron_to_delete = $builder->build_object( { class => 'Koha::Patrons' } ); |
1192 |
my $unused_userid = $patron_to_delete->userid; |
1193 |
my $unused_cardnumber = $patron_to_delete->cardnumber; |
1194 |
$patron_to_delete->delete; |
1195 |
|
1196 |
my $ticket = '123456'; |
1197 |
my $query = CGI->new; |
1198 |
$query->param( -name => 'ticket', -value => $ticket ); |
1199 |
|
1200 |
my @cas_return = ( 1, $patron->cardnumber, $patron->userid, $ticket, Koha::Patrons->find( $patron->id ) ); |
1201 |
|
1202 |
my $cas_mock = Test::MockModule->new('C4::Auth'); |
1203 |
$cas_mock->mock( 'checkpw_cas', sub { return @cas_return; } ); |
1204 |
|
1205 |
$account_locked = 1; |
1206 |
my @return = checkpw( $patron->userid, $password, $query, ); |
1207 |
is_deeply( \@return, [], 'If the account is locked, empty list is returned' ); |
1208 |
|
1209 |
$account_locked = 0; |
1210 |
|
1211 |
my @matchpoints = qw(userid cardnumber); |
1212 |
foreach my $matchpoint (@matchpoints) { |
1213 |
|
1214 |
@return = checkpw( $patron->$matchpoint, $password, $query, ); |
1215 |
|
1216 |
is( $return[0], 1, "Password validation successful returns 1 ($matchpoint)" ); |
1217 |
is( $return[1], $patron->cardnumber, '`cardnumber` returned' ); |
1218 |
is( $return[2], $patron->userid, '`userid` returned' ); |
1219 |
is( ref( $return[3] ), 'Koha::Patron', 'Koha::Patron object reference returned' ); |
1220 |
is( $return[3]->id, $patron->id, 'Correct patron returned' ); |
1221 |
} |
1222 |
|
1223 |
@return = checkpw( $patron->userid, $password . 'hey', $query, ); |
1224 |
|
1225 |
is( scalar @return, 2, "Two results on invalid password scenario" ); |
1226 |
is( $return[0], 0, '0 returned on invalid password' ); |
1227 |
is( ref( $return[1] ), 'Koha::Patron' ); |
1228 |
is( $return[1]->id, $patron->id, 'Patron matched correctly' ); |
1229 |
|
1230 |
$password_expired = 1; |
1231 |
@return = checkpw( $patron->userid, $password, $query, ); |
1232 |
|
1233 |
is( scalar @return, 2, "Two results on expired password scenario" ); |
1234 |
is( $return[0], -2, '-2 returned' ); |
1235 |
is( ref( $return[1] ), 'Koha::Patron' ); |
1236 |
is( $return[1]->id, $patron->id, 'Patron matched correctly' ); |
1237 |
|
1238 |
@return = checkpw( $unused_userid, $password, $query, ); |
1239 |
|
1240 |
is( scalar @return, 2, "Two results on non-existing userid scenario" ); |
1241 |
is( $return[0], 0, '0 returned' ); |
1242 |
is( $return[1], undef, 'Undef returned, representing no match' ); |
1243 |
|
1244 |
@return = checkpw( $unused_cardnumber, $password, $query, ); |
1245 |
|
1246 |
is( scalar @return, 2, "Only one result on non-existing cardnumber scenario" ); |
1247 |
is( $return[0], 0, '0 returned' ); |
1248 |
is( $return[1], undef, 'Undef returned, representing no match' ); |
1249 |
|
1250 |
$schema->storage->txn_rollback; |
1251 |
}; |
1252 |
|
1253 |
subtest 'Shibboleth check (mocked) tests' => sub { |
1254 |
|
1255 |
plan tests => 6; |
1256 |
|
1257 |
$schema->storage->txn_begin; |
1258 |
|
1259 |
my $account_locked; |
1260 |
my $password_expired; |
1261 |
|
1262 |
my $mock_patron = Test::MockModule->new('Koha::Patron'); |
1263 |
$mock_patron->mock( 'account_locked', sub { return $account_locked; } ); |
1264 |
$mock_patron->mock( 'password_expired', sub { return $password_expired; } ); |
1265 |
|
1266 |
# Only interested here in regular login |
1267 |
t::lib::Mocks::mock_config( 'useshibboleth', 1 ); |
1268 |
$C4::Auth::cas = 0; |
1269 |
$C4::Auth::ldap = 0; |
1270 |
|
1271 |
my $patron = $builder->build_object( { class => 'Koha::Patrons' } ); |
1272 |
my $password = 'thePassword123'; |
1273 |
$patron->set_password( { password => $password, skip_validation => 1 } ); |
1274 |
|
1275 |
my $patron_to_delete = $builder->build_object( { class => 'Koha::Patrons' } ); |
1276 |
my $unused_userid = $patron_to_delete->userid; |
1277 |
my $unused_cardnumber = $patron_to_delete->cardnumber; |
1278 |
$patron_to_delete->delete; |
1279 |
|
1280 |
my @shib_return = ( 1, $patron->cardnumber, $patron->userid, Koha::Patrons->find( $patron->id ) ); |
1281 |
|
1282 |
my $auth_mock = Test::MockModule->new('C4::Auth'); |
1283 |
$auth_mock->mock( 'shib_ok', 1 ); |
1284 |
$auth_mock->mock( 'get_login_shib', 1 ); |
1285 |
|
1286 |
my $shib_mock = Test::MockModule->new('C4::Auth_with_shibboleth'); |
1287 |
$shib_mock->mock( 'checkpw_shib', sub { return @shib_return; } ); |
1288 |
|
1289 |
$account_locked = 1; |
1290 |
my @return = checkpw( $patron->userid ); |
1291 |
is_deeply( \@return, [], 'If the account is locked, empty list is returned' ); |
1292 |
|
1293 |
$account_locked = 0; |
1294 |
|
1295 |
@return = checkpw(); |
1296 |
|
1297 |
is( $return[0], 1, "Password validation successful returns 1" ); |
1298 |
is( $return[1], $patron->cardnumber, '`cardnumber` returned' ); |
1299 |
is( $return[2], $patron->userid, '`userid` returned' ); |
1300 |
is( ref( $return[3] ), 'Koha::Patron', 'Koha::Patron object reference returned' ); |
1301 |
is( $return[3]->id, $patron->id, 'Correct patron returned' ); |
1302 |
|
1303 |
$schema->storage->txn_rollback; |
1304 |
}; |
1305 |
}; |