|
|
|
@ -18,7 +18,7 @@ sub check200 { |
|
|
|
|
} |
|
|
|
|
sub check404 { |
|
|
|
|
my ( $test, $res ) = splice @_; |
|
|
|
|
#diag Dumper($res); |
|
|
|
|
diag Dumper($res); |
|
|
|
|
ok( $res->[0] == 404, "$test: Result code is 404" ); |
|
|
|
|
count(1); |
|
|
|
|
checkJson($test, $res); |
|
|
|
@ -71,9 +71,7 @@ sub get { |
|
|
|
|
my ( $test, $type, $confKey) = splice @_; |
|
|
|
|
my $res; |
|
|
|
|
ok( |
|
|
|
|
$res = &client->_get( |
|
|
|
|
"/v1/providers/$type/$confKey", '', '', 'application/json', 0 |
|
|
|
|
), |
|
|
|
|
$res = &client->_get("/v1/providers/$type/$confKey", ''), |
|
|
|
|
"$test: Request succeed" |
|
|
|
|
); |
|
|
|
|
count(1); |
|
|
|
@ -166,14 +164,74 @@ sub checkReplaceWithUnknownAttribute { |
|
|
|
|
check405($test, replace($test, $type, $confKey, $replace)); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
# TODO |
|
|
|
|
sub checkFindByConfKey {} |
|
|
|
|
sub findByConfKey { |
|
|
|
|
my ( $test, $type, $confKey) = splice @_; |
|
|
|
|
my $res; |
|
|
|
|
ok( |
|
|
|
|
$res = &client->_get("/v1/providers/$type/findByConfKey", "pattern=$confKey"), |
|
|
|
|
"$test: Request succeed" |
|
|
|
|
); |
|
|
|
|
count(1); |
|
|
|
|
return $res; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
sub checkFindByConfKeyNoHits {} |
|
|
|
|
sub checkFindByConfKey { |
|
|
|
|
my ( $test, $type, $confKey, $expectedHits, $attribute, $expectedValues) = splice @_; |
|
|
|
|
my $res = findByConfKey($test, $type, $confKey); |
|
|
|
|
check200($test, $res); |
|
|
|
|
my $hits = from_json($res->[2]->[0]); |
|
|
|
|
my $hit; |
|
|
|
|
my $counter = 0; |
|
|
|
|
foreach $hit (@{$hits}) { |
|
|
|
|
my $expected = grep {/^$hit->{options}->{$attribute}$/} @{$expectedValues}; |
|
|
|
|
$counter++; |
|
|
|
|
ok ( |
|
|
|
|
$expected, |
|
|
|
|
"$test: check if $attribute value \"$hit->{options}->{$attribute}\" matches one of expectedValues: " . $_json->encode($expectedValues) |
|
|
|
|
); |
|
|
|
|
count(1); |
|
|
|
|
} |
|
|
|
|
ok ( |
|
|
|
|
$counter eq $expectedHits, |
|
|
|
|
"$test: check if returned nb of hits ($counter) matches $expectedHits" |
|
|
|
|
); |
|
|
|
|
count(1); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
sub findByProviderId { |
|
|
|
|
my ( $test, $type, $providerIdName, $providerId) = splice @_; |
|
|
|
|
my $res; |
|
|
|
|
ok( |
|
|
|
|
$res = &client->_get("/v1/providers/$type/findBy" . ucfirst $providerIdName, "$providerIdName=$providerId"), |
|
|
|
|
"$test: Request succeed" |
|
|
|
|
); |
|
|
|
|
count(1); |
|
|
|
|
return $res; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
sub checkFindByProviderId {} |
|
|
|
|
sub checkFindByProviderId { |
|
|
|
|
my ( $test, $type, $providerIdName, $providerId) = splice @_; |
|
|
|
|
my $res = findByProviderId($test, $type, $providerIdName, $providerId); |
|
|
|
|
check200($test, $res); |
|
|
|
|
my $result = from_json($res->[2]->[0]); |
|
|
|
|
ok( |
|
|
|
|
$result->{$providerIdName} eq $providerId, |
|
|
|
|
"$test: Check $providerIdName value returned \"$result->{$providerIdName}\" matched expected value \"$providerId\"" |
|
|
|
|
); |
|
|
|
|
count(1); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
sub checkFindByProviderId404 {} |
|
|
|
|
sub checkFindByProviderIdNotFound { |
|
|
|
|
my ( $test, $type, $providerIdName, $providerId) = splice @_; |
|
|
|
|
my $res = findByProviderId($test, $type, $providerIdName, $providerId); |
|
|
|
|
check200($test, $res); |
|
|
|
|
my $result = from_json($res->[2]->[0]); |
|
|
|
|
ok( |
|
|
|
|
!defined $result->{$providerIdName}, |
|
|
|
|
"$test: Check object is empty" |
|
|
|
|
); |
|
|
|
|
count(1); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
sub deleteProvider { |
|
|
|
|
my ( $test, $type, $confKey) = splice @_; |
|
|
|
@ -198,9 +256,10 @@ sub checkDeleteNotFound { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
my $test; |
|
|
|
|
|
|
|
|
|
my $oidcRp = { |
|
|
|
|
confKey => 'newOidcRp', |
|
|
|
|
clientId => 'newOidcRpClientId', |
|
|
|
|
confKey => 'myOidcRp1', |
|
|
|
|
clientId => 'myOidcClient1', |
|
|
|
|
exportedVars => { |
|
|
|
|
'sub' => "uid", |
|
|
|
|
family_name => "sn", |
|
|
|
@ -216,62 +275,91 @@ my $oidcRp = { |
|
|
|
|
} |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
# $test="Delete after crash"; |
|
|
|
|
# checkDelete($test, '/oidc/rp', 'newOidcRp'); |
|
|
|
|
|
|
|
|
|
$test = "Add should succeed"; |
|
|
|
|
checkAdd($test, '/oidc/rp', $oidcRp); |
|
|
|
|
checkGet($test, '/oidc/rp', 'newOidcRp', 'oidcRPMetaDataOptionsIcon', 'web.png'); |
|
|
|
|
checkGet($test, '/oidc/rp', 'newOidcRp', 'oidcRPMetaDataOptionsClientSecret', 'secret'); |
|
|
|
|
checkAdd($test, 'oidc/rp', $oidcRp); |
|
|
|
|
checkGet($test, 'oidc/rp', 'myOidcRp1', 'oidcRPMetaDataOptionsIcon', 'web.png'); |
|
|
|
|
checkGet($test, 'oidc/rp', 'myOidcRp1', 'oidcRPMetaDataOptionsClientSecret', 'secret'); |
|
|
|
|
|
|
|
|
|
$test = "Check attribute default value was set after add"; |
|
|
|
|
checkGet($test, '/oidc/rp', 'newOidcRp', 'oidcRPMetaDataOptionsIDTokenSignAlg', 'HS512'); |
|
|
|
|
checkGet($test, 'oidc/rp', 'myOidcRp1', 'oidcRPMetaDataOptionsIDTokenSignAlg', 'HS512'); |
|
|
|
|
|
|
|
|
|
$test = "Add Should fail on duplicate confKey"; |
|
|
|
|
checkAddFailsIfExists($test, '/oidc/rp', $oidcRp); |
|
|
|
|
checkAddFailsIfExists($test, 'oidc/rp', $oidcRp); |
|
|
|
|
|
|
|
|
|
$test = "Update should succeed"; |
|
|
|
|
$oidcRp->{options}->{oidcRPMetaDataOptionsClientSecret} = 'secret2'; |
|
|
|
|
checkUpdate($test, '/oidc/rp', 'newOidcRp', $oidcRp); |
|
|
|
|
checkGet($test, '/oidc/rp', 'newOidcRp', 'oidcRPMetaDataOptionsClientSecret', 'secret2'); |
|
|
|
|
$oidcRp->{options}->{oidcRPMetaDataOptionsIDTokenSignAlg} = 'RS512'; |
|
|
|
|
checkUpdate($test, 'oidc/rp', 'myOidcRp1', $oidcRp); |
|
|
|
|
checkGet($test, 'oidc/rp', 'myOidcRp1', 'oidcRPMetaDataOptionsClientSecret', 'secret2'); |
|
|
|
|
checkGet($test, 'oidc/rp', 'myOidcRp1', 'oidcRPMetaDataOptionsIDTokenSignAlg', 'RS512'); |
|
|
|
|
|
|
|
|
|
$test = "Update should fail on non existing options"; |
|
|
|
|
$oidcRp->{options}->{playingPossum} = 'elephant'; |
|
|
|
|
checkUpdateWithUnknownAttributes($test, '/oidc/rp', 'newOidcRp', $oidcRp); |
|
|
|
|
checkUpdateWithUnknownAttributes($test, 'oidc/rp', 'myOidcRp1', $oidcRp); |
|
|
|
|
delete $oidcRp->{options}->{playingPossum}; |
|
|
|
|
|
|
|
|
|
$test = "Add Should fail on duplicate clientId"; |
|
|
|
|
$oidcRp->{confKey} = 'newOidcRp2'; |
|
|
|
|
checkAddFailsIfExists($test, '/oidc/rp', $oidcRp); |
|
|
|
|
$oidcRp->{confKey} = 'myOidcRp2'; |
|
|
|
|
checkAddFailsIfExists($test, 'oidc/rp', $oidcRp); |
|
|
|
|
|
|
|
|
|
$test = "Add Should fail on non existing options"; |
|
|
|
|
$oidcRp->{confKey} = 'newOidcRp2'; |
|
|
|
|
$oidcRp->{clientId} = 'newOidcRpClientId2'; |
|
|
|
|
$oidcRp->{confKey} = 'myOidcRp2'; |
|
|
|
|
$oidcRp->{clientId} = 'myOidcClient2'; |
|
|
|
|
$oidcRp->{options}->{playingPossum} = 'ElephantInTheRoom'; |
|
|
|
|
checkAddWithUnknownAttributes($test, '/oidc/rp', $oidcRp); |
|
|
|
|
checkAddWithUnknownAttributes($test, 'oidc/rp', $oidcRp); |
|
|
|
|
delete $oidcRp->{options}->{playingPossum}; |
|
|
|
|
|
|
|
|
|
$test = "2nd add should succeed"; |
|
|
|
|
checkAdd($test, '/oidc/rp', $oidcRp); |
|
|
|
|
checkAdd($test, 'oidc/rp', $oidcRp); |
|
|
|
|
|
|
|
|
|
$test = "Update should fail if client id exists"; |
|
|
|
|
$oidcRp->{clientId} = 'newOidcRpClientId'; |
|
|
|
|
checkUpdateFailsIfExists($test, '/oidc/rp', 'newOidcRp2', $oidcRp); |
|
|
|
|
$oidcRp->{clientId} = 'myOidcClient1'; |
|
|
|
|
checkUpdateFailsIfExists($test, 'oidc/rp', 'myOidcRp2', $oidcRp); |
|
|
|
|
|
|
|
|
|
$test = "Update should fail if confKey not found"; |
|
|
|
|
$oidcRp->{confKey} = 'EasyAsPie'; |
|
|
|
|
checkUpdateNotFound($test, '/oidc/rp', 'EasyAsPie', $oidcRp); |
|
|
|
|
$oidcRp->{confKey} = 'myOidcRp3'; |
|
|
|
|
checkUpdateNotFound($test, 'oidc/rp', 'myOidcRp3', $oidcRp); |
|
|
|
|
|
|
|
|
|
$test = "Replace should succeed"; |
|
|
|
|
$oidcRp->{confKey} = 'myOidcRp2'; |
|
|
|
|
$oidcRp->{clientId} = 'myOidcClient2'; |
|
|
|
|
delete $oidcRp->{options}->{oidcRPMetaDataOptionsIcon}; |
|
|
|
|
delete $oidcRp->{options}->{oidcRPMetaDataOptionsIDTokenSignAlg}; |
|
|
|
|
checkReplace($test, 'oidc/rp', 'myOidcRp2', $oidcRp); |
|
|
|
|
|
|
|
|
|
$test = "Check attribute default value was set after replace"; |
|
|
|
|
checkGet($test, 'oidc/rp', 'myOidcRp2', 'oidcRPMetaDataOptionsIDTokenSignAlg', 'HS512'); |
|
|
|
|
|
|
|
|
|
$test = "Replace should fail on non existing options"; |
|
|
|
|
$oidcRp->{options}->{playingPossum} = 'elephant'; |
|
|
|
|
checkReplaceWithUnknownAttribute($test, 'oidc/rp', 'myOidcRp2', $oidcRp); |
|
|
|
|
delete $oidcRp->{options}->{playingPossum}; |
|
|
|
|
|
|
|
|
|
$test = "Replace should fail if confKey not found"; |
|
|
|
|
$oidcRp->{confKey} = 'myOidcRp3'; |
|
|
|
|
checkReplaceNotFound($test, 'oidc/rp', 'myOidcRp3', $oidcRp); |
|
|
|
|
|
|
|
|
|
$test = "FindByConfKey should find 2 hits"; |
|
|
|
|
checkFindByConfKey($test, 'oidc/rp', '^myOidcRp.$', 2, 'oidcRPMetaDataOptionsClientID', ['myOidcClient1','myOidcClient2']); |
|
|
|
|
|
|
|
|
|
$test = "FindByConfKey should find 1 hit"; |
|
|
|
|
checkFindByConfKey($test, 'oidc/rp', 'myOidcRp1', 1, 'oidcRPMetaDataOptionsClientID', ['myOidcClient1']); |
|
|
|
|
|
|
|
|
|
$test = "FindByConfKey should find 0 hits"; |
|
|
|
|
checkFindByConfKey($test, 'oidc/rp', 'myOidcRp3', 0); |
|
|
|
|
|
|
|
|
|
$test = "FindByClientId should find one entry"; |
|
|
|
|
checkFindByProviderId($test, 'oidc/rp', 'clientId', 'myOidcClient1'); |
|
|
|
|
|
|
|
|
|
# TODO oidcRP checkReplace checkReplaceWithUnknownAttribute checkReplaceNotFound checkReplaceWithUnknownAttribute |
|
|
|
|
$test = "FindByClientId should find nothing"; |
|
|
|
|
checkFindByProviderIdNotFound($test, 'oidc/rp', 'clientId', 'myOidcClient3'); |
|
|
|
|
|
|
|
|
|
$test = "Clean up"; |
|
|
|
|
checkDelete($test, '/oidc/rp', 'newOidcRp'); |
|
|
|
|
checkDelete($test, '/oidc/rp', 'newOidcRp2'); |
|
|
|
|
checkDelete($test, 'oidc/rp', 'myOidcRp1'); |
|
|
|
|
checkDelete($test, 'oidc/rp', 'myOidcRp2'); |
|
|
|
|
$test = "Entity should not be found after clean up"; |
|
|
|
|
checkDeleteNotFound($test, '/oidc/rp', 'newOidcRp'); |
|
|
|
|
checkDeleteNotFound($test, 'oidc/rp', 'myOidcRp1'); |
|
|
|
|
|
|
|
|
|
# TODO samlSP |
|
|
|
|
|
|
|
|
|
# Clean up generated conf files, except for "lmConf-1.json" |
|
|
|
|
unlink grep { $_ ne "t/conf/lmConf-1.json" } glob "t/conf/lmConf-*.json"; |
|
|
|
|