Search in sources :

Example 1 with BasicAuthFilter

use of net.codestory.http.filters.basic.BasicAuthFilter in project datashare by ICIJ.

the class SettingsResourceTest method test_patch_configuration_should_answer_403_in_server_mode.

@Test
public void test_patch_configuration_should_answer_403_in_server_mode() {
    PropertiesProvider properties = new PropertiesProvider(new HashMap<String, String>() {

        {
            put("mode", "SERVER");
        }
    });
    configure(routes -> routes.add(new SettingsResource(properties)).filter(new BasicAuthFilter("/", "icij", singleUser(local()))));
    patch("/api/settings", "{\"data\": {\"foo\": \"qux\", \"xyzzy\":\"fred\"}}").withPreemptiveAuthentication("local", "pass").should().respond(403);
}
Also used : PropertiesProvider(org.icij.datashare.PropertiesProvider) BasicAuthFilter(net.codestory.http.filters.basic.BasicAuthFilter) AbstractProdWebServerTest(org.icij.datashare.web.testhelpers.AbstractProdWebServerTest) Test(org.junit.Test)

Example 2 with BasicAuthFilter

use of net.codestory.http.filters.basic.BasicAuthFilter in project datashare by ICIJ.

the class UserTaskResourceTest method setupAppWith.

private void setupAppWith(String... userLogins) {
    final PropertiesProvider propertiesProvider = new PropertiesProvider();
    taskManager = new TaskManagerMemory(propertiesProvider);
    configure(new CommonMode(new Properties()) {

        @Override
        protected void configure() {
            bind(PropertiesProvider.class).toInstance(propertiesProvider);
            bind(PipelineRegistry.class).toInstance(mock(PipelineRegistry.class));
            bind(SessionIdStore.class).toInstance(SessionIdStore.inMemory());
            bind(TaskManager.class).toInstance(taskManager);
            bind(Filter.class).toInstance(new BasicAuthFilter("/", "ds", DatashareUser.users(userLogins)));
            bind(TaskFactory.class).toInstance(mock(TaskFactory.class));
            bind(Indexer.class).toInstance(mock(Indexer.class));
        }

        @Override
        protected Routes addModeConfiguration(Routes routes) {
            return routes.add(TaskResource.class).filter(Filter.class);
        }
    }.createWebConfiguration());
}
Also used : BasicAuthFilter(net.codestory.http.filters.basic.BasicAuthFilter) CommonMode(org.icij.datashare.mode.CommonMode) Routes(net.codestory.http.routes.Routes) Properties(java.util.Properties) PipelineRegistry(org.icij.datashare.extension.PipelineRegistry) PropertiesProvider(org.icij.datashare.PropertiesProvider) SessionIdStore(net.codestory.http.security.SessionIdStore) Indexer(org.icij.datashare.text.indexing.Indexer) Filter(net.codestory.http.filters.Filter) BasicAuthFilter(net.codestory.http.filters.basic.BasicAuthFilter)

Example 3 with BasicAuthFilter

use of net.codestory.http.filters.basic.BasicAuthFilter in project datashare by ICIJ.

the class SettingsResourceTest method test_patch_configuration.

@Test
public void test_patch_configuration() throws IOException {
    File settings = folder.newFile("file.settings");
    Files.write(settings.toPath(), asList("foo=doe", "bar=baz"));
    configure(routes -> routes.add(new SettingsResource(new PropertiesProvider(settings.getAbsolutePath()))).filter(new BasicAuthFilter("/", "icij", singleUser(local()))));
    patch("/api/settings", "{\"data\": {\"foo\": \"qux\", \"xyzzy\":\"fred\"}}").withPreemptiveAuthentication("local", "pass").should().respond(200);
    Properties properties = new PropertiesProvider(settings.getAbsolutePath()).getProperties();
    assertThat(properties).includes(entry("foo", "qux"), entry("bar", "baz"), entry("xyzzy", "fred"));
}
Also used : PropertiesProvider(org.icij.datashare.PropertiesProvider) BasicAuthFilter(net.codestory.http.filters.basic.BasicAuthFilter) Properties(java.util.Properties) File(java.io.File) AbstractProdWebServerTest(org.icij.datashare.web.testhelpers.AbstractProdWebServerTest) Test(org.junit.Test)

Example 4 with BasicAuthFilter

use of net.codestory.http.filters.basic.BasicAuthFilter in project datashare by ICIJ.

the class NamedEntityResourceTest method test_get_named_entity_in_prod_mode.

@Test
public void test_get_named_entity_in_prod_mode() {
    configure(routes -> routes.add(new NamedEntityResource(indexer)).filter(new BasicAuthFilter("/", "icij", DatashareUser.singleUser("anne"))));
    NamedEntity toBeReturned = create(PERSON, "mention", asList(123L), "docId", "root", CORENLP, FRENCH);
    doReturn(toBeReturned).when(indexer).get("anne-datashare", "my_id", "root_parent");
    get("/api/anne-datashare/namedEntities/my_id?routing=root_parent").withAuthentication("anne", "notused").should().respond(200).haveType("application/json");
}
Also used : BasicAuthFilter(net.codestory.http.filters.basic.BasicAuthFilter) NamedEntity(org.icij.datashare.text.NamedEntity) AbstractProdWebServerTest(org.icij.datashare.web.testhelpers.AbstractProdWebServerTest) Test(org.junit.Test)

Aggregations

BasicAuthFilter (net.codestory.http.filters.basic.BasicAuthFilter)4 PropertiesProvider (org.icij.datashare.PropertiesProvider)3 AbstractProdWebServerTest (org.icij.datashare.web.testhelpers.AbstractProdWebServerTest)3 Test (org.junit.Test)3 Properties (java.util.Properties)2 File (java.io.File)1 Filter (net.codestory.http.filters.Filter)1 Routes (net.codestory.http.routes.Routes)1 SessionIdStore (net.codestory.http.security.SessionIdStore)1 PipelineRegistry (org.icij.datashare.extension.PipelineRegistry)1 CommonMode (org.icij.datashare.mode.CommonMode)1 NamedEntity (org.icij.datashare.text.NamedEntity)1 Indexer (org.icij.datashare.text.indexing.Indexer)1