use of javax.security.auth.callback.ConfirmationCallback in project OpenAM by OpenRock.
the class RestAuthConfirmationCallbackHandlerTest method shouldHandleCallback.
@Test
public void shouldHandleCallback() {
//Given
HttpServletRequest request = mock(HttpServletRequest.class);
HttpServletResponse response = mock(HttpServletResponse.class);
JsonValue jsonPostBody = mock(JsonValue.class);
ConfirmationCallback originalConfirmationCallback = mock(ConfirmationCallback.class);
//When
ConfirmationCallback confirmationCallback = restAuthConfirmationCallbackHandler.handle(request, response, jsonPostBody, originalConfirmationCallback);
//Then
assertEquals(originalConfirmationCallback, confirmationCallback);
}
use of javax.security.auth.callback.ConfirmationCallback in project OpenAM by OpenRock.
the class RestAuthConfirmationCallbackHandlerTest method shouldNotUpdateCallbackFromRequest.
@Test
public void shouldNotUpdateCallbackFromRequest() throws RestAuthResponseException, RestAuthException {
//Given
HttpServletRequest request = mock(HttpServletRequest.class);
HttpServletResponse response = mock(HttpServletResponse.class);
ConfirmationCallback confirmationCallback = mock(ConfirmationCallback.class);
//When
boolean updated = restAuthConfirmationCallbackHandler.updateCallbackFromRequest(request, response, confirmationCallback);
//Then
assertFalse(updated);
}
use of javax.security.auth.callback.ConfirmationCallback in project OpenAM by OpenRock.
the class RestAuthConfirmationCallbackHandlerTest method shouldConvertFromJsonWithStringChoice.
@Test
public void shouldConvertFromJsonWithStringChoice() throws RestAuthException {
//Given
ConfirmationCallback confirmationCallback = new ConfirmationCallback("Select confirmation:", ConfirmationCallback.INFORMATION, new String[] { "OK", "NO", "CANCEL" }, 0);
JsonValue jsonConfirmationCallback = JsonValueBuilder.jsonValue().array("input").addLast(JsonValueBuilder.jsonValue().put("value", 2).build()).array("output").add(JsonValueBuilder.jsonValue().put("value", "Select confirmation:").build()).add(JsonValueBuilder.jsonValue().put("value", 0).build()).add(JsonValueBuilder.jsonValue().put("value", new String[] { "OK", "NO", "CANCEL" }).build()).add(JsonValueBuilder.jsonValue().put("value", -1).build()).addLast(JsonValueBuilder.jsonValue().put("value", "0").build()).put("type", "ConfirmationCallback").build();
//When
ConfirmationCallback convertedConfirmationCallback = restAuthConfirmationCallbackHandler.convertFromJson(confirmationCallback, jsonConfirmationCallback);
//Then
assertEquals(confirmationCallback, convertedConfirmationCallback);
assertEquals("Select confirmation:", convertedConfirmationCallback.getPrompt());
assertEquals(ConfirmationCallback.INFORMATION, convertedConfirmationCallback.getMessageType());
assertEquals("OK", convertedConfirmationCallback.getOptions()[0]);
assertEquals("NO", convertedConfirmationCallback.getOptions()[1]);
assertEquals("CANCEL", convertedConfirmationCallback.getOptions()[2]);
assertEquals(-1, convertedConfirmationCallback.getOptionType());
assertEquals(0, convertedConfirmationCallback.getDefaultOption());
assertEquals(2, convertedConfirmationCallback.getSelectedIndex());
}
use of javax.security.auth.callback.ConfirmationCallback in project OpenAM by OpenRock.
the class RestAuthConfirmationCallbackHandlerTest method shouldNotFailToConvertFromJsonWithTypeLowerCase.
@Test
public void shouldNotFailToConvertFromJsonWithTypeLowerCase() throws RestAuthException {
//Given
ConfirmationCallback confirmationCallback = new ConfirmationCallback("Select confirmation:", ConfirmationCallback.INFORMATION, new String[] { "OK", "NO", "CANCEL" }, 0);
JsonValue jsonConfirmationCallback = JsonValueBuilder.jsonValue().array("input").addLast(JsonValueBuilder.jsonValue().put("value", 2).build()).array("output").add(JsonValueBuilder.jsonValue().put("value", "Select confirmation:").build()).add(JsonValueBuilder.jsonValue().put("value", 0).build()).add(JsonValueBuilder.jsonValue().put("value", new String[] { "OK", "NO", "CANCEL" }).build()).add(JsonValueBuilder.jsonValue().put("value", -1).build()).addLast(JsonValueBuilder.jsonValue().put("value", 0).build()).put("type", "confirmationcallback").build();
//When
ConfirmationCallback convertedConfirmationCallback = restAuthConfirmationCallbackHandler.convertFromJson(confirmationCallback, jsonConfirmationCallback);
//Then
assertEquals(confirmationCallback, convertedConfirmationCallback);
assertEquals("Select confirmation:", convertedConfirmationCallback.getPrompt());
assertEquals(ConfirmationCallback.INFORMATION, convertedConfirmationCallback.getMessageType());
assertEquals("OK", convertedConfirmationCallback.getOptions()[0]);
assertEquals("NO", convertedConfirmationCallback.getOptions()[1]);
assertEquals("CANCEL", convertedConfirmationCallback.getOptions()[2]);
assertEquals(-1, convertedConfirmationCallback.getOptionType());
assertEquals(0, convertedConfirmationCallback.getDefaultOption());
assertEquals(2, convertedConfirmationCallback.getSelectedIndex());
}
use of javax.security.auth.callback.ConfirmationCallback in project OpenAM by OpenRock.
the class RestAuthConfirmationCallbackHandlerTest method shouldFailToConvertFromJsonWithInvalidType.
@Test(expectedExceptions = RestAuthException.class)
public void shouldFailToConvertFromJsonWithInvalidType() throws RestAuthException {
//Given
ConfirmationCallback confirmationCallback = new ConfirmationCallback("Select confirmation:", ConfirmationCallback.INFORMATION, new String[] { "OK", "NO", "CANCEL" }, 0);
JsonValue jsonConfirmationCallback = JsonValueBuilder.jsonValue().array("input").addLast(JsonValueBuilder.jsonValue().put("value", 2).build()).array("output").add(JsonValueBuilder.jsonValue().put("value", "Select confirmation:").build()).add(JsonValueBuilder.jsonValue().put("value", 0).build()).add(JsonValueBuilder.jsonValue().put("value", new String[] { "OK", "NO", "CANCEL" }).build()).add(JsonValueBuilder.jsonValue().put("value", -1).build()).addLast(JsonValueBuilder.jsonValue().put("value", 0).build()).put("type", "PasswordCallback").build();
//When
restAuthConfirmationCallbackHandler.convertFromJson(confirmationCallback, jsonConfirmationCallback);
//Then
fail();
}
Aggregations