script/sample.pl untested

filter: Statementstmt 0.0% 0 / 28 Branchbran 0.0% 0 / 14 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 1 Podpod n/a totaltotal 0.0% 0 / 43 CC 1 SCAR 6.9
CC
1
Cov
0%
BEGIN
2.0
CRAP 2.0
1 #!/usr/local/bin/perl
2  
3 use Mojolicious::Lite;
4  
5 plugin 'basic_auth_plus';
6  
7 # Use a callback requiring user ID 'foo' and password 'bar'
8 get '/callback' => sub {
9 my $self = shift;
10  
11 $self->render(text => 'ok')
12 if $self->basic_auth(
13 "Callback Test" => sub { return 1 if "@_" eq 'foo bar' } );
14 };
15  
16 # Explicit username and password without using a callback
17 get '/futurama' => sub {
18 my $self = shift;
19  
20 $self->render( 'text' => "Whoop whoop whoop!" )
21 if $self->basic_auth(
22 "Futurama Rules!" => {
23 username => 'zoidberg',
24 password => 'decapod10'
25 }
26 );
27 };
28  
29 # With encrypted password
30 get '/crypt' => sub {
31 my $self = shift;
32  
33 $self->render( 'text' => "Hooray!" )
34 if $self->basic_auth(
35 "Dr. Zoidberg" => {
36 username => 'zoidberg',
37 password => 'JVkvO/y7RL9M.'
38 }
39 );
40 };
41  
42 # LDAP authentication (with anonymous bind)
43 get '/ldap' => sub {
44 my $self = shift;
45  
46 $self->render(text => 'ok')
47 if $self->basic_auth(
48 "Some Realm" => {
49 host => 'ldap.company.com',
50 basedn => 'ou=People,dc=company,dc=com'
51 }
52 );
53 };
54  
55 # Active Directory authentication (with authenticated bind)
56 get '/activedirectory' => sub {
57 my $self = shift;
58  
59 $self->render(text => 'ok')
60 if $self->basic_auth(
61 "Another Realm" => {
62 host => 'ldap.company.com',
63 basedn => 'dc=company,dc=com',
64 binddn => 'ou=People,dc=company,dc=com',
65 bindpw => 'secret'
66 }
67 );
68 };
69  
70 # Passwd file authentication
71 under sub {
72 my $self = shift;
73 return 1
74 if $self->basic_auth(
75 "Your Realm" => { path => '/path/to/some/passwd/file.txt' } );
76 };
77  
78 get '/farnsworth' => sub { shift->render('Good news, everyone!') };
79 get '/bender' =>
80 sub { shift->render( text => 'What do you mean "we", flesh-tube? ' ) };
81  
82 app->start;
83