1.1 --- a/pom.xml Thu Apr 15 23:43:25 2010 +0200
1.2 +++ b/pom.xml Sun Apr 25 21:20:09 2010 +0200
1.3 @@ -35,7 +35,7 @@
1.4 </organization>
1.5 <properties>
1.6 <quoridorVersion>1.2</quoridorVersion>
1.7 - <webidorVersion>1.16</webidorVersion>
1.8 + <webidorVersion>1.17</webidorVersion>
1.9 <visidorVersion>1.0-SNAPSHOT</visidorVersion>
1.10 <freemarkerVersion>1.60</freemarkerVersion>
1.11 <emailerVersion>1.0</emailerVersion>
2.1 --- a/webidor/src/main/java/cz/xelfi/quoridor/webidor/resources/Games.java Thu Apr 15 23:43:25 2010 +0200
2.2 +++ b/webidor/src/main/java/cz/xelfi/quoridor/webidor/resources/Games.java Sun Apr 25 21:20:09 2010 +0200
2.3 @@ -184,13 +184,16 @@
2.4 @QueryParam("player") String player,
2.5 @QueryParam("move") String move,
2.6 @QueryParam("comment") String comment
2.7 - ) throws IllegalPositionException {
2.8 + ) throws IllegalPositionException, IOException {
2.9 String logUser = quoridor.isLoggedIn(loginId);
2.10 if (logUser == null) {
2.11 throw new WebApplicationException(Status.UNAUTHORIZED);
2.12 }
2.13 if (!logUser.equals(player)) {
2.14 - throw new WebApplicationException(Status.UNAUTHORIZED);
2.15 + User info = quoridor.getUsers().getUserInfo(loginId, logUser);
2.16 + if (info == null || !info.hasPermission("resign")) {
2.17 + throw new WebApplicationException(Status.UNAUTHORIZED);
2.18 + }
2.19 }
2.20 if (comment == null && move == null) {
2.21 throw new WebApplicationException(Status.BAD_REQUEST);
3.1 --- a/webidor/src/test/java/cz/xelfi/quoridor/webidor/FinishedGameTest.java Thu Apr 15 23:43:25 2010 +0200
3.2 +++ b/webidor/src/test/java/cz/xelfi/quoridor/webidor/FinishedGameTest.java Sun Apr 25 21:20:09 2010 +0200
3.3 @@ -26,6 +26,7 @@
3.4
3.5 package cz.xelfi.quoridor.webidor;
3.6
3.7 +import java.util.Properties;
3.8 import com.sun.jersey.api.client.GenericType;
3.9 import com.sun.jersey.api.client.UniformInterfaceException;
3.10 import com.sun.jersey.test.framework.JerseyTest;
3.11 @@ -59,7 +60,7 @@
3.12 dir.mkdirs();
3.13 File passwd = new File(dir, "passwd");
3.14 FileOutputStream os = new FileOutputStream(passwd);
3.15 - os.write("Jarda=heslo\nJirka=pesko\n".getBytes("UTF-8"));
3.16 + os.write("Jarda=heslo\nJirka=pesko\nMaster=mr\n".getBytes("UTF-8"));
3.17 os.close();
3.18 super.setUp();
3.19 }
3.20 @@ -225,4 +226,47 @@
3.21 assertFalse("is finished", end.getId().getStatus().isInProgress());
3.22 }
3.23
3.24 + @Test public void testResignForeignGame() throws Exception {
3.25 + String logJarda = webResource.path("login").
3.26 + queryParam("name", "Jarda").
3.27 + queryParam("password", "heslo").
3.28 + accept(MediaType.TEXT_PLAIN).
3.29 + put(String.class);
3.30 + GameId s = webResource.path("games").queryParam("white", "Jarda")
3.31 + .queryParam("loginID", logJarda)
3.32 + .queryParam("black", "Jirka").post(GameId.class);
3.33 + File usersDir = new File(dir, "users");
3.34 + usersDir.mkdirs();
3.35 + File Master = new File(usersDir, "Master");
3.36 + {
3.37 + Properties p = new Properties();
3.38 + p.setProperty("email", "mas@ter.cz");
3.39 + p.setProperty("permission.resign", "true");
3.40 + p.store(new FileOutputStream(Master), "");
3.41 + }
3.42 +
3.43 + assertTrue("In progress", s.getStatus().isInProgress());
3.44 + String logMaster = webResource.path("login").
3.45 + queryParam("name", "Master").
3.46 + queryParam("password", "mr").
3.47 + accept(MediaType.TEXT_PLAIN).
3.48 + put(String.class);
3.49 +
3.50 + webResource.path("games/" + s.getId()).
3.51 + queryParam("loginID", logMaster).
3.52 + queryParam("player", "Jarda").
3.53 + queryParam("move", "RESIGN").put(GameId.class);
3.54 + try {
3.55 + Game end = webResource.path("games/" + s.getId()).accept(MediaType.TEXT_XML).get(Game.class);
3.56 + fail("Should not be able to get game when finished");
3.57 + } catch (UniformInterfaceException ex) {
3.58 + // OK
3.59 + }
3.60 + Game end = webResource.path("games/" + s.getId()).queryParam("loginID", logJarda).accept(MediaType.TEXT_XML).get(Game.class);
3.61 + assertEquals("BlackWins", GameStatus.blackWon, end.getId().getStatus());
3.62 + assertEquals("Jirka wins", "Jirka", end.getCurrentPlayer());
3.63 +
3.64 + assertFalse("is finished", end.getId().getStatus().isInProgress());
3.65 + }
3.66 +
3.67 }