use of org.eclipse.che.commons.subject.SubjectImpl in project che by eclipse.
the class DashboardRedirectionFilterTest method shouldRedirectIfRequestWithoutNamespace.
@Test(dataProvider = "nonNamespacePathProvider")
public void shouldRedirectIfRequestWithoutNamespace(String uri, String url) throws Exception {
//given
when(request.getMethod()).thenReturn("GET");
when(request.getRequestURI()).thenReturn(uri);
when(request.getRequestURL()).thenReturn(new StringBuffer(url));
EnvironmentContext context = new EnvironmentContext();
context.setSubject(new SubjectImpl("id123", "name", "token123", false));
EnvironmentContext.setCurrent(context);
//when
filter.doFilter(request, response, chain);
//then
verify(response).sendRedirect(eq("/dashboard/"));
}
use of org.eclipse.che.commons.subject.SubjectImpl in project che by eclipse.
the class ProjectServiceTest method testGetProjectCheckUserPermissions.
@Test
public void testGetProjectCheckUserPermissions() throws Exception {
// Without roles Collections.<String>emptySet() should get default set of permissions
env.setSubject(new SubjectImpl(vfsUser, vfsUser, "dummy_token", false));
ContainerResponse response = launcher.service(GET, "http://localhost:8080/api/project/my_project", "http://localhost:8080/api", null, null, null);
assertEquals(response.getStatus(), 200, "Error: " + response.getEntity());
ProjectConfigDto result = (ProjectConfigDto) response.getEntity();
assertNotNull(result);
}
use of org.eclipse.che.commons.subject.SubjectImpl in project che by eclipse.
the class MachineProviderImplTest method setUp.
@BeforeMethod
public void setUp() throws Exception {
when(dockerConnectorConfiguration.getDockerHostIp()).thenReturn("123.123.123.123");
provider = spy(new MachineProviderBuilder().build());
EnvironmentContext envCont = new EnvironmentContext();
envCont.setSubject(new SubjectImpl(USER_NAME, "userId", USER_TOKEN, false));
EnvironmentContext.setCurrent(envCont);
when(recipeRetriever.getRecipe(any(MachineConfig.class))).thenReturn(new RecipeImpl().withType(DOCKER_FILE_TYPE).withScript("FROM codenvy"));
when(dockerMachineFactory.createNode(anyString(), anyString())).thenReturn(dockerNode);
when(dockerConnector.createContainer(any(CreateContainerParams.class))).thenReturn(new ContainerCreated(CONTAINER_ID, new String[0]));
when(dockerConnector.inspectContainer(any(InspectContainerParams.class))).thenReturn(containerInfo);
when(containerInfo.getState()).thenReturn(containerState);
when(containerState.isRunning()).thenReturn(false);
}
use of org.eclipse.che.commons.subject.SubjectImpl in project che by eclipse.
the class TestUtils method createTestUser.
/**
* Creates a user and makes that user be the current user.
*
* @param userProfileDao
* the User Profile DAO
* @throws Exception
* if anything goes wrong
*/
public static void createTestUser(final ProfileDao userProfileDao) throws Exception {
// set current user
EnvironmentContext.getCurrent().setSubject(new SubjectImpl("codenvy", "codenvy", null, false));
// rules for mock
final Map<String, String> profileAttributes = new HashMap<>();
profileAttributes.put("firstName", "Codenvy");
profileAttributes.put("lastName", "Codenvy");
profileAttributes.put("email", "che@eclipse.org");
Mockito.when(userProfileDao.getById("codenvy")).thenReturn(new ProfileImpl("codenvy", profileAttributes));
}
use of org.eclipse.che.commons.subject.SubjectImpl in project che by eclipse.
the class WorkspaceRuntimeIntegrationTest method setUp.
@BeforeMethod
public void setUp() throws Exception {
CheEnvironmentEngine environmentEngine = new CheEnvironmentEngine(snapshotDao, machineInstanceProviders, "/tmp", 2000, eventService, environmentParser, new DefaultServicesStartStrategy(), instanceProvider, infrastructureProvisioner, "http://localhost:8080/api", recipeDownloader, containerNameGenerator, agentRegistry, sharedPool);
runtimes = new WorkspaceRuntimes(eventService, environmentEngine, agentSorter, launcherFactory, agentRegistry, snapshotDao, sharedPool);
executor = Executors.newFixedThreadPool(1, new ThreadFactoryBuilder().setNameFormat(this.getClass().toString() + "-%d").build());
EnvironmentContext.getCurrent().setSubject(new SubjectImpl("name", "id", "token", false));
}
Aggregations