use of org.forgerock.json.resource.CreateRequest in project OpenAM by OpenRock.
the class PrivilegeAuthzModuleTest method crestCreateIsAllowed.
@Test
public void crestCreateIsAllowed() throws SSOException, DelegationException {
// Given...
final Set<String> actions = new HashSet<>(Arrays.asList("MODIFY"));
final DelegationPermission permission = new DelegationPermission("/abc", "rest", "1.0", "policies", "modify", actions, EXTENSIONS, DUMB_FUNC);
given(factory.newInstance("/abc", "rest", "1.0", "policies", "modify", actions, EXTENSIONS)).willReturn(permission);
given(subjectContext.getCallerSSOToken()).willReturn(token);
given(evaluator.isAllowed(eq(token), eq(permission), eq(ENVIRONMENT))).willReturn(true);
JsonValue jsonValue = json(object(field("someKey", "someValue")));
Promise<ResourceResponse, ResourceException> promise = Promises.newResultPromise(Responses.newResourceResponse("1", "1.0", jsonValue));
given(provider.createInstance(isA(Context.class), isA(CreateRequest.class))).willReturn(promise);
// When...
final FilterChain chain = AuthorizationFilters.createAuthorizationFilter(provider, module);
final Router router = new Router();
router.addRoute(RoutingMode.STARTS_WITH, Router.uriTemplate("/policies"), chain);
final RealmContext context = new RealmContext(subjectContext);
context.setSubRealm("abc", "abc");
final CreateRequest request = Requests.newCreateRequest("/policies", JsonValue.json(new Object()));
Promise<ResourceResponse, ResourceException> result = router.handleCreate(context, request);
// Then...
assertThat(result).succeeded().withContent().stringAt("someKey").isEqualTo("someValue");
}
use of org.forgerock.json.resource.CreateRequest in project OpenAM by OpenRock.
the class AuditFilterTest method shouldReturnNullForCreateSuccess.
@Test
public void shouldReturnNullForCreateSuccess() {
CreateRequest createRequest = mock(CreateRequest.class);
ResourceResponse resourceResponse = mock(ResourceResponse.class);
JsonValue filterResponse = auditFilter.getCreateSuccessDetail(createRequest, resourceResponse);
assertThat(filterResponse).isEqualTo(null);
}
use of org.forgerock.json.resource.CreateRequest in project OpenAM by OpenRock.
the class ScriptResourceTest method shouldFailIfNoNameIsSuppliedOnCreate.
@Test(expectedExceptions = BadRequestException.class)
public void shouldFailIfNoNameIsSuppliedOnCreate() throws ResourceException {
// given
JsonValue requestJson = json(object(field(SCRIPT_TEXT, encodeScript), field(SCRIPT_LANGUAGE, "JAVASCRIPT"), field(SCRIPT_CONTEXT, "POLICY_CONDITION")));
CreateRequest createRequest = mock(CreateRequest.class);
when(createRequest.getContent()).thenReturn(requestJson);
// when
scriptResource.createInstance(context, createRequest).getOrThrowUninterruptibly();
// then - exception
}
use of org.forgerock.json.resource.CreateRequest in project OpenAM by OpenRock.
the class ScriptResourceTest method shouldCreateScriptConfigurationWithoutError.
@Test
public void shouldCreateScriptConfigurationWithoutError() throws Exception {
// given
JsonValue requestJson = json(object(field(SCRIPT_NAME, "MyJavaScript"), field(SCRIPT_DESCRIPTION, "A test script configuration"), field(SCRIPT_TEXT, encodeScript), field(SCRIPT_LANGUAGE, "JAVASCRIPT"), field(SCRIPT_CONTEXT, "POLICY_CONDITION")));
CreateRequest createRequest = mock(CreateRequest.class);
when(createRequest.getContent()).thenReturn(requestJson);
// when
ResourceResponse response = scriptResource.createInstance(context, createRequest).getOrThrowUninterruptibly();
// then
JsonValue responseJson = response.getContent();
assertEquals(responseJson.get(SCRIPT_NAME).asString(), "MyJavaScript");
assertEquals(responseJson.get(SCRIPT_DESCRIPTION).asString(), "A test script configuration");
assertEquals(responseJson.get(SCRIPT_TEXT).asString(), encodeScript);
assertEquals(getLanguageFromString(responseJson.get(SCRIPT_LANGUAGE).asString()), JAVASCRIPT);
assertEquals(getContextFromString(responseJson.get(SCRIPT_CONTEXT).asString()), POLICY_CONDITION);
}
use of org.forgerock.json.resource.CreateRequest in project OpenAM by OpenRock.
the class ScriptResourceTest method shouldFailIfNoContextIsSuppliedOnCreate.
@Test(expectedExceptions = BadRequestException.class)
public void shouldFailIfNoContextIsSuppliedOnCreate() throws ResourceException {
// given
JsonValue requestJson = json(object(field(SCRIPT_NAME, "MyJavaScript"), field(SCRIPT_TEXT, encodeScript), field(SCRIPT_LANGUAGE, "JAVASCRIPT")));
CreateRequest createRequest = mock(CreateRequest.class);
when(createRequest.getContent()).thenReturn(requestJson);
// when
scriptResource.createInstance(context, createRequest).getOrThrowUninterruptibly();
// then - exception
}
Aggregations