forked from andk/cpanpm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path60credentials.t
60 lines (51 loc) · 1.73 KB
/
60credentials.t
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
use strict;
#use FindBin qw($Bin);
#use lib "$Bin/../lib";
#use lib "$Bin/../blib";
use CPAN;
use Test::More tests => 5;
my $TRUE = 1;
my $FALSE = undef;
test_can_get_basic_credentials();
test_get_basic_credentials_for_proxy();
test_get_basic_credentials_without_proxy();
# exit;
#############################################################################
sub test_can_get_basic_credentials {
set_up();
can_ok('CPAN::LWP::UserAgent', 'get_basic_credentials');
can_ok('CPAN::HTTP::Credentials', 'get_proxy_credentials');
can_ok('CPAN::HTTP::Credentials', 'get_non_proxy_credentials');
}
sub test_get_basic_credentials_for_proxy {
set_up();
$CPAN::Config->{proxy_user} = 'proxy_username';
$CPAN::Config->{proxy_pass} = 'proxy_password';
my @proxy_credentials =
CPAN::LWP::UserAgent->get_basic_credentials('realm', 'uri', $TRUE);
is_deeply(\@proxy_credentials,
[$CPAN::Config->{proxy_user}, $CPAN::Config->{proxy_pass}],
'get_basic_credentials for proxy');
}
sub test_get_basic_credentials_without_proxy {
set_up();
$CPAN::Config->{username} = 'test_username';
$CPAN::Config->{password} = 'test_password';
my @credentials =
CPAN::LWP::UserAgent->get_basic_credentials('realm', 'uri', $FALSE);
is_deeply(\@credentials,
[$CPAN::Config->{username}, $CPAN::Config->{password}],
'get_basic_credentials for non-proxy');
}
sub set_up {
undef $CPAN::Config->{username};
undef $CPAN::Config->{password};
undef $CPAN::Config->{proxy_user};
undef $CPAN::Config->{proxy_pass};
undef $CPAN::HTTP::Credentials::USER;
undef $CPAN::HTTP::Credentials::PASSWORD;
}
# Local Variables:
# mode: cperl
# cperl-indent-level: 4
# End: