Ejemplo n.º 1
0
    def test_roa_assume_role_request_with_sts_token(self):
        self._create_default_ram_user()
        # self._attach_default_policy()
        self._create_access_key()
        self._create_default_ram_role()

        roa_client = ClientConfig(region_id=self.region_id)
        ram_role_arn_credential = RamRoleCredentialsProvider(
            roa_client,
            AccessKeyCredentials(self.ram_user_access_key_id,
                                 self.ram_user_access_key_secret),
            self.ram_role_arn, "alice_test")
        client = AlibabaCloudClient(roa_client, ram_role_arn_credential)
        client.product_code = "ROS"
        client.api_version = "2015-09-01"
        client.location_service_code = 'ros'
        client.location_endpoint_type = "openAPI"
        api_request = APIRequest('DescribeResourceTypes', 'GET', 'https',
                                 'ROA')
        api_request.uri_pattern = '/resource_types'
        api_request.path_params = None
        response = client._handle_request(api_request)

        response_credentials = response.http_request.credentials
        self.assertTrue(response_credentials.access_key_id.startswith("STS."))

        response = response.http_response.content
        ret = self.get_dict_response(response)
        self.assertTrue(ret.get("ResourceTypes"))
 def test_call_roa_request_with_config_default(self):
     client = AlibabaCloudClient(
         self.client_config,
         credentials_provider=self.init_credentials_provider())
     client.product_code = "ROS"
     client.api_version = "2015-09-01"
     client.location_service_code = 'ros'
     client.location_endpoint_type = "openAPI"
     api_request = APIRequest('DescribeResourceTypes', 'GET', 'https',
                              'ROA')
     api_request.uri_pattern = '/resource_types'
     api_request.path_params = None
     response = client._handle_request(api_request)
     response = response.http_response.content
     ret = self.get_dict_response(response)
     self.assertTrue(ret.get("ResourceTypes"))
    def test_call_roa_request_with_client(self):
        client = AlibabaCloudClient(self.client_config,
                                    self.init_credentials_provider())
        client.product_code = "ROS"
        client.api_version = "2015-09-01"
        client.location_service_code = 'ros'
        client.location_endpoint_type = "openAPI"
        api_request = APIRequest('DescribeResourceTypes', 'GET', 'https',
                                 'ROA')
        api_request.uri_pattern = '/stacks/[StackName]/[StackId]/resources'
        api_request.path_params = None
        api_request._params = {"StackId": "StackId", "StackName": "StackName"}

        try:
            response = client._handle_request(api_request)
            assert False
        except ServerException as e:
            self.assertEqual("InvalidUrl", e.error_code)
            self.assertTrue(
                e.error_message.startswith("Request url is invalid"))
    def test_call_roa_request_with_env_ak(self):
        os.environ["ALIBABA_CLOUD_ACCESS_KEY_ID"] = self.access_key_id
        os.environ["ALIBABA_CLOUD_ACCESS_KEY_SECRET"] = self.access_key_secret

        client_config = ClientConfig(region_id=self.region_id)
        client = AlibabaCloudClient(
            client_config,
            credentials_provider=self.init_credentials_provider())
        client.product_code = "ROS"
        client.api_version = "2015-09-01"
        client.location_service_code = 'ros'
        client.location_endpoint_type = "openAPI"
        api_request = APIRequest('DescribeResourceTypes', 'GET', 'https',
                                 'ROA')
        api_request.uri_pattern = '/resource_types'
        api_request.path_params = None
        response = client._handle_request(api_request)
        response = response.http_response.content
        ret = self.get_dict_response(response)
        self.assertTrue(ret.get("ResourceTypes"))
        os.environ.pop("ALIBABA_CLOUD_ACCESS_KEY_ID")
        os.environ.pop("ALIBABA_CLOUD_ACCESS_KEY_SECRET")