Exemplo n.º 1
0
 def test_bytes_encrypt_and_decrypt(self):
     """Test encryption/decryption of numbers"""
     key = os.urandom(32)
     tree = OrderedDict()
     tree['data'] = os.urandom(4096)
     tree['sops'] = dict()
     crypttree = sops.walk_and_encrypt(OrderedDict(tree), key, isRoot=True)
     assert tree['sops']['mac'].startswith("ENC[AES256_GCM,data:")
     cleartree = sops.walk_and_decrypt(OrderedDict(crypttree), key, isRoot=True)
     assert cleartree == tree
Exemplo n.º 2
0
 def test_walk_and_encrypt_and_decrypt(self):
     """Test a roundtrip on the tree encryption/decryption code"""
     m = mock.mock_open(read_data=sops.DEFAULT_JSON)
     key = os.urandom(32)
     tree = OrderedDict()
     with mock.patch.object(builtins, 'open', m):
         tree = sops.load_file_into_tree('path', 'json')
     tree['sops'] = dict()
     crypttree = sops.walk_and_encrypt(OrderedDict(tree), key, isRoot=True)
     cleartree = sops.walk_and_decrypt(OrderedDict(crypttree), key, isRoot=True)
     assert cleartree == tree
Exemplo n.º 3
0
 def test_numbers_encrypt_and_decrypt(self):
     """Test encryption/decryption of numbers"""
     m = mock.mock_open(read_data='{"a":1234,"b":[567,890.123],"c":5.4999517527e+10}')
     key = os.urandom(32)
     tree = OrderedDict()
     with mock.patch.object(builtins, 'open', m):
         tree = sops.load_file_into_tree('path', 'json')
     tree['sops'] = dict()
     crypttree = sops.walk_and_encrypt(OrderedDict(tree), key, isRoot=True)
     assert tree['sops']['mac'].startswith("ENC[AES256_GCM,data:")
     cleartree = sops.walk_and_decrypt(OrderedDict(crypttree), key, isRoot=True)
     assert cleartree == tree
Exemplo n.º 4
0
 def test_bytes_encrypt_and_decrypt(self):
     """Test encryption/decryption of numbers"""
     key = os.urandom(32)
     tree = OrderedDict()
     tree['data'] = os.urandom(4096)
     tree['sops'] = dict()
     crypttree = sops.walk_and_encrypt(OrderedDict(tree), key, isRoot=True)
     assert tree['sops']['mac'].startswith("ENC[AES256_GCM,data:")
     cleartree = sops.walk_and_decrypt(OrderedDict(crypttree),
                                       key,
                                       isRoot=True)
     assert cleartree == tree
Exemplo n.º 5
0
 def test_walk_and_encrypt_and_decrypt(self):
     """Test a roundtrip on the tree encryption/decryption code"""
     m = mock.mock_open(read_data=sops.DEFAULT_JSON)
     key = os.urandom(32)
     tree = OrderedDict()
     with mock.patch.object(builtins, 'open', m):
         tree = sops.load_file_into_tree('path', 'json')
     tree['sops'] = dict()
     crypttree = sops.walk_and_encrypt(OrderedDict(tree), key, isRoot=True)
     cleartree = sops.walk_and_decrypt(OrderedDict(crypttree),
                                       key,
                                       isRoot=True)
     assert cleartree == tree
Exemplo n.º 6
0
 def test_numbers_encrypt_and_decrypt(self):
     """Test encryption/decryption of numbers"""
     m = mock.mock_open(
         read_data='{"a":1234,"b":[567,890.123],"c":5.4999517527e+10}')
     key = os.urandom(32)
     tree = OrderedDict()
     with mock.patch.object(builtins, 'open', m):
         tree = sops.load_file_into_tree('path', 'json')
     tree['sops'] = dict()
     crypttree = sops.walk_and_encrypt(OrderedDict(tree), key, isRoot=True)
     assert tree['sops']['mac'].startswith("ENC[AES256_GCM,data:")
     cleartree = sops.walk_and_decrypt(OrderedDict(crypttree),
                                       key,
                                       isRoot=True)
     assert cleartree == tree
Exemplo n.º 7
0
 def test_walk_and_encrypt_and_decrypt_unencrypted(self):
     """Test a roundtrip on the tree encryption/decryption code with unencrypted leaves"""
     m = mock.mock_open(read_data="""{
         "str_unencrypted": "STRING",
         "list_unencrypted": ["A", "B"],
         "dict_unencrypted": {
             "key": "value"
         },
         "foo": "bar"
     }""")
     key = os.urandom(32)
     tree = OrderedDict()
     with mock.patch.object(builtins, 'open', m):
         tree = sops.load_file_into_tree('path', 'json')
     tree['sops'] = dict()
     crypttree = sops.walk_and_encrypt(OrderedDict(tree), key, isRoot=True)
     assert tree['sops']['mac'].startswith("ENC[AES256_GCM,data:")
     cleartree = sops.walk_and_decrypt(OrderedDict(crypttree), key, isRoot=True)
     assert cleartree == tree
Exemplo n.º 8
0
 def test_walk_and_encrypt_and_decrypt_unencrypted(self):
     """Test a roundtrip on the tree encryption/decryption code with unencrypted leaves"""
     m = mock.mock_open(read_data="""{
         "str_unencrypted": "STRING",
         "list_unencrypted": ["A", "B"],
         "dict_unencrypted": {
             "key": "value"
         },
         "foo": "bar"
     }""")
     key = os.urandom(32)
     tree = OrderedDict()
     with mock.patch.object(builtins, 'open', m):
         tree = sops.load_file_into_tree('path', 'json')
     tree['sops'] = dict()
     crypttree = sops.walk_and_encrypt(OrderedDict(tree), key, isRoot=True)
     assert tree['sops']['mac'].startswith("ENC[AES256_GCM,data:")
     cleartree = sops.walk_and_decrypt(OrderedDict(crypttree),
                                       key,
                                       isRoot=True)
     assert cleartree == tree