2019-04-13 20:28:22 +02:00
|
|
|
use lib 'inc';
|
|
|
|
use Test::More;
|
|
|
|
use strict;
|
|
|
|
use IO::String;
|
|
|
|
use LWP::UserAgent;
|
|
|
|
use LWP::Protocol::PSGI;
|
|
|
|
use MIME::Base64;
|
|
|
|
|
|
|
|
BEGIN {
|
|
|
|
require 't/test-lib.pm';
|
|
|
|
}
|
|
|
|
|
|
|
|
my $debug = 'error';
|
|
|
|
my ( $op, $rp, $res );
|
|
|
|
my %handlerOR = ( op => [], rp => [] );
|
|
|
|
|
|
|
|
LWP::Protocol::PSGI->register(
|
|
|
|
sub {
|
|
|
|
my $req = Plack::Request->new(@_);
|
|
|
|
ok( $req->uri =~ m#http://auth.((?:o|r)p).com(.*)#, ' REST request' );
|
|
|
|
my $host = $1;
|
|
|
|
my $url = $2;
|
|
|
|
my ( $res, $client );
|
|
|
|
count(1);
|
|
|
|
if ( $host eq 'op' ) {
|
|
|
|
pass(" Request from RP to OP, endpoint $url");
|
|
|
|
$client = $op;
|
|
|
|
}
|
|
|
|
elsif ( $host eq 'rp' ) {
|
|
|
|
pass(' Request from OP to RP');
|
|
|
|
$client = $rp;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
fail(' Aborting REST request (external)');
|
|
|
|
return [ 500, [], [] ];
|
|
|
|
}
|
|
|
|
if ( $req->method =~ /^post$/i ) {
|
|
|
|
my $s = $req->content;
|
|
|
|
ok(
|
|
|
|
$res = $client->_post(
|
|
|
|
$url, IO::String->new($s),
|
|
|
|
length => length($s),
|
|
|
|
type => $req->header('Content-Type'),
|
|
|
|
),
|
|
|
|
' Execute request'
|
|
|
|
);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
ok(
|
|
|
|
$res = $client->_get(
|
|
|
|
$url,
|
|
|
|
custom => {
|
|
|
|
HTTP_AUTHORIZATION => $req->header('Authorization'),
|
|
|
|
}
|
|
|
|
),
|
|
|
|
' Execute request'
|
|
|
|
);
|
|
|
|
}
|
|
|
|
ok( $res->[0] == 200, ' Response is 200' );
|
|
|
|
ok( getHeader( $res, 'Content-Type' ) =~ m#^application/json#,
|
|
|
|
' Content is JSON' )
|
|
|
|
or explain( $res->[1], 'Content-Type => application/json' );
|
|
|
|
count(4);
|
|
|
|
return $res;
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
|
|
|
# Initialization
|
|
|
|
ok( $op = op(), 'OP portal' );
|
|
|
|
|
|
|
|
ok( $res = $op->_get('/oauth2/jwks'), 'Get JWKS, endpoint /oauth2/jwks' );
|
|
|
|
expectOK($res);
|
|
|
|
my $jwks = $res->[2]->[0];
|
|
|
|
|
|
|
|
ok(
|
|
|
|
$res = $op->_get('/.well-known/openid-configuration'),
|
|
|
|
'Get metadata, endpoint /.well-known/openid-configuration'
|
|
|
|
);
|
|
|
|
expectOK($res);
|
|
|
|
my $metadata = $res->[2]->[0];
|
|
|
|
count(3);
|
|
|
|
|
2019-05-11 20:18:43 +02:00
|
|
|
switch ('rp');
|
2019-04-13 20:28:22 +02:00
|
|
|
&Lemonldap::NG::Handler::Main::cfgNum( 0, 0 );
|
|
|
|
ok( $rp = rp( $jwks, $metadata ), 'RP portal' );
|
|
|
|
count(1);
|
|
|
|
|
|
|
|
# Query RP for auth
|
|
|
|
ok( $res = $rp->_get( '/', accept => 'text/html' ), 'Unauth SP request' );
|
|
|
|
count(1);
|
|
|
|
|
|
|
|
# OIDC idp must be sorted
|
|
|
|
my @idp = map /idploop py-3" val="(.+?)">/g, $res->[2]->[0];
|
|
|
|
ok( $idp[0] eq 'op2', '1st = op2' ) or print STDERR Dumper( \@idp );
|
|
|
|
ok( $idp[1] eq 'op3', '2nd = op3' ) or print STDERR Dumper( \@idp );
|
|
|
|
ok( $idp[2] eq 'op', '3rd = op' ) or print STDERR Dumper( \@idp );
|
|
|
|
count(3);
|
|
|
|
|
|
|
|
# Found OIDC idp logo and display name
|
|
|
|
ok(
|
|
|
|
$res->[2]->[0] =~
|
|
|
|
qr%<img src="http://auth.rp.com/static/common/icons/sfa_manager.png" class="mr-2" alt="op2" title="op2" />%,
|
|
|
|
'Found OIDC idp logo'
|
|
|
|
) or print STDERR Dumper( $res->[2]->[0] );
|
|
|
|
ok( $res->[2]->[0] =~ qr%idpOPtest%, 'Found OIDC idp display name' )
|
|
|
|
or print STDERR Dumper( $res->[2]->[0] );
|
|
|
|
count(2);
|
|
|
|
clean_sessions();
|
|
|
|
done_testing( count() );
|
|
|
|
|
|
|
|
sub switch {
|
|
|
|
my $type = shift;
|
|
|
|
pass( '==> Switching to ' . uc($type) . ' <==' );
|
|
|
|
count(1);
|
|
|
|
@Lemonldap::NG::Handler::Main::_onReload = @{
|
|
|
|
$handlerOR{$type};
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
sub op {
|
2019-07-02 20:03:40 +02:00
|
|
|
return LLNG::Manager::Test->new( {
|
2019-04-13 20:28:22 +02:00
|
|
|
ini => {
|
|
|
|
logLevel => $debug,
|
|
|
|
domain => 'idp.com',
|
|
|
|
portal => 'http://auth.op.com',
|
|
|
|
authentication => 'Demo',
|
|
|
|
userDB => 'Same',
|
|
|
|
issuerDBOpenIDConnectActivation => "1",
|
|
|
|
oidcRPMetaDataExportedVars => {
|
|
|
|
rp => {
|
|
|
|
email => "mail",
|
|
|
|
family_name => "cn",
|
|
|
|
name => "cn"
|
|
|
|
}
|
|
|
|
},
|
|
|
|
oidcServiceMetaDataAuthorizeURI => "authorize",
|
|
|
|
oidcServiceMetaDataCheckSessionURI => "checksession",
|
|
|
|
oidcServiceMetaDataJWKSURI => "jwks",
|
|
|
|
oidcServiceMetaDataEndSessionURI => "logout",
|
|
|
|
oidcServiceMetaDataRegistrationURI => "register",
|
|
|
|
oidcServiceMetaDataTokenURI => "token",
|
|
|
|
oidcServiceMetaDataUserInfoURI => "userinfo",
|
|
|
|
oidcServiceAllowHybridFlow => 1,
|
|
|
|
oidcServiceAllowImplicitFlow => 1,
|
|
|
|
oidcServiceAllowDynamicRegistration => 1,
|
|
|
|
oidcServiceAllowAuthorizationCodeFlow => 1,
|
|
|
|
oidcRPMetaDataOptions => {
|
|
|
|
rp => {
|
|
|
|
oidcRPMetaDataOptionsDisplayName => "RP",
|
|
|
|
oidcRPMetaDataOptionsIDTokenExpiration => 3600,
|
|
|
|
oidcRPMetaDataOptionsClientID => "rpid",
|
|
|
|
oidcRPMetaDataOptionsIDTokenSignAlg => "HS512",
|
|
|
|
oidcRPMetaDataOptionsBypassConsent => 0,
|
|
|
|
oidcRPMetaDataOptionsClientSecret => "rpsecret",
|
|
|
|
oidcRPMetaDataOptionsUserIDAttr => "",
|
|
|
|
oidcRPMetaDataOptionsAccessTokenExpiration => 3600
|
|
|
|
}
|
|
|
|
},
|
|
|
|
oidcOPMetaDataOptions => {},
|
|
|
|
oidcOPMetaDataJSON => {},
|
|
|
|
oidcOPMetaDataJWKS => {},
|
|
|
|
oidcServiceMetaDataAuthnContext => {
|
|
|
|
'loa-4' => 4,
|
|
|
|
'loa-1' => 1,
|
|
|
|
'loa-5' => 5,
|
|
|
|
'loa-2' => 2,
|
|
|
|
'loa-3' => 3
|
|
|
|
},
|
|
|
|
oidcServicePrivateKeySig => "-----BEGIN RSA PRIVATE KEY-----
|
|
|
|
MIIEowIBAAKCAQEAs2jsmIoFuWzMkilJaA8//5/T30cnuzX9GImXUrFR2k9EKTMt
|
|
|
|
GMHCdKlWOl3BV+BTAU9TLz7Jzd/iJ5GJ6B8TrH1PHFmHpy8/qE/S5OhinIpIi7eb
|
|
|
|
ABqnoVcwDdCa8ugzq8k8SWxhRNXfVIlwz4NH1caJ8lmiERFj7IvNKqEhzAk0pyDr
|
|
|
|
8hubveTC39xREujKlsqutpPAFPJ3f2ybVsdykX5rx0h5SslG3jVWYhZ/SOb2aIzO
|
|
|
|
r0RMjhQmsYRwbpt3anjlBZ98aOzg7GAkbO8093X5VVk9vaPRg0zxJQ0Do0YLyzkR
|
|
|
|
isSAIFb0tdKuDnjRGK6y/N2j6At2HjkxntbtGQIDAQABAoIBADYq6LxJd977LWy3
|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7KgcEvNxtlytbt7muil
|
|
|
|
5Z6X3tf+VodJ0Swe2NhTmNEB26uwxzLe68BE3VFCsbSYn2y48HAq+MawPZr18bHG
|
|
|
|
ZfgMxwKBgHHRg6HYqF5Pegzk1746uH2G+OoCovk5ylGGYzcH2ghWTK4agCHfBcDt
|
|
|
|
EYqYAev/l82wi+OZ5O8U+qjFUpT1CVeUJdDs0o5u19v0UJjunU1cwh9jsxBZAWLy
|
|
|
|
PAGd6SWf4S3uQCTw6dLeMna25YIlPh5qPA6I/pAahe8e3nSu2ckl
|
|
|
|
-----END RSA PRIVATE KEY-----
|
|
|
|
",
|
|
|
|
oidcServicePublicKeySig => "-----BEGIN PUBLIC KEY-----
|
|
|
|
MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAs2jsmIoFuWzMkilJaA8/
|
|
|
|
/5/T30cnuzX9GImXUrFR2k9EKTMtGMHCdKlWOl3BV+BTAU9TLz7Jzd/iJ5GJ6B8T
|
|
|
|
rH1PHFmHpy8/qE/S5OhinIpIi7ebABqnoVcwDdCa8ugzq8k8SWxhRNXfVIlwz4NH
|
|
|
|
1caJ8lmiERFj7IvNKqEhzAk0pyDr8hubveTC39xREujKlsqutpPAFPJ3f2ybVsdy
|
|
|
|
kX5rx0h5SslG3jVWYhZ/SOb2aIzOr0RMjhQmsYRwbpt3anjlBZ98aOzg7GAkbO80
|
|
|
|
93X5VVk9vaPRg0zxJQ0Do0YLyzkRisSAIFb0tdKuDnjRGK6y/N2j6At2Hjkxntbt
|
|
|
|
GQIDAQAB
|
|
|
|
-----END PUBLIC KEY-----
|
|
|
|
",
|
|
|
|
}
|
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
sub rp {
|
|
|
|
my ( $jwks, $metadata ) = @_;
|
2019-07-02 20:03:40 +02:00
|
|
|
return LLNG::Manager::Test->new( {
|
2019-04-13 20:28:22 +02:00
|
|
|
ini => {
|
|
|
|
logLevel => $debug,
|
|
|
|
domain => 'rp.com',
|
|
|
|
portal => 'http://auth.rp.com',
|
|
|
|
authentication => 'OpenIDConnect',
|
|
|
|
userDB => 'Same',
|
|
|
|
oidcOPMetaDataExportedVars => {
|
|
|
|
op => {
|
|
|
|
cn => "name",
|
|
|
|
uid => "sub",
|
|
|
|
sn => "family_name",
|
|
|
|
mail => "email"
|
|
|
|
},
|
|
|
|
op2 => {
|
|
|
|
cn => "name",
|
|
|
|
uid => "sub",
|
|
|
|
sn => "family_name",
|
|
|
|
mail => "email"
|
|
|
|
},
|
|
|
|
op3 => {
|
|
|
|
cn => "name",
|
|
|
|
uid => "sub",
|
|
|
|
sn => "family_name",
|
|
|
|
mail => "email"
|
|
|
|
}
|
|
|
|
},
|
|
|
|
oidcOPMetaDataOptions => {
|
|
|
|
op => {
|
2019-07-02 17:27:17 +02:00
|
|
|
oidcOPMetaDataOptionsCheckJWTSignature => 1,
|
|
|
|
oidcOPMetaDataOptionsJWKSTimeout => 0,
|
|
|
|
oidcOPMetaDataOptionsClientSecret => "rpsecret",
|
2019-04-13 20:28:22 +02:00
|
|
|
oidcOPMetaDataOptionsScope => "openid profile",
|
|
|
|
oidcOPMetaDataOptionsStoreIDToken => 0,
|
|
|
|
oidcOPMetaDataOptionsDisplay => "",
|
|
|
|
oidcOPMetaDataOptionsClientID => "rpid",
|
|
|
|
oidcOPMetaDataOptionsDisplayName => 'idpOPtest',
|
|
|
|
oidcOPMetaDataOptionsSortNumber => '3',
|
|
|
|
oidcOPMetaDataOptionsConfigurationURI =>
|
|
|
|
"https://auth.op.com/.well-known/openid-configuration"
|
|
|
|
},
|
|
|
|
op2 => {
|
2019-07-02 17:27:17 +02:00
|
|
|
oidcOPMetaDataOptionsCheckJWTSignature => 1,
|
|
|
|
oidcOPMetaDataOptionsJWKSTimeout => 0,
|
|
|
|
oidcOPMetaDataOptionsClientSecret => "rpsecret",
|
2019-04-13 20:28:22 +02:00
|
|
|
oidcOPMetaDataOptionsScope => "openid profile",
|
|
|
|
oidcOPMetaDataOptionsStoreIDToken => 0,
|
|
|
|
oidcOPMetaDataOptionsDisplay => "",
|
|
|
|
oidcOPMetaDataOptionsIcon => 'icons/sfa_manager.png',
|
|
|
|
oidcOPMetaDataOptionsClientID => "rpid",
|
|
|
|
oidcOPMetaDataOptionsConfigurationURI =>
|
|
|
|
"https://auth.op.com/.well-known/openid-configuration"
|
|
|
|
},
|
|
|
|
op3 => {
|
2019-07-02 17:27:17 +02:00
|
|
|
oidcOPMetaDataOptionsCheckJWTSignature => 1,
|
|
|
|
oidcOPMetaDataOptionsJWKSTimeout => 0,
|
|
|
|
oidcOPMetaDataOptionsClientSecret => "rpsecret",
|
2019-04-13 20:28:22 +02:00
|
|
|
oidcOPMetaDataOptionsScope => "openid profile",
|
|
|
|
oidcOPMetaDataOptionsStoreIDToken => 0,
|
|
|
|
oidcOPMetaDataOptionsDisplay => "",
|
|
|
|
oidcOPMetaDataOptionsSortNumber => '1',
|
|
|
|
oidcOPMetaDataOptionsClientID => "rpid",
|
|
|
|
oidcOPMetaDataOptionsConfigurationURI =>
|
|
|
|
"https://auth.op.com/.well-known/openid-configuration"
|
|
|
|
}
|
|
|
|
},
|
|
|
|
oidcOPMetaDataJWKS => {
|
|
|
|
op => $jwks,
|
|
|
|
op2 => $jwks,
|
|
|
|
op3 => $jwks,
|
|
|
|
},
|
|
|
|
oidcOPMetaDataJSON => {
|
|
|
|
op => $metadata,
|
|
|
|
op2 => $metadata,
|
|
|
|
op3 => $metadata,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|