Lambda/HTTP/Authen/NTLM.pm untested

filter: Statementstmt 0.0% 0 / 29 Branchbran 0.0% 0 / 6 Conditioncond 0.0% 0 / 2 MC/DCmcdc n/a Subroutinesub 0.0% 0 / 4 Podpod 0.0% 0 / 1 totaltotal 0.0% 0 / 42 CC 4 SCAR 25.1
CC
4
Cov
0%
authenticate
20.0
BEGIN
2.0
BEGIN
2.0
CRAP 12.3
1 # $Id: NTLM.pm,v 1.9 2008/12/17 10:51:39 dk Exp $
2
3 package IO::Lambda::HTTP::Authen::NTLM;
4
5 use strict;
6 use Authen::NTLM 1.05;
7
8 use IO::Lambda qw(:all);
9
10 sub authenticate
11 {
12 my ( $class, $self, $req, $response) = @_;
13
14 lambda {
15 # issue req phase 1
16 my $method = ($class =~ /:(\w+)$/)[0];
17
18 my $ntlm = Authen::NTLM-> new(
19 user => $self-> {username},
20 password => $self-> {password},
21 domain => $self-> {domain},
22 version => $self-> {ntlm_version},
23 );
24
25 my $r = $req-> clone;
26 $r-> content('');
27 $r-> header('Content-Length' => 0);
28 $r-> header('Authorization' => "$method " . $ntlm-> challenge);
29
30 context $self-> handle_connection( $r);
31 tail {
32 my $answer = shift;
33 return $answer unless ref($answer);
34
35 return $answer if $answer-> code != 401;
36 my $challenge = $answer-> header('WWW-Authenticate') || '';
37 return $answer unless $challenge =~ s/^$method //;
38
39 # issue req phase 2
40 my $r = $req-> clone;
41 $r-> header('Authorization' => "$method ". $ntlm-> challenge($challenge));
42
43 context $self-> handle_connection( $r);
44 &tail();
45 }}
46 }
47
48 1;
49
50 __DATA__