File: user.t

package info (click to toggle)
libmojomojo-perl 1.11%2Bdfsg-3
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 4,496 kB
  • ctags: 927
  • sloc: perl: 14,671; sh: 148; xml: 120; makefile: 8; ruby: 6
file content (63 lines) | stat: -rw-r--r-- 1,790 bytes parent folder | download | duplicates (5)
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
61
62
63
#!/usr/bin/env perl
use strict;
use warnings;
use Test::More tests => 13;

BEGIN{
    $ENV{CATALYST_CONFIG} = 't/var/mojomojo.yml';
    use_ok('Catalyst::Test', 'MojoMojo');
    use_ok('MojoMojo::Controller::User');
    use_ok('Test::WWW::Mechanize::Catalyst', 'MojoMojo');
};

my $mech = Test::WWW::Mechanize::Catalyst->new;

#----------------------------------------------------------------------------
$mech->get('/.login?login=admin&pass=admin');
ok !$mech->success, 'non-POST logins return 400 and the login form';
ok !$mech->find_link(
    text => 'admin',
    url_regex => qr'/admin$'
), 'must login via POST';


#----------------------------------------------------------------------------
$mech->get_ok('/.users', 'got user list');
ok $mech->find_link(
    text => $ENV{USER} || 'admin',  # that's how MojoMojo::Schema sets the admin user's name
    url => '/admin.profile'
), 'found admin in the user list';
ok $mech->find_link(
    text => 'Anonymous Coward',
    url => '/anonymouscoward.profile'
), 'found Anonymous Coward in the user list';


#----------------------------------------------------------------------------
$mech->get_ok('/.login', 'got login form');
$mech->submit_form(
    with_fields => {
        login => 'admin',
        pass => 'wrong',
    }
);

ok !$mech->success, 'failing to login with wrong password';
ok !$mech->find_link(
    text => 'admin',
    url_regex => qr'/admin$'
), 'can log in as admin via URL';


#----------------------------------------------------------------------------
$mech->submit_form(
    with_fields => {
        login => 'admin',
        pass => 'admin',
    }
);
ok $mech->success, 'trying to login as admin via POST';
ok $mech->find_link(
    #text => 'admin',
    url_regex => qr'/admin$'
), 'can log in as admin via URL';