Search in sources :

Example 11 with SConfiguration

use of io.cdap.cdap.common.conf.SConfiguration in project cdap by caskdata.

the class TaskWorkerServiceTest method testRestartAfterMultipleExecutions.

@Test
public void testRestartAfterMultipleExecutions() throws IOException {
    CConfiguration cConf = createCConf();
    SConfiguration sConf = createSConf();
    cConf.setInt(Constants.TaskWorker.CONTAINER_KILL_AFTER_REQUEST_COUNT, 2);
    cConf.setInt(Constants.TaskWorker.CONTAINER_KILL_AFTER_DURATION_SECOND, 0);
    TaskWorkerService taskWorkerService = new TaskWorkerService(cConf, sConf, new InMemoryDiscoveryService(), (namespaceId, retryStrategy) -> null, metricsCollectionService, new CommonNettyHttpServiceFactory(cConf, metricsCollectionService));
    serviceCompletionFuture = TaskWorkerTestUtil.getServiceCompletionFuture(taskWorkerService);
    // start the service
    taskWorkerService.startAndWait();
    InetSocketAddress addr = taskWorkerService.getBindAddress();
    URI uri = URI.create(String.format("http://%s:%s", addr.getHostName(), addr.getPort()));
    // Post valid request
    String want = "100";
    RunnableTaskRequest req = RunnableTaskRequest.getBuilder(TestRunnableClass.class.getName()).withParam(want).build();
    String reqBody = GSON.toJson(req);
    HttpResponse response = HttpRequests.execute(HttpRequest.post(uri.resolve("/v3Internal/worker/run").toURL()).withBody(reqBody).build(), new DefaultHttpRequestConfig(false));
    response = HttpRequests.execute(HttpRequest.post(uri.resolve("/v3Internal/worker/run").toURL()).withBody(reqBody).build(), new DefaultHttpRequestConfig(false));
    TaskWorkerTestUtil.waitForServiceCompletion(serviceCompletionFuture);
    Assert.assertEquals(Service.State.TERMINATED, taskWorkerService.state());
}
Also used : InetSocketAddress(java.net.InetSocketAddress) DefaultHttpRequestConfig(io.cdap.cdap.common.http.DefaultHttpRequestConfig) SConfiguration(io.cdap.cdap.common.conf.SConfiguration) HttpResponse(io.cdap.common.http.HttpResponse) CommonNettyHttpServiceFactory(io.cdap.cdap.common.http.CommonNettyHttpServiceFactory) CConfiguration(io.cdap.cdap.common.conf.CConfiguration) InMemoryDiscoveryService(org.apache.twill.discovery.InMemoryDiscoveryService) URI(java.net.URI) RunnableTaskRequest(io.cdap.cdap.api.service.worker.RunnableTaskRequest) Test(org.junit.Test)

Example 12 with SConfiguration

use of io.cdap.cdap.common.conf.SConfiguration in project cdap by caskdata.

the class SystemWorkerServiceTest method beforeTest.

@Before
public void beforeTest() throws IOException {
    File keyDir = TEMP_FOLDER.newFolder();
    File keyFile = new File(keyDir, "key");
    CConfiguration cConf = createCConf();
    cConf.set(Constants.Security.CFG_FILE_BASED_KEYFILE_PATH, keyFile.getAbsolutePath());
    Injector injector = Guice.createInjector(new IOModule(), new ConfigModule(cConf), new FileBasedCoreSecurityModule(), new InMemoryDiscoveryModule());
    SConfiguration sConf = createSConf();
    SystemWorkerService service = new SystemWorkerService(cConf, sConf, new InMemoryDiscoveryService(), metricsCollectionService, new CommonNettyHttpServiceFactory(cConf, metricsCollectionService), injector.getInstance(FileBasedKeyManager.class), new NoopTwillRunnerService(), getInjector().getInstance(ProvisioningService.class), Guice.createInjector(new RunnableTaskModule(cConf)));
    service.startAndWait();
    this.systemWorkerService = service;
}
Also used : IOModule(io.cdap.cdap.common.guice.IOModule) InMemoryDiscoveryModule(io.cdap.cdap.common.guice.InMemoryDiscoveryModule) ConfigModule(io.cdap.cdap.common.guice.ConfigModule) RunnableTaskModule(io.cdap.cdap.internal.app.worker.RunnableTaskModule) CConfiguration(io.cdap.cdap.common.conf.CConfiguration) NoopTwillRunnerService(io.cdap.cdap.common.twill.NoopTwillRunnerService) Injector(com.google.inject.Injector) ProvisioningService(io.cdap.cdap.internal.provision.ProvisioningService) SConfiguration(io.cdap.cdap.common.conf.SConfiguration) CommonNettyHttpServiceFactory(io.cdap.cdap.common.http.CommonNettyHttpServiceFactory) FileBasedKeyManager(io.cdap.cdap.security.auth.FileBasedKeyManager) File(java.io.File) InMemoryDiscoveryService(org.apache.twill.discovery.InMemoryDiscoveryService) FileBasedCoreSecurityModule(io.cdap.cdap.security.guice.FileBasedCoreSecurityModule) Before(org.junit.Before)

Example 13 with SConfiguration

use of io.cdap.cdap.common.conf.SConfiguration in project cdap by caskdata.

the class ExternalLDAPAuthenticationServerSSLTest method beforeClass.

@BeforeClass
public static void beforeClass() throws Exception {
    URL certUrl = ExternalLDAPAuthenticationServerSSLTest.class.getClassLoader().getResource("cert.jks");
    Assert.assertNotNull(certUrl);
    String authHandlerConfigBase = Constants.Security.AUTH_HANDLER_CONFIG_BASE;
    CConfiguration cConf = CConfiguration.create();
    SConfiguration sConf = SConfiguration.create();
    cConf.set(Constants.Security.AUTH_SERVER_BIND_ADDRESS, InetAddress.getLoopbackAddress().getHostName());
    cConf.set(Constants.Security.SSL.EXTERNAL_ENABLED, "true");
    cConf.setInt(Constants.Security.AuthenticationServer.SSL_PORT, 0);
    cConf.set(authHandlerConfigBase.concat("useLdaps"), "true");
    cConf.set(authHandlerConfigBase.concat("ldapsVerifyCertificate"), "false");
    sConf.set(Constants.Security.AuthenticationServer.SSL_KEYSTORE_PATH, certUrl.getPath());
    configuration = cConf;
    sConfiguration = sConf;
    String keystorePassword = sConf.get(Constants.Security.AuthenticationServer.SSL_KEYSTORE_PASSWORD);
    KeyStoreKeyManager keyManager = new KeyStoreKeyManager(certUrl.getFile(), keystorePassword.toCharArray());
    SSLUtil sslUtil = new SSLUtil(keyManager, new TrustAllTrustManager());
    ldapListenerConfig = InMemoryListenerConfig.createLDAPSConfig("LDAP", InetAddress.getLoopbackAddress(), ldapPort, sslUtil.createSSLServerSocketFactory(), sslUtil.createSSLSocketFactory());
    testServer = new ExternalLDAPAuthenticationServerSSLTest();
    testServer.setup();
}
Also used : KeyStoreKeyManager(com.unboundid.util.ssl.KeyStoreKeyManager) SSLUtil(com.unboundid.util.ssl.SSLUtil) SConfiguration(io.cdap.cdap.common.conf.SConfiguration) TrustAllTrustManager(com.unboundid.util.ssl.TrustAllTrustManager) CConfiguration(io.cdap.cdap.common.conf.CConfiguration) URL(java.net.URL) BeforeClass(org.junit.BeforeClass)

Example 14 with SConfiguration

use of io.cdap.cdap.common.conf.SConfiguration in project cdap by caskdata.

the class TinkCipherTest method testDecryptExceptionTagMismatch.

@Test(expected = CipherException.class)
public void testDecryptExceptionTagMismatch() throws CipherException, IOException, GeneralSecurityException {
    SConfiguration sConf = SConfiguration.create();
    sConf.set(Constants.Security.Authentication.USER_CREDENTIAL_ENCRYPTION_KEYSET, generateKeySet());
    TinkCipher cipher = new TinkCipher(sConf);
    byte[] plainData = generateRandomBytes(128);
    byte[] associatedData = generateRandomBytes(64);
    byte[] cipherData = cipher.encrypt(plainData, associatedData);
    byte[] invalidAssociatedData = generateRandomBytes(64);
    byte[] decryptedData = cipher.decrypt(cipherData, invalidAssociatedData);
}
Also used : SConfiguration(io.cdap.cdap.common.conf.SConfiguration) Test(org.junit.Test)

Example 15 with SConfiguration

use of io.cdap.cdap.common.conf.SConfiguration in project cdap by caskdata.

the class TinkCipherTest method testInitException.

@Test(expected = CipherException.class)
public void testInitException() throws CipherException {
    SConfiguration sConf = SConfiguration.create();
    sConf.set(Constants.Security.Authentication.USER_CREDENTIAL_ENCRYPTION_KEYSET, "invalid keyset");
    TinkCipher cipher = new TinkCipher(sConf);
}
Also used : SConfiguration(io.cdap.cdap.common.conf.SConfiguration) Test(org.junit.Test)

Aggregations

SConfiguration (io.cdap.cdap.common.conf.SConfiguration)70 CConfiguration (io.cdap.cdap.common.conf.CConfiguration)52 Test (org.junit.Test)32 BeforeClass (org.junit.BeforeClass)20 InMemoryDiscoveryService (org.apache.twill.discovery.InMemoryDiscoveryService)16 Injector (com.google.inject.Injector)14 CommonNettyHttpServiceFactory (io.cdap.cdap.common.http.CommonNettyHttpServiceFactory)12 File (java.io.File)12 InetSocketAddress (java.net.InetSocketAddress)10 ConfigModule (io.cdap.cdap.common.guice.ConfigModule)8 Principal (io.cdap.cdap.proto.security.Principal)8 NoOpAccessController (io.cdap.cdap.security.spi.authorization.NoOpAccessController)8 Configuration (org.apache.hadoop.conf.Configuration)8 Before (org.junit.Before)8 RunnableTaskRequest (io.cdap.cdap.api.service.worker.RunnableTaskRequest)6 IOModule (io.cdap.cdap.common.guice.IOModule)6 InMemoryDiscoveryModule (io.cdap.cdap.common.guice.InMemoryDiscoveryModule)6 DefaultHttpRequestConfig (io.cdap.cdap.common.http.DefaultHttpRequestConfig)6 InMemoryNamespaceAdmin (io.cdap.cdap.common.namespace.InMemoryNamespaceAdmin)6 HttpResponse (io.cdap.common.http.HttpResponse)6