use of javax.ws.rs.core.MultivaluedHashMap in project oxAuth by GluuFederation.
the class TokenEndpointAuthMethodRestrictionEmbeddedTest method tokenEndpointAuthMethodClientSecretBasicFail1.
/**
* Fail 1: Call to Token Endpoint with Auth Method
* <code>client_secret_post</code> should fail.
*/
@Parameters({ "tokenPath", "userId", "userSecret" })
@Test(dependsOnMethods = "tokenEndpointAuthMethodClientSecretBasicStep2")
public void tokenEndpointAuthMethodClientSecretBasicFail1(final String tokenPath, final String userId, final String userSecret) throws Exception {
Builder request = ResteasyClientBuilder.newClient().target(url.toString() + tokenPath).request();
TokenRequest tokenRequest = new TokenRequest(GrantType.RESOURCE_OWNER_PASSWORD_CREDENTIALS);
tokenRequest.setAuthenticationMethod(AuthenticationMethod.CLIENT_SECRET_POST);
tokenRequest.setUsername(userId);
tokenRequest.setPassword(userSecret);
tokenRequest.setScope("email read_stream manage_pages");
tokenRequest.setAuthUsername(clientId2);
tokenRequest.setAuthPassword(clientSecret2);
request.header("Content-Type", MediaType.APPLICATION_FORM_URLENCODED);
Response response = request.post(Entity.form(new MultivaluedHashMap<String, String>(tokenRequest.getParameters())));
String entity = response.readEntity(String.class);
showResponse("tokenEndpointAuthMethodClientSecretBasicFail1", response, entity);
assertEquals(response.getStatus(), 401, "Unexpected response code.");
assertNotNull(entity, "Unexpected result: " + entity);
try {
JSONObject jsonObj = new JSONObject(entity);
assertTrue(jsonObj.has("error"), "The error type is null");
assertTrue(jsonObj.has("error_description"), "The error description is null");
} catch (JSONException e) {
e.printStackTrace();
fail(e.getMessage() + "\nResponse was: " + entity);
}
}
use of javax.ws.rs.core.MultivaluedHashMap in project oxAuth by GluuFederation.
the class TokenEndpointAuthMethodRestrictionEmbeddedTest method tokenEndpointAuthMethodClientSecretPostFail1.
/**
* Fail 1: Call to Token Endpoint with Auth Method
* <code>client_secret_basic</code> should fail.
*/
@Parameters({ "tokenPath", "userId", "userSecret" })
@Test(dependsOnMethods = "tokenEndpointAuthMethodClientSecretPostStep2")
public void tokenEndpointAuthMethodClientSecretPostFail1(final String tokenPath, final String userId, final String userSecret) throws Exception {
Builder request = ResteasyClientBuilder.newClient().target(url.toString() + tokenPath).request();
TokenRequest tokenRequest = new TokenRequest(GrantType.RESOURCE_OWNER_PASSWORD_CREDENTIALS);
tokenRequest.setAuthenticationMethod(AuthenticationMethod.CLIENT_SECRET_BASIC);
tokenRequest.setUsername(userId);
tokenRequest.setPassword(userSecret);
tokenRequest.setScope("email read_stream manage_pages");
tokenRequest.setAuthUsername(clientId3);
tokenRequest.setAuthPassword(clientSecret3);
request.header("Authorization", "Basic " + tokenRequest.getEncodedCredentials());
request.header("Content-Type", MediaType.APPLICATION_FORM_URLENCODED);
Response response = request.post(Entity.form(new MultivaluedHashMap<String, String>(tokenRequest.getParameters())));
String entity = response.readEntity(String.class);
showResponse("tokenEndpointAuthMethodClientSecretPostFail1", response, entity);
assertEquals(response.getStatus(), 401, "Unexpected response code.");
assertNotNull(entity, "Unexpected result: " + entity);
try {
JSONObject jsonObj = new JSONObject(entity);
assertTrue(jsonObj.has("error"), "The error type is null");
assertTrue(jsonObj.has("error_description"), "The error description is null");
} catch (JSONException e) {
e.printStackTrace();
fail(e.getMessage() + "\nResponse was: " + entity);
}
}
use of javax.ws.rs.core.MultivaluedHashMap in project ddf by codice.
the class TestOpenSearchSource method givenSource.
private OpenSearchSource givenSource(Answer<BinaryContent> answer) throws IOException, ResourceNotFoundException, ResourceNotSupportedException {
WebClient client = mock(WebClient.class);
ResourceReader mockReader = mock(ResourceReader.class);
Response clientResponse = mock(Response.class);
when(clientResponse.getEntity()).thenReturn(getBinaryData());
when(clientResponse.getHeaderString(eq(OpenSearchSource.HEADER_ACCEPT_RANGES))).thenReturn(OpenSearchSource.BYTES);
when(client.get()).thenReturn(clientResponse);
SecureCxfClientFactory factory = getMockFactory(client);
when(mockReader.retrieveResource(any(URI.class), any(Map.class))).thenReturn(new ResourceResponseImpl(new ResourceImpl(getBinaryData(), "")));
MultivaluedMap<String, Object> headers = new MultivaluedHashMap<String, Object>();
headers.put(HttpHeaders.CONTENT_TYPE, Arrays.<Object>asList("application/octet-stream"));
when(clientResponse.getHeaders()).thenReturn(headers);
OverriddenOpenSearchSource source = new OverriddenOpenSearchSource(FILTER_ADAPTER, encryptionService);
source.setEndpointUrl("http://localhost:8181/services/catalog/query");
source.setParameters(DEFAULT_PARAMETERS);
source.init();
source.setLocalQueryOnly(true);
source.setInputTransformer(getMockInputTransformer());
source.factory = factory;
source.setResourceReader(mockReader);
return source;
}
use of javax.ws.rs.core.MultivaluedHashMap in project ddf by codice.
the class ResourceReaderTest method testNameInContentDisposition.
@Test
public void testNameInContentDisposition() throws Exception {
URI uri = new URI(HTTP_SCHEME_PLUS_SEP + HOST + TEST_PATH + BAD_FILE_NAME);
Response mockResponse = mock(Response.class);
when(mockWebClient.get()).thenReturn(mockResponse);
MultivaluedMap<String, Object> map = new MultivaluedHashMap<>();
map.put(HttpHeaders.CONTENT_DISPOSITION, Arrays.<Object>asList("inline; filename=\"" + JPEG_FILE_NAME_1 + "\""));
when(mockResponse.getHeaders()).thenReturn(map);
when(mockResponse.getStatus()).thenReturn(Response.Status.OK.getStatusCode());
when(mockResponse.getEntity()).thenReturn(getBinaryData());
ResourceResponse response = verifyFileFromURLResourceReader(uri, JPEG_FILE_NAME_1, JPEG_MIME_TYPE, null);
// verify that we got the entire resource
assertEquals(5, response.getResource().getByteArray().length);
}
use of javax.ws.rs.core.MultivaluedHashMap in project ddf by codice.
the class ResourceReaderTest method testUnquotedNameInContentDisposition.
@Test
public void testUnquotedNameInContentDisposition() throws Exception {
URI uri = new URI(HTTP_SCHEME_PLUS_SEP + HOST + TEST_PATH + BAD_FILE_NAME);
Response mockResponse = mock(Response.class);
when(mockWebClient.get()).thenReturn(mockResponse);
MultivaluedMap<String, Object> map = new MultivaluedHashMap<>();
map.put(HttpHeaders.CONTENT_DISPOSITION, Arrays.<Object>asList("inline; filename=" + JPEG_FILE_NAME_1));
when(mockResponse.getHeaders()).thenReturn(map);
when(mockResponse.getStatus()).thenReturn(Response.Status.OK.getStatusCode());
when(mockResponse.getEntity()).thenReturn(getBinaryData());
verifyFileFromURLResourceReader(uri, JPEG_FILE_NAME_1, JPEG_MIME_TYPE, null);
}
Aggregations