Пример #1
0
    def test_destination_region_always_changed(self):
        # If the user provides a destination region, we will still
        # override the DesinationRegion with the region_name from
        # the endpoint object.
        actual_region = 'us-west-1'

        credentials = Credentials('key', 'secret')
        request_signer = RequestSigner(
            'ec2', actual_region, 'ec2', 'v4', credentials, None)
        request_dict = {}
        params = {
            'SourceRegion': 'us-west-2',
            'DestinationRegion': 'us-east-1'}
        request_dict['body'] = params
        request_dict['url'] = 'https://ec2.us-west-1.amazonaws.com'
        request_dict['method'] = 'POST'
        request_dict['headers'] = {}

        # The user provides us-east-1, but we will override this to
        # endpoint.region_name, of 'us-west-1' in this case.
        handlers.copy_snapshot_encrypted(request_dict, request_signer)

        self.assertIn('https://ec2.us-west-2.amazonaws.com?',
                      params['PresignedUrl'])

        # Always use the DestinationRegion from the endpoint, regardless of
        # whatever value the user provides.
        self.assertEqual(params['DestinationRegion'], actual_region)
Пример #2
0
    def test_destination_region_always_changed(self):
        # If the user provides a destination region, we will still
        # override the DesinationRegion with the region_name from
        # the endpoint object.
        actual_region = 'us-west-1'

        credentials = Credentials('key', 'secret')
        request_signer = RequestSigner('ec2', actual_region, 'ec2', 'v4',
                                       credentials, None)
        request_dict = {}
        params = {
            'SourceRegion': 'us-west-2',
            'DestinationRegion': 'us-east-1'
        }
        request_dict['body'] = params
        request_dict['url'] = 'https://ec2.us-west-1.amazonaws.com'
        request_dict['method'] = 'POST'
        request_dict['headers'] = {}

        # The user provides us-east-1, but we will override this to
        # endpoint.region_name, of 'us-west-1' in this case.
        handlers.copy_snapshot_encrypted(request_dict, request_signer)

        self.assertIn('https://ec2.us-west-2.amazonaws.com?',
                      params['PresignedUrl'])

        # Always use the DestinationRegion from the endpoint, regardless of
        # whatever value the user provides.
        self.assertEqual(params['DestinationRegion'], actual_region)
Пример #3
0
    def test_destination_region_always_changed(self):
        # If the user provides a destination region, we will still
        # override the DesinationRegion with the region_name from
        # the endpoint object.
        actual_region = 'us-west-1'
        v4query_auth = mock.Mock()

        def add_auth(request):
            request.url += '?PRESIGNED_STUFF'

        v4query_auth.add_auth = add_auth

        request_signer = mock.Mock()
        request_signer._region_name = actual_region
        request_signer.get_auth.return_value = v4query_auth

        endpoint = mock.Mock()
        request = AWSRequest()
        request.method = 'POST'
        request.url = 'https://ec2.us-east-1.amazonaws.com'
        request = request.prepare()
        endpoint.create_request.return_value = request

        # The user provides us-east-1, but we will override this to
        # endpoint.region_name, of 'us-west-1' in this case.
        params = {'SourceRegion': 'us-west-2', 'DestinationRegion': 'us-east-1'}
        handlers.copy_snapshot_encrypted({'body': params},
                                         request_signer,
                                         endpoint)
        # Always use the DestinationRegion from the endpoint, regardless of
        # whatever value the user provides.
        self.assertEqual(params['DestinationRegion'], actual_region)
Пример #4
0
    def test_copy_snapshot_encrypted(self):
        v4query_auth = mock.Mock()

        def add_auth(request):
            request.url += '?PRESIGNED_STUFF'

        v4query_auth.add_auth = add_auth

        request_signer = mock.Mock()
        request_signer._region_name = 'us-east-1'
        request_signer.get_auth.return_value = v4query_auth

        params = {'SourceRegion': 'us-west-2'}
        endpoint = mock.Mock()
        request = AWSRequest()
        request.method = 'POST'
        request.url = 'https://ec2.us-east-1.amazonaws.com'
        request = request.prepare()
        endpoint.create_request.return_value = request

        handlers.copy_snapshot_encrypted({'body': params},
                                         request_signer,
                                         endpoint)
        self.assertEqual(params['PresignedUrl'],
                         'https://ec2.us-west-2.amazonaws.com?PRESIGNED_STUFF')
        # We should also populate the DestinationRegion with the
        # region_name of the endpoint object.
        self.assertEqual(params['DestinationRegion'], 'us-east-1')
Пример #5
0
    def test_copy_snapshot_encrypted(self):
        operation = mock.Mock()
        source_endpoint = mock.Mock()
        signed_request = mock.Mock()
        signed_request.url = 'SIGNED_REQUEST'
        source_endpoint.auth.credentials = mock.sentinel.credentials
        source_endpoint.create_request.return_value = signed_request
        operation.service.get_endpoint.return_value = source_endpoint

        params = {'SourceRegion': 'us-west-2'}
        copy_snapshot_encrypted(operation, params)
        self.assertEqual(params['PresignedUrl'], 'SIGNED_REQUEST')
        # We created an endpoint in the source region.
        operation.service.get_endpoint.assert_called_with('us-west-2')
Пример #6
0
    def test_copy_snapshot_encrypted(self):
        operation = mock.Mock()
        source_endpoint = mock.Mock()
        signed_request = mock.Mock()
        signed_request.url = 'SIGNED_REQUEST'
        source_endpoint.auth.credentials = mock.sentinel.credentials
        source_endpoint.create_request.return_value = signed_request
        operation.service.get_endpoint.return_value = source_endpoint

        params = {'SourceRegion': 'us-west-2'}
        copy_snapshot_encrypted(operation, params)
        self.assertEqual(params['PresignedUrl'], 'SIGNED_REQUEST')
        # We created an endpoint in the source region.
        operation.service.get_endpoint.assert_called_with('us-west-2')
Пример #7
0
    def test_copy_snapshot_encrypted(self):
        credentials = Credentials("key", "secret")
        request_signer = RequestSigner("ec2", "us-east-1", "ec2", "v4", credentials, mock.Mock())
        request_dict = {}
        params = {"SourceRegion": "us-west-2"}
        request_dict["body"] = params
        request_dict["url"] = "https://ec2.us-east-1.amazonaws.com"
        request_dict["method"] = "POST"
        request_dict["headers"] = {}

        handlers.copy_snapshot_encrypted(request_dict, request_signer)

        self.assertIn("https://ec2.us-west-2.amazonaws.com?", params["PresignedUrl"])
        self.assertIn("X-Amz-Signature", params["PresignedUrl"])
        # We should also populate the DestinationRegion with the
        # region_name of the endpoint object.
        self.assertEqual(params["DestinationRegion"], "us-east-1")
Пример #8
0
    def test_copy_snapshot_encrypted(self):
        operation = mock.Mock()
        source_endpoint = mock.Mock()
        signed_request = mock.Mock()
        signed_request.original.prepare().url = 'SIGNED_REQUEST'
        source_endpoint.create_request.return_value = signed_request
        operation.service.get_endpoint.return_value = source_endpoint
        request_signer = mock.Mock()
        request_signer._region_name = 'us-east-1'

        params = {'SourceRegion': 'us-west-2'}
        handlers.copy_snapshot_encrypted(operation, {'body': params},
                                         request_signer)
        self.assertEqual(params['PresignedUrl'], 'SIGNED_REQUEST')
        # We created an endpoint in the source region.
        operation.service.get_endpoint.assert_called_with('us-west-2')
        # We should also populate the DestinationRegion with the
        # region_name of the endpoint object.
        self.assertEqual(params['DestinationRegion'], 'us-east-1')
Пример #9
0
    def test_copy_snapshot_encrypted(self):
        credentials = Credentials('key', 'secret')
        request_signer = RequestSigner('ec2', 'us-east-1', 'ec2', 'v4',
                                       credentials, None)
        request_dict = {}
        params = {'SourceRegion': 'us-west-2'}
        request_dict['body'] = params
        request_dict['url'] = 'https://ec2.us-east-1.amazonaws.com'
        request_dict['method'] = 'POST'
        request_dict['headers'] = {}

        handlers.copy_snapshot_encrypted(request_dict, request_signer)

        self.assertIn('https://ec2.us-west-2.amazonaws.com?',
                      params['PresignedUrl'])
        self.assertIn('X-Amz-Signature', params['PresignedUrl'])
        # We should also populate the DestinationRegion with the
        # region_name of the endpoint object.
        self.assertEqual(params['DestinationRegion'], 'us-east-1')
Пример #10
0
    def test_copy_snapshot_encrypted(self):
        operation = mock.Mock()
        source_endpoint = mock.Mock()
        signed_request = mock.Mock()
        signed_request.url = 'SIGNED_REQUEST'
        source_endpoint.auth.credentials = mock.sentinel.credentials
        source_endpoint.create_request.return_value = signed_request
        operation.service.get_endpoint.return_value = source_endpoint
        endpoint = mock.Mock()
        endpoint.region_name = 'us-east-1'

        params = {'SourceRegion': 'us-west-2'}
        handlers.copy_snapshot_encrypted(operation, {'body': params}, endpoint)
        self.assertEqual(params['PresignedUrl'], 'SIGNED_REQUEST')
        # We created an endpoint in the source region.
        operation.service.get_endpoint.assert_called_with('us-west-2')
        # We should also populate the DestinationRegion with the
        # region_name of the endpoint object.
        self.assertEqual(params['DestinationRegion'], 'us-east-1')
Пример #11
0
    def test_copy_snapshot_encrypted(self):
        credentials = Credentials('key', 'secret')
        request_signer = RequestSigner(
            'ec2', 'us-east-1', 'ec2', 'v4', credentials, None)
        request_dict = {}
        params = {'SourceRegion': 'us-west-2'}
        request_dict['body'] = params
        request_dict['url'] = 'https://ec2.us-east-1.amazonaws.com'
        request_dict['method'] = 'POST'
        request_dict['headers'] = {}

        handlers.copy_snapshot_encrypted(request_dict, request_signer)

        self.assertIn('https://ec2.us-west-2.amazonaws.com?',
                      params['PresignedUrl'])
        self.assertIn('X-Amz-Signature',
                      params['PresignedUrl'])
        # We should also populate the DestinationRegion with the
        # region_name of the endpoint object.
        self.assertEqual(params['DestinationRegion'], 'us-east-1')
Пример #12
0
    def test_destination_region_left_untouched(self):
        # If the user provides a destination region, we will still
        # override the DesinationRegion with the region_name from
        # the endpoint object.
        operation = mock.Mock()
        source_endpoint = mock.Mock()
        signed_request = mock.Mock()
        signed_request.url = 'SIGNED_REQUEST'
        source_endpoint.auth.credentials = mock.sentinel.credentials
        source_endpoint.create_request.return_value = signed_request
        operation.service.get_endpoint.return_value = source_endpoint
        endpoint = mock.Mock()
        endpoint.region_name = 'us-west-1'

        # The user provides us-east-1, but we will override this to
        # endpoint.region_name, of 'us-west-1' in this case.
        params = {'SourceRegion': 'us-west-2', 'DestinationRegion': 'us-east-1'}
        handlers.copy_snapshot_encrypted(operation, {'body': params}, endpoint)
        # Always use the DestinationRegion from the endpoint, regardless of
        # whatever value the user provides.
        self.assertEqual(params['DestinationRegion'], 'us-west-1')
Пример #13
0
    def test_destination_region_left_untouched(self):
        # If the user provides a destination region, we will still
        # override the DesinationRegion with the region_name from
        # the endpoint object.
        operation = mock.Mock()
        source_endpoint = mock.Mock()
        signed_request = mock.Mock()
        signed_request.url = 'SIGNED_REQUEST'
        source_endpoint.auth.credentials = mock.sentinel.credentials
        source_endpoint.create_request.return_value = signed_request
        operation.service.get_endpoint.return_value = source_endpoint
        request_signer = mock.Mock()
        request_signer._region_name = 'us-west-1'

        # The user provides us-east-1, but we will override this to
        # endpoint.region_name, of 'us-west-1' in this case.
        params = {'SourceRegion': 'us-west-2', 'DestinationRegion': 'us-east-1'}
        handlers.copy_snapshot_encrypted(operation, {'body': params},
                                         request_signer)
        # Always use the DestinationRegion from the endpoint, regardless of
        # whatever value the user provides.
        self.assertEqual(params['DestinationRegion'], 'us-west-1')
Пример #14
0
    def test_destination_region_always_changed(self):
        # If the user provides a destination region, we will still
        # override the DesinationRegion with the region_name from
        # the endpoint object.
        actual_region = "us-west-1"

        credentials = Credentials("key", "secret")
        request_signer = RequestSigner("ec2", actual_region, "ec2", "v4", credentials, mock.Mock())
        request_dict = {}
        params = {"SourceRegion": "us-west-2", "DestinationRegion": "us-east-1"}
        request_dict["body"] = params
        request_dict["url"] = "https://ec2.us-west-1.amazonaws.com"
        request_dict["method"] = "POST"
        request_dict["headers"] = {}

        # The user provides us-east-1, but we will override this to
        # endpoint.region_name, of 'us-west-1' in this case.
        handlers.copy_snapshot_encrypted(request_dict, request_signer)

        self.assertIn("https://ec2.us-west-2.amazonaws.com?", params["PresignedUrl"])

        # Always use the DestinationRegion from the endpoint, regardless of
        # whatever value the user provides.
        self.assertEqual(params["DestinationRegion"], actual_region)
Пример #15
0
 def test_presigned_url_already_present(self):
     params = {"body": {"PresignedUrl": "https://foo"}}
     handlers.copy_snapshot_encrypted(params, None)
     self.assertEqual(params["body"]["PresignedUrl"], "https://foo")
Пример #16
0
 def test_presigned_url_already_present(self):
     params = {'body': {'PresignedUrl': 'https://foo'}}
     handlers.copy_snapshot_encrypted(params, None)
     self.assertEqual(params['body']['PresignedUrl'], 'https://foo')
Пример #17
0
 def test_presigned_url_already_present(self):
     params = {'body': {'PresignedUrl': 'https://foo'}}
     handlers.copy_snapshot_encrypted(params, None)
     self.assertEqual(params['body']['PresignedUrl'], 'https://foo')