# HG changeset patch # User Jaroslav Tulach # Date 1272223209 -7200 # Node ID a4f6aca595e80149b43f44a25d962e43cad4fa7f # Parent 38db4aae19d939d1cd45f39c790da8a280615256 Support for permission.resign to allow the emailer cancel long running games diff -r 38db4aae19d9 -r a4f6aca595e8 pom.xml --- a/pom.xml Thu Apr 15 23:43:25 2010 +0200 +++ b/pom.xml Sun Apr 25 21:20:09 2010 +0200 @@ -35,7 +35,7 @@ 1.2 - 1.16 + 1.17 1.0-SNAPSHOT 1.60 1.0 diff -r 38db4aae19d9 -r a4f6aca595e8 webidor/src/main/java/cz/xelfi/quoridor/webidor/resources/Games.java --- a/webidor/src/main/java/cz/xelfi/quoridor/webidor/resources/Games.java Thu Apr 15 23:43:25 2010 +0200 +++ b/webidor/src/main/java/cz/xelfi/quoridor/webidor/resources/Games.java Sun Apr 25 21:20:09 2010 +0200 @@ -184,13 +184,16 @@ @QueryParam("player") String player, @QueryParam("move") String move, @QueryParam("comment") String comment - ) throws IllegalPositionException { + ) throws IllegalPositionException, IOException { String logUser = quoridor.isLoggedIn(loginId); if (logUser == null) { throw new WebApplicationException(Status.UNAUTHORIZED); } if (!logUser.equals(player)) { - throw new WebApplicationException(Status.UNAUTHORIZED); + User info = quoridor.getUsers().getUserInfo(loginId, logUser); + if (info == null || !info.hasPermission("resign")) { + throw new WebApplicationException(Status.UNAUTHORIZED); + } } if (comment == null && move == null) { throw new WebApplicationException(Status.BAD_REQUEST); diff -r 38db4aae19d9 -r a4f6aca595e8 webidor/src/test/java/cz/xelfi/quoridor/webidor/FinishedGameTest.java --- a/webidor/src/test/java/cz/xelfi/quoridor/webidor/FinishedGameTest.java Thu Apr 15 23:43:25 2010 +0200 +++ b/webidor/src/test/java/cz/xelfi/quoridor/webidor/FinishedGameTest.java Sun Apr 25 21:20:09 2010 +0200 @@ -26,6 +26,7 @@ package cz.xelfi.quoridor.webidor; +import java.util.Properties; import com.sun.jersey.api.client.GenericType; import com.sun.jersey.api.client.UniformInterfaceException; import com.sun.jersey.test.framework.JerseyTest; @@ -59,7 +60,7 @@ dir.mkdirs(); File passwd = new File(dir, "passwd"); FileOutputStream os = new FileOutputStream(passwd); - os.write("Jarda=heslo\nJirka=pesko\n".getBytes("UTF-8")); + os.write("Jarda=heslo\nJirka=pesko\nMaster=mr\n".getBytes("UTF-8")); os.close(); super.setUp(); } @@ -225,4 +226,47 @@ assertFalse("is finished", end.getId().getStatus().isInProgress()); } + @Test public void testResignForeignGame() throws Exception { + String logJarda = webResource.path("login"). + queryParam("name", "Jarda"). + queryParam("password", "heslo"). + accept(MediaType.TEXT_PLAIN). + put(String.class); + GameId s = webResource.path("games").queryParam("white", "Jarda") + .queryParam("loginID", logJarda) + .queryParam("black", "Jirka").post(GameId.class); + File usersDir = new File(dir, "users"); + usersDir.mkdirs(); + File Master = new File(usersDir, "Master"); + { + Properties p = new Properties(); + p.setProperty("email", "mas@ter.cz"); + p.setProperty("permission.resign", "true"); + p.store(new FileOutputStream(Master), ""); + } + + assertTrue("In progress", s.getStatus().isInProgress()); + String logMaster = webResource.path("login"). + queryParam("name", "Master"). + queryParam("password", "mr"). + accept(MediaType.TEXT_PLAIN). + put(String.class); + + webResource.path("games/" + s.getId()). + queryParam("loginID", logMaster). + queryParam("player", "Jarda"). + queryParam("move", "RESIGN").put(GameId.class); + try { + Game end = webResource.path("games/" + s.getId()).accept(MediaType.TEXT_XML).get(Game.class); + fail("Should not be able to get game when finished"); + } catch (UniformInterfaceException ex) { + // OK + } + Game end = webResource.path("games/" + s.getId()).queryParam("loginID", logJarda).accept(MediaType.TEXT_XML).get(Game.class); + assertEquals("BlackWins", GameStatus.blackWon, end.getId().getStatus()); + assertEquals("Jirka wins", "Jirka", end.getCurrentPlayer()); + + assertFalse("is finished", end.getId().getStatus().isInProgress()); + } + }