35-SOAP-sessions-with-SOAP-server.t 4.01 KB
Newer Older
1
use lib 'inc';
2 3 4
use Test::More;
use strict;
use IO::String;
5
use LWP::UserAgent;
6
use LWP::Protocol::PSGI;
7 8 9 10 11

BEGIN {
    require 't/test-lib.pm';
}

Xavier Guimard's avatar
Xavier Guimard committed
12
my $maintests = 9;
13 14 15 16
my $debug     = 'error';
my ( $issuer, $sp, $res );
my %handlerOR = ( issuer => [], sp => [] );

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
# Redefine LWP methods for tests
LWP::Protocol::PSGI->register(
    sub {
        my $req = Plack::Request->new(@_);
        ok( $req->uri =~ m#http://auth.((?:id|s)p).com(.*)#,
            ' @ SOAP REQUEST @' );
        my $host = $1;
        my $url  = $2;
        my $res;
        my $s = $req->content;
        my $client = ( $host eq 'idp' ? $issuer : $sp );
        ok(
            $res = $client->_post(
                $url,
                IO::String->new($s),
                length => length($s),
                type   => $req->header('Content-Type'),
                custom => {
                    HTTP_SOAPACTION => $req->header('Soapaction'),
                },
            ),
            ' Execute request'
        );
        expectOK($res);
        ok( getHeader( $res, 'Content-Type' ) =~ m#^(?:text|application)/xml#,
            ' Content is XML' )
          or explain( $res->[1], 'Content-Type => application/xml' );
        pass(' @ END OF SOAP REQUEST @');
        count(4);
        return $res;
    }
);

50 51 52 53 54 55 56
SKIP: {
    eval 'use SOAP::Lite';
    if ($@) {
        skip 'SOAP::Lite not found', $maintests;
    }

    ok( $issuer = issuer(), 'Issuer portal' );
57
    $handlerOR{issuer} = \@Lemonldap::NG::Handler::Main::_onReload;
58
    switch ('sp');
Xavier Guimard's avatar
Tidy  
Xavier Guimard committed
59
    &Lemonldap::NG::Handler::Main::cfgNum( 0, 0 );
60 61

    ok( $sp = sp(), 'SP portal' );
62
    $handlerOR{sp} = \@Lemonldap::NG::Handler::Main::_onReload;
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83

    # Simple SP access
    my $res;
    ok(
        $res = $sp->_get(
            '/', accept => 'text/html',
        ),
        'Unauth SP request'
    );
    expectOK($res);

    # Try to auth
    ok(
        $res = $sp->_post(
            '/', IO::String->new('user=dwho&password=dwho'),
            length => 23,
            accept => 'text/html'
        ),
        'Post user/password'
    );
    expectRedirection( $res, 'http://auth.sp.com' );
Xavier Guimard's avatar
Xavier Guimard committed
84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110
    my $spId = expectCookie($res);

    # Test if we're authenticated
    ok( $res = $sp->_get( '/', cookie => "lemonldap=$spId" ),
        'Try to get menu' );
    expectOK($res);

    # Logout
    ok(
        $res = $sp->_get(
            '/',
            query  => 'logout',
            accept => 'text/html',
            cookie => "lemonldap=$spId"
        ),
        'Ask for logout'
    );
    expectOK($res);

    # Test if logout is done
    ok(
        $res = $sp->_get(
            '/', cookie => "lemonldap=$spId",
        ),
        'Test if user is reject on IdP'
    );
    expectReject($res);
Xavier Guimard's avatar
Xavier Guimard committed
111 112 113
    ok( $res = $issuer->_get('/portal.wsdl'), 'Test WSDL' );
    expectOK($res);
    ok( $res->[2]->[0] =~ /wsdl:operation/s, ' Content contains wsdl def' );
114 115 116 117 118 119 120 121
}

count($maintests);
clean_sessions();
done_testing( count() );

sub switch {
    my $type = shift;
122
    @Lemonldap::NG::Handler::Main::_onReload = @{
123 124 125 126 127 128 129 130 131 132 133 134 135
        $handlerOR{$type};
    };
}

sub issuer {
    return LLNG::Manager::Test->new(
        {
            ini => {
                logLevel          => $debug,
                templatesDir      => 'site/htdocs/static',
                domain            => 'idp.com',
                portal            => 'http://auth.idp.com',
                authentication    => 'Demo',
136
                userDB            => 'Same',
137
                soapSessionServer => 1,
Xavier Guimard's avatar
Xavier Guimard committed
138
                wsdlServer        => 1,
139 140 141 142 143 144 145 146 147 148 149 150 151
            }
        }
    );
}

sub sp {
    return LLNG::Manager::Test->new(
        {
            ini => {
                logLevel       => $debug,
                domain         => 'sp.com',
                portal         => 'http://auth.sp.com',
                authentication => 'Demo',
152
                userDB         => 'Same',
153 154 155 156 157 158 159
                globalStorage => 'Lemonldap::NG::Common::Apache::Session::SOAP',
                globalStorageOptions =>
                  { proxy => 'http://auth.idp.com/adminSessions' },
            },
        }
    );
}