예제 #1
0
 def test_to_python_dict_invalid_ciphertext_base64(self):
     field = SecureField(name='asdf')
     with pytest.raises(ValueError):
         field.to_python(StubConfig(), {
             'method': 'xor',
             'ciphertext': 'hello'
         })
예제 #2
0
    def test_to_python_dict_invalid_ciphertext_int(self):
        cfg = StubConfig()
        field = SecureField(name='asdf')
        cfg._keyfile.decrypt.side_effect = EncryptionError()
        cfg._keyfile.__exit__.return_value = False

        with pytest.raises(ValueError):
            field.to_python(cfg, {'method': 'test', 'ciphertext': 10})
예제 #3
0
    def test_to_python_dict_invalid_ciphertext(self):
        cfg = StubConfig()
        field = SecureField(name='asdf')
        cfg._keyfile.decrypt.side_effect = EncryptionError()
        cfg._keyfile.__exit__.return_value = False

        with pytest.raises(ValueError):
            field.to_python(cfg, {'method': 'test', 'ciphertext': 'aGVsbG8='})

        cfg._keyfile.decrypt.assert_called_once_with(
            SecureValue('test', b'hello'))
예제 #4
0
    def test_to_python_dict_valid(self):
        cfg = StubConfig()
        field = SecureField(name='asdf')

        assert field.to_python(cfg, {
            'method': 'test',
            'ciphertext': 'aGVsbG8='
        }) == 'plaintext'
예제 #5
0
 def test_to_python_str(self):
     field = SecureField()
     assert field.to_python(StubConfig(), 'hello') == 'hello'
예제 #6
0
 def test_to_python_empty_string(self):
     field = SecureField()
     assert field.to_python(None, "") == ""
예제 #7
0
 def test_to_python_none(self):
     field = SecureField()
     assert field.to_python(StubConfig(), None) is None
예제 #8
0
 def test_to_python_invalid_type(self):
     field = SecureField()
     with pytest.raises(ValueError):
         field.to_python(StubConfig(), 100)
예제 #9
0
 def test_to_python_dict_invalid_method(self):
     field = SecureField(name='asdf')
     with pytest.raises(ValueError):
         field.to_python(None, {'method': None, 'ciphertext': b'hello'})
예제 #10
0
 def test_to_python_str(self):
     field = SecureField()
     assert field.to_python(None, 'hello') == 'hello'
예제 #11
0
 def test_to_python_none(self):
     field = SecureField()
     assert field.to_python(None, None) is None