def test_unpack_response_secret_string_empty_string(self):
     secret_id = "test-secret"
     secret_string = ""
     self.connection.create_secret(Name=secret_id, SecretString=secret_string)
     secret_response = self.connection.get_secret_value(SecretId=secret_id)
     with assert_raises(simplejson.errors.JSONDecodeError):
         Secrets.unpack_response(secret_response)
    def test_delete_secret(self):
        self.connection.create_secret(Name="test-secret", SecretBinary=b("{}"))
        secrets = Secrets("test-secret", connection=self.connection)
        secrets.delete()
        from botocore.exceptions import ClientError

        with assert_raises(ClientError):
            self.connection.get_secret_value(SecretId="test-secret")
 def test_unpack_response_secret_string(self):
     secret_id = "test-secret"
     secret_dictionary = {"A": "A", "B": "B"}
     secret_string = json.dumps(secret_dictionary)
     self.connection.create_secret(Name=secret_id, SecretString=secret_string)
     secret_response = self.connection.get_secret_value(SecretId=secret_id)
     assert json.loads(secret_string) == Secrets.unpack_response(secret_response)
 def test_unset_secrets(self):
     secrets = Secrets(self.secret_name,
                       connection=self.connection,
                       is_binary=True)
     secrets.set(self.secret_key, self.secret_value)
     secrets.unset(self.secret_key)
     assert dict(secrets).get(self.secret_key) is None
    def test_unpack_response_secret_binary(self):
        import base64
        import simplejson as json

        secret_id = "test-secret"
        expected = {"A": "A", "B": "B"}
        binary_secret_dictionary = {}
        for k, v in expected.items():
            binary_secret_dictionary[k] = base64.b64encode(v.encode("ascii"))
        self.connection.create_secret(
            Name=secret_id, SecretBinary=json.dumps(binary_secret_dictionary))
        secret_response = self.connection.get_secret_value(SecretId=secret_id)
        actual = Secrets.unpack_response(secret_response)
        assert expected == actual
 def test__create_secret_resource(self):
     secrets = Secrets(
         "super-secret", connection=self.connection, create_if_not_present=True
     )
     assert secrets.secrets == dict()
 def test_create_secret(self):
     secrets = Secrets(self.secret_name, connection=self.connection)
     secrets.set(self.secret_key, self.secret_value)
     assert dict(secrets).get(self.secret_key) == self.secret_value