use of org.forgerock.json.resource.http.HttpContext in project OpenAM by OpenRock.
the class RestRouterIT method mockRequiredContexts.
private Context mockRequiredContexts() {
final HttpContext httpContext = new HttpContext(json(object(field(HttpContext.ATTR_HEADERS, Collections.singletonMap("Accept-Language", Arrays.asList("en"))), field(HttpContext.ATTR_PARAMETERS, Collections.emptyMap()))), null);
SecurityContext securityContext = new SecurityContext(mockContext(httpContext), null, null);
return new SSOTokenContext(mock(Debug.class), null, securityContext) {
@Override
public Subject getCallerSubject() {
return new Subject();
}
@Override
public SSOToken getCallerSSOToken() {
SSOToken token = mock(SSOToken.class);
try {
given(token.getProperty(Constants.AM_CTX_ID)).willReturn("TRACKING_ID");
given(token.getProperty(Constants.UNIVERSAL_IDENTIFIER)).willReturn("USER_ID");
} catch (SSOException e) {
// won't happen - it's a mock
}
return token;
}
};
}
use of org.forgerock.json.resource.http.HttpContext in project OpenAM by OpenRock.
the class ScriptResourceTest method setUp.
@BeforeMethod
public void setUp() throws ResourceException {
Logger logger = mock(Logger.class);
ScriptingService scriptingService = new MockScriptingService();
ScriptingServiceFactory serviceFactory = mock(ScriptingServiceFactory.class);
when(serviceFactory.create(any(Subject.class), anyString())).thenReturn(scriptingService);
ExceptionMappingHandler<ScriptException, ResourceException> errorHandler = new ScriptExceptionMappingHandler();
scriptResource = new ScriptResource(logger, serviceFactory, errorHandler, new StandardScriptValidator(new StandardScriptEngineManager()));
context = mock(Context.class);
given(context.asContext(HttpContext.class)).willReturn(new HttpContext(json(object(field("headers", Collections.emptyMap()), field("parameters", Collections.emptyMap()))), null));
}
use of org.forgerock.json.resource.http.HttpContext in project OpenAM by OpenRock.
the class ForwardedHeaderBaseURLProviderTest method testGetBaseURLFromHTTPContextWithContext.
@Test
public void testGetBaseURLFromHTTPContextWithContext() throws Exception {
// Given
Map<String, List<String>> headers = new HashMap<>();
headers.put("Forwarded", Arrays.asList("host=\"fred\";proto=\"http\""));
HttpContext httpContext = new HttpContext(json(object(field(BaseURLConstants.ATTR_HEADERS, headers), field(BaseURLConstants.ATTR_PARAMETERS, Collections.emptyMap()))), null);
provider.setContextPath("/openam");
// When
String url = provider.getRootURL(httpContext);
// Then
assertThat(url).isEqualTo("http://fred/openam");
}
use of org.forgerock.json.resource.http.HttpContext in project OpenAM by OpenRock.
the class ForwardedHeaderBaseURLProviderTest method testGetBaseURLFromHTTPContextNoHeader.
@Test(expectedExceptions = IllegalArgumentException.class)
public void testGetBaseURLFromHTTPContextNoHeader() throws Exception {
// Given
HttpContext httpContext = new HttpContext(json(object(field(BaseURLConstants.ATTR_HEADERS, Collections.emptyMap()), field(BaseURLConstants.ATTR_PARAMETERS, Collections.emptyMap()))), null);
// When
String url = provider.getRootURL(httpContext);
// Then - illegal argument exception;
}
use of org.forgerock.json.resource.http.HttpContext in project OpenAM by OpenRock.
the class ForwardedHeaderBaseURLProviderTest method testGetBaseURLFromHTTPContextHeaderMissingAttributes.
@Test(expectedExceptions = IllegalArgumentException.class)
public void testGetBaseURLFromHTTPContextHeaderMissingAttributes() throws Exception {
// Given
Map<String, List<String>> headers = new HashMap<>();
headers.put("host", Arrays.asList("fred"));
HttpContext httpContext = new HttpContext(json(object(field(BaseURLConstants.ATTR_HEADERS, headers), field(BaseURLConstants.ATTR_PARAMETERS, Collections.emptyMap()))), null);
provider.setContextPath("");
// When
String url = provider.getRootURL(httpContext);
// Then - illegal argument exception;
}
Aggregations