use of com.sun.jersey.api.representation.Form in project OpenAM by OpenRock.
the class RestTest method getDecisionsTest.
@Test
public void getDecisionsTest() throws Exception {
Form params = new Form();
params.add("subject", hashedUserTokenId);
params.add("resources", RESOURCE_NAME + "/index.html");
params.add("action", "GET");
params.add("env", ATTR_NAME + "=" + ATTR_VAL);
params.add("realm", REALM);
String json = decisionsClient.queryParams(params).header(RestServiceManager.SUBJECT_HEADER_NAME, userTokenIdHeader).cookie(cookie).accept("application/json").get(String.class);
JSONObject jo = new JSONObject(json);
if (jo.optInt("statusCode") != 200) {
throw new Exception("RESTTest.getDecisionsTest() failed, status code not 200");
}
JSONObject jbody = jo.optJSONObject("body");
if (jbody == null) {
throw new Exception("RESTTest.getDecisionsTest() failed, body element is null");
}
JSONArray results = jbody.optJSONArray("results");
if (results == null) {
throw new Exception("RESTTest.getDecisionsTest() failed, results array is null");
}
if (results.length() < 1) {
throw new Exception("RESTTest.getDecisionsTest() failed, results array is empty");
}
JSONEntitlement ent = new JSONEntitlement(results.getJSONObject(0));
boolean result = ent.getActionValue("GET");
if (!result) {
throw new Exception("RESTTest.getDecisionsTest() failed");
}
}
use of com.sun.jersey.api.representation.Form in project OpenAM by OpenRock.
the class RestTest method negativeTest.
@Test
public void negativeTest() throws Exception {
Form params = new Form();
params.add("subject", hashedUserTokenId);
params.add("resource", RESOURCE_NAME + "/index.html");
params.add("action", "GET");
params.add("realm", REALM);
String decision = decisionClient.queryParams(params).header(RestServiceManager.SUBJECT_HEADER_NAME, userTokenIdHeader).cookie(cookie).accept("text/plain").get(String.class);
if ((decision != null) && decision.equals("allow")) {
throw new Exception("RESTTest.negativeTest (/decision) failed");
}
String json = entitlementClient.queryParams(params).header(RestServiceManager.SUBJECT_HEADER_NAME, userTokenIdHeader).cookie(cookie).accept("application/json").get(String.class);
JSONObject jo = new JSONObject(json);
if (jo.optInt("statusCode") != 200) {
throw new Exception("RESTTest.negativeTest() failed, status code not 200");
}
JSONObject jbody = jo.optJSONObject("body");
if (jbody == null) {
throw new Exception("RESTTest.negativeTest() failed, body element is null");
}
JSONEntitlement ent = new JSONEntitlement(jbody);
boolean result = false;
Object resultObj = ent.getActionValue("GET");
if (resultObj != null) {
result = ent.getActionValue("GET");
}
if (result) {
throw new Exception("RESTTest.getnegativeTest() failed");
}
Map<String, Set<String>> advices = ent.getAdvices();
Set<String> setNumericCondAdvice = advices.get(NumericAttributeCondition.class.getName());
if ((setNumericCondAdvice == null) || setNumericCondAdvice.isEmpty()) {
throw new Exception("RESTTest.negativeTest: no advice");
}
String advice = setNumericCondAdvice.iterator().next();
if (!advice.equals(ATTR_NAME + "=" + ATTR_VAL)) {
throw new Exception("RESTTest.negativeTest: incorrect advice");
}
}
use of com.sun.jersey.api.representation.Form in project OpenAM by OpenRock.
the class RestTest method getDecisionTest.
@Test
public void getDecisionTest() throws Exception {
Form params = new Form();
params.add("subject", hashedUserTokenId);
params.add("resource", RESOURCE_NAME + "/index.html");
params.add("action", "GET");
params.add("env", ATTR_NAME + "=" + ATTR_VAL);
params.add("realm", REALM);
String decision = decisionClient.queryParams(params).header(RestServiceManager.SUBJECT_HEADER_NAME, userTokenIdHeader).cookie(cookie).accept("text/plain").get(String.class);
if ((decision == null) || !decision.equals("allow")) {
throw new Exception("RESTTest.getDecisionTest() failed");
}
}
use of com.sun.jersey.api.representation.Form in project OpenAM by OpenRock.
the class RestTest method missingActionTest.
@Test
public void missingActionTest() throws Exception {
Form params = new Form();
params.add("subject", hashedUserTokenId);
params.add("resource", RESOURCE_NAME + "/index.html");
params.add("env", ATTR_NAME + "=" + ATTR_VAL);
params.add("realm", REALM);
try {
decisionClient.queryParams(params).header(RestServiceManager.SUBJECT_HEADER_NAME, userTokenIdHeader).cookie(cookie).accept("text/plain").get(String.class);
throw new Exception("RESTTest.missingActionTest: no exception thrown.");
} catch (UniformInterfaceException e) {
int errorCode = e.getResponse().getStatus();
if (errorCode != 400) {
throw new Exception("RESTTest.missingActionTest: incorrect error code");
}
}
}
use of com.sun.jersey.api.representation.Form in project OpenAM by OpenRock.
the class ListenerRestTest method noURLInPost.
private void noURLInPost() throws Exception {
Form form = new Form();
form.add("resources", RESOURCE_NAME + "/*");
form.add("subject", hashedTokenId);
try {
listenerClient.header(RestServiceManager.SUBJECT_HEADER_NAME, tokenIdHeader).cookie(cookie).post(String.class, form);
} catch (UniformInterfaceException e) {
validateUniformInterfaceException(e, 426, "noURLInPost");
}
}
Aggregations