Merge pull request #3678 from vramik/KEYCLOAK-3777

KEYCLOAK-3777 added missing test
This commit is contained in:
Stian Thorgersen 2016-12-20 14:04:35 +01:00 committed by GitHub
commit f97a3e0745
5 changed files with 55 additions and 4 deletions

View file

@ -19,7 +19,12 @@
<body data-ng-controller="TokenCtrl">
<a href data-ng-click="showRpt()">Show Requesting Party Token </a> | <a href data-ng-click="showAccessToken()">Show Access Token </a> | <a href data-ng-click="requestEntitlements()">Request Entitlements</a> | <a href="" ng-click="Identity.logout()">Sign Out</a>
<!--<a href data-ng-click="showRpt()">Show Requesting Party Token </a> | <a href data-ng-click="showAccessToken()">Show Access Token </a> | <a href data-ng-click="requestEntitlements()">Request Entitlements</a> | <a href data-ng-click="requestEntitlement()">Request Entitlement</a> |<a href="" ng-click="Identity.logout()">Sign Out</a>-->
<a href data-ng-click="showRpt()">Show Requesting Party Token </a> |
<a href data-ng-click="showAccessToken()">Show Access Token </a> |
<a id="entitlements" href data-ng-click="requestEntitlements()">Request Entitlements</a> |
<a id="entitlement" href data-ng-click="requestEntitlement()">Request Entitlement</a> |
<a href="" ng-click="Identity.logout()">Sign Out</a>
<div id="content-area" class="col-md-9" role="main">
<div id="content" ng-view/>

View file

@ -62,7 +62,16 @@ module.controller('TokenCtrl', function ($scope, Identity) {
}
$scope.requestEntitlements = function () {
Identity.authorization.entitlement('photoz-restful-api').then(function (rpt) {});
Identity.authorization.entitlement('photoz-restful-api').then(function (rpt) {
document.getElementById("output").innerHTML = JSON.stringify(jwt_decode(rpt), null, ' ');
});
}
$scope.requestEntitlement = function () {
var param={"permissions" : [{"resource_set_name" : "Album Resource"}]};
Identity.authorization.entitlement('photoz-restful-api', param).then(function (rpt) {
document.getElementById("output").innerHTML = JSON.stringify(jwt_decode(rpt), null, ' ');
});
}
$scope.Identity = Identity;

View file

@ -47,7 +47,7 @@
"logic": "POSITIVE",
"decisionStrategy": "UNANIMOUS",
"config": {
"mavenArtifactVersion": "2.1.0-SNAPSHOT",
"mavenArtifactVersion": "2.5.0.Final-SNAPSHOT",
"mavenArtifactId": "photoz-authz-policy",
"sessionName": "MainOwnerSession",
"mavenArtifactGroupId": "org.keycloak.testsuite",

View file

@ -54,7 +54,13 @@ public class PhotozClientAuthzTestApp extends AbstractPageWithInjectedUrl {
@FindBy(xpath = "//a[@ng-click = 'Identity.logout()']")
WebElement signOutButton;
@FindBy(id = "entitlement")
WebElement entitlement;
@FindBy(id = "entitlements")
WebElement entitlements;
public void createAlbum(String name) {
navigateTo();
this.driver.findElement(By.id("create-album")).click();
@ -85,6 +91,16 @@ public class PhotozClientAuthzTestApp extends AbstractPageWithInjectedUrl {
signOutButton.click(); // Sometimes doesn't work in PhantomJS!
pause(WAIT_AFTER_OPERATION);
}
public void requestEntitlement() {
entitlement.click();
pause(WAIT_AFTER_OPERATION);
}
public void requestEntitlements() {
entitlements.click();
pause(WAIT_AFTER_OPERATION);
}
public void login(String username, String password, String... scopes) {
if (scopes.length > 0) {

View file

@ -609,6 +609,27 @@ public abstract class AbstractPhotozExampleAdapterTest extends AbstractExampleAd
this.deployer.undeploy(RESOURCE_SERVER_ID);
}
}
//KEYCLOAK-3777
@Test
public void testEntitlementRequest() {
try {
this.deployer.deploy(RESOURCE_SERVER_ID);
clientPage.navigateTo();
loginToClientPage("admin", "admin");
clientPage.requestEntitlements();
assertTrue(driver.getPageSource().contains("urn:photoz.com:scopes:album:admin:manage"));
clientPage.requestEntitlement();
String pageSource = driver.getPageSource();
assertTrue(pageSource.contains("urn:photoz.com:scopes:album:view"));
assertFalse(pageSource.contains("urn:photoz.com:scopes:album:admin:manage"));
} finally {
this.deployer.undeploy(RESOURCE_SERVER_ID);
}
}
private void importResourceServerSettings() throws FileNotFoundException {
getAuthorizationResource().importSettings(loadJson(new FileInputStream(new File(TEST_APPS_HOME_DIR + "/photoz/photoz-restful-api-authz-service.json")), ResourceServerRepresentation.class));