use of org.forgerock.openam.rest.resource.SSOTokenContext in project OpenAM by OpenRock.
the class ResourceTypesResourceTest method setUp.
@BeforeMethod
public void setUp() throws ResourceException {
callerSubject = new Subject();
// to mock the HTTP method, we need the following contexts
Context httpContext = new HttpContext(json(object(field(HttpContext.ATTR_HEADERS, Collections.singletonMap("method", Arrays.asList("PUT"))), field(HttpContext.ATTR_PARAMETERS, Collections.emptyMap()))), null);
Context securityContext = new SecurityContext(httpContext, null, null);
Context subjectContext = new SSOTokenContext(mock(Debug.class), null, securityContext) {
@Override
public Subject getCallerSubject() {
return callerSubject;
}
};
RealmContext realmContext = new RealmContext(subjectContext);
realmContext.setSubRealm("/", "/");
mockServerContext = ClientContext.newInternalClientContext(realmContext);
resourceTypeService = mock(MockResourceTypeService.class);
Debug debug = mock(Debug.class);
resourceTypesResource = new ResourceTypesResource(debug, new EntitlementsExceptionMappingHandler(EntitlementRestGuiceModule.getEntitlementsErrorHandlers()), resourceTypeService);
rawData.put("name", Collections.singleton("myResourceType"));
rawData.put("description", Collections.singleton("myResourceType"));
rawData.put("realm", Collections.singleton("/"));
rawData.put("actions", Collections.singleton("CREATE"));
rawData.put("patterns", Collections.singleton("http://example.com:80/*"));
rawData.put("creationDate", Collections.singleton(String.valueOf(new Date().getTime())));
rawData.put("lastModifiedDate", Collections.singleton(String.valueOf(new Date().getTime())));
}
use of org.forgerock.openam.rest.resource.SSOTokenContext in project OpenAM by OpenRock.
the class SubjectAttributesResourceV1Test method shouldPerformQueryForSubjectAttributes.
@Test
public void shouldPerformQueryForSubjectAttributes() throws Exception {
//given
SSOTokenContext mockSSOTokenContext = mock(SSOTokenContext.class);
RealmContext realmContext = new RealmContext(mockSSOTokenContext);
Context mockServerContext = ClientContext.newInternalClientContext(realmContext);
Subject mockSubject = new Subject();
given(mockSSOTokenContext.getCallerSubject()).willReturn(mockSubject);
QueryRequest mockRequest = mock(QueryRequest.class);
QueryResourceHandler mockHandler = mock(QueryResourceHandler.class);
Set<String> attributes = new HashSet<>();
attributes.add("attr");
attributes.add("attr2");
given(mockSAM.getAvailableSubjectAttributeNames()).willReturn(attributes);
//when
Promise<QueryResponse, ResourceException> promise = subjectAttributesResource.queryCollection(mockServerContext, mockRequest, mockHandler);
//then
promise.getOrThrowUninterruptibly();
ArgumentCaptor<ResourceResponse> captor = ArgumentCaptor.forClass(ResourceResponse.class);
verify(mockHandler, times(2)).handleResource(captor.capture());
}
use of org.forgerock.openam.rest.resource.SSOTokenContext in project OpenAM by OpenRock.
the class SubjectTypesResourceTest method testSuccessfulJsonificationAndLogicalIsCorrect.
@Test
public void testSuccessfulJsonificationAndLogicalIsCorrect() throws JsonMappingException {
//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);
ReadRequest mockRequest = mock(ReadRequest.class);
QueryResourceHandler mockHandler = mock(QueryResourceHandler.class);
JsonSchema mockSchema = mock(JsonSchema.class);
given(mockMapper.generateJsonSchema((Class<?>) any(Class.class))).willReturn(mockSchema);
//when
Promise<ResourceResponse, ResourceException> promise = testResource.readInstance(mockServerContext, TEST_LOGICAL_CONDITION, mockRequest);
//then
assertThat(promise).succeeded().withContent().hasBoolean("logical");
assertThat(promise).succeeded().withContent().booleanAt("logical").isTrue();
}
use of org.forgerock.openam.rest.resource.SSOTokenContext in project OpenAM by OpenRock.
the class SubjectAttributesResourceV1Test method shouldErrorWhenAttributeRetrievalFails.
@Test
public void shouldErrorWhenAttributeRetrievalFails() throws EntitlementException {
//given
SSOTokenContext mockSSOTokenContext = mock(SSOTokenContext.class);
RealmContext realmContext = new RealmContext(mockSSOTokenContext);
Context mockServerContext = ClientContext.newInternalClientContext(realmContext);
Subject mockSubject = new Subject();
given(mockSSOTokenContext.getCallerSubject()).willReturn(mockSubject);
QueryRequest mockRequest = mock(QueryRequest.class);
QueryResourceHandler mockHandler = mock(QueryResourceHandler.class);
given(mockSAM.getAvailableSubjectAttributeNames()).willThrow(new EntitlementException(401));
//when
Promise<QueryResponse, ResourceException> promise = subjectAttributesResource.queryCollection(mockServerContext, mockRequest, mockHandler);
//then
verify(mockDebug, times(1)).error(anyString());
assertThat(promise).failedWithResourceException().withCode(ResourceException.INTERNAL_ERROR);
}
use of org.forgerock.openam.rest.resource.SSOTokenContext in project OpenAM by OpenRock.
the class SubjectAttributesResourceV1Test method shouldReturnNoResultWhenNoAttributes.
@Test
public void shouldReturnNoResultWhenNoAttributes() throws Exception {
//given
SSOTokenContext mockSSOTokenContext = mock(SSOTokenContext.class);
RealmContext realmContext = new RealmContext(mockSSOTokenContext);
Context mockServerContext = ClientContext.newInternalClientContext(realmContext);
Subject mockSubject = new Subject();
given(mockSSOTokenContext.getCallerSubject()).willReturn(mockSubject);
QueryRequest mockRequest = mock(QueryRequest.class);
QueryResourceHandler mockHandler = mock(QueryResourceHandler.class);
Set<String> attributes = new HashSet<>();
given(mockSAM.getAvailableSubjectAttributeNames()).willReturn(attributes);
//when
Promise<QueryResponse, ResourceException> promise = subjectAttributesResource.queryCollection(mockServerContext, mockRequest, mockHandler);
//then
promise.getOrThrowUninterruptibly();
ArgumentCaptor<ResourceResponse> captor = ArgumentCaptor.forClass(ResourceResponse.class);
verify(mockHandler, never()).handleResource(captor.capture());
}
Aggregations