use of io.cdap.cdap.security.auth.context.AuthenticationTestContext in project cdap by caskdata.
the class ArtifactLocalizerServiceTest method setupArtifactLocalizerService.
private ArtifactLocalizerService setupArtifactLocalizerService(CConfiguration cConf) {
DiscoveryServiceClient discoveryClient = getInjector().getInstance(DiscoveryServiceClient.class);
RemoteClientFactory remoteClientFactory = new RemoteClientFactory(discoveryClient, new DefaultInternalAuthenticator(new AuthenticationTestContext()));
ArtifactLocalizerService artifactLocalizerService = new ArtifactLocalizerService(cConf, new ArtifactLocalizer(cConf, remoteClientFactory, (namespaceId, retryStrategy) -> {
return new NoOpArtifactManager();
}));
// start the service
artifactLocalizerService.startAndWait();
return artifactLocalizerService;
}
use of io.cdap.cdap.security.auth.context.AuthenticationTestContext in project cdap by caskdata.
the class OAuthMacroEvaluatorTest method init.
@BeforeClass
public static void init() throws Exception {
httpService = NettyHttpService.builder("OAuthTest").setHttpHandlers(new OAuthHandler(ImmutableMap.of(PROVIDER, ImmutableMap.of(CREDENTIAL_ID, new OAuthInfo("accessToken", "bearer"))))).build();
httpService.start();
InMemoryDiscoveryService discoveryService = new InMemoryDiscoveryService();
String discoveryName = ServiceDiscoverable.getName(NamespaceId.SYSTEM.getNamespace(), Constants.PIPELINEID, ProgramType.SERVICE, Constants.STUDIO_SERVICE_NAME);
discoveryService.register(new Discoverable(discoveryName, httpService.getBindAddress()));
RemoteClientFactory remoteClientFactory = new RemoteClientFactory(discoveryService, new DefaultInternalAuthenticator(new AuthenticationTestContext()));
serviceDiscoverer = new AbstractServiceDiscoverer(NamespaceId.DEFAULT.app("testapp").spark("testspark")) {
@Override
protected RemoteClientFactory getRemoteClientFactory() {
return remoteClientFactory;
}
};
}
use of io.cdap.cdap.security.auth.context.AuthenticationTestContext in project cdap by caskdata.
the class AbstractDatasetFrameworkTest method testAuditPublish.
@Test
public void testAuditPublish() throws Exception {
// Clear all audit messages
inMemoryAuditPublisher.popMessages();
List<AuditMessage> expectedMessages = new ArrayList<>();
// Adding modules
DatasetFramework framework = getFramework();
framework.addModule(IN_MEMORY, new InMemoryTableModule());
// Creating instances
framework.addInstance(Table.class.getName(), MY_TABLE, DatasetProperties.EMPTY);
expectedMessages.add(new AuditMessage(0, MY_TABLE, "", AuditType.CREATE, AuditPayload.EMPTY_PAYLOAD));
framework.addInstance(Table.class.getName(), MY_TABLE2, DatasetProperties.EMPTY);
expectedMessages.add(new AuditMessage(0, MY_TABLE2, "", AuditType.CREATE, AuditPayload.EMPTY_PAYLOAD));
// Update instance
framework.updateInstance(MY_TABLE, DatasetProperties.EMPTY);
expectedMessages.add(new AuditMessage(0, MY_TABLE, "", AuditType.UPDATE, AuditPayload.EMPTY_PAYLOAD));
// Access instance
ProgramRunId runId = new ProgramId("ns", "app", ProgramType.WORKER, "worker").run(RunIds.generate().getId());
LineageWriterDatasetFramework lineageFramework = new LineageWriterDatasetFramework(framework, new NoOpLineageWriter(), new NoOpUsageRegistry(), new AuthenticationTestContext(), new NoOpAccessController());
lineageFramework.setContext(new TestProgramContext(runId));
lineageFramework.setAuditPublisher(inMemoryAuditPublisher);
lineageFramework.getDataset(MY_TABLE, ImmutableMap.<String, String>of(), getClass().getClassLoader());
expectedMessages.add(new AuditMessage(0, MY_TABLE, "", AuditType.ACCESS, new AccessPayload(AccessType.UNKNOWN, runId)));
// Truncate instance
framework.truncateInstance(MY_TABLE);
expectedMessages.add(new AuditMessage(0, MY_TABLE, "", AuditType.TRUNCATE, AuditPayload.EMPTY_PAYLOAD));
// Delete instance
framework.deleteInstance(MY_TABLE);
expectedMessages.add(new AuditMessage(0, MY_TABLE, "", AuditType.DELETE, AuditPayload.EMPTY_PAYLOAD));
// Delete all instances in a namespace
framework.deleteAllInstances(MY_TABLE2.getParent());
expectedMessages.add(new AuditMessage(0, MY_TABLE2, "", AuditType.DELETE, AuditPayload.EMPTY_PAYLOAD));
Assert.assertEquals(expectedMessages, inMemoryAuditPublisher.popMessages());
// cleanup
framework.deleteModule(IN_MEMORY);
}
use of io.cdap.cdap.security.auth.context.AuthenticationTestContext in project cdap by caskdata.
the class DefaultMasterEnvironmentRunnableContextTest method setup.
@BeforeClass
public static void setup() throws Exception {
DiscoveryService discoveryService = new InMemoryDiscoveryService();
LocationFactory locationFactory = new LocalLocationFactory(TMP_FOLDER.newFolder());
RemoteClientFactory remoteClientFactory = new RemoteClientFactory((DiscoveryServiceClient) discoveryService, new DefaultInternalAuthenticator(new AuthenticationTestContext()));
context = new DefaultMasterEnvironmentRunnableContext(locationFactory, remoteClientFactory);
httpService = NettyHttpService.builder(Constants.Service.APP_FABRIC_HTTP).setHttpHandlers(new MockHttpHandler()).build();
httpService.start();
cancelDiscovery = discoveryService.register(ResolvingDiscoverable.of(URIScheme.createDiscoverable(Constants.Service.APP_FABRIC_HTTP, httpService)));
}
use of io.cdap.cdap.security.auth.context.AuthenticationTestContext in project cdap by caskdata.
the class TetheringServerHandlerTest method setUp.
@Before
public void setUp() throws Exception {
// Define all StructuredTable before starting any services that need StructuredTable
StoreDefinition.createAllTables(injector.getInstance(StructuredTableAdmin.class));
cConf.setBoolean(Constants.Tethering.TETHERING_SERVER_ENABLED, true);
cConf.setInt(Constants.Tethering.CONNECTION_TIMEOUT_SECONDS, 1);
List<Permission> tetheringPermissions = Arrays.asList(InstancePermission.TETHER);
InMemoryAccessController inMemoryAccessController = new InMemoryAccessController();
inMemoryAccessController.grant(Authorizable.fromEntityId(InstanceId.SELF), MASTER_PRINCIPAL, Collections.unmodifiableSet(new HashSet<>(tetheringPermissions)));
ContextAccessEnforcer contextAccessEnforcer = new DefaultContextAccessEnforcer(new AuthenticationTestContext(), inMemoryAccessController);
AuthenticationTestContext.actAsPrincipal(MASTER_PRINCIPAL);
service = new CommonNettyHttpServiceBuilder(CConfiguration.create(), getClass().getSimpleName()).setHttpHandlers(new TetheringServerHandler(cConf, tetheringStore, messagingService, contextAccessEnforcer), new TetheringHandler(cConf, tetheringStore, messagingService)).build();
service.start();
config = ClientConfig.builder().setConnectionConfig(ConnectionConfig.builder().setHostname(service.getBindAddress().getHostName()).setPort(service.getBindAddress().getPort()).setSSLEnabled(false).build()).build();
}
Aggregations