Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RESTWS-954: Ensures session endpoint returns locale even when user is not logged in #621

Merged
merged 1 commit into from
Sep 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,11 @@ public Object get() {
boolean authenticated = Context.isAuthenticated();
SimpleObject session = new SimpleObject();
session.add("authenticated", authenticated);
session.add("locale", Context.getLocale());
session.add("allowedLocales", Context.getAdministrationService().getAllowedLocales());
if (authenticated) {
session.add("user", ConversionUtil.convertToRepresentation(Context.getAuthenticatedUser(),
new CustomRepresentation(USER_CUSTOM_REP)));
session.add("locale", Context.getLocale());
session.add("allowedLocales", Context.getAdministrationService().getAllowedLocales());
session.add("sessionLocation", ConversionUtil.convertToRepresentation(Context.getUserContext().getLocation(), Representation.REF));
session.add("currentProvider", ConversionUtil.convertToRepresentation(getCurrentProvider(), Representation.REF));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,8 @@
import org.springframework.mock.web.MockHttpServletRequest;
import org.springframework.mock.web.MockHttpSession;
import org.springframework.mock.web.MockServletContext;
import org.springframework.web.context.request.ServletWebRequest;
import org.springframework.web.context.request.WebRequest;

import javax.servlet.http.HttpServletRequest;
import java.lang.reflect.InvocationTargetException;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
Expand Down Expand Up @@ -85,6 +83,22 @@ public void get_shouldReturnTheUserIfTheUserIsAuthenticated() throws Exception {
Assert.assertEquals(Context.getAuthenticatedUser().getPerson().getUuid(),
PropertyUtils.getProperty(personProp, "uuid"));
}

@Test
public void get_shouldReturnLocaleInfoIfTheUserIsNotAuthenticated() throws InvocationTargetException, IllegalAccessException, NoSuchMethodException {
Assert.assertTrue(Context.isAuthenticated());

// log out the current authenticated user
controller.delete(hsr);
Assert.assertFalse(Context.isAuthenticated());
Assert.assertNull(hsr.getSession(false));

// check if the unauthenticated user response has locale and allowedLocales
Object ret = controller.get();
Assert.assertEquals(Context.getLocale(), PropertyUtils.getProperty(ret, "locale"));
Assert.assertArrayEquals(Context.getAdministrationService().getAllowedLocales().toArray(),
((List<Locale>) PropertyUtils.getProperty(ret, "allowedLocales")).toArray());
}

@Test
public void get_shouldReturnLocaleInfoIfTheUserIsAuthenticated() throws Exception {
Expand Down
Loading