2 # Copyright (C) The Arvados Authors. All rights reserved.
4 # SPDX-License-Identifier: Apache-2.0
6 $ENV{ARVADOS_API_HOST_INSECURE} = 1;
7 use Authen::PAM qw(:constants);
9 for my $case (['good', 1, 'active', '3kg6k6lzmp9kj5cpkcoxie963cmvjahbt2fod9zru30k1jqdmi'],
10 ['badtoken', 0, 'active', 'badtokenmp9kj5cpkcoxie963cmvjahbt2fod9zru30k1jqdmi'],
11 ['badusername', 0, 'baduser', '3kg6k6lzmp9kj5cpkcoxie963cmvjahbt2fod9zru30k1jqdmi']) {
17 my ($label, $expect_ok, $user, $token) = @_;
19 my $service_name = 'login';
20 $main::Token = $token;
21 my $pamh = new Authen::PAM($service_name, $user, \&token_conv_func);
22 ref($pamh) || die "Error code $pamh during PAM init!";
23 $pamh->pam_set_item(PAM_RHOST(), '::1');
24 $pamh->pam_set_item(PAM_RUSER(), 'none');
25 $pamh->pam_set_item(PAM_TTY(), '/dev/null');
26 my $flags = PAM_SILENT();
27 $res = $pamh->pam_authenticate($flags);
28 $msg = $pamh->pam_strerror($res);
29 print "Result (code $res): $msg\n";
30 if (($res == 0) != ($expect_ok == 1)) {
41 print "Message (type $code): $msg\n";
42 if ($code == PAM_PROMPT_ECHO_OFF() || $code == PAM_PROMPT_ECHO_ON()) {
47 push @res, PAM_SUCCESS();