Skip to content

Commit

Permalink
CHE-1298; remove war name from url schema (#1572)
Browse files Browse the repository at this point in the history
  • Loading branch information
mshaposhnik authored Jun 29, 2016
1 parent 58654df commit 64ad23e
Show file tree
Hide file tree
Showing 12 changed files with 47 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
*/

public class DashboardRedirectionFilter implements Filter {
private static Pattern projectPattern = Pattern.compile("^/ide/[^/]+?/.+");
private static Pattern projectPattern = Pattern.compile("^/[^/]+?/.+");

@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
Expand Down
6 changes: 3 additions & 3 deletions assembly/assembly-ide-war/src/main/webapp/IDE.jsp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<meta name="mobile-web-app-capable" content="yes">
<title>Eclipse Che</title>
<link rel="shortcut icon" href="/ide/_app/favicon.ico"/>
<link rel="shortcut icon" href="/_app/favicon.ico"/>
<link href="http://fonts.googleapis.com/css?family=Droid+Sans+Mono" rel="stylesheet" type="text/css"/>

<script type="text/javascript" language="javascript">
Expand Down Expand Up @@ -55,7 +55,7 @@
};
</script>

<script type="text/javascript" language="javascript" src="/ide/_app/browserNotSupported.js"></script>
<script type="text/javascript" language="javascript" src="/ide/_app/_app.nocache.js"></script>
<script type="text/javascript" language="javascript" src="/_app/browserNotSupported.js"></script>
<script type="text/javascript" language="javascript" src="/_app/_app.nocache.js"></script>
</head>
</html>
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@

RewriteRule ^/api/(.*)$ /wsmaster/api/$1 [L]
RewriteRule ^/$ /dashboard [R]
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ public class DashboardRedirectionFilterTest {
public void shouldSkipRequestToProject() throws Exception {
//given
when(request.getMethod()).thenReturn("GET");
when(request.getRequestURI()).thenReturn("/ide/namespace/ws-id/project1");
when(request.getRequestURL()).thenReturn(new StringBuffer("http://localhost:8080/ide/namespace/ws-id/project1"));
when(request.getRequestURI()).thenReturn("/namespace/ws-id/project1");
when(request.getRequestURL()).thenReturn(new StringBuffer("http://localhost:8080/namespace/ws-id/project1"));
EnvironmentContext context = new EnvironmentContext();
context.setWorkspaceId("ws-id");
EnvironmentContext.setCurrent(context);
Expand Down Expand Up @@ -88,17 +88,17 @@ public void shouldRedirectIfRequestWithoutNamespace(String uri, String url) thro

@DataProvider(name = "nonNamespacePathProvider")
public Object[][] nonProjectPathProvider() {
return new Object[][]{{"/ws-id/", "http://localhost:8080/ide/ws-id123123/"},
{"/wsname", "http://localhost:8080/ide/wsname_only"},
return new Object[][]{{"/ws-id/", "http://localhost:8080/ws-id123123/"},
{"/wsname", "http://localhost:8080/wsname_only"},
};
}

@Test(dataProvider = "notGETMethodProvider")
public void shouldSkipNotGETRequest(String method) throws Exception {
//given
when(request.getMethod()).thenReturn(method);
when(request.getRequestURI()).thenReturn("/ide/ws-id/project1");
when(request.getRequestURL()).thenReturn(new StringBuffer("http://localhost:8080/ide/ws-id/project1"));
when(request.getRequestURI()).thenReturn("/ws-id/project1");
when(request.getRequestURL()).thenReturn(new StringBuffer("http://localhost:8080/ws-id/project1"));
EnvironmentContext context = new EnvironmentContext();
context.setWorkspaceId("ws-id");
EnvironmentContext.setCurrent(context);
Expand Down
2 changes: 1 addition & 1 deletion assembly/assembly-main/src/assembly/assembly.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
<useProjectArtifact>false</useProjectArtifact>
<unpack>false</unpack>
<outputDirectory>tomcat/webapps</outputDirectory>
<outputFileNameMapping>ide.war</outputFileNameMapping>
<outputFileNameMapping>ROOT.war</outputFileNameMapping>
<includes>
<include>org.eclipse.che:assembly-ide-war</include>
</includes>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,6 @@ che.machine.projects.internal.storage=/projects
# Che stores various internal data objects as JSON on the file system.
che.conf.storage=${che.home}/storage

# The dashboard uses this to manage direction of requests to the IDE
# Generally, do not modify.
che.ide.context=ide

### Configuration of embedded templates and samples
# Folder that contains JSON files with code templates and samples
project.template_description.location_dir=${che.home}/templates
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@
@Singleton
public class BrowserQueryFieldRenderer {

private static final int WORKSPACE_ORDER_IN_URL = 3;
private static final int NAMESPACE_ORDER_IN_URL = 2;
private static final int WORKSPACE_ORDER_IN_URL = 2;
private static final int NAMESPACE_ORDER_IN_URL = 1;
//Used in the JSNI methods follow
private static final int AMOUNT_URL_PARTS = 5;
private static final int AMOUNT_URL_PARTS = 4;

//Used in the JSNI methods follow
private final ProductInfoDataProvider productInfoDataProvider;
Expand Down Expand Up @@ -148,9 +148,9 @@ public native void setQueryField(String namespace, String workspaceName, String
var browserUrl = window.location.pathname;
var urlParts = browserUrl.split('/');
urlParts[2] = namespace;
urlParts[3] = workspaceName;
urlParts[4] = projectName;
urlParts[1] = namespace;
urlParts[2] = workspaceName;
urlParts[3] = projectName;
var sliceIndex = @org.eclipse.che.ide.context.BrowserQueryFieldRenderer::AMOUNT_URL_PARTS;
if (namespace == null || namespace.length == 0) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
*******************************************************************************/
package org.eclipse.che.api.user.server;

import com.google.common.collect.Sets;

import org.eclipse.che.api.core.ConflictException;
import org.eclipse.che.api.core.NotFoundException;
import org.eclipse.che.api.core.ServerException;
Expand All @@ -22,9 +24,11 @@
import org.slf4j.LoggerFactory;

import javax.inject.Inject;
import javax.inject.Named;

import java.util.HashMap;
import java.util.Map;
import java.util.Set;

import static com.google.common.base.MoreObjects.firstNonNull;
import static java.lang.String.format;
Expand All @@ -45,15 +49,17 @@ public class UserManager {
private final UserDao userDao;
private final UserProfileDao profileDao;
private final PreferenceDao preferenceDao;

private final Set<String> reservedNames;

@Inject
public UserManager(UserDao userDao,
UserProfileDao profileDao,
PreferenceDao preferenceDao) {
PreferenceDao preferenceDao,
@Named("user.reserved_names") String[] reservedNames) {
this.userDao = userDao;
this.profileDao = profileDao;
this.preferenceDao = preferenceDao;
this.reservedNames = Sets.newHashSet(reservedNames);
}


Expand All @@ -68,6 +74,9 @@ public UserManager(UserDao userDao,
* when any other error occurs
*/
public void create(User user, boolean isTemporary) throws ConflictException, ServerException {
if (reservedNames.contains(user.getName().toLowerCase())) {
throw new ConflictException(String.format("Username \"%s\" is reserved", user.getName()));
}
user.withId(generate("user", ID_LENGTH))
.withPassword(firstNonNull(user.getPassword(), generate("", PASSWORD_LENGTH)));
userDao.create(user);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,23 +10,22 @@
*******************************************************************************/
package org.eclipse.che.api.user.server;

import org.eclipse.che.api.core.BadRequestException;
import org.eclipse.che.api.core.ConflictException;
import org.eclipse.che.api.user.server.dao.PreferenceDao;
import org.eclipse.che.api.user.server.dao.Profile;
import org.eclipse.che.api.user.server.dao.User;
import org.eclipse.che.api.user.server.dao.UserDao;
import org.eclipse.che.api.user.server.dao.UserProfileDao;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.testng.MockitoTestNGListener;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Listeners;
import org.testng.annotations.Test;

import static org.mockito.Matchers.any;
import static org.mockito.Matchers.anyMapOf;
import static org.mockito.Matchers.anyString;
import static org.mockito.Matchers.eq;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.verify;

/**
Expand All @@ -45,12 +44,17 @@ public class UserManagerTest {
@Mock
PreferenceDao preferenceDao;

@InjectMocks
UserManager manager;

@BeforeMethod
public void setUp() {
manager = new UserManager(userDao, profileDao, preferenceDao, new String[0]);
}

@Test
public void shouldCreateProfileAndPreferencesOnUserCreation() throws Exception {
final User user = new User().withEmail("[email protected]").withName("testName");

manager.create(user, false);

verify(profileDao).create(any(Profile.class));
Expand All @@ -60,8 +64,16 @@ public void shouldCreateProfileAndPreferencesOnUserCreation() throws Exception {
@Test
public void shouldGeneratedPasswordWhenCreatingUserAndItIsMissing() throws Exception {
final User user = new User().withEmail("[email protected]").withName("testName");

manager.create(user, false);

verify(userDao).create(eq(user.withPassword("<none>")));
}

@Test(expectedExceptions = ConflictException.class)
public void shouldThrowConflictExceptionOnCreationIfUserNameIsReserved() throws Exception {
final User user = new User().withEmail("[email protected]").withName("reserved");

new UserManager(userDao, profileDao, preferenceDao, new String[] {"reserved"}).create(user, false);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,10 @@ public class WorkspaceServiceLinksInjector {

//TODO: we need keep IDE context in some property to have possibility configure it because context is different in Che and Hosted packaging
//TODO: not good solution do it here but critical for this task https://jira.codenvycorp.com/browse/IDEX-3619
private final String ideContext;
private final MachineServiceLinksInjector machineLinksInjector;

@Inject
public WorkspaceServiceLinksInjector(@Named("che.ide.context") String ideContext,
MachineServiceLinksInjector machineLinksInjector) {
this.ideContext = ideContext;
public WorkspaceServiceLinksInjector(MachineServiceLinksInjector machineLinksInjector) {
this.machineLinksInjector = machineLinksInjector;
}

Expand Down Expand Up @@ -113,7 +110,7 @@ public WorkspaceDto injectLinks(WorkspaceDto workspace, ServiceContext serviceCo

//TODO here we add url to IDE with workspace name not good solution do it here but critical for this task https://jira.codenvycorp.com/browse/IDEX-3619
final URI ideUri = uriBuilder.clone()
.replacePath(ideContext)
.replacePath("")
.path(workspace.getNamespace())
.path(workspace.getConfig().getName())
.build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,6 @@ public class WorkspaceServiceTest {
private static final ApiExceptionMapper MAPPER = new ApiExceptionMapper();
private static final String NAMESPACE = "user";
private static final String USER_ID = "user123";
private static final String IDE_CONTEXT = "ws";
@SuppressWarnings("unused")
private static final EnvironmentFilter FILTER = new EnvironmentFilter();

Expand All @@ -130,7 +129,7 @@ public void setup() {
service = new WorkspaceService(wsManager,
machineManager,
validator,
new WorkspaceServiceLinksInjector(IDE_CONTEXT, new MachineServiceLinksInjector()));
new WorkspaceServiceLinksInjector(new MachineServiceLinksInjector()));
}

@Test
Expand Down

0 comments on commit 64ad23e

Please sign in to comment.