use of org.wso2.identity.integration.test.utils.DataExtractUtil.KeyValue in project product-is by wso2.
the class OAuth2ServiceImplicitGrantTestCase method testSendAuthorozedPost.
@Test(groups = "wso2.is", description = "Send authorize user request", dependsOnMethods = "testRegisterApplication")
public void testSendAuthorozedPost() throws Exception {
List<NameValuePair> urlParameters = new ArrayList<NameValuePair>();
urlParameters.add(new BasicNameValuePair("grantType", OAuth2Constant.OAUTH2_GRANT_TYPE_IMPLICIT));
urlParameters.add(new BasicNameValuePair("consumerKey", consumerKey));
urlParameters.add(new BasicNameValuePair("scope", scopes));
urlParameters.add(new BasicNameValuePair("callbackurl", OAuth2Constant.CALLBACK_URL));
urlParameters.add(new BasicNameValuePair("authorizeEndpoint", OAuth2Constant.APPROVAL_URL));
urlParameters.add(new BasicNameValuePair("authorize", OAuth2Constant.AUTHORIZE_PARAM));
urlParameters.add(new BasicNameValuePair("consumerSecret", consumerSecret));
HttpResponse response = sendPostRequestWithParameters(client, urlParameters, OAuth2Constant.AUTHORIZED_USER_URL);
Assert.assertNotNull(response, "Authorization request failed. Authorized response is null");
Header locationHeader = response.getFirstHeader(OAuth2Constant.HTTP_RESPONSE_HEADER_LOCATION);
Assert.assertNotNull(locationHeader, "Authorized response header is null");
EntityUtils.consume(response.getEntity());
response = sendGetRequest(client, locationHeader.getValue());
Assert.assertNotNull(response, "Authorized user response is null.");
Map<String, Integer> keyPositionMap = new HashMap<String, Integer>(1);
keyPositionMap.put("name=\"sessionDataKey\"", 1);
List<KeyValue> keyValues = DataExtractUtil.extractDataFromResponse(response, keyPositionMap);
Assert.assertNotNull(keyValues, "sessionDataKey key value is null");
sessionDataKey = keyValues.get(0).getValue();
Assert.assertNotNull(sessionDataKey, "Session data key is null.");
EntityUtils.consume(response.getEntity());
}
use of org.wso2.identity.integration.test.utils.DataExtractUtil.KeyValue in project product-is by wso2.
the class OAuth2ServiceImplicitGrantTestCase method testValidateAccessToken.
@Test(groups = "wso2.is", description = "Validate access token", dependsOnMethods = "testSendApprovalPost")
public void testValidateAccessToken() throws Exception {
HttpResponse response = sendValidateAccessTokenPost(client, accessToken);
Assert.assertNotNull(response, "Validate access token response is invalid.");
Map<String, Integer> keyPositionMap = new HashMap<String, Integer>(1);
keyPositionMap.put("name=\"valid\"", 1);
List<KeyValue> keyValues = DataExtractUtil.extractInputValueFromResponse(response, keyPositionMap);
Assert.assertNotNull(keyValues, "Access token Key value is null.");
String valid = keyValues.get(0).getValue();
EntityUtils.consume(response.getEntity());
Assert.assertEquals(valid, "true", "Token Validation failed");
EntityUtils.consume(response.getEntity());
}
use of org.wso2.identity.integration.test.utils.DataExtractUtil.KeyValue in project product-is by wso2.
the class OAuth2ServiceIntrospectionTestCase method testGetAccessToken.
@Test(groups = "wso2.is", description = "Send authorize user request and get access token", dependsOnMethods = "testRegisterApplication")
public void testGetAccessToken() throws Exception {
List<NameValuePair> urlParameters = new ArrayList<NameValuePair>();
urlParameters.add(new BasicNameValuePair("grantType", OAuth2Constant.OAUTH2_GRANT_TYPE_CLIENT_CREDENTIALS));
urlParameters.add(new BasicNameValuePair("consumerKey", consumerKey));
urlParameters.add(new BasicNameValuePair("consumerSecret", consumerSecret));
urlParameters.add(new BasicNameValuePair("accessEndpoint", OAuth2Constant.ACCESS_TOKEN_ENDPOINT));
urlParameters.add(new BasicNameValuePair("authorize", OAuth2Constant.AUTHORIZE_PARAM));
HttpResponse response = sendPostRequestWithParameters(client, urlParameters, OAuth2Constant.AUTHORIZED_USER_URL);
Assert.assertNotNull(response, "Authorization request failed. Authorized response is null");
EntityUtils.consume(response.getEntity());
response = sendPostRequest(client, OAuth2Constant.AUTHORIZED_URL);
Map<String, Integer> keyPositionMap = new HashMap<String, Integer>(1);
keyPositionMap.put("name=\"accessToken\"", 1);
List<KeyValue> keyValues = DataExtractUtil.extractInputValueFromResponse(response, keyPositionMap);
Assert.assertNotNull(keyValues, "Access token Key value is null.");
accessToken = keyValues.get(0).getValue();
EntityUtils.consume(response.getEntity());
Assert.assertNotNull(accessToken, "Access token is null.");
}
use of org.wso2.identity.integration.test.utils.DataExtractUtil.KeyValue in project product-is by wso2.
the class OAuth2ServiceAuthCodeGrantOpenIdRequestObjectTestCase method testSendAuthorozedPost.
@Test(groups = "wso2.is", description = "Send authorize user request", dependsOnMethods = "testRegisterApplication")
public void testSendAuthorozedPost() throws Exception {
List<NameValuePair> urlParameters = new ArrayList<NameValuePair>();
urlParameters.add(new BasicNameValuePair("grantType", OAuth2Constant.OAUTH2_GRANT_TYPE_CODE));
urlParameters.add(new BasicNameValuePair("consumerKey", consumerKey));
urlParameters.add(new BasicNameValuePair("callbackurl", OAuth2Constant.CALLBACK_URL));
urlParameters.add(new BasicNameValuePair("authorizeEndpoint", OAuth2Constant.APPROVAL_URL + "?request=" + REQUEST));
urlParameters.add(new BasicNameValuePair("authorize", OAuth2Constant.AUTHORIZE_PARAM));
urlParameters.add(new BasicNameValuePair("scope", OAuth2Constant.OAUTH2_SCOPE_OPENID + " " + OAuth2Constant.OAUTH2_SCOPE_EMAIL + " " + OAuth2Constant.OAUTH2_SCOPE_PROFILE));
HttpResponse response = sendPostRequestWithParameters(client, urlParameters, OAuth2Constant.AUTHORIZED_USER_URL);
Assert.assertNotNull(response, "Authorization request failed. Authorized response is null");
Header locationHeader = response.getFirstHeader(OAuth2Constant.HTTP_RESPONSE_HEADER_LOCATION);
Assert.assertNotNull(locationHeader, "Authorization request failed. Authorized response header is null");
EntityUtils.consume(response.getEntity());
response = sendGetRequest(client, locationHeader.getValue());
Assert.assertNotNull(response, "Authorization request failed. Authorized user response is null.");
Map<String, Integer> keyPositionMap = new HashMap<String, Integer>(1);
keyPositionMap.put("name=\"sessionDataKey\"", 1);
List<KeyValue> keyValues = DataExtractUtil.extractDataFromResponse(response, keyPositionMap);
Assert.assertNotNull(keyValues, "sessionDataKey key value is null");
sessionDataKey = keyValues.get(0).getValue();
Assert.assertNotNull(sessionDataKey, "Session data key is null.");
EntityUtils.consume(response.getEntity());
}
use of org.wso2.identity.integration.test.utils.DataExtractUtil.KeyValue in project product-is by wso2.
the class OAuth2ServiceAuthCodeGrantOpenIdRequestObjectTestCase method testGetAccessToken.
@Test(groups = "wso2.is", description = "Get access token", dependsOnMethods = "testSendApprovalPost")
public void testGetAccessToken() throws Exception {
HttpResponse response = sendGetAccessTokenPost(client, consumerSecret);
Assert.assertNotNull(response, "Approval response is invalid.");
EntityUtils.consume(response.getEntity());
response = sendPostRequest(client, OAuth2Constant.AUTHORIZED_URL);
Map<String, Integer> keyPositionMap = new HashMap<String, Integer>(1);
keyPositionMap.put("name=\"accessToken\"", 1);
List<KeyValue> keyValues = DataExtractUtil.extractInputValueFromResponse(response, keyPositionMap);
Assert.assertNotNull(keyValues, "Access token Key value is null.");
accessToken = keyValues.get(0).getValue();
Assert.assertNotNull(accessToken, "Access token is null.");
EntityUtils.consume(response.getEntity());
response = sendPostRequest(client, OAuth2Constant.AUTHORIZED_URL);
keyPositionMap = new HashMap<String, Integer>(1);
keyPositionMap.put("id=\"loggedUser\"", 1);
keyValues = DataExtractUtil.extractLabelValueFromResponse(response, keyPositionMap);
Assert.assertNotNull(keyValues, "Access token Key value is null.");
String loggedUser = keyValues.get(0).getValue();
Assert.assertNotNull(loggedUser, "Logged user is null.");
Assert.assertNotEquals(loggedUser, "null", "Logged user is null.");
Assert.assertNotEquals(loggedUser, "", "Logged user is null.");
EntityUtils.consume(response.getEntity());
}
Aggregations