Search in sources :

Example 91 with Context

use of org.forgerock.services.context.Context in project OpenAM by OpenRock.

the class RealmContextFilterTest method filterShouldConsumeRealmFromRequest.

@Test
public void filterShouldConsumeRealmFromRequest() throws Exception {
    //Given
    Context context = mockContext(ENDPOINT_PATH_ELEMENT);
    Request request = createRequest(HOSTNAME, ENDPOINT_PATH_ELEMENT);
    mockDnsAlias(HOSTNAME, "/");
    //When
    filter.filter(context, request, handler);
    //Then
    ArgumentCaptor<Context> contextCaptor = ArgumentCaptor.forClass(Context.class);
    verify(handler).handle(contextCaptor.capture(), eq(request));
    verifyRealmContext(contextCaptor.getValue(), "", "/", null);
    verifyUriRouterContext(contextCaptor.getValue(), "");
}
Also used : RootContext(org.forgerock.services.context.RootContext) UriRouterContext(org.forgerock.http.routing.UriRouterContext) Context(org.forgerock.services.context.Context) AttributesContext(org.forgerock.services.context.AttributesContext) CreateRequest(org.forgerock.json.resource.CreateRequest) ActionRequest(org.forgerock.json.resource.ActionRequest) ReadRequest(org.forgerock.json.resource.ReadRequest) DeleteRequest(org.forgerock.json.resource.DeleteRequest) UpdateRequest(org.forgerock.json.resource.UpdateRequest) PatchRequest(org.forgerock.json.resource.PatchRequest) Request(org.forgerock.http.protocol.Request) QueryRequest(org.forgerock.json.resource.QueryRequest) Test(org.testng.annotations.Test)

Example 92 with Context

use of org.forgerock.services.context.Context in project OpenAM by OpenRock.

the class RealmContextFilterTest method filterShouldConsumeRealmFromRequestWithDnsAliasAndOverrideRealm.

@Test
public void filterShouldConsumeRealmFromRequestWithDnsAliasAndOverrideRealm() throws Exception {
    //Given
    Context context = mockContext(ENDPOINT_PATH_ELEMENT);
    Request request = createRequest(DNS_ALIAS_HOSTNAME, ENDPOINT_PATH_ELEMENT + "?realm=" + OVERRIDE_REALM);
    mockDnsAlias(DNS_ALIAS_HOSTNAME, "/" + DNS_ALIS_SUB_REALM);
    mockRealmAlias(OVERRIDE_REALM, OVERRIDE_REALM);
    //When
    filter.filter(context, request, handler);
    //Then
    ArgumentCaptor<Context> contextCaptor = ArgumentCaptor.forClass(Context.class);
    verify(handler).handle(contextCaptor.capture(), eq(request));
    verifyRealmContext(contextCaptor.getValue(), "/" + DNS_ALIS_SUB_REALM, "", OVERRIDE_REALM);
    verifyUriRouterContext(contextCaptor.getValue(), "");
}
Also used : RootContext(org.forgerock.services.context.RootContext) UriRouterContext(org.forgerock.http.routing.UriRouterContext) Context(org.forgerock.services.context.Context) AttributesContext(org.forgerock.services.context.AttributesContext) CreateRequest(org.forgerock.json.resource.CreateRequest) ActionRequest(org.forgerock.json.resource.ActionRequest) ReadRequest(org.forgerock.json.resource.ReadRequest) DeleteRequest(org.forgerock.json.resource.DeleteRequest) UpdateRequest(org.forgerock.json.resource.UpdateRequest) PatchRequest(org.forgerock.json.resource.PatchRequest) Request(org.forgerock.http.protocol.Request) QueryRequest(org.forgerock.json.resource.QueryRequest) Test(org.testng.annotations.Test)

Example 93 with Context

use of org.forgerock.services.context.Context in project OpenAM by OpenRock.

the class RealmContextFilterTest method filterShouldFailToConsumeRealmFromRequestWithInvalidUriRealm.

@Test
public void filterShouldFailToConsumeRealmFromRequestWithInvalidUriRealm() throws Exception {
    //Given
    Context context = mockContext(INVALID_SUB_REALM + "/" + ENDPOINT_PATH_ELEMENT);
    Request request = createRequest(HOSTNAME, INVALID_SUB_REALM + "/" + ENDPOINT_PATH_ELEMENT);
    mockDnsAlias(HOSTNAME, "/");
    mockInvalidRealmAlias(INVALID_SUB_REALM);
    //When
    filter.filter(context, request, handler);
    //Then
    ArgumentCaptor<Context> contextCaptor = ArgumentCaptor.forClass(Context.class);
    verify(handler).handle(contextCaptor.capture(), eq(request));
    verifyRealmContext(contextCaptor.getValue(), "", "/", null);
    verifyUriRouterContextForInvalidRealm(contextCaptor.getValue());
}
Also used : RootContext(org.forgerock.services.context.RootContext) UriRouterContext(org.forgerock.http.routing.UriRouterContext) Context(org.forgerock.services.context.Context) AttributesContext(org.forgerock.services.context.AttributesContext) CreateRequest(org.forgerock.json.resource.CreateRequest) ActionRequest(org.forgerock.json.resource.ActionRequest) ReadRequest(org.forgerock.json.resource.ReadRequest) DeleteRequest(org.forgerock.json.resource.DeleteRequest) UpdateRequest(org.forgerock.json.resource.UpdateRequest) PatchRequest(org.forgerock.json.resource.PatchRequest) Request(org.forgerock.http.protocol.Request) QueryRequest(org.forgerock.json.resource.QueryRequest) Test(org.testng.annotations.Test)

Example 94 with Context

use of org.forgerock.services.context.Context in project OpenAM by OpenRock.

the class AuditFilterTest method shouldAuditSuccessForResults.

@Test
public void shouldAuditSuccessForResults() throws Exception {
    ResourceResponse response = mock(ResourceResponse.class);
    Promise<ResourceResponse, ResourceException> myPromise = Promises.newResultPromise(response);
    given(filterChain.handleUpdate(any(Context.class), any(UpdateRequest.class))).willReturn(myPromise);
    given(auditorFactory.create(context, updateRequest)).willReturn(auditor);
    AuditFilter auditFilter = new AuditFilter(debug, auditorFactory);
    auditFilter.filterUpdate(context, updateRequest, filterChain);
    verify(auditor).auditAccessSuccess(null);
}
Also used : Context(org.forgerock.services.context.Context) ResourceResponse(org.forgerock.json.resource.ResourceResponse) UpdateRequest(org.forgerock.json.resource.UpdateRequest) ResourceException(org.forgerock.json.resource.ResourceException) Test(org.testng.annotations.Test)

Example 95 with Context

use of org.forgerock.services.context.Context in project OpenAM by OpenRock.

the class RequesterTest method emptyLocationBreaksDelete.

//
// test delete()
//
@Test(expectedExceptions = IllegalArgumentException.class)
public void emptyLocationBreaksDelete() throws ResourceException {
    // given
    String location = "";
    String resourceId = "resourceId";
    Context fakeContext = mock(Context.class);
    // when
    requester.delete(location, resourceId, fakeContext);
// then -- matched by expectedExceptions
}
Also used : RealmContext(org.forgerock.openam.rest.RealmContext) Context(org.forgerock.services.context.Context) SSOTokenContext(org.forgerock.openam.rest.resource.SSOTokenContext) Test(org.testng.annotations.Test) BeforeTest(org.testng.annotations.BeforeTest)

Aggregations

Context (org.forgerock.services.context.Context)250 Test (org.testng.annotations.Test)231 RealmContext (org.forgerock.openam.rest.RealmContext)150 ResourceException (org.forgerock.json.resource.ResourceException)132 ClientContext (org.forgerock.services.context.ClientContext)120 SSOTokenContext (org.forgerock.openam.rest.resource.SSOTokenContext)101 ResourceResponse (org.forgerock.json.resource.ResourceResponse)82 SubjectContext (org.forgerock.openam.rest.resource.SubjectContext)76 RootContext (org.forgerock.services.context.RootContext)62 JsonValue (org.forgerock.json.JsonValue)56 QueryRequest (org.forgerock.json.resource.QueryRequest)54 ReadRequest (org.forgerock.json.resource.ReadRequest)50 AttributesContext (org.forgerock.services.context.AttributesContext)44 ActionRequest (org.forgerock.json.resource.ActionRequest)43 QueryResponse (org.forgerock.json.resource.QueryResponse)43 Subject (javax.security.auth.Subject)42 Matchers.anyString (org.mockito.Matchers.anyString)38 Request (org.forgerock.http.protocol.Request)37 UpdateRequest (org.forgerock.json.resource.UpdateRequest)36 DeleteRequest (org.forgerock.json.resource.DeleteRequest)35