File: credentials.t

package info (click to toggle)
libwww-mechanize-perl 2.03-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, sid
  • size: 988 kB
  • sloc: perl: 4,088; makefile: 6
file content (54 lines) | stat: -rw-r--r-- 1,706 bytes parent folder | download | duplicates (3)
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
#!perl -T

use warnings;
use strict;

use WWW::Mechanize;
use Test::More tests => 14;

my $mech = WWW::Mechanize->new;
isa_ok( $mech, 'WWW::Mechanize' );

my ($user, $pass);

my $uri = URI->new( 'http://localhost' );

($user, $pass) = $mech->get_basic_credentials('myrealm', $uri, 0);
is $user, undef, 'default username is undefined at first';
is $pass, undef, 'default password is undefined at first';


$mech->credentials("username", "password");

($user, $pass) = $mech->get_basic_credentials('myrealm', $uri, 0);
is $user, 'username',
   'calling credentials sets username for get_basic_credentials';
is $pass, 'password',
   'calling credentials sets password for get_basic_credentials';

my $mech2 = $mech->clone;

($user, $pass) = $mech2->get_basic_credentials('myrealm', $uri, 0);
is $user, 'username',
   'cloned object has username for get_basic_credentials';
is $pass, 'password',
   'cloned object has password for get_basic_credentials';

my $mech3 = WWW::Mechanize->new;
isa_ok( $mech3, 'WWW::Mechanize' );

($user, $pass) = $mech3->get_basic_credentials('myrealm', $uri, 0);
is $user, undef, 'new object has no username for get_basic_credentials';
is $pass, undef, 'new object has no password for get_basic_credentials';

$mech->clear_credentials;

($user, $pass) = $mech->get_basic_credentials('myrealm', $uri, 0);
is $user, undef, 'username is undefined after clear_credentials';
is $pass, undef, 'password is undefined after clear_credentials';

($user, $pass) = $mech2->get_basic_credentials('myrealm', $uri, 0);
is $user, 'username',
   'cloned object still has username for get_basic_credentials';
is $pass, 'password',
   'cloned object still has password for get_basic_credentials';