File: 10-attrs.t

package info (click to toggle)
libwww-perl 6.78-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,008 kB
  • sloc: perl: 4,148; makefile: 10; sh: 6
file content (47 lines) | stat: -rw-r--r-- 1,815 bytes parent folder | download | duplicates (2)
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
use strict;
use warnings;
use Test::More;

use LWP::UserAgent ();
plan tests => 9;

# Prevent environment from interfering with test:
delete $ENV{PERL_LWP_SSL_VERIFY_HOSTNAME};
delete $ENV{HTTPS_CA_FILE};
delete $ENV{HTTPS_CA_DIR};
delete $ENV{PERL_LWP_SSL_CA_FILE};
delete $ENV{PERL_LWP_SSL_CA_PATH};
delete $ENV{PERL_LWP_ENV_PROXY};

# credentials
{
    my $ua = LWP::UserAgent->new();
    $ua->credentials(undef, 'my realm', 'user', 'pass');
    is($ua->credentials(undef, 'my realm'), 'user:pass', 'credentials: undef netloc');

    $ua->credentials('example.com:80', undef, 'user', 'pass');
    is($ua->credentials('example.com:80', undef), 'user:pass', 'credentials: undef realm');

    $ua->credentials('example.com:80', 'my realm', undef, 'pass');
    is($ua->credentials('example.com:80', 'my realm'), ':pass', 'credentials: undef username');

    $ua->credentials('example.com:80', 'my realm', 'user', undef);
    is($ua->credentials('example.com:80', 'my realm'), 'user:', 'credentials: undef pass');

    $ua->credentials(undef, undef, 'user', 'pass');
    is($ua->credentials(undef, undef), 'user:pass', 'credentials: undef netloc and realm');

    $ua->credentials(undef, undef, undef, undef);
    is($ua->credentials(undef, undef), ':', 'credentials: undef all');

    $ua->credentials('example.com:80', 'my realm', 'user', 'pass');
    is($ua->credentials('example.com:80', 'my realm'), 'user:pass', 'credentials: got proper creds for example:80');

    # ask for the credentials incorrectly
    my $creds = $ua->credentials('example.com');
    is($creds, undef, 'credentials: no realm on request for info');

    # ask for the credentials incorrectly with bad realm
    $creds = $ua->credentials('example.com', 'invalid');
    is($creds, undef, 'credentials: invalid realm on request for info');
}