def test_decrypt_all_encrypted_plain(self, kms_stub): obj = EnvironmentDict( TREEHUGGER_APP='foo', TREEHUGGER_STAGE='bar', baz=Encrypted(base64.b64encode(b'qux').decode('utf-8')), corge=ToEncrypt('grault'), ) kms_stub.add_response( 'decrypt', expected_params={ 'CiphertextBlob': b'qux', 'EncryptionContext': { 'treehugger_app': 'foo', 'treehugger_key': 'baz', 'treehugger_stage': 'bar', } }, service_response={ 'KeyId': 'treehugger', 'Plaintext': b'quux', } ) assert obj.decrypt_all_encrypted(plain=True) == EnvironmentDict( TREEHUGGER_APP='foo', TREEHUGGER_STAGE='bar', baz='quux', corge='grault', )
def test_encrypt_all_to_encrypt(kms_stub): obj = EnvironmentDict( TREEHUGGER_APP='foo', TREEHUGGER_STAGE='bar', baz=ToEncrypt('qux'), ) kms_stub.add_response('encrypt', expected_params={ 'KeyId': 'alias/treehugger', 'Plaintext': b'qux', 'EncryptionContext': { 'treehugger_app': 'foo', 'treehugger_key': 'baz', 'treehugger_stage': 'bar', } }, service_response={ 'KeyId': 'treehugger', 'CiphertextBlob': b'quux', }) assert obj.encrypt_all_to_encrypt() == EnvironmentDict( TREEHUGGER_APP='foo', TREEHUGGER_STAGE='bar', baz=Encrypted(base64.b64encode(b'quux').decode('utf-8')), )
def test_remove_all_encrypted_plain(self): obj = EnvironmentDict( TREEHUGGER_APP='foo', TREEHUGGER_STAGE='bar', baz=ToEncrypt('qux'), corge=Encrypted('grault'), ) assert obj.remove_all_encrypted(plain=True) == EnvironmentDict( TREEHUGGER_APP='foo', TREEHUGGER_STAGE='bar', baz='qux', )
def test_to_yaml_dict_success_encrypted(self): obj = EnvironmentDict(foo=Encrypted('bar')) assert obj.to_yaml_dict() == {'foo': {'encrypted': 'bar'}}
def test_from_yaml_dict_success_encrypted(self): obj = EnvironmentDict.from_yaml_dict({'foo': {'encrypted': 'foo'}}) assert obj == EnvironmentDict({'foo': Encrypted('foo')})