Esempio n. 1
0
 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',
     )
Esempio n. 2
0
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')),
    )
Esempio n. 3
0
 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',
     )
Esempio n. 4
0
 def test_to_yaml_dict_success_encrypted(self):
     obj = EnvironmentDict(foo=Encrypted('bar'))
     assert obj.to_yaml_dict() == {'foo': {'encrypted': 'bar'}}
Esempio n. 5
0
 def test_from_yaml_dict_success_encrypted(self):
     obj = EnvironmentDict.from_yaml_dict({'foo': {'encrypted': 'foo'}})
     assert obj == EnvironmentDict({'foo': Encrypted('foo')})