Search in sources :

Example 16 with AuthConfig

use of io.druid.server.security.AuthConfig in project druid by druid-io.

the class DatasourcesResourceTest method testSecuredGetFullQueryableDataSources.

@Test
public void testSecuredGetFullQueryableDataSources() throws Exception {
    EasyMock.expect(server.getDataSources()).andReturn(ImmutableList.of(listDataSources.get(0), listDataSources.get(1))).atLeastOnce();
    EasyMock.expect(inventoryView.getInventory()).andReturn(ImmutableList.of(server)).atLeastOnce();
    EasyMock.expect(request.getAttribute(AuthConfig.DRUID_AUTH_TOKEN)).andReturn(new AuthorizationInfo() {

        @Override
        public Access isAuthorized(Resource resource, Action action) {
            if (resource.getName().equals("datasource1")) {
                return new Access(true);
            } else {
                return new Access(false);
            }
        }
    }).times(2);
    EasyMock.replay(inventoryView, server, request);
    DatasourcesResource datasourcesResource = new DatasourcesResource(inventoryView, null, null, new AuthConfig(true));
    Response response = datasourcesResource.getQueryableDataSources("full", null, request);
    Set<DruidDataSource> result = (Set<DruidDataSource>) response.getEntity();
    DruidDataSource[] resultantDruidDataSources = new DruidDataSource[result.size()];
    result.toArray(resultantDruidDataSources);
    Assert.assertEquals(200, response.getStatus());
    Assert.assertEquals(1, resultantDruidDataSources.length);
    Assert.assertArrayEquals(listDataSources.subList(0, 1).toArray(), resultantDruidDataSources);
    response = datasourcesResource.getQueryableDataSources(null, null, request);
    List<String> result1 = (List<String>) response.getEntity();
    Assert.assertEquals(200, response.getStatus());
    Assert.assertEquals(1, result1.size());
    Assert.assertTrue(result1.contains("datasource1"));
    EasyMock.verify(inventoryView, server, request);
}
Also used : Action(io.druid.server.security.Action) TreeSet(java.util.TreeSet) ImmutableSet(com.google.common.collect.ImmutableSet) Set(java.util.Set) Resource(io.druid.server.security.Resource) Access(io.druid.server.security.Access) AuthConfig(io.druid.server.security.AuthConfig) AuthorizationInfo(io.druid.server.security.AuthorizationInfo) DruidDataSource(io.druid.client.DruidDataSource) Response(javax.ws.rs.core.Response) ArrayList(java.util.ArrayList) ImmutableList(com.google.common.collect.ImmutableList) List(java.util.List) Test(org.junit.Test)

Example 17 with AuthConfig

use of io.druid.server.security.AuthConfig in project druid by druid-io.

the class DatasourcesResourceTest method testSimpleGetTheDataSource.

@Test
public void testSimpleGetTheDataSource() throws Exception {
    DruidDataSource dataSource1 = new DruidDataSource("datasource1", new HashMap());
    dataSource1.addSegment("partition", new DataSegment("datasegment1", new Interval("2010-01-01/P1D"), null, null, null, null, null, 0x9, 10));
    EasyMock.expect(server.getDataSource("datasource1")).andReturn(dataSource1).atLeastOnce();
    EasyMock.expect(server.getTier()).andReturn(null).atLeastOnce();
    EasyMock.expect(inventoryView.getInventory()).andReturn(ImmutableList.of(server)).atLeastOnce();
    EasyMock.replay(inventoryView, server);
    DatasourcesResource datasourcesResource = new DatasourcesResource(inventoryView, null, null, new AuthConfig());
    Response response = datasourcesResource.getTheDataSource("datasource1", null);
    Assert.assertEquals(200, response.getStatus());
    Map<String, Map<String, Object>> result = (Map<String, Map<String, Object>>) response.getEntity();
    Assert.assertEquals(1, ((Map) (result.get("tiers").get(null))).get("segmentCount"));
    Assert.assertEquals(10L, ((Map) (result.get("tiers").get(null))).get("size"));
    Assert.assertNotNull(result.get("segments"));
    Assert.assertEquals("2010-01-01T00:00:00.000Z", result.get("segments").get("minTime").toString());
    Assert.assertEquals("2010-01-02T00:00:00.000Z", result.get("segments").get("maxTime").toString());
    Assert.assertEquals(1, result.get("segments").get("count"));
    Assert.assertEquals(10L, result.get("segments").get("size"));
    EasyMock.verify(inventoryView, server);
}
Also used : Response(javax.ws.rs.core.Response) HashMap(java.util.HashMap) AuthConfig(io.druid.server.security.AuthConfig) DruidDataSource(io.druid.client.DruidDataSource) DataSegment(io.druid.timeline.DataSegment) HashMap(java.util.HashMap) Map(java.util.Map) TreeMap(java.util.TreeMap) Interval(org.joda.time.Interval) Test(org.junit.Test)

Example 18 with AuthConfig

use of io.druid.server.security.AuthConfig in project druid by druid-io.

the class DatasourcesResourceTest method testFullGetTheDataSource.

@Test
public void testFullGetTheDataSource() throws Exception {
    DruidDataSource dataSource1 = new DruidDataSource("datasource1", new HashMap());
    EasyMock.expect(server.getDataSource("datasource1")).andReturn(dataSource1).atLeastOnce();
    EasyMock.expect(inventoryView.getInventory()).andReturn(ImmutableList.of(server)).atLeastOnce();
    EasyMock.replay(inventoryView, server);
    DatasourcesResource datasourcesResource = new DatasourcesResource(inventoryView, null, null, new AuthConfig());
    Response response = datasourcesResource.getTheDataSource("datasource1", "full");
    DruidDataSource result = (DruidDataSource) response.getEntity();
    Assert.assertEquals(200, response.getStatus());
    Assert.assertEquals(dataSource1, result);
    EasyMock.verify(inventoryView, server);
}
Also used : Response(javax.ws.rs.core.Response) HashMap(java.util.HashMap) AuthConfig(io.druid.server.security.AuthConfig) DruidDataSource(io.druid.client.DruidDataSource) Test(org.junit.Test)

Example 19 with AuthConfig

use of io.druid.server.security.AuthConfig in project druid by druid-io.

the class DatasourcesResourceTest method testNullGetTheDataSource.

@Test
public void testNullGetTheDataSource() throws Exception {
    EasyMock.expect(server.getDataSource("none")).andReturn(null).atLeastOnce();
    EasyMock.expect(inventoryView.getInventory()).andReturn(ImmutableList.of(server)).atLeastOnce();
    EasyMock.replay(inventoryView, server);
    DatasourcesResource datasourcesResource = new DatasourcesResource(inventoryView, null, null, new AuthConfig());
    Assert.assertEquals(204, datasourcesResource.getTheDataSource("none", null).getStatus());
    EasyMock.verify(inventoryView, server);
}
Also used : AuthConfig(io.druid.server.security.AuthConfig) Test(org.junit.Test)

Example 20 with AuthConfig

use of io.druid.server.security.AuthConfig in project druid by druid-io.

the class IntervalsResourceTest method testFullGetSpecificIntervals.

@Test
public void testFullGetSpecificIntervals() {
    EasyMock.expect(inventoryView.getInventory()).andReturn(ImmutableList.of(server)).atLeastOnce();
    EasyMock.replay(inventoryView);
    List<Interval> expectedIntervals = new ArrayList<>();
    expectedIntervals.add(new Interval("2010-01-01T00:00:00.000Z/2010-01-02T00:00:00.000Z"));
    IntervalsResource intervalsResource = new IntervalsResource(inventoryView, new AuthConfig());
    Response response = intervalsResource.getSpecificIntervals("2010-01-01T00:00:00.000Z/P1D", null, "full", request);
    TreeMap<Interval, Map<String, Map<String, Object>>> actualIntervals = (TreeMap) response.getEntity();
    Assert.assertEquals(1, actualIntervals.size());
    Assert.assertEquals(expectedIntervals.get(0), actualIntervals.firstKey());
    Assert.assertEquals(20L, actualIntervals.get(expectedIntervals.get(0)).get("datasource1").get("size"));
    Assert.assertEquals(1, actualIntervals.get(expectedIntervals.get(0)).get("datasource1").get("count"));
    Assert.assertEquals(5L, actualIntervals.get(expectedIntervals.get(0)).get("datasource2").get("size"));
    Assert.assertEquals(1, actualIntervals.get(expectedIntervals.get(0)).get("datasource2").get("count"));
}
Also used : Response(javax.ws.rs.core.Response) ArrayList(java.util.ArrayList) AuthConfig(io.druid.server.security.AuthConfig) TreeMap(java.util.TreeMap) TreeMap(java.util.TreeMap) Map(java.util.Map) Interval(org.joda.time.Interval) Test(org.junit.Test)

Aggregations

AuthConfig (io.druid.server.security.AuthConfig)21 Test (org.junit.Test)19 Response (javax.ws.rs.core.Response)18 Map (java.util.Map)10 TreeMap (java.util.TreeMap)9 ArrayList (java.util.ArrayList)8 Interval (org.joda.time.Interval)7 HashMap (java.util.HashMap)6 ImmutableList (com.google.common.collect.ImmutableList)5 Access (io.druid.server.security.Access)5 Action (io.druid.server.security.Action)5 AuthorizationInfo (io.druid.server.security.AuthorizationInfo)5 Resource (io.druid.server.security.Resource)5 List (java.util.List)5 DruidDataSource (io.druid.client.DruidDataSource)4 DruidServer (io.druid.client.DruidServer)3 NoopRequestLogger (io.druid.server.log.NoopRequestLogger)3 NoopServiceEmitter (io.druid.server.metrics.NoopServiceEmitter)3 ByteArrayInputStream (java.io.ByteArrayInputStream)3 TreeSet (java.util.TreeSet)3