Repository: jena Updated Branches: refs/heads/master 863c246a6 -> cee0769ff
Stablise build - different ports for Fuseki1 and Fuseki2 testing Use 4 different ports for the testing servers for Fuseki1 (TestServer and TestAuth) and Fuseki2 (TestServer and TestAuth). Sometimes, ports from earlier test servers are not released quickly by the OS (seen on linux; intermittant) and later parts of the build break with "port in use". Project: http://git-wip-us.apache.org/repos/asf/jena/repo Commit: http://git-wip-us.apache.org/repos/asf/jena/commit/cee0769f Tree: http://git-wip-us.apache.org/repos/asf/jena/tree/cee0769f Diff: http://git-wip-us.apache.org/repos/asf/jena/diff/cee0769f Branch: refs/heads/master Commit: cee0769ff86ec1ffa1ab03178613651295803a08 Parents: 863c246 Author: Andy Seaborne <[email protected]> Authored: Fri Feb 20 19:01:11 2015 +0000 Committer: Andy Seaborne <[email protected]> Committed: Fri Feb 20 19:01:11 2015 +0000 ---------------------------------------------------------------------- .../java/org/apache/jena/fuseki/ServerTest.java | 2 +- .../java/org/apache/jena/fuseki/TestAuth.java | 93 +++++++++++--------- .../java/org/apache/jena/fuseki/ServerTest.java | 12 +-- .../java/org/apache/jena/fuseki/TestAuth.java | 90 ++++++++++--------- 4 files changed, 107 insertions(+), 90 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/jena/blob/cee0769f/jena-fuseki/src/test/java/org/apache/jena/fuseki/ServerTest.java ---------------------------------------------------------------------- diff --git a/jena-fuseki/src/test/java/org/apache/jena/fuseki/ServerTest.java b/jena-fuseki/src/test/java/org/apache/jena/fuseki/ServerTest.java index 7a4f6dc..18150b1 100644 --- a/jena-fuseki/src/test/java/org/apache/jena/fuseki/ServerTest.java +++ b/jena-fuseki/src/test/java/org/apache/jena/fuseki/ServerTest.java @@ -44,7 +44,7 @@ public class ServerTest { // Abstraction that runs a SPARQL server for tests. - public static final int port = 3535 ; + public static final int port = 3635 ; // Different to the Fuseki2 test port. public static final String urlRoot = "http://localhost:"+port+"/" ; public static final String datasetPath = "/dataset" ; public static final String serviceUpdate = "http://localhost:"+port+datasetPath+"/update" ; http://git-wip-us.apache.org/repos/asf/jena/blob/cee0769f/jena-fuseki/src/test/java/org/apache/jena/fuseki/TestAuth.java ---------------------------------------------------------------------- diff --git a/jena-fuseki/src/test/java/org/apache/jena/fuseki/TestAuth.java b/jena-fuseki/src/test/java/org/apache/jena/fuseki/TestAuth.java index 3324a92..4cff28d 100644 --- a/jena-fuseki/src/test/java/org/apache/jena/fuseki/TestAuth.java +++ b/jena-fuseki/src/test/java/org/apache/jena/fuseki/TestAuth.java @@ -59,8 +59,17 @@ import com.hp.hpl.jena.update.UpdateRequest ; /** * Tests Fuseki operation with authentication enabled */ -public class TestAuth extends ServerTest { +public class TestAuth { + // Use different port etc because sometimes the previous testing servers + // don't release ports fast enough (OS issue / Linux) + public static final int authPort = ServerTest.port+10 ; + public static final String authUrlRoot = "http://localhost:"+authPort+"/" ; + public static final String authDatasetPath = "/dataset" ; + public static final String authServiceUpdate = "http://localhost:"+authPort+authDatasetPath+"/update" ; + public static final String authServiceQuery = "http://localhost:"+authPort+authDatasetPath+"/query" ; + public static final String authServiceREST = "http://localhost:"+authPort+authDatasetPath+"/data" ; + private static File realmFile; private static SPARQLServer server; @@ -83,9 +92,9 @@ public class TestAuth extends ServerTest { DatasetGraph dsg = DatasetGraphFactory.createMem(); // This must agree with ServerTest - ServerConfig conf = FusekiConfig.defaultConfiguration(datasetPath, dsg, true, true); - conf.port = ServerTest.port; - conf.pagesPort = ServerTest.port; + ServerConfig conf = FusekiConfig.defaultConfiguration(authDatasetPath, dsg, true, true); + conf.port = authPort ; + conf.pagesPort = authPort ; conf.authConfigFile = realmFile.getAbsolutePath(); server = new SPARQLServer(conf); @@ -104,14 +113,14 @@ public class TestAuth extends ServerTest { @Test(expected = QueryExceptionHTTP.class) public void query_with_auth_01() { - QueryEngineHTTP qe = (QueryEngineHTTP) QueryExecutionFactory.sparqlService(serviceQuery, "ASK { }"); + QueryEngineHTTP qe = (QueryEngineHTTP) QueryExecutionFactory.sparqlService(authServiceQuery, "ASK { }"); // No auth credentials should result in an error qe.execAsk(); } @Test(expected = QueryExceptionHTTP.class) public void query_with_auth_02() { - QueryEngineHTTP qe = (QueryEngineHTTP) QueryExecutionFactory.sparqlService(serviceQuery, "ASK { }"); + QueryEngineHTTP qe = (QueryEngineHTTP) QueryExecutionFactory.sparqlService(authServiceQuery, "ASK { }"); // Auth credentials for valid user with bad password qe.setBasicAuthentication("allowed", "incorrect".toCharArray()); qe.execAsk(); @@ -119,7 +128,7 @@ public class TestAuth extends ServerTest { @Test public void query_with_auth_03() { - QueryEngineHTTP qe = (QueryEngineHTTP) QueryExecutionFactory.sparqlService(serviceQuery, "ASK { }"); + QueryEngineHTTP qe = (QueryEngineHTTP) QueryExecutionFactory.sparqlService(authServiceQuery, "ASK { }"); // Auth credentials for valid user with correct password qe.setBasicAuthentication("allowed", "password".toCharArray()); Assert.assertTrue(qe.execAsk()); @@ -127,7 +136,7 @@ public class TestAuth extends ServerTest { @Test(expected = QueryExceptionHTTP.class) public void query_with_auth_04() { - QueryEngineHTTP qe = (QueryEngineHTTP) QueryExecutionFactory.sparqlService(serviceQuery, "ASK { }"); + QueryEngineHTTP qe = (QueryEngineHTTP) QueryExecutionFactory.sparqlService(authServiceQuery, "ASK { }"); // Auth credentials for valid user with correct password BUT not in // correct role qe.setBasicAuthentication("forbidden", "password".toCharArray()); @@ -137,7 +146,7 @@ public class TestAuth extends ServerTest { @Test public void query_with_auth_05() { // Uses auth and enables compression - QueryEngineHTTP qe = (QueryEngineHTTP) QueryExecutionFactory.sparqlService(serviceQuery, "ASK { }"); + QueryEngineHTTP qe = (QueryEngineHTTP) QueryExecutionFactory.sparqlService(authServiceQuery, "ASK { }"); qe.setAllowDeflate(true); qe.setAllowGZip(true); @@ -149,7 +158,7 @@ public class TestAuth extends ServerTest { @Test(expected = QueryExceptionHTTP.class) public void query_with_auth_06() { // Uses auth and enables compression - QueryEngineHTTP qe = (QueryEngineHTTP) QueryExecutionFactory.sparqlService(serviceQuery, "ASK { }"); + QueryEngineHTTP qe = (QueryEngineHTTP) QueryExecutionFactory.sparqlService(authServiceQuery, "ASK { }"); qe.setAllowDeflate(true); qe.setAllowGZip(true); @@ -160,7 +169,7 @@ public class TestAuth extends ServerTest { @Test(expected = QueryExceptionHTTP.class) public void query_with_auth_07() throws URISyntaxException { - QueryEngineHTTP qe = (QueryEngineHTTP) QueryExecutionFactory.sparqlService(serviceQuery, "ASK { }"); + QueryEngineHTTP qe = (QueryEngineHTTP) QueryExecutionFactory.sparqlService(authServiceQuery, "ASK { }"); // Auth credentials for valid user with correct password but scoped to // wrong URI @@ -172,22 +181,22 @@ public class TestAuth extends ServerTest { @Test public void query_with_auth_08() throws URISyntaxException { - QueryEngineHTTP qe = (QueryEngineHTTP) QueryExecutionFactory.sparqlService(serviceQuery, "ASK { }"); + QueryEngineHTTP qe = (QueryEngineHTTP) QueryExecutionFactory.sparqlService(authServiceQuery, "ASK { }"); // Auth credentials for valid user with correct password and scoped to // correct URI - ScopedAuthenticator authenticator = new ScopedAuthenticator(new URI(serviceQuery), "allowed", "password".toCharArray()); + ScopedAuthenticator authenticator = new ScopedAuthenticator(new URI(authServiceQuery), "allowed", "password".toCharArray()); qe.setAuthenticator(authenticator); Assert.assertTrue(qe.execAsk()); } @Test public void query_with_auth_09() throws URISyntaxException { - QueryEngineHTTP qe = (QueryEngineHTTP) QueryExecutionFactory.sparqlService(serviceQuery, "ASK { }"); + QueryEngineHTTP qe = (QueryEngineHTTP) QueryExecutionFactory.sparqlService(authServiceQuery, "ASK { }"); // Auth credentials for valid user with correct password using // pre-emptive auth - ScopedAuthenticator authenticator = new ScopedAuthenticator(new URI(serviceQuery), "allowed", "password".toCharArray()); + ScopedAuthenticator authenticator = new ScopedAuthenticator(new URI(authServiceQuery), "allowed", "password".toCharArray()); qe.setAuthenticator(new PreemptiveBasicAuthenticator(authenticator)); Assert.assertTrue(qe.execAsk()); } @@ -196,7 +205,7 @@ public class TestAuth extends ServerTest { public void query_with_auth_10() { Context ctx = ARQ.getContext(); try { - QueryEngineHTTP qe = (QueryEngineHTTP) QueryExecutionFactory.sparqlService(serviceQuery, "ASK { }"); + QueryEngineHTTP qe = (QueryEngineHTTP) QueryExecutionFactory.sparqlService(authServiceQuery, "ASK { }"); // Auth credentials for valid user with correct password and scoped // to correct URI @@ -205,7 +214,7 @@ public class TestAuth extends ServerTest { Context authContext = new Context(); authContext.put(Service.queryAuthUser, "allowed"); authContext.put(Service.queryAuthPwd, "password"); - serviceContext.put(serviceQuery, authContext); + serviceContext.put(authServiceQuery, authContext); ctx.put(Service.serviceContext, serviceContext); qe.setAuthenticator(new ServiceAuthenticator()); @@ -219,7 +228,7 @@ public class TestAuth extends ServerTest { public void query_with_auth_11() { Context ctx = ARQ.getContext(); try { - QueryEngineHTTP qe = (QueryEngineHTTP) QueryExecutionFactory.sparqlService(serviceQuery, "ASK { }"); + QueryEngineHTTP qe = (QueryEngineHTTP) QueryExecutionFactory.sparqlService(authServiceQuery, "ASK { }"); // Auth credentials for valid user with correct password and scoped // to base URI of the actual service URL @@ -228,7 +237,7 @@ public class TestAuth extends ServerTest { Context authContext = new Context(); authContext.put(Service.queryAuthUser, "allowed"); authContext.put(Service.queryAuthPwd, "password"); - serviceContext.put(urlRoot, authContext); + serviceContext.put(authUrlRoot, authContext); ctx.put(Service.serviceContext, serviceContext); qe.setAuthenticator(new ServiceAuthenticator()); @@ -242,7 +251,7 @@ public class TestAuth extends ServerTest { public void query_with_auth_12() { ARQ.getContext().remove(Service.serviceContext); - QueryEngineHTTP qe = (QueryEngineHTTP) QueryExecutionFactory.sparqlService(serviceQuery, "ASK { }"); + QueryEngineHTTP qe = (QueryEngineHTTP) QueryExecutionFactory.sparqlService(authServiceQuery, "ASK { }"); // Auth credentials for valid user with correct password // Use service authenticator with fallback credentials. @@ -252,22 +261,22 @@ public class TestAuth extends ServerTest { @Test public void query_with_auth_13() throws URISyntaxException { - QueryEngineHTTP qe = (QueryEngineHTTP) QueryExecutionFactory.sparqlService(serviceQuery, "ASK { }"); + QueryEngineHTTP qe = (QueryEngineHTTP) QueryExecutionFactory.sparqlService(authServiceQuery, "ASK { }"); // Auth credentials for valid user with correct password and scoped to // base URI of the actual service URL - ScopedAuthenticator authenticator = new ScopedAuthenticator(new URI(urlRoot), "allowed", "password".toCharArray()); + ScopedAuthenticator authenticator = new ScopedAuthenticator(new URI(authUrlRoot), "allowed", "password".toCharArray()); qe.setAuthenticator(authenticator); Assert.assertTrue(qe.execAsk()); } @Test public void query_with_auth_14() throws URISyntaxException { - QueryEngineHTTP qe = (QueryEngineHTTP) QueryExecutionFactory.sparqlService(serviceQuery, "ASK { }"); + QueryEngineHTTP qe = (QueryEngineHTTP) QueryExecutionFactory.sparqlService(authServiceQuery, "ASK { }"); // Auth credentials for valid user with correct password and scoped to // base URI of the actual service URL - ScopedAuthenticator authenticator = new ScopedAuthenticator(new URI("http://localhost:" + port), "allowed", "password".toCharArray()); + ScopedAuthenticator authenticator = new ScopedAuthenticator(new URI("http://localhost:" + authPort), "allowed", "password".toCharArray()); qe.setAuthenticator(authenticator); Assert.assertTrue(qe.execAsk()); } @@ -275,7 +284,7 @@ public class TestAuth extends ServerTest { @Test(expected = HttpException.class) public void update_with_auth_01() { UpdateRequest updates = UpdateFactory.create("CREATE SILENT GRAPH <http://graph>"); - UpdateProcessRemoteBase ue = (UpdateProcessRemoteBase) UpdateExecutionFactory.createRemote(updates, serviceUpdate); + UpdateProcessRemoteBase ue = (UpdateProcessRemoteBase) UpdateExecutionFactory.createRemote(updates, authServiceUpdate); // No auth credentials should result in an error ue.execute(); } @@ -283,7 +292,7 @@ public class TestAuth extends ServerTest { @Test(expected = HttpException.class) public void update_with_auth_02() { UpdateRequest updates = UpdateFactory.create("CREATE SILENT GRAPH <http://graph>"); - UpdateProcessRemoteBase ue = (UpdateProcessRemoteBase) UpdateExecutionFactory.createRemote(updates, serviceUpdate); + UpdateProcessRemoteBase ue = (UpdateProcessRemoteBase) UpdateExecutionFactory.createRemote(updates, authServiceUpdate); // Auth credentials for valid user with bad password ue.setAuthentication("allowed", "incorrect".toCharArray()); ue.execute(); @@ -292,7 +301,7 @@ public class TestAuth extends ServerTest { @Test public void update_with_auth_03() { UpdateRequest updates = UpdateFactory.create("CREATE SILENT GRAPH <http://graph>"); - UpdateProcessRemoteBase ue = (UpdateProcessRemoteBase) UpdateExecutionFactory.createRemote(updates, serviceUpdate); + UpdateProcessRemoteBase ue = (UpdateProcessRemoteBase) UpdateExecutionFactory.createRemote(updates, authServiceUpdate); // Auth credentials for valid user with correct password ue.setAuthentication("allowed", "password".toCharArray()); ue.execute(); @@ -301,7 +310,7 @@ public class TestAuth extends ServerTest { @Test(expected = HttpException.class) public void update_with_auth_04() { UpdateRequest updates = UpdateFactory.create("CREATE SILENT GRAPH <http://graph>"); - UpdateProcessRemoteBase ue = (UpdateProcessRemoteBase) UpdateExecutionFactory.createRemote(updates, serviceUpdate); + UpdateProcessRemoteBase ue = (UpdateProcessRemoteBase) UpdateExecutionFactory.createRemote(updates, authServiceUpdate); // Auth credentials for valid user with correct password BUT not in // correct role ue.setAuthentication("forbidden", "password".toCharArray()); @@ -311,7 +320,7 @@ public class TestAuth extends ServerTest { @Test(expected = HttpException.class) public void update_with_auth_05() { UpdateRequest updates = UpdateFactory.create("CREATE SILENT GRAPH <http://graph>"); - UpdateProcessRemoteBase ue = (UpdateProcessRemoteBase) UpdateExecutionFactory.createRemoteForm(updates, serviceUpdate); + UpdateProcessRemoteBase ue = (UpdateProcessRemoteBase) UpdateExecutionFactory.createRemoteForm(updates, authServiceUpdate); // No auth credentials should result in an error ue.execute(); } @@ -319,7 +328,7 @@ public class TestAuth extends ServerTest { @Test(expected = HttpException.class) public void update_with_auth_06() { UpdateRequest updates = UpdateFactory.create("CREATE SILENT GRAPH <http://graph>"); - UpdateProcessRemoteBase ue = (UpdateProcessRemoteBase) UpdateExecutionFactory.createRemoteForm(updates, serviceUpdate); + UpdateProcessRemoteBase ue = (UpdateProcessRemoteBase) UpdateExecutionFactory.createRemoteForm(updates, authServiceUpdate); // Auth credentials for valid user with bad password ue.setAuthentication("allowed", "incorrect".toCharArray()); ue.execute(); @@ -328,7 +337,7 @@ public class TestAuth extends ServerTest { @Test public void update_with_auth_07() { UpdateRequest updates = UpdateFactory.create("CREATE SILENT GRAPH <http://graph>"); - UpdateProcessRemoteBase ue = (UpdateProcessRemoteBase) UpdateExecutionFactory.createRemoteForm(updates, serviceUpdate); + UpdateProcessRemoteBase ue = (UpdateProcessRemoteBase) UpdateExecutionFactory.createRemoteForm(updates, authServiceUpdate); // Auth credentials for valid user with correct password ue.setAuthentication("allowed", "password".toCharArray()); ue.execute(); @@ -337,7 +346,7 @@ public class TestAuth extends ServerTest { @Test(expected = HttpException.class) public void update_with_auth_08() { UpdateRequest updates = UpdateFactory.create("CREATE SILENT GRAPH <http://graph>"); - UpdateProcessRemoteBase ue = (UpdateProcessRemoteBase) UpdateExecutionFactory.createRemoteForm(updates, serviceUpdate); + UpdateProcessRemoteBase ue = (UpdateProcessRemoteBase) UpdateExecutionFactory.createRemoteForm(updates, authServiceUpdate); // Auth credentials for valid user with correct password BUT not in // correct role ue.setAuthentication("forbidden", "password".toCharArray()); @@ -347,7 +356,7 @@ public class TestAuth extends ServerTest { @Test(expected = HttpException.class) public void update_with_auth_09() throws URISyntaxException { UpdateRequest updates = UpdateFactory.create("CREATE SILENT GRAPH <http://graph>"); - UpdateProcessRemoteBase ue = (UpdateProcessRemoteBase) UpdateExecutionFactory.createRemote(updates, serviceUpdate); + UpdateProcessRemoteBase ue = (UpdateProcessRemoteBase) UpdateExecutionFactory.createRemote(updates, authServiceUpdate); // Auth credentials for valid user with correct password but scoped to // wrong URI @@ -360,11 +369,11 @@ public class TestAuth extends ServerTest { @Test public void update_with_auth_10() throws URISyntaxException { UpdateRequest updates = UpdateFactory.create("CREATE SILENT GRAPH <http://graph>"); - UpdateProcessRemoteBase ue = (UpdateProcessRemoteBase) UpdateExecutionFactory.createRemote(updates, serviceUpdate); + UpdateProcessRemoteBase ue = (UpdateProcessRemoteBase) UpdateExecutionFactory.createRemote(updates, authServiceUpdate); // Auth credentials for valid user with correct password scoped to // correct URI - ScopedAuthenticator authenticator = new ScopedAuthenticator(new URI(serviceUpdate), "allowed", "password".toCharArray()); + ScopedAuthenticator authenticator = new ScopedAuthenticator(new URI(authServiceUpdate), "allowed", "password".toCharArray()); ue.setAuthenticator(authenticator); ue.execute(); } @@ -372,12 +381,12 @@ public class TestAuth extends ServerTest { @Test public void update_with_auth_11() throws URISyntaxException { UpdateRequest updates = UpdateFactory.create("CREATE SILENT GRAPH <http://graph>"); - UpdateProcessRemoteBase ue = (UpdateProcessRemoteBase) UpdateExecutionFactory.createRemote(updates, serviceUpdate); + UpdateProcessRemoteBase ue = (UpdateProcessRemoteBase) UpdateExecutionFactory.createRemote(updates, authServiceUpdate); // Auth credentials for valid user with correct password scoped to // correct URI // Also using pre-emptive auth - ScopedAuthenticator authenticator = new ScopedAuthenticator(new URI(serviceUpdate), "allowed", "password".toCharArray()); + ScopedAuthenticator authenticator = new ScopedAuthenticator(new URI(authServiceUpdate), "allowed", "password".toCharArray()); ue.setAuthenticator(new PreemptiveBasicAuthenticator(authenticator)); ue.execute(); } @@ -385,21 +394,21 @@ public class TestAuth extends ServerTest { @Test(expected = HttpException.class) public void graphstore_with_auth_01() { // No auth credentials - DatasetAccessor accessor = DatasetAccessorFactory.createHTTP(serviceREST); + DatasetAccessor accessor = DatasetAccessorFactory.createHTTP(authServiceREST); accessor.getModel(); } @Test(expected = HttpException.class) public void graphstore_with_auth_02() { // Incorrect auth credentials - DatasetAccessor accessor = DatasetAccessorFactory.createHTTP(serviceREST, new SimpleAuthenticator("allowed", "incorrect".toCharArray())); + DatasetAccessor accessor = DatasetAccessorFactory.createHTTP(authServiceREST, new SimpleAuthenticator("allowed", "incorrect".toCharArray())); accessor.getModel(); } @Test public void graphstore_with_auth_03() { // Correct auth credentials - DatasetAccessor accessor = DatasetAccessorFactory.createHTTP(serviceREST, new SimpleAuthenticator("allowed", "password".toCharArray())); + DatasetAccessor accessor = DatasetAccessorFactory.createHTTP(authServiceREST, new SimpleAuthenticator("allowed", "password".toCharArray())); Model m = accessor.getModel(); Assert.assertTrue(m.isEmpty()); } @@ -407,14 +416,14 @@ public class TestAuth extends ServerTest { @Test(expected = HttpException.class) public void graphstore_with_auth_04() throws URISyntaxException { // Correct auth credentials scoped to wrong URI - DatasetAccessor accessor = DatasetAccessorFactory.createHTTP(serviceREST, new ScopedAuthenticator(new URI("http://example.org/"), "allowed", "password".toCharArray())); + DatasetAccessor accessor = DatasetAccessorFactory.createHTTP(authServiceREST, new ScopedAuthenticator(new URI("http://example.org/"), "allowed", "password".toCharArray())); accessor.getModel(); } @Test public void graphstore_with_auth_05() throws URISyntaxException { // Correct auth credentials scoped to correct URI - DatasetAccessor accessor = DatasetAccessorFactory.createHTTP(serviceREST, new ScopedAuthenticator(new URI(serviceREST), "allowed", "password".toCharArray())); + DatasetAccessor accessor = DatasetAccessorFactory.createHTTP(authServiceREST, new ScopedAuthenticator(new URI(authServiceREST), "allowed", "password".toCharArray())); accessor.getModel(); } } http://git-wip-us.apache.org/repos/asf/jena/blob/cee0769f/jena-fuseki2/jena-fuseki-core/src/test/java/org/apache/jena/fuseki/ServerTest.java ---------------------------------------------------------------------- diff --git a/jena-fuseki2/jena-fuseki-core/src/test/java/org/apache/jena/fuseki/ServerTest.java b/jena-fuseki2/jena-fuseki-core/src/test/java/org/apache/jena/fuseki/ServerTest.java index 1a70869..852fdaa 100644 --- a/jena-fuseki2/jena-fuseki-core/src/test/java/org/apache/jena/fuseki/ServerTest.java +++ b/jena-fuseki2/jena-fuseki-core/src/test/java/org/apache/jena/fuseki/ServerTest.java @@ -105,31 +105,31 @@ public class ServerTest { FileOps.ensureDir(TS_Fuseki.FusekiTestHome); FileOps.ensureDir(TS_Fuseki.FusekiTestBase) ; FusekiEnv.FUSEKI_BASE = Paths.get(TS_Fuseki.FusekiTestBase).toAbsolutePath() ; - setupServer(null) ; + setupServer(ServerTest.port, null, ServerTest.datasetPath) ; } - protected static void setupServer(String authConfigFile) { + protected static void setupServer(int port, String authConfigFile, String datasetPath) { SystemState.location = Location.mem() ; SystemState.init$() ; ServerInitialConfig params = new ServerInitialConfig() ; DatasetGraph dsg = DatasetGraphFactory.createMem() ; params.dsg = dsg ; - params.datasetPath = ServerTest.datasetPath ; + params.datasetPath = datasetPath ; params.allowUpdate = true ; FusekiServerListener.initialSetup = params ; - JettyServerConfig config = make(true, true) ; + JettyServerConfig config = make(port, true, true) ; config.authConfigFile = authConfigFile ; JettyFuseki.initializeServer(config); JettyFuseki.instance.start() ; server = JettyFuseki.instance ; } - public static JettyServerConfig make(boolean allowUpdate, boolean listenLocal) { + public static JettyServerConfig make(int port, boolean allowUpdate, boolean listenLocal) { JettyServerConfig config = new JettyServerConfig() ; // Avoid any persistent record. - config.port = ServerTest.port ; + config.port = port ; config.contextPath = "/" ; config.loopback = listenLocal ; config.jettyConfigFile = null ; http://git-wip-us.apache.org/repos/asf/jena/blob/cee0769f/jena-fuseki2/jena-fuseki-core/src/test/java/org/apache/jena/fuseki/TestAuth.java ---------------------------------------------------------------------- diff --git a/jena-fuseki2/jena-fuseki-core/src/test/java/org/apache/jena/fuseki/TestAuth.java b/jena-fuseki2/jena-fuseki-core/src/test/java/org/apache/jena/fuseki/TestAuth.java index 0deb01d..12150a6 100644 --- a/jena-fuseki2/jena-fuseki-core/src/test/java/org/apache/jena/fuseki/TestAuth.java +++ b/jena-fuseki2/jena-fuseki-core/src/test/java/org/apache/jena/fuseki/TestAuth.java @@ -54,8 +54,16 @@ import com.hp.hpl.jena.update.UpdateRequest ; /** * Tests Fuseki operation with authentication enabled */ -public class TestAuth extends ServerTest { - +public class TestAuth { + + // Use different port etc because sometimes the previous testing servers + // don't release ports fast enough (OS issue / Linux) + public static final int authPort = ServerTest.port+10 ; + public static final String authUrlRoot = "http://localhost:"+authPort+"/" ; + public static final String authDatasetPath = "/dataset" ; + public static final String authServiceUpdate = "http://localhost:"+authPort+authDatasetPath+"/update" ; + public static final String authServiceQuery = "http://localhost:"+authPort+authDatasetPath+"/query" ; + public static final String authServiceREST = "http://localhost:"+authPort+authDatasetPath+"/data" ; private static File realmFile; /** @@ -75,7 +83,7 @@ public class TestAuth extends ServerTest { LogCtl.logLevel(Fuseki.actionLog.getName(), org.apache.log4j.Level.WARN, java.util.logging.Level.WARNING); LogCtl.logLevel("org.eclipse.jetty", org.apache.log4j.Level.WARN, java.util.logging.Level.WARNING); - ServerTest.setupServer(realmFile.getAbsolutePath()); + ServerTest.setupServer(authPort, realmFile.getAbsolutePath(), authDatasetPath); } /** @@ -89,14 +97,14 @@ public class TestAuth extends ServerTest { @Test(expected = QueryExceptionHTTP.class) public void query_with_auth_01() { - QueryEngineHTTP qe = (QueryEngineHTTP) QueryExecutionFactory.sparqlService(serviceQuery, "ASK { }"); + QueryEngineHTTP qe = (QueryEngineHTTP) QueryExecutionFactory.sparqlService(authServiceQuery, "ASK { }"); // No auth credentials should result in an error qe.execAsk(); } @Test(expected = QueryExceptionHTTP.class) public void query_with_auth_02() { - QueryEngineHTTP qe = (QueryEngineHTTP) QueryExecutionFactory.sparqlService(serviceQuery, "ASK { }"); + QueryEngineHTTP qe = (QueryEngineHTTP) QueryExecutionFactory.sparqlService(authServiceQuery, "ASK { }"); // Auth credentials for valid user with bad password qe.setBasicAuthentication("allowed", "incorrect".toCharArray()); qe.execAsk(); @@ -104,7 +112,7 @@ public class TestAuth extends ServerTest { @Test public void query_with_auth_03() { - QueryEngineHTTP qe = (QueryEngineHTTP) QueryExecutionFactory.sparqlService(serviceQuery, "ASK { }"); + QueryEngineHTTP qe = (QueryEngineHTTP) QueryExecutionFactory.sparqlService(authServiceQuery, "ASK { }"); // Auth credentials for valid user with correct password qe.setBasicAuthentication("allowed", "password".toCharArray()); Assert.assertTrue(qe.execAsk()); @@ -112,7 +120,7 @@ public class TestAuth extends ServerTest { @Test(expected = QueryExceptionHTTP.class) public void query_with_auth_04() { - QueryEngineHTTP qe = (QueryEngineHTTP) QueryExecutionFactory.sparqlService(serviceQuery, "ASK { }"); + QueryEngineHTTP qe = (QueryEngineHTTP) QueryExecutionFactory.sparqlService(authServiceQuery, "ASK { }"); // Auth credentials for valid user with correct password BUT not in // correct role qe.setBasicAuthentication("forbidden", "password".toCharArray()); @@ -122,7 +130,7 @@ public class TestAuth extends ServerTest { @Test public void query_with_auth_05() { // Uses auth and enables compression - QueryEngineHTTP qe = (QueryEngineHTTP) QueryExecutionFactory.sparqlService(serviceQuery, "ASK { }"); + QueryEngineHTTP qe = (QueryEngineHTTP) QueryExecutionFactory.sparqlService(authServiceQuery, "ASK { }"); qe.setAllowDeflate(true); qe.setAllowGZip(true); @@ -134,7 +142,7 @@ public class TestAuth extends ServerTest { @Test(expected = QueryExceptionHTTP.class) public void query_with_auth_06() { // Uses auth and enables compression - QueryEngineHTTP qe = (QueryEngineHTTP) QueryExecutionFactory.sparqlService(serviceQuery, "ASK { }"); + QueryEngineHTTP qe = (QueryEngineHTTP) QueryExecutionFactory.sparqlService(authServiceQuery, "ASK { }"); qe.setAllowDeflate(true); qe.setAllowGZip(true); @@ -145,7 +153,7 @@ public class TestAuth extends ServerTest { @Test(expected = QueryExceptionHTTP.class) public void query_with_auth_07() throws URISyntaxException { - QueryEngineHTTP qe = (QueryEngineHTTP) QueryExecutionFactory.sparqlService(serviceQuery, "ASK { }"); + QueryEngineHTTP qe = (QueryEngineHTTP) QueryExecutionFactory.sparqlService(authServiceQuery, "ASK { }"); // Auth credentials for valid user with correct password but scoped to // wrong URI @@ -157,22 +165,22 @@ public class TestAuth extends ServerTest { @Test public void query_with_auth_08() throws URISyntaxException { - QueryEngineHTTP qe = (QueryEngineHTTP) QueryExecutionFactory.sparqlService(serviceQuery, "ASK { }"); + QueryEngineHTTP qe = (QueryEngineHTTP) QueryExecutionFactory.sparqlService(authServiceQuery, "ASK { }"); // Auth credentials for valid user with correct password and scoped to // correct URI - ScopedAuthenticator authenticator = new ScopedAuthenticator(new URI(serviceQuery), "allowed", "password".toCharArray()); + ScopedAuthenticator authenticator = new ScopedAuthenticator(new URI(authServiceQuery), "allowed", "password".toCharArray()); qe.setAuthenticator(authenticator); Assert.assertTrue(qe.execAsk()); } @Test public void query_with_auth_09() throws URISyntaxException { - QueryEngineHTTP qe = (QueryEngineHTTP) QueryExecutionFactory.sparqlService(serviceQuery, "ASK { }"); + QueryEngineHTTP qe = (QueryEngineHTTP) QueryExecutionFactory.sparqlService(authServiceQuery, "ASK { }"); // Auth credentials for valid user with correct password using // pre-emptive auth - ScopedAuthenticator authenticator = new ScopedAuthenticator(new URI(serviceQuery), "allowed", "password".toCharArray()); + ScopedAuthenticator authenticator = new ScopedAuthenticator(new URI(authServiceQuery), "allowed", "password".toCharArray()); qe.setAuthenticator(new PreemptiveBasicAuthenticator(authenticator)); Assert.assertTrue(qe.execAsk()); } @@ -181,7 +189,7 @@ public class TestAuth extends ServerTest { public void query_with_auth_10() { Context ctx = ARQ.getContext(); try { - QueryEngineHTTP qe = (QueryEngineHTTP) QueryExecutionFactory.sparqlService(serviceQuery, "ASK { }"); + QueryEngineHTTP qe = (QueryEngineHTTP) QueryExecutionFactory.sparqlService(authServiceQuery, "ASK { }"); // Auth credentials for valid user with correct password and scoped // to correct URI @@ -190,7 +198,7 @@ public class TestAuth extends ServerTest { Context authContext = new Context(); authContext.put(Service.queryAuthUser, "allowed"); authContext.put(Service.queryAuthPwd, "password"); - serviceContext.put(serviceQuery, authContext); + serviceContext.put(authServiceQuery, authContext); ctx.put(Service.serviceContext, serviceContext); qe.setAuthenticator(new ServiceAuthenticator()); @@ -204,7 +212,7 @@ public class TestAuth extends ServerTest { public void query_with_auth_11() { Context ctx = ARQ.getContext(); try { - QueryEngineHTTP qe = (QueryEngineHTTP) QueryExecutionFactory.sparqlService(serviceQuery, "ASK { }"); + QueryEngineHTTP qe = (QueryEngineHTTP) QueryExecutionFactory.sparqlService(authServiceQuery, "ASK { }"); // Auth credentials for valid user with correct password and scoped // to base URI of the actual service URL @@ -213,7 +221,7 @@ public class TestAuth extends ServerTest { Context authContext = new Context(); authContext.put(Service.queryAuthUser, "allowed"); authContext.put(Service.queryAuthPwd, "password"); - serviceContext.put(urlRoot, authContext); + serviceContext.put(authUrlRoot, authContext); ctx.put(Service.serviceContext, serviceContext); qe.setAuthenticator(new ServiceAuthenticator()); @@ -227,7 +235,7 @@ public class TestAuth extends ServerTest { public void query_with_auth_12() { ARQ.getContext().remove(Service.serviceContext); - QueryEngineHTTP qe = (QueryEngineHTTP) QueryExecutionFactory.sparqlService(serviceQuery, "ASK { }"); + QueryEngineHTTP qe = (QueryEngineHTTP) QueryExecutionFactory.sparqlService(authServiceQuery, "ASK { }"); // Auth credentials for valid user with correct password // Use service authenticator with fallback credentials. @@ -237,22 +245,22 @@ public class TestAuth extends ServerTest { @Test public void query_with_auth_13() throws URISyntaxException { - QueryEngineHTTP qe = (QueryEngineHTTP) QueryExecutionFactory.sparqlService(serviceQuery, "ASK { }"); + QueryEngineHTTP qe = (QueryEngineHTTP) QueryExecutionFactory.sparqlService(authServiceQuery, "ASK { }"); // Auth credentials for valid user with correct password and scoped to // base URI of the actual service URL - ScopedAuthenticator authenticator = new ScopedAuthenticator(new URI(urlRoot), "allowed", "password".toCharArray()); + ScopedAuthenticator authenticator = new ScopedAuthenticator(new URI(authUrlRoot), "allowed", "password".toCharArray()); qe.setAuthenticator(authenticator); Assert.assertTrue(qe.execAsk()); } @Test public void query_with_auth_14() throws URISyntaxException { - QueryEngineHTTP qe = (QueryEngineHTTP) QueryExecutionFactory.sparqlService(serviceQuery, "ASK { }"); + QueryEngineHTTP qe = (QueryEngineHTTP) QueryExecutionFactory.sparqlService(authServiceQuery, "ASK { }"); // Auth credentials for valid user with correct password and scoped to // base URI of the actual service URL - ScopedAuthenticator authenticator = new ScopedAuthenticator(new URI("http://localhost:" + port), "allowed", "password".toCharArray()); + ScopedAuthenticator authenticator = new ScopedAuthenticator(new URI("http://localhost:" + authPort), "allowed", "password".toCharArray()); qe.setAuthenticator(authenticator); Assert.assertTrue(qe.execAsk()); } @@ -260,7 +268,7 @@ public class TestAuth extends ServerTest { @Test(expected = HttpException.class) public void update_with_auth_01() { UpdateRequest updates = UpdateFactory.create("CREATE SILENT GRAPH <http://graph>"); - UpdateProcessRemoteBase ue = (UpdateProcessRemoteBase) UpdateExecutionFactory.createRemote(updates, serviceUpdate); + UpdateProcessRemoteBase ue = (UpdateProcessRemoteBase) UpdateExecutionFactory.createRemote(updates, authServiceUpdate); // No auth credentials should result in an error ue.execute(); } @@ -268,7 +276,7 @@ public class TestAuth extends ServerTest { @Test(expected = HttpException.class) public void update_with_auth_02() { UpdateRequest updates = UpdateFactory.create("CREATE SILENT GRAPH <http://graph>"); - UpdateProcessRemoteBase ue = (UpdateProcessRemoteBase) UpdateExecutionFactory.createRemote(updates, serviceUpdate); + UpdateProcessRemoteBase ue = (UpdateProcessRemoteBase) UpdateExecutionFactory.createRemote(updates, authServiceUpdate); // Auth credentials for valid user with bad password ue.setAuthentication("allowed", "incorrect".toCharArray()); ue.execute(); @@ -277,7 +285,7 @@ public class TestAuth extends ServerTest { @Test public void update_with_auth_03() { UpdateRequest updates = UpdateFactory.create("CREATE SILENT GRAPH <http://graph>"); - UpdateProcessRemoteBase ue = (UpdateProcessRemoteBase) UpdateExecutionFactory.createRemote(updates, serviceUpdate); + UpdateProcessRemoteBase ue = (UpdateProcessRemoteBase) UpdateExecutionFactory.createRemote(updates, authServiceUpdate); // Auth credentials for valid user with correct password ue.setAuthentication("allowed", "password".toCharArray()); ue.execute(); @@ -286,7 +294,7 @@ public class TestAuth extends ServerTest { @Test(expected = HttpException.class) public void update_with_auth_04() { UpdateRequest updates = UpdateFactory.create("CREATE SILENT GRAPH <http://graph>"); - UpdateProcessRemoteBase ue = (UpdateProcessRemoteBase) UpdateExecutionFactory.createRemote(updates, serviceUpdate); + UpdateProcessRemoteBase ue = (UpdateProcessRemoteBase) UpdateExecutionFactory.createRemote(updates, authServiceUpdate); // Auth credentials for valid user with correct password BUT not in // correct role ue.setAuthentication("forbidden", "password".toCharArray()); @@ -296,7 +304,7 @@ public class TestAuth extends ServerTest { @Test(expected = HttpException.class) public void update_with_auth_05() { UpdateRequest updates = UpdateFactory.create("CREATE SILENT GRAPH <http://graph>"); - UpdateProcessRemoteBase ue = (UpdateProcessRemoteBase) UpdateExecutionFactory.createRemoteForm(updates, serviceUpdate); + UpdateProcessRemoteBase ue = (UpdateProcessRemoteBase) UpdateExecutionFactory.createRemoteForm(updates, authServiceUpdate); // No auth credentials should result in an error ue.execute(); } @@ -304,7 +312,7 @@ public class TestAuth extends ServerTest { @Test(expected = HttpException.class) public void update_with_auth_06() { UpdateRequest updates = UpdateFactory.create("CREATE SILENT GRAPH <http://graph>"); - UpdateProcessRemoteBase ue = (UpdateProcessRemoteBase) UpdateExecutionFactory.createRemoteForm(updates, serviceUpdate); + UpdateProcessRemoteBase ue = (UpdateProcessRemoteBase) UpdateExecutionFactory.createRemoteForm(updates, authServiceUpdate); // Auth credentials for valid user with bad password ue.setAuthentication("allowed", "incorrect".toCharArray()); ue.execute(); @@ -313,7 +321,7 @@ public class TestAuth extends ServerTest { @Test public void update_with_auth_07() { UpdateRequest updates = UpdateFactory.create("CREATE SILENT GRAPH <http://graph>"); - UpdateProcessRemoteBase ue = (UpdateProcessRemoteBase) UpdateExecutionFactory.createRemoteForm(updates, serviceUpdate); + UpdateProcessRemoteBase ue = (UpdateProcessRemoteBase) UpdateExecutionFactory.createRemoteForm(updates, authServiceUpdate); // Auth credentials for valid user with correct password ue.setAuthentication("allowed", "password".toCharArray()); ue.execute(); @@ -322,7 +330,7 @@ public class TestAuth extends ServerTest { @Test(expected = HttpException.class) public void update_with_auth_08() { UpdateRequest updates = UpdateFactory.create("CREATE SILENT GRAPH <http://graph>"); - UpdateProcessRemoteBase ue = (UpdateProcessRemoteBase) UpdateExecutionFactory.createRemoteForm(updates, serviceUpdate); + UpdateProcessRemoteBase ue = (UpdateProcessRemoteBase) UpdateExecutionFactory.createRemoteForm(updates, authServiceUpdate); // Auth credentials for valid user with correct password BUT not in // correct role ue.setAuthentication("forbidden", "password".toCharArray()); @@ -332,7 +340,7 @@ public class TestAuth extends ServerTest { @Test(expected = HttpException.class) public void update_with_auth_09() throws URISyntaxException { UpdateRequest updates = UpdateFactory.create("CREATE SILENT GRAPH <http://graph>"); - UpdateProcessRemoteBase ue = (UpdateProcessRemoteBase) UpdateExecutionFactory.createRemote(updates, serviceUpdate); + UpdateProcessRemoteBase ue = (UpdateProcessRemoteBase) UpdateExecutionFactory.createRemote(updates, authServiceUpdate); // Auth credentials for valid user with correct password but scoped to // wrong URI @@ -345,11 +353,11 @@ public class TestAuth extends ServerTest { @Test public void update_with_auth_10() throws URISyntaxException { UpdateRequest updates = UpdateFactory.create("CREATE SILENT GRAPH <http://graph>"); - UpdateProcessRemoteBase ue = (UpdateProcessRemoteBase) UpdateExecutionFactory.createRemote(updates, serviceUpdate); + UpdateProcessRemoteBase ue = (UpdateProcessRemoteBase) UpdateExecutionFactory.createRemote(updates, authServiceUpdate); // Auth credentials for valid user with correct password scoped to // correct URI - ScopedAuthenticator authenticator = new ScopedAuthenticator(new URI(serviceUpdate), "allowed", "password".toCharArray()); + ScopedAuthenticator authenticator = new ScopedAuthenticator(new URI(authServiceUpdate), "allowed", "password".toCharArray()); ue.setAuthenticator(authenticator); ue.execute(); } @@ -357,12 +365,12 @@ public class TestAuth extends ServerTest { @Test public void update_with_auth_11() throws URISyntaxException { UpdateRequest updates = UpdateFactory.create("CREATE SILENT GRAPH <http://graph>"); - UpdateProcessRemoteBase ue = (UpdateProcessRemoteBase) UpdateExecutionFactory.createRemote(updates, serviceUpdate); + UpdateProcessRemoteBase ue = (UpdateProcessRemoteBase) UpdateExecutionFactory.createRemote(updates, authServiceUpdate); // Auth credentials for valid user with correct password scoped to // correct URI // Also using pre-emptive auth - ScopedAuthenticator authenticator = new ScopedAuthenticator(new URI(serviceUpdate), "allowed", "password".toCharArray()); + ScopedAuthenticator authenticator = new ScopedAuthenticator(new URI(authServiceUpdate), "allowed", "password".toCharArray()); ue.setAuthenticator(new PreemptiveBasicAuthenticator(authenticator)); ue.execute(); } @@ -370,21 +378,21 @@ public class TestAuth extends ServerTest { @Test(expected = HttpException.class) public void graphstore_with_auth_01() { // No auth credentials - DatasetAccessor accessor = DatasetAccessorFactory.createHTTP(serviceREST); + DatasetAccessor accessor = DatasetAccessorFactory.createHTTP(authServiceREST); accessor.getModel(); } @Test(expected = HttpException.class) public void graphstore_with_auth_02() { // Incorrect auth credentials - DatasetAccessor accessor = DatasetAccessorFactory.createHTTP(serviceREST, new SimpleAuthenticator("allowed", "incorrect".toCharArray())); + DatasetAccessor accessor = DatasetAccessorFactory.createHTTP(authServiceREST, new SimpleAuthenticator("allowed", "incorrect".toCharArray())); accessor.getModel(); } @Test public void graphstore_with_auth_03() { // Correct auth credentials - DatasetAccessor accessor = DatasetAccessorFactory.createHTTP(serviceREST, new SimpleAuthenticator("allowed", "password".toCharArray())); + DatasetAccessor accessor = DatasetAccessorFactory.createHTTP(authServiceREST, new SimpleAuthenticator("allowed", "password".toCharArray())); Model m = accessor.getModel(); Assert.assertTrue(m.isEmpty()); } @@ -392,14 +400,14 @@ public class TestAuth extends ServerTest { @Test(expected = HttpException.class) public void graphstore_with_auth_04() throws URISyntaxException { // Correct auth credentials scoped to wrong URI - DatasetAccessor accessor = DatasetAccessorFactory.createHTTP(serviceREST, new ScopedAuthenticator(new URI("http://example.org/"), "allowed", "password".toCharArray())); + DatasetAccessor accessor = DatasetAccessorFactory.createHTTP(authServiceREST, new ScopedAuthenticator(new URI("http://example.org/"), "allowed", "password".toCharArray())); accessor.getModel(); } @Test public void graphstore_with_auth_05() throws URISyntaxException { // Correct auth credentials scoped to correct URI - DatasetAccessor accessor = DatasetAccessorFactory.createHTTP(serviceREST, new ScopedAuthenticator(new URI(serviceREST), "allowed", "password".toCharArray())); + DatasetAccessor accessor = DatasetAccessorFactory.createHTTP(authServiceREST, new ScopedAuthenticator(new URI(authServiceREST), "allowed", "password".toCharArray())); accessor.getModel(); } }
