Repository: ignite Updated Branches: refs/heads/ignite-8201 3780ac0a0 -> 6c01882d7
IGNITE-8201 Fixed tests. Project: http://git-wip-us.apache.org/repos/asf/ignite/repo Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/6c01882d Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/6c01882d Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/6c01882d Branch: refs/heads/ignite-8201 Commit: 6c01882d7ef6a94bbb0b6f10d5290cb1a1e4a04f Parents: 3780ac0 Author: Alexey Kuznetsov <akuznet...@apache.org> Authored: Thu Apr 12 00:29:56 2018 +0700 Committer: Alexey Kuznetsov <akuznet...@apache.org> Committed: Thu Apr 12 00:29:56 2018 +0700 ---------------------------------------------------------------------- .../JettyRestProcessorAbstractSelfTest.java | 29 ++++++++++++++++++-- ...ettyRestProcessorAuthenticationSelfTest.java | 27 ++++++++++++++++-- .../processors/rest/GridRestProcessor.java | 15 ++++++---- 3 files changed, 61 insertions(+), 10 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/ignite/blob/6c01882d/modules/clients/src/test/java/org/apache/ignite/internal/processors/rest/JettyRestProcessorAbstractSelfTest.java ---------------------------------------------------------------------- diff --git a/modules/clients/src/test/java/org/apache/ignite/internal/processors/rest/JettyRestProcessorAbstractSelfTest.java b/modules/clients/src/test/java/org/apache/ignite/internal/processors/rest/JettyRestProcessorAbstractSelfTest.java index 38f22ba..e36447b 100644 --- a/modules/clients/src/test/java/org/apache/ignite/internal/processors/rest/JettyRestProcessorAbstractSelfTest.java +++ b/modules/clients/src/test/java/org/apache/ignite/internal/processors/rest/JettyRestProcessorAbstractSelfTest.java @@ -302,7 +302,11 @@ public abstract class JettyRestProcessorAbstractSelfTest extends AbstractRestPro JsonNode node = JSON_MAPPER.readTree(content); - assertEquals(bulk, node.get("affinityNodeId").isNull()); + JsonNode affNode = node.get("affinityNodeId"); + + if (affNode != null) + assertEquals(bulk, affNode.isNull()); + assertEquals(STATUS_SUCCESS, node.get("successStatus").asInt()); assertTrue(node.get("error").isNull()); @@ -350,7 +354,7 @@ public abstract class JettyRestProcessorAbstractSelfTest extends AbstractRestPro JsonNode node = JSON_MAPPER.readTree(content); - assertEquals(0, node.get("successStatus").asInt()); + assertEquals(STATUS_SUCCESS, node.get("successStatus").asInt()); assertTrue(node.get("error").isNull()); assertNotSame(securityEnabled(), node.get("sessionToken").isNull()); @@ -368,7 +372,7 @@ public abstract class JettyRestProcessorAbstractSelfTest extends AbstractRestPro JsonNode node = JSON_MAPPER.readTree(content); - assertEquals(0, node.get("successStatus").asInt()); + assertEquals(STATUS_SUCCESS, node.get("successStatus").asInt()); assertTrue(node.get("error").isNull()); assertFalse(node.get("response").isNull()); @@ -974,10 +978,25 @@ public abstract class JettyRestProcessorAbstractSelfTest extends AbstractRestPro assertCacheOperation(ret, true); } + /** */ + private void failIgnite_5874() { + DataStorageConfiguration dsCfg = ignite(0).configuration().getDataStorageConfiguration(); + + if (dsCfg.getDefaultDataRegionConfiguration().isPersistenceEnabled()) + fail("IGNITE-5874"); + + for (DataRegionConfiguration dataRegCfg : dsCfg.getDataRegionConfigurations()) { + if (dataRegCfg.isPersistenceEnabled()) + fail("IGNITE-5874"); + } + } + /** * @throws Exception If failed. */ public void testPutWithExpiration() throws Exception { + failIgnite_5874(); + String ret = content(DEFAULT_CACHE_NAME, GridRestCommand.CACHE_PUT, "key", "putKey", "val", "putVal", @@ -1014,6 +1033,8 @@ public abstract class JettyRestProcessorAbstractSelfTest extends AbstractRestPro * @throws Exception If failed. */ public void testAddWithExpiration() throws Exception { + failIgnite_5874(); + String ret = content(DEFAULT_CACHE_NAME, GridRestCommand.CACHE_ADD, "key", "addKey", "val", "addVal", @@ -1153,6 +1174,8 @@ public abstract class JettyRestProcessorAbstractSelfTest extends AbstractRestPro * @throws Exception If failed. */ public void testReplaceWithExpiration() throws Exception { + failIgnite_5874(); + jcache().put("replaceKey", "replaceVal"); assertEquals("replaceVal", jcache().get("replaceKey")); http://git-wip-us.apache.org/repos/asf/ignite/blob/6c01882d/modules/clients/src/test/java/org/apache/ignite/internal/processors/rest/JettyRestProcessorAuthenticationSelfTest.java ---------------------------------------------------------------------- diff --git a/modules/clients/src/test/java/org/apache/ignite/internal/processors/rest/JettyRestProcessorAuthenticationSelfTest.java b/modules/clients/src/test/java/org/apache/ignite/internal/processors/rest/JettyRestProcessorAuthenticationSelfTest.java index 1536d9d..fd52ee7 100644 --- a/modules/clients/src/test/java/org/apache/ignite/internal/processors/rest/JettyRestProcessorAuthenticationSelfTest.java +++ b/modules/clients/src/test/java/org/apache/ignite/internal/processors/rest/JettyRestProcessorAuthenticationSelfTest.java @@ -130,12 +130,35 @@ public class JettyRestProcessorAuthenticationSelfTest extends JettyRestProcessor /** * @throws Exception If failed. */ - public void testMissingSessionToken() throws Exception { + public void testInvalidSessionToken() throws Exception { tok = null; String ret = content(null, GridRestCommand.VERSION); - assertResponseContainsError(ret, "The user name or password is incorrect"); + assertResponseContainsError(ret, "Failed to handle request - session token not found or invalid"); + + tok = "InvalidToken"; + + ret = content(null, GridRestCommand.VERSION); + + assertResponseContainsError(ret, "Failed to handle request - session token not found or invalid"); + + tok = "26BE027D32CC42329DEC92D517B44E9E"; + + ret = content(null, GridRestCommand.VERSION); + + assertResponseContainsError(ret, "Failed to handle request - unknown session token (maybe expired session)"); + + tok = null; // Cleanup token for next tests. + } + + /** + * @throws Exception If failed. + */ + public void testWithToken() throws Exception { + String ret = content(null, GridRestCommand.VERSION); + + assertResponseSucceeded(ret, false); } /** http://git-wip-us.apache.org/repos/asf/ignite/blob/6c01882d/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/GridRestProcessor.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/GridRestProcessor.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/GridRestProcessor.java index 6ca1351..c7a74c5 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/GridRestProcessor.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/GridRestProcessor.java @@ -82,6 +82,7 @@ import org.apache.ignite.plugin.security.SecurityPermission; import org.apache.ignite.thread.IgniteThread; import static org.apache.ignite.IgniteSystemProperties.IGNITE_REST_START_ON_CLIENT; +import static org.apache.ignite.internal.processors.rest.GridRestCommand.AUTHENTICATE; import static org.apache.ignite.internal.processors.rest.GridRestResponse.STATUS_AUTH_FAILED; import static org.apache.ignite.internal.processors.rest.GridRestResponse.STATUS_FAILED; import static org.apache.ignite.internal.processors.rest.GridRestResponse.STATUS_SECURITY_CHECK_FAILED; @@ -231,10 +232,11 @@ public class GridRestProcessor extends GridProcessorAdapter { try { ses = session(req); } + catch (IgniteAuthenticationException e) { + return new GridFinishedFuture<>(new GridRestResponse(STATUS_AUTH_FAILED, e.getMessage())); + } catch (IgniteCheckedException e) { - GridRestResponse res = new GridRestResponse(STATUS_FAILED, e.getMessage()); - - return new GridFinishedFuture<>(res); + return new GridFinishedFuture<>(new GridRestResponse(STATUS_FAILED, e.getMessage())); } assert ses != null; @@ -285,9 +287,9 @@ public class GridRestProcessor extends GridProcessorAdapter { throw new IgniteAuthenticationException("The user name or password is incorrect"); ses.authCtx = ctx.authentication().authenticate(login, pwd); - - req.authorizationContext(ses.authCtx); } + + req.authorizationContext(ses.authCtx); } catch (IgniteCheckedException e) { return new GridFinishedFuture<>(new GridRestResponse(STATUS_AUTH_FAILED, e.getMessage())); @@ -363,6 +365,9 @@ public class GridRestProcessor extends GridProcessorAdapter { while (true) { if (F.isEmpty(sesTok) && clientId == null) { + if (ctx.authentication().enabled() && req.command() != AUTHENTICATE) + throw new IgniteAuthenticationException("Failed to handle request - session token not found or invalid"); + Session ses = Session.random(); UUID oldSesId = clientId2SesId.put(ses.clientId, ses.sesId);