Пример #1
0
 def setup(self):
     """Setup before each method"""
     self._dispatcher = PagerDutyOutput(REGION, FUNCTION_NAME, CONFIG)
     remove_temp_secrets()
     output_name = self._dispatcher.output_cred_name(self.DESCRIPTOR)
     put_mock_creds(output_name, self.CREDS,
                    self._dispatcher.secrets_bucket, REGION, KMS_ALIAS)
Пример #2
0
 def setup(self):
     """Setup before each method"""
     self._dispatcher = SlackOutput(REGION, ACCOUNT_ID, FUNCTION_NAME, None)
     remove_temp_secrets()
     output_name = self._dispatcher.output_cred_name(self.DESCRIPTOR)
     put_mock_creds(output_name, self.CREDS,
                    self._dispatcher.secrets_bucket, REGION, KMS_ALIAS)
 def setup(self):
     """Setup before each method"""
     self._dispatcher = PagerDutyIncidentOutput(REGION, ACCOUNT_ID, FUNCTION_NAME, CONFIG)
     self._dispatcher._base_url = self.CREDS['api']
     remove_temp_secrets()
     output_name = self._dispatcher.output_cred_name(self.DESCRIPTOR)
     put_mock_creds(output_name, self.CREDS, self._dispatcher.secrets_bucket, REGION, KMS_ALIAS)
Пример #4
0
 def setup(self):
     """Setup before each method"""
     self._mock_s3 = mock_s3()
     self._mock_s3.start()
     self._mock_kms = mock_kms()
     self._mock_kms.start()
     self._dispatcher = PagerDutyOutputV2(REGION, ACCOUNT_ID, FUNCTION_NAME, None)
     remove_temp_secrets()
     output_name = self._dispatcher.output_cred_name(self.DESCRIPTOR)
     put_mock_creds(output_name, self.CREDS, self._dispatcher.secrets_bucket, REGION, KMS_ALIAS)
Пример #5
0
 def setup(self):
     """Setup before each method"""
     self._mock_s3 = mock_s3()
     self._mock_s3.start()
     self._mock_kms = mock_kms()
     self._mock_kms.start()
     self._dispatcher = SlackOutput(None)
     remove_temp_secrets()
     output_name = self._dispatcher.output_cred_name(self.DESCRIPTOR)
     put_mock_creds(output_name, self.CREDS, self._dispatcher.secrets_bucket, REGION, KMS_ALIAS)
Пример #6
0
 def setup(self):
     """Setup before each method"""
     self._mock_s3 = mock_s3()
     self._mock_s3.start()
     self._mock_kms = mock_kms()
     self._mock_kms.start()
     self._dispatcher = PagerDutyIncidentOutput(None)
     self._dispatcher._base_url = self.CREDS['api']
     remove_temp_secrets()
     output_name = self._dispatcher.output_cred_name(self.DESCRIPTOR)
     put_mock_creds(output_name, self.CREDS, self._dispatcher.secrets_bucket, REGION, KMS_ALIAS)
Пример #7
0
    def _setup_dispatch(self):
        """Helper for setting up SlackOutput dispatch"""
        remove_temp_secrets()

        output_name = self.__dispatcher.output_cred_name(self.__descriptor)

        creds = {'url': 'https://api.slack.com/web-hook-key'}

        put_mock_creds(output_name, creds, self.__dispatcher.secrets_bucket,
                       REGION, KMS_ALIAS)

        return get_alert()
Пример #8
0
    def _setup_dispatch(self, url):
        """Helper for setting up PhantomOutput dispatch"""
        remove_temp_secrets()

        output_name = self.__dispatcher.output_cred_name(self.__descriptor)

        creds = {'url': url,
                 'ph_auth_token': 'mocked_auth_token'}

        put_mock_creds(output_name, creds, self.__dispatcher.secrets_bucket, REGION, KMS_ALIAS)

        return get_alert()
Пример #9
0
    def test_load_creds(self):
        """OutputDispatcher - Load Credentials"""
        remove_temp_secrets()
        output_name = self._dispatcher.output_cred_name(self._descriptor)

        creds = {'url': 'http://www.foo.bar/test', 'token': 'token_to_encrypt'}

        put_mock_creds(output_name, creds, self._dispatcher.secrets_bucket,
                       REGION, KMS_ALIAS)

        loaded_creds = self._dispatcher._load_creds(self._descriptor)

        assert_is_not_none(loaded_creds)
        assert_equal(len(loaded_creds), 2)
        assert_equal(loaded_creds['url'], u'http://www.foo.bar/test')
        assert_equal(loaded_creds['token'], u'token_to_encrypt')
Пример #10
0
    def _setup_dispatch(self):
        """Helper for setting up PagerDutyOutput dispatch"""
        remove_temp_secrets()

        # Cache the _get_default_properties and set it to return None
        self.__backup_method = self.__dispatcher._get_default_properties
        self.__dispatcher._get_default_properties = lambda: None

        output_name = self.__dispatcher.output_cred_name(self.__descriptor)

        creds = {'url': 'http://pagerduty.foo.bar/create_event.json',
                 'service_key': 'mocked_service_key'}

        put_mock_creds(output_name, creds, self.__dispatcher.secrets_bucket, REGION, KMS_ALIAS)

        return get_alert()
Пример #11
0
    def test_load_credentials(self):
        """S3Driver - With File Driver - Load Credentials - Pulls into LocalFileStore

        Here we use the S3Driver's caching ability to yank stuff into a local driver."""
        remove_temp_secrets()

        creds = {'my_secret': 'i ate two portions of biscuits and gravy'}
        input_credentials = Credentials(creds,
                                        is_encrypted=False,
                                        region=REGION)
        descriptor = 'test_descriptor'

        # Annoyingly, moto needs us to create the bucket first
        # We put a random unrelated object into the bucket and this will set up the bucket for us
        put_mock_s3_object(self._s3_driver.get_s3_secrets_bucket(), 'aaa',
                           'bbb', REGION)

        # First, check if the Local driver can find the credentials (we don't expect it to)
        assert_false(self._fs_driver.has_credentials(descriptor))

        # Save the credentials using S3 driver
        result = self._s3_driver.save_credentials_into_s3(
            descriptor, input_credentials, KMS_ALIAS)
        assert_true(result)

        # We still don't expect the Local driver to find the credentials
        assert_false(self._fs_driver.has_credentials(descriptor))

        # Use S3Driver to warm up the Local driver
        self._s3_driver.load_credentials(descriptor)

        # Now we should be able to get the credentials from the local fs
        assert_true(self._fs_driver.has_credentials(descriptor))
        credentials = self._fs_driver.load_credentials(descriptor)

        assert_is_not_none(credentials)
        assert_true(credentials.is_encrypted())

        loaded_creds = json.loads(credentials.get_data_kms_decrypted())

        assert_equal(loaded_creds, creds)

        remove_temp_secrets()
Пример #12
0
    def test_load_creds(self):
        """OutputDispatcher - Load Credentials"""
        remove_temp_secrets()
        key = get_formatted_output_credentials_name(
            'test_service',
            self._descriptor
        )

        creds = {'url': 'http://www.foo.bar/test',
                 'token': 'token_to_encrypt'}

        put_mock_creds(key, creds,
                       self._dispatcher._credentials_provider._core_driver._bucket,
                       REGION, KMS_ALIAS)

        loaded_creds = self._dispatcher._load_creds(self._descriptor)

        assert_is_not_none(loaded_creds)
        assert_equal(len(loaded_creds), 2)
        assert_equal(loaded_creds['url'], u'http://www.foo.bar/test')
        assert_equal(loaded_creds['token'], u'token_to_encrypt')