use of org.forgerock.openam.rest.resource.SSOTokenContext in project OpenAM by OpenRock.
the class SpecialOrAdminOrAgentAuthzModuleTest method shouldErrorInvalidContext.
@Test
public void shouldErrorInvalidContext() throws Exception {
//given
SSOTokenContext mockSSOTokenContext = mock(SSOTokenContext.class);
SSOToken mockSSOToken = mock(SSOToken.class);
Principal principal = mock(Principal.class);
given(mockSSOToken.getPrincipal()).willReturn(principal);
given(mockSSOTokenContext.getCallerSSOToken()).willReturn(mockSSOToken);
given(mockSSOToken.getProperty(Constants.UNIVERSAL_IDENTIFIER)).willThrow(new SSOException(""));
//when
Promise<AuthorizationResult, ResourceException> result = testModule.authorize(mockSSOTokenContext);
//then
assertFalse(result.get().isAuthorized());
}
use of org.forgerock.openam.rest.resource.SSOTokenContext in project OpenAM by OpenRock.
the class RequesterTest method theSetUp.
@BeforeTest
private void theSetUp() {
// you need this
SSOTokenContext mockSSOTokenContext = mock(SSOTokenContext.class);
RealmContext realmContext = new RealmContext(mockSSOTokenContext);
realmContext.setSubRealm("REALM", "REALM");
mockServerContext = mock(Context.class);
}
use of org.forgerock.openam.rest.resource.SSOTokenContext in project OpenAM by OpenRock.
the class AuditTestUtils method mockAuditContext.
public static Context mockAuditContext() throws Exception {
final Context httpContext = new HttpContext(jsonFromFile("/org/forgerock/openam/rest/fluent/httpContext.json"), AbstractAuditFilterTest.class.getClassLoader());
final Subject callerSubject = new Subject();
final Context securityContext = new SecurityContext(httpContext, null, null);
final Context subjectContext = new SSOTokenContext(mock(Debug.class), null, securityContext) {
@Override
public Subject getCallerSubject() {
return callerSubject;
}
@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;
}
};
final Context clientContext = ClientContext.newInternalClientContext(subjectContext);
return new RequestAuditContext(new AuditInfoContext(clientContext, AuditConstants.Component.AUDIT));
}
use of org.forgerock.openam.rest.resource.SSOTokenContext in project OpenAM by OpenRock.
the class ApplicationTypesResourceTest method shouldReadInstanceCorrectly.
@Test
public void shouldReadInstanceCorrectly() throws IllegalAccessException, InstantiationException, ExecutionException, InterruptedException {
//given
SSOTokenContext mockSubjectContext = mock(SSOTokenContext.class);
RealmContext realmContext = new RealmContext(mockSubjectContext);
Context mockServerContext = ClientContext.newInternalClientContext(realmContext);
Subject subject = new Subject();
given(mockSubjectContext.getCallerSubject()).willReturn(subject);
ReadRequest request = mock(ReadRequest.class);
ApplicationType mockApplicationType = new ApplicationType("test", null, null, null, null);
given(mockApplicationTypeManager.getApplicationType(subject, "test")).willReturn(mockApplicationType);
//when
Promise<ResourceResponse, ResourceException> result = testResource.readInstance(mockServerContext, "test", request);
//then
assertTrue(result.get().getId().equals("test"));
}
use of org.forgerock.openam.rest.resource.SSOTokenContext in project OpenAM by OpenRock.
the class SubjectTypesResourceTest method testSuccessfulJsonificationAndQuery.
@Test
public void testSuccessfulJsonificationAndQuery() throws Exception {
//given
SSOTokenContext mockSubjectContext = mock(SSOTokenContext.class);
RealmContext realmContext = new RealmContext(mockSubjectContext);
Context mockServerContext = ClientContext.newInternalClientContext(realmContext);
Subject mockSubject = new Subject();
given(mockSubjectContext.getCallerSubject()).willReturn(mockSubject);
QueryRequest mockRequest = mock(QueryRequest.class);
JsonSchema mockSchema = mock(JsonSchema.class);
QueryResourceHandler mockHandler = mock(QueryResourceHandler.class);
given(mockRequest.getPageSize()).willReturn(2);
given(mockHandler.handleResource(any(ResourceResponse.class))).willReturn(true);
given(mockMapper.generateJsonSchema((Class<?>) any(Class.class))).willReturn(mockSchema);
//when
Promise<QueryResponse, ResourceException> promise = testResource.queryCollection(mockServerContext, mockRequest, mockHandler);
//then
assertThat(promise).succeeded();
verify(mockHandler, times(2)).handleResource(any(ResourceResponse.class));
}
Aggregations