Search in sources :

Example 1 with KeyValue

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());
}
Also used : BasicNameValuePair(org.apache.http.message.BasicNameValuePair) NameValuePair(org.apache.http.NameValuePair) KeyValue(org.wso2.identity.integration.test.utils.DataExtractUtil.KeyValue) Header(org.apache.http.Header) HashMap(java.util.HashMap) BasicNameValuePair(org.apache.http.message.BasicNameValuePair) ArrayList(java.util.ArrayList) HttpResponse(org.apache.http.HttpResponse) Test(org.testng.annotations.Test)

Example 2 with KeyValue

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());
}
Also used : KeyValue(org.wso2.identity.integration.test.utils.DataExtractUtil.KeyValue) HashMap(java.util.HashMap) HttpResponse(org.apache.http.HttpResponse) Test(org.testng.annotations.Test)

Example 3 with KeyValue

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.");
}
Also used : BasicNameValuePair(org.apache.http.message.BasicNameValuePair) NameValuePair(org.apache.http.NameValuePair) KeyValue(org.wso2.identity.integration.test.utils.DataExtractUtil.KeyValue) HashMap(java.util.HashMap) BasicNameValuePair(org.apache.http.message.BasicNameValuePair) ArrayList(java.util.ArrayList) HttpResponse(org.apache.http.HttpResponse) Test(org.testng.annotations.Test)

Example 4 with KeyValue

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());
}
Also used : BasicNameValuePair(org.apache.http.message.BasicNameValuePair) NameValuePair(org.apache.http.NameValuePair) KeyValue(org.wso2.identity.integration.test.utils.DataExtractUtil.KeyValue) Header(org.apache.http.Header) HashMap(java.util.HashMap) BasicNameValuePair(org.apache.http.message.BasicNameValuePair) ArrayList(java.util.ArrayList) HttpResponse(org.apache.http.HttpResponse) Test(org.testng.annotations.Test) BeforeTest(org.testng.annotations.BeforeTest) AfterTest(org.testng.annotations.AfterTest)

Example 5 with KeyValue

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());
}
Also used : KeyValue(org.wso2.identity.integration.test.utils.DataExtractUtil.KeyValue) HashMap(java.util.HashMap) HttpResponse(org.apache.http.HttpResponse) Test(org.testng.annotations.Test) BeforeTest(org.testng.annotations.BeforeTest) AfterTest(org.testng.annotations.AfterTest)

Aggregations

HashMap (java.util.HashMap)27 BLangRecordLiteral (org.wso2.ballerinalang.compiler.tree.expressions.BLangRecordLiteral)26 HttpResponse (org.apache.http.HttpResponse)25 KeyValue (org.wso2.identity.integration.test.utils.DataExtractUtil.KeyValue)25 Test (org.testng.annotations.Test)24 BLangExpression (org.wso2.ballerinalang.compiler.tree.expressions.BLangExpression)19 HashSet (java.util.HashSet)17 Header (org.apache.http.Header)12 BLangListConstructorExpr (org.wso2.ballerinalang.compiler.tree.expressions.BLangListConstructorExpr)12 ArrayList (java.util.ArrayList)11 BLangAnnotationAttachment (org.wso2.ballerinalang.compiler.tree.BLangAnnotationAttachment)10 NameValuePair (org.apache.http.NameValuePair)9 BasicNameValuePair (org.apache.http.message.BasicNameValuePair)9 KubernetesPluginException (org.ballerinax.kubernetes.exceptions.KubernetesPluginException)7 SecretModel (org.ballerinax.kubernetes.models.SecretModel)5 AfterTest (org.testng.annotations.AfterTest)5 BeforeTest (org.testng.annotations.BeforeTest)5 BLangRecordKeyValue (org.wso2.ballerinalang.compiler.tree.expressions.BLangRecordLiteral.BLangRecordKeyValue)4 IntOrString (io.fabric8.kubernetes.api.model.IntOrString)3 Path (java.nio.file.Path)3