Search in sources :

Example 46 with CreateRequest

use of org.forgerock.json.resource.CreateRequest in project OpenAM by OpenRock.

the class ResourceTypesResourceTest method createShouldIgnoreNewResourceId.

/*
     * This expected failure when the newResourceId in the create request is not the resource type name.
     *
     * Now the new resource id is not used.
     *
     */
@Test
public void createShouldIgnoreNewResourceId() throws EntitlementException {
    //given
    CreateRequest mockCreateRequest = mock(CreateRequest.class);
    JsonValue content = mock(JsonValue.class);
    given(mockCreateRequest.getContent()).willReturn(content);
    // the resource ID in the request is differs form anything in the JSON resource type
    given(mockCreateRequest.getNewResourceId()).willReturn("ignored-new-resource-id");
    given(content.toString()).willReturn(jsonResourceType);
    doCallRealMethod().when(resourceTypeService).saveResourceType(any(Subject.class), anyString(), any(ResourceType.class));
    //when
    Promise<ResourceResponse, ResourceException> promise = resourceTypesResource.createInstance(mockServerContext, mockCreateRequest);
    //then
    assertThat(promise).succeeded();
}
Also used : ResourceResponse(org.forgerock.json.resource.ResourceResponse) CreateRequest(org.forgerock.json.resource.CreateRequest) JsonValue(org.forgerock.json.JsonValue) ResourceType(org.forgerock.openam.entitlement.ResourceType) ResourceException(org.forgerock.json.resource.ResourceException) Subject(javax.security.auth.Subject) Test(org.testng.annotations.Test)

Example 47 with CreateRequest

use of org.forgerock.json.resource.CreateRequest in project OpenAM by OpenRock.

the class RealmContextFilterTest method filterShouldConsumeRealmFromRequestWithInvalidDnsAlias.

@Test
public void filterShouldConsumeRealmFromRequestWithInvalidDnsAlias() throws Exception {
    //Given
    Context context = mockContext(ENDPOINT_PATH_ELEMENT);
    Request request = createRequest(INVALID_DNS_ALIAS_HOSTNAME, ENDPOINT_PATH_ELEMENT);
    mockInvalidDnsAlias(INVALID_DNS_ALIAS_HOSTNAME);
    //When
    Response response = filter.filter(context, request, handler).getOrThrowUninterruptibly();
    //Then
    assertThat(response.getStatus()).isSameAs(Status.BAD_REQUEST);
}
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) Response(org.forgerock.http.protocol.Response) ActionResponse(org.forgerock.json.resource.ActionResponse) QueryResponse(org.forgerock.json.resource.QueryResponse) ResourceResponse(org.forgerock.json.resource.ResourceResponse) 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 48 with CreateRequest

use of org.forgerock.json.resource.CreateRequest in project OpenAM by OpenRock.

the class RealmContextFilterTest method filterShouldConsumeRealmFromRequestWithInvalidOverrideRealm.

@Test
public void filterShouldConsumeRealmFromRequestWithInvalidOverrideRealm() throws Exception {
    //Given
    Context context = mockContext(ENDPOINT_PATH_ELEMENT);
    Request request = createRequest(HOSTNAME, ENDPOINT_PATH_ELEMENT + "?realm=" + INVALID_OVERRIDE_REALM);
    mockDnsAlias(HOSTNAME, "/");
    mockInvalidRealmAlias(INVALID_OVERRIDE_REALM);
    //When
    Response response = filter.filter(context, request, handler).getOrThrowUninterruptibly();
    //Then
    verifyInvalidRealmResponse(response, INVALID_OVERRIDE_REALM);
}
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) Response(org.forgerock.http.protocol.Response) ActionResponse(org.forgerock.json.resource.ActionResponse) QueryResponse(org.forgerock.json.resource.QueryResponse) ResourceResponse(org.forgerock.json.resource.ResourceResponse) 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 49 with CreateRequest

use of org.forgerock.json.resource.CreateRequest in project OpenAM by OpenRock.

the class RealmContextFilterTest method filterShouldFailToConsumeRealmFromRequestOnExceptionWhenResolvingServerName.

@Test
public void filterShouldFailToConsumeRealmFromRequestOnExceptionWhenResolvingServerName() throws Exception {
    //Given
    Context context = mockContext(ENDPOINT_PATH_ELEMENT);
    Request request = createRequest(HOSTNAME, ENDPOINT_PATH_ELEMENT);
    IdRepoException exception = mock(IdRepoException.class);
    given(exception.getMessage()).willReturn("EXCEPTION_MESSAGE");
    doThrow(exception).when(coreWrapper).getOrganization(any(SSOToken.class), eq(HOSTNAME));
    //When
    Response response = filter.filter(context, request, handler).getOrThrowUninterruptibly();
    //Then
    assertThat(response.getStatus()).isSameAs(Status.BAD_REQUEST);
    assertThat(response.getEntity().getJson()).isEqualTo(new BadRequestException("FQDN \"HOSTNAME\" is not valid.").toJsonValue().getObject());
}
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) Response(org.forgerock.http.protocol.Response) ActionResponse(org.forgerock.json.resource.ActionResponse) QueryResponse(org.forgerock.json.resource.QueryResponse) ResourceResponse(org.forgerock.json.resource.ResourceResponse) SSOToken(com.iplanet.sso.SSOToken) 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) IdRepoException(com.sun.identity.idm.IdRepoException) BadRequestException(org.forgerock.json.resource.BadRequestException) Test(org.testng.annotations.Test)

Example 50 with CreateRequest

use of org.forgerock.json.resource.CreateRequest in project OpenAM by OpenRock.

the class RealmContextFilterTest method filterShouldConsumeRealmFromRequestWithDnsAliasAndUriRealmAndOverrideRealm.

@Test
public void filterShouldConsumeRealmFromRequestWithDnsAliasAndUriRealmAndOverrideRealm() throws Exception {
    //Given
    Context context = mockContext(SUB_REALM + "/" + ENDPOINT_PATH_ELEMENT);
    Request request = createRequest(DNS_ALIAS_HOSTNAME, SUB_REALM + "/" + ENDPOINT_PATH_ELEMENT + "?realm=" + OVERRIDE_REALM);
    mockDnsAlias(DNS_ALIAS_HOSTNAME, "/" + DNS_ALIS_SUB_REALM);
    mockRealmAlias("/" + DNS_ALIS_SUB_REALM + "/" + SUB_REALM, "/" + DNS_ALIS_SUB_REALM + "/" + 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, "/" + SUB_REALM, OVERRIDE_REALM);
    verifyUriRouterContext(contextCaptor.getValue(), SUB_REALM);
}
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)

Aggregations

CreateRequest (org.forgerock.json.resource.CreateRequest)70 Test (org.testng.annotations.Test)62 ResourceResponse (org.forgerock.json.resource.ResourceResponse)42 JsonValue (org.forgerock.json.JsonValue)39 ResourceException (org.forgerock.json.resource.ResourceException)38 Context (org.forgerock.services.context.Context)27 DeleteRequest (org.forgerock.json.resource.DeleteRequest)19 ReadRequest (org.forgerock.json.resource.ReadRequest)18 RootContext (org.forgerock.services.context.RootContext)18 UriRouterContext (org.forgerock.http.routing.UriRouterContext)17 ActionRequest (org.forgerock.json.resource.ActionRequest)17 PatchRequest (org.forgerock.json.resource.PatchRequest)17 QueryRequest (org.forgerock.json.resource.QueryRequest)17 UpdateRequest (org.forgerock.json.resource.UpdateRequest)17 Request (org.forgerock.http.protocol.Request)16 AttributesContext (org.forgerock.services.context.AttributesContext)16 Subject (javax.security.auth.Subject)13 RealmContext (org.forgerock.openam.rest.RealmContext)11 EntitlementException (com.sun.identity.entitlement.EntitlementException)9 ResourceType (org.forgerock.openam.entitlement.ResourceType)9