KEYCLOAK-3704 Add missing test
This commit is contained in:
parent
732d56b0c0
commit
61e7936d79
5 changed files with 54 additions and 9 deletions
|
@ -88,6 +88,16 @@ module.controller('AlbumCtrl', function ($scope, $http, $routeParams, $location,
|
||||||
$location.path('/');
|
$location.path('/');
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
$scope.createWithInvalidUser = function () {
|
||||||
|
var newAlbum = new Album($scope.album);
|
||||||
|
newAlbum.$save({user: 'invalidUser'}, function (data) {
|
||||||
|
document.getElementById("output").innerHTML = 'Request was successful'
|
||||||
|
},
|
||||||
|
function (response) {
|
||||||
|
document.getElementById("output").innerHTML = response.data;
|
||||||
|
});
|
||||||
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
module.controller('ProfileCtrl', function ($scope, $http, $routeParams, $location, Profile) {
|
module.controller('ProfileCtrl', function ($scope, $http, $routeParams, $location, Profile) {
|
||||||
|
|
|
@ -4,4 +4,5 @@
|
||||||
Name: <input type="text" id="album.name" ng-model="album.name"/>
|
Name: <input type="text" id="album.name" ng-model="album.name"/>
|
||||||
|
|
||||||
<button ng-click="create()" id="save-album">Save</button>
|
<button ng-click="create()" id="save-album">Save</button>
|
||||||
|
<button ng-click="createWithInvalidUser()" id="save-album-invalid">Save with invalid user</button>
|
||||||
</form>
|
</form>
|
||||||
|
|
|
@ -22,6 +22,7 @@ import javax.ws.rs.POST;
|
||||||
import javax.ws.rs.Path;
|
import javax.ws.rs.Path;
|
||||||
import javax.ws.rs.PathParam;
|
import javax.ws.rs.PathParam;
|
||||||
import javax.ws.rs.Produces;
|
import javax.ws.rs.Produces;
|
||||||
|
import javax.ws.rs.QueryParam;
|
||||||
import javax.ws.rs.core.Context;
|
import javax.ws.rs.core.Context;
|
||||||
import javax.ws.rs.core.Response;
|
import javax.ws.rs.core.Response;
|
||||||
import javax.ws.rs.core.Response.Status;
|
import javax.ws.rs.core.Response.Status;
|
||||||
|
@ -54,17 +55,18 @@ public class AlbumService {
|
||||||
|
|
||||||
@POST
|
@POST
|
||||||
@Consumes("application/json")
|
@Consumes("application/json")
|
||||||
public Response create(Album newAlbum) {
|
public Response create(Album newAlbum, @QueryParam("user") String username) {
|
||||||
newAlbum.setId(++nextId);
|
newAlbum.setId(++nextId);
|
||||||
|
|
||||||
Principal userPrincipal = request.getUserPrincipal();
|
if (username == null) {
|
||||||
|
username = request.getUserPrincipal().getName();
|
||||||
newAlbum.setUserId(userPrincipal.getName());
|
}
|
||||||
|
|
||||||
|
newAlbum.setUserId(username);
|
||||||
Query queryDuplicatedAlbum = this.entityManager.createQuery("from Album where name = :name and userId = :userId");
|
Query queryDuplicatedAlbum = this.entityManager.createQuery("from Album where name = :name and userId = :userId");
|
||||||
|
|
||||||
queryDuplicatedAlbum.setParameter("name", newAlbum.getName());
|
queryDuplicatedAlbum.setParameter("name", newAlbum.getName());
|
||||||
queryDuplicatedAlbum.setParameter("userId", userPrincipal.getName());
|
queryDuplicatedAlbum.setParameter("userId", username);
|
||||||
|
|
||||||
if (!queryDuplicatedAlbum.getResultList().isEmpty()) {
|
if (!queryDuplicatedAlbum.getResultList().isEmpty()) {
|
||||||
throw new ErrorResponse("Name [" + newAlbum.getName() + "] already taken. Choose another one.", Status.CONFLICT);
|
throw new ErrorResponse("Name [" + newAlbum.getName() + "] already taken. Choose another one.", Status.CONFLICT);
|
||||||
|
|
|
@ -53,23 +53,34 @@ public class PhotozClientAuthzTestApp extends AbstractPageWithInjectedUrl {
|
||||||
protected ConsentPage consentPage;
|
protected ConsentPage consentPage;
|
||||||
|
|
||||||
@FindBy(xpath = "//a[@ng-click = 'Identity.logout()']")
|
@FindBy(xpath = "//a[@ng-click = 'Identity.logout()']")
|
||||||
WebElement signOutButton;
|
private WebElement signOutButton;
|
||||||
|
|
||||||
@FindBy(id = "entitlement")
|
@FindBy(id = "entitlement")
|
||||||
WebElement entitlement;
|
private WebElement entitlement;
|
||||||
|
|
||||||
@FindBy(id = "entitlements")
|
@FindBy(id = "entitlements")
|
||||||
WebElement entitlements;
|
private WebElement entitlements;
|
||||||
|
|
||||||
|
@FindBy(id = "output")
|
||||||
|
private WebElement output;
|
||||||
|
|
||||||
public void createAlbum(String name) {
|
public void createAlbum(String name) {
|
||||||
|
createAlbum(name, "save-album");
|
||||||
|
}
|
||||||
|
|
||||||
|
public void createAlbum(String name, String buttonId) {
|
||||||
navigateTo();
|
navigateTo();
|
||||||
this.driver.findElement(By.id("create-album")).click();
|
this.driver.findElement(By.id("create-album")).click();
|
||||||
Form.setInputValue(this.driver.findElement(By.id("album.name")), name);
|
Form.setInputValue(this.driver.findElement(By.id("album.name")), name);
|
||||||
pause(200); // We need to wait a bit for the form to "accept" the input (otherwise it registers the input as empty)
|
pause(200); // We need to wait a bit for the form to "accept" the input (otherwise it registers the input as empty)
|
||||||
this.driver.findElement(By.id("save-album")).click();
|
this.driver.findElement(By.id(buttonId)).click();
|
||||||
pause(WAIT_AFTER_OPERATION);
|
pause(WAIT_AFTER_OPERATION);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void createAlbumWithInvalidUser(String name) {
|
||||||
|
createAlbum(name, "save-album-invalid");
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public URL getInjectedUrl() {
|
public URL getInjectedUrl() {
|
||||||
return this.url;
|
return this.url;
|
||||||
|
@ -137,6 +148,10 @@ public class PhotozClientAuthzTestApp extends AbstractPageWithInjectedUrl {
|
||||||
pause(WAIT_AFTER_OPERATION);
|
pause(WAIT_AFTER_OPERATION);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public WebElement getOutput() {
|
||||||
|
return output;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void navigateTo(boolean waitForMatch) {
|
public void navigateTo(boolean waitForMatch) {
|
||||||
super.navigateTo(waitForMatch);
|
super.navigateTo(waitForMatch);
|
||||||
|
|
|
@ -59,6 +59,7 @@ import static org.junit.Assert.assertFalse;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.Assert.assertTrue;
|
||||||
import static org.keycloak.testsuite.util.IOUtil.loadJson;
|
import static org.keycloak.testsuite.util.IOUtil.loadJson;
|
||||||
import static org.keycloak.testsuite.util.IOUtil.loadRealm;
|
import static org.keycloak.testsuite.util.IOUtil.loadRealm;
|
||||||
|
import static org.keycloak.testsuite.util.WaitUtils.waitUntilElement;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author <a href="mailto:psilva@redhat.com">Pedro Igor</a>
|
* @author <a href="mailto:psilva@redhat.com">Pedro Igor</a>
|
||||||
|
@ -141,6 +142,22 @@ public abstract class AbstractPhotozExampleAdapterTest extends AbstractExampleAd
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void createAlbumWithInvalidUser() {
|
||||||
|
try {
|
||||||
|
this.deployer.deploy(RESOURCE_SERVER_ID);
|
||||||
|
|
||||||
|
loginToClientPage("alice", "alice");
|
||||||
|
|
||||||
|
clientPage.createAlbumWithInvalidUser("Alice Family Album");
|
||||||
|
|
||||||
|
waitUntilElement(clientPage.getOutput()).text().not().contains("Request was successful");
|
||||||
|
waitUntilElement(clientPage.getOutput()).text().contains("Could not register protected resource");
|
||||||
|
} finally {
|
||||||
|
this.deployer.undeploy(RESOURCE_SERVER_ID);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testOnlyOwnerCanDeleteAlbum() throws Exception {
|
public void testOnlyOwnerCanDeleteAlbum() throws Exception {
|
||||||
try {
|
try {
|
||||||
|
|
Loading…
Reference in a new issue