public static final String serviceQuery() { return "http://localhost:"+port()+datasetPath()+"/query" ; } public static final String serviceGSP() { return "http://localhost:"+port()+datasetPath()+"/data" ; }
@BeforeClass public static void ctlBeforeClass() { SecurityHandler sh = FusekiTestAuth.makeSimpleSecurityHandler("/*", USER, PASSWORD); FusekiTestAuth.setupServer(false, sh); }
@Test(expected=HttpException.class) public void testServer_auth_no_auth() { // No Auth try ( TypedInputStream in = HttpOp.execHttpGet(FusekiTestAuth.urlDataset(), "*/*") ) {} catch (HttpException ex) { throw assertAuthHttpException(ex); } }
/** Create a Jetty {@link SecurityHandler} for basic authentication, one user/password/role. */ public static SecurityHandler makeSimpleSecurityHandler(String pathSpec, String user, String password) { return makeSimpleSecurityHandler(pathSpec, null, user, password, "FusekiTestRole"); }
public static final String urlRoot() { return "http://localhost:"+port()+"/" ; } public static final String datasetPath() { return "/dataset" ; }
/** Setup a testing server, using the given Jetty {@link SecurityHandler} for authentication. * The server will have an empty, in-emory transactional dataset. */ public static void setupServer(boolean updateable, SecurityHandler sh) { setupServer(updateable, sh, DatasetGraphFactory.createTxnMem()); }
@Test public void testServer_auth() { BasicCredentialsProvider credsProvider = new BasicCredentialsProvider(); Credentials credentials = new UsernamePasswordCredentials(USER, PASSWORD); credsProvider.setCredentials(AuthScope.ANY, credentials); HttpClient client = HttpClients.custom().setDefaultCredentialsProvider(credsProvider).build(); try ( TypedInputStream in = HttpOp.execHttpGet(FusekiTestAuth.urlDataset(), "*/*", client, null) ) {} }
@AfterClass public static void ctlAfterClass() { FusekiTestAuth.teardownServer(); HttpOp.setDefaultHttpClient(HttpOp.createPoolingHttpClient()); }
securityHandler.setIdentityService(identService) ; UserStore userStore = makeUserStore(user, password, role);
@Test(expected=HttpException.class) public void testServer_auth_bad_password() { BasicCredentialsProvider credsProv = new BasicCredentialsProvider(); credsProv.setCredentials(AuthScope.ANY, new UsernamePasswordCredentials(USER, "WRONG")); HttpClient client = HttpClients.custom().setDefaultCredentialsProvider(credsProv).build(); try ( TypedInputStream in = HttpOp.execHttpGet(FusekiTestAuth.urlDataset(), "*/*", client, null) ) {} catch (HttpException ex) { throw assertAuthHttpException(ex); } } }
public static final String serviceGSP() { return "http://localhost:"+port()+datasetPath()+"/data" ; }
@Test(expected=HttpException.class) public void testServer_auth_bad_user() { BasicCredentialsProvider credsProvider = new BasicCredentialsProvider(); Credentials credentials = new UsernamePasswordCredentials("USERUSER", PASSWORD); credsProvider.setCredentials(AuthScope.ANY, credentials); HttpClient client = HttpClients.custom().setDefaultCredentialsProvider(credsProvider).build(); try ( TypedInputStream in = HttpOp.execHttpGet(FusekiTestAuth.urlDataset(), "*/*", client, null) ) {} catch (HttpException ex) { throw assertAuthHttpException(ex); } }
public static final String urlDataset() { return "http://localhost:"+port()+datasetPath() ; } public static final DatasetGraph getDataset() { return dsgTesting ; }
public static final String serviceUpdate() { return "http://localhost:"+port()+datasetPath()+"/update" ; } public static final String serviceQuery() { return "http://localhost:"+port()+datasetPath()+"/query" ; }
/** Setup a testing server, using the given Jetty {@link SecurityHandler} for authentication. */ public static void setupServer(boolean updateable, SecurityHandler sh, DatasetGraph dsg) { dsgTesting = dsg; server = FusekiServer.create() .add(datasetPath(), dsgTesting) .setPort(port()) .setSecurityHandler(sh) .build() .start(); }