- @Test
- public void testStatisticsConstructorIsPrivate() {
- try {
- final Constructor<XacmlPdpStatisticsManager> constructor =
- XacmlPdpStatisticsManager.class.getDeclaredConstructor();
- assertTrue(Modifier.isPrivate(constructor.getModifiers()));
- constructor.setAccessible(true);
- constructor.newInstance();
- fail("Expected an InstantiationException to be thrown");
- } catch (final Exception exp) {
- assertTrue(exp.getCause().toString().contains("Instantiation of the class is not allowed"));
- }
- }
-
- private Main startXacmlPdpService(final boolean http) {
- final String[] xacmlPdpConfigParameters = new String[2];
- if (http) {
- xacmlPdpConfigParameters[0] = "-c";
- xacmlPdpConfigParameters[1] = "parameters/XacmlPdpConfigParameters.json";
- } else {
- final Properties systemProps = System.getProperties();
- systemProps.put("javax.net.ssl.keyStore", KEYSTORE);
- systemProps.put("javax.net.ssl.keyStorePassword", "Pol1cy_0nap");
- System.setProperties(systemProps);
- xacmlPdpConfigParameters[0] = "-c";
- xacmlPdpConfigParameters[1] = "parameters/XacmlPdpConfigParameters_Https.json";
- }
- return new Main(xacmlPdpConfigParameters);
- }
-
- private void stopXacmlPdpService(final Main main) throws PolicyXacmlPdpException {
- main.shutdown();
- }
-
- private Invocation.Builder sendHttpRequest(final String endpoint) throws IOException, InterruptedException {
- final ClientConfig clientConfig = new ClientConfig();
-
- final HttpAuthenticationFeature feature = HttpAuthenticationFeature.basic("healthcheck", "zb!XztG34");
- clientConfig.register(feature);
-
- final Client client = ClientBuilder.newClient(clientConfig);
- final WebTarget webTarget = client.target("http://localhost:6969/policy/pdpx/v1/" + endpoint);
-
- final Invocation.Builder invocationBuilder = webTarget.request(MediaType.APPLICATION_JSON);
-
- if (!NetworkUtil.isTcpPortOpen("localhost", 6969, 6, 10000L)) {
- throw new IllegalStateException("cannot connect to port 6969");
- }
- return invocationBuilder;
- }
-
- private Invocation.Builder sendHttpsRequest(final String endpoint) throws Exception {
-
- final TrustManager[] noopTrustManager = new TrustManager[] {new X509TrustManager() {
-
- @Override
- public X509Certificate[] getAcceptedIssuers() {
- return new X509Certificate[0];
- }
-
- @Override
- public void checkClientTrusted(final java.security.cert.X509Certificate[] certs, final String authType) {}
-
- @Override
- public void checkServerTrusted(final java.security.cert.X509Certificate[] certs, final String authType) {}
- } };
-
- final SSLContext sc = SSLContext.getInstance("TLSv1.2");
- sc.init(null, noopTrustManager, new SecureRandom());
- final ClientBuilder clientBuilder =
- ClientBuilder.newBuilder().sslContext(sc).hostnameVerifier((host, session) -> true);
- final Client client = clientBuilder.build();
- final HttpAuthenticationFeature feature = HttpAuthenticationFeature.basic("healthcheck", "zb!XztG34");
- client.register(feature);
-
- final WebTarget webTarget = client.target("https://localhost:6969/policy/pdpx/v1/" + endpoint);
-
- final Invocation.Builder invocationBuilder = webTarget.request(MediaType.APPLICATION_JSON);
-
- if (!NetworkUtil.isTcpPortOpen("localhost", 6969, 6, 10000L)) {
- throw new IllegalStateException("cannot connect to port 6969");
- }
- return invocationBuilder;
- }
-