private ClientInfoResource getResourceTestHelper( FilteredServerInventoryView serverInventoryView, TimelineServerView timelineServerView, SegmentMetadataQueryConfig segmentMetadataQueryConfig ) { return new ClientInfoResource( serverInventoryView, timelineServerView, segmentMetadataQueryConfig, new AuthConfig(), null ) { @Override protected DateTime getCurrentTime() { return FIXED_TEST_TIME; } }; } }
AuthenticationUtils.addNoopAuthorizationFilters(root, authConfig.getUnsecuredPaths()); AuthenticationUtils.addAllowOptionsFilter(root, authConfig.isAllowUnauthenticatedHttpOptions());
@Override public int hashCode() { return Objects.hash( getAuthenticatorChain(), getAuthorizers(), getUnsecuredPaths(), isAllowUnauthenticatedHttpOptions() ); }
List<String> authenticators = authConfig.getAuthenticatorChain();
List<String> authorizers = authConfig.getAuthorizers();
List<String> authenticators = authConfig.getAuthenticatorChain();
List<String> authorizers = authConfig.getAuthorizers();
@Override public void configure(Binder binder) { for (Class clazz : mockableInjections) { binder.bind(clazz).toInstance(EasyMock.createNiceMock(clazz)); } for (Object obj : injectedObjs) { binder.bind((Class) obj.getClass()).toInstance(obj); } for (Key<?> key : mockableKeys) { binder.bind((Key<Object>) key).toInstance(EasyMock.createNiceMock(key.getTypeLiteral().getRawType())); } binder.bind(AuthConfig.class).toInstance(new AuthConfig()); } }
AuthenticationUtils.addNoopAuthorizationFilters(root, authConfig.getUnsecuredPaths()); AuthenticationUtils.addAllowOptionsFilter(root, authConfig.isAllowUnauthenticatedHttpOptions());
@Override public boolean equals(Object o) { if (this == o) { return true; } if (o == null || getClass() != o.getClass()) { return false; } AuthConfig that = (AuthConfig) o; return isAllowUnauthenticatedHttpOptions() == that.isAllowUnauthenticatedHttpOptions() && Objects.equals(getAuthenticatorChain(), that.getAuthenticatorChain()) && Objects.equals(getAuthorizers(), that.getAuthorizers()) && Objects.equals(getUnsecuredPaths(), that.getUnsecuredPaths()); }
@Test public void testNullGetTheDataSource() { 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, null, new AuthConfig(), null); Assert.assertEquals(204, DataSourcesResource.getTheDataSource("none", null).getStatus()); EasyMock.verify(inventoryView, server); }
AuthenticationUtils.addNoopAuthorizationFilters(root, authConfig.getUnsecuredPaths()); AuthenticationUtils.addAllowOptionsFilter(root, authConfig.isAllowUnauthenticatedHttpOptions());
@Override public int hashCode() { return Objects.hash( getAuthenticatorChain(), getAuthorizers(), getUnsecuredPaths(), isAllowUnauthenticatedHttpOptions() ); }
@Test public void testDeleteDataSource() { IndexingServiceClient indexingServiceClient = EasyMock.createStrictMock(IndexingServiceClient.class); EasyMock.replay(indexingServiceClient, server); DataSourcesResource DataSourcesResource = new DataSourcesResource( inventoryView, null, null, indexingServiceClient, new AuthConfig(), null ); Response response = DataSourcesResource.deleteDataSource("datasource", "true", "???"); Assert.assertEquals(400, response.getStatus()); Assert.assertNotNull(response.getEntity()); Assert.assertTrue(response.getEntity().toString().contains("java.lang.IllegalArgumentException")); EasyMock.verify(indexingServiceClient, server); }
AuthenticationUtils.addNoopAuthorizationFilters(root, authConfig.getUnsecuredPaths()); AuthenticationUtils.addAuthenticationFilterChain(root, authenticators); AuthenticationUtils.addAllowOptionsFilter(root, authConfig.isAllowUnauthenticatedHttpOptions());
@Override public boolean equals(Object o) { if (this == o) { return true; } if (o == null || getClass() != o.getClass()) { return false; } AuthConfig that = (AuthConfig) o; return isAllowUnauthenticatedHttpOptions() == that.isAllowUnauthenticatedHttpOptions() && Objects.equals(getAuthenticatorChain(), that.getAuthenticatorChain()) && Objects.equals(getAuthorizers(), that.getAuthorizers()) && Objects.equals(getUnsecuredPaths(), that.getUnsecuredPaths()); }
@Test public void testFullGetTheDataSource() { 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, null, new AuthConfig(), null); Response response = DataSourcesResource.getTheDataSource("datasource1", "full"); ImmutableDruidDataSource result = (ImmutableDruidDataSource) response.getEntity(); Assert.assertEquals(200, response.getStatus()); Assert.assertEquals(dataSource1.toImmutableDruidDataSource(), result); EasyMock.verify(inventoryView, server); }
AuthenticationUtils.addNoopAuthorizationFilters(root, authConfig.getUnsecuredPaths()); AuthenticationUtils.addAllowOptionsFilter(root, authConfig.isAllowUnauthenticatedHttpOptions());
@Test public void testFullGetSpecificIntervals() { EasyMock.expect(inventoryView.getInventory()).andReturn( ImmutableList.of(server) ).atLeastOnce(); EasyMock.expect(request.getAttribute(AuthConfig.DRUID_ALLOW_UNSECURED_PATH)).andReturn(null).once(); EasyMock.expect(request.getAttribute(AuthConfig.DRUID_AUTHORIZATION_CHECKED)).andReturn(null).once(); EasyMock.expect(request.getAttribute(AuthConfig.DRUID_AUTHENTICATION_RESULT)).andReturn( new AuthenticationResult("druid", "druid", null, null) ).once(); request.setAttribute(AuthConfig.DRUID_AUTHORIZATION_CHECKED, true); EasyMock.expectLastCall().times(1); EasyMock.replay(inventoryView, request); List<Interval> expectedIntervals = new ArrayList<>(); expectedIntervals.add(Intervals.of("2010-01-01T00:00:00.000Z/2010-01-02T00:00:00.000Z")); IntervalsResource intervalsResource = new IntervalsResource( inventoryView, new AuthConfig(), AuthTestUtils.TEST_AUTHORIZER_MAPPER ); 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")); }
AuthenticationUtils.addNoopAuthorizationFilters(root, authConfig.getUnsecuredPaths()); AuthenticationUtils.addAllowOptionsFilter(root, authConfig.isAllowUnauthenticatedHttpOptions());