Exemplo n.º 1
0
 def test_list(self):
     # Setup
     path = os.path.join(self.tmp_dir, 'A')
     fp = open(path, 'w')
     fp.write(CONTENT)
     fp.close()
     # Test
     path_out = os.path.join(self.tmp_dir, 'B')
     packed = link.pack(path, path_out)
     lst = [
         {'elmer':packed},
         packed,
         10,
         'stones'
     ]
     self.assertTrue(link.is_link(lst[0]['elmer']))
     self.assertTrue(link.is_link(lst[1]))
     unpacked = link.unpack_all(lst)
     self.assertEqual(unpacked[0]['elmer'], path_out)
     self.assertEqual(unpacked[1], path_out)
     self.assertEqual(unpacked[2], 10)
     self.assertEqual(unpacked[3], 'stones')
     f = open(path_out)
     s = f.read()
     f.close()
     self.assertEqual(s, CONTENT)
Exemplo n.º 2
0
 def test_pack(self):
     # Setup
     path = os.path.join(self.tmp_dir, 'A')
     fp = open(path, 'w')
     fp.write(CONTENT)
     fp.close()
     # Test
     path_out = os.path.join(self.tmp_dir, 'B')
     packed = link.pack(path, path_out)
     # Verify
     self.assertTrue(isinstance(packed, dict))
     self.assertTrue(link.SIGNATURE in packed)
     self.assertEqual(packed[link.SIGNATURE]['path'], path_out)
     self.assertEqual(packed[link.SIGNATURE]['content'], b64encode(CONTENT))
Exemplo n.º 3
0
 def test_shallow(self):
     # Setup
     path = os.path.join(self.tmp_dir, 'A')
     fp = open(path, 'w')
     fp.write(CONTENT)
     fp.close()
     # Test
     path_out = os.path.join(self.tmp_dir, 'B')
     packed = link.pack(path, path_out)
     d = {'elmer':packed}
     self.assertTrue(link.is_link(d['elmer']))
     unpacked = link.unpack_all(d)
     self.assertEqual(unpacked['elmer'], path_out)
     f = open(path_out)
     s = f.read()
     f.close()
     self.assertEqual(s, CONTENT)
Exemplo n.º 4
0
 def _ssl_conf(self, ssl_dict):
     """
     Build the SSL configuration.
     The certificate paths are replaced with packed links.
     :param ssl_dict: The SSL part of the configuration.
     :type ssl_dict: dict
     :return: A built SSL configuration.
     :rtype: dict
     :see: Link
     """
     if not ssl_dict:
         return {}
     conf = {}
     for key in ("client_cert",):
         value = ssl_dict.get(key)
         path = value["local"]
         path_out = value["child"]
         conf[key] = link.pack(path, path_out)
     return conf