Esempio n. 1
0
 def test_match_first_variable(self):
     tree = {'$anything': [{'$releasever': [{'bar': [{PATH_END: None}]}]}]}
     data = open(DATA, 'rb').read()
     pt = PathTree(data)
     # just swap out the pre-cooked data with out with
     pt.path_tree = tree
     self.assertTrue(pt.match_path('/foo/path/bar'))
     self.assertFalse(pt.match_path('/foo/path/abc'))
Esempio n. 2
0
    def test_generate_path_leaves(self):
        data = open(DATA, 'rb').read()
        nodes, bits = PathTree._unpack_data(data)
        ret = PathTree._generate_path_leaves(GhettoBitStream(bits))

        self.assertEqual(len(ret), 4)
        for node in ret:
            self.assertTrue(isinstance(node, HuffmanNode))
Esempio n. 3
0
 def test_match_variable(self):
     tree = {'foo': [{'$releasever': [{'bar':[{PATH_END: None}]}]}]}
     data = open(DATA).read()
     pt = PathTree(data)
     # just swap out the pre-cooked data with out with
     pt.path_tree = tree
     self.assertTrue(pt.match_path('/foo/path/bar'))
     self.assertFalse(pt.match_path('/foo/path/abc'))
 def test_match_first_variable(self):
     tree = {"$anything": [{"$releasever": [{"bar": [{PATH_END: None}]}]}]}
     data = open(DATA, "rb").read()
     pt = PathTree(data)
     # just swap out the pre-cooked data with out with
     pt.path_tree = tree
     self.assertTrue(pt.match_path("/foo/path/bar"))
     self.assertFalse(pt.match_path("/foo/path/abc"))
Esempio n. 5
0
    def test_generate_path_leaves(self):
        data = open(DATA).read()
        nodes, bits = PathTree._unpack_data(data)
        ret = PathTree._generate_path_leaves(GhettoBitStream(bits))

        self.assertEqual(len(ret), 4)
        for node in ret:
            self.assertTrue(isinstance(node, HuffmanNode))
 def test_build_path_list(self):
     f = os.path.join(os.path.dirname(os.path.abspath(__file__)), "satellite_generated_data.bin")
     data = open(f, 'rb').read()
     pt = PathTree(data)
     paths = []
     pt.build_path_list(paths)
     expected = [
         '/DPS_Satellite/Library/WF-RHEL-7-CV-2018_33-OS/content/dist/rhel/server/7/$releasever/$basearch/os',
         '/DPS_Satellite/Library/WF-RHEL-7-CV-2018_33-OS/content/dist/rhel/server/7/$releasever/$basearch/optional/os',
         '/DPS_Satellite/Library/WF-RHEL-7-CV-2018_33-OS/content/dist/rhel/server/7/$releasever/$basearch/rh-common/os',
         '/DPS_Satellite/Library/WF-RHEL-7-CV-2018_33-OS/content/dist/rhel/server/7/$releasever/$basearch/rhn-tools/os',
         '/DPS_Satellite/Library/WF-RHEL-7-CV-2018_33-OS/content/dist/rhel/server/7/7Server/$basearch/extras/os',
         '/DPS_Satellite/Library/WF-RHEL-7-CV-2018_33-OS/content/dist/rhel/server/7/7Server/$basearch/sat-tools/6.3/os'
     ]
     # Assert the lists contain the same items regardless of order
     six.assertCountEqual(self, expected, paths)
Esempio n. 7
0
 def test_build_path_list(self):
     f = os.path.join(os.path.dirname(os.path.abspath(__file__)),
                      "satellite_generated_data.bin")
     data = open(f, 'rb').read()
     pt = PathTree(data)
     paths = []
     pt.build_path_list(paths)
     expected = [
         '/DPS_Satellite/Library/WF-RHEL-7-CV-2018_33-OS/content/dist/rhel/server/7/$releasever/$basearch/os',
         '/DPS_Satellite/Library/WF-RHEL-7-CV-2018_33-OS/content/dist/rhel/server/7/$releasever/$basearch/optional/os',
         '/DPS_Satellite/Library/WF-RHEL-7-CV-2018_33-OS/content/dist/rhel/server/7/$releasever/$basearch/rh-common/os',
         '/DPS_Satellite/Library/WF-RHEL-7-CV-2018_33-OS/content/dist/rhel/server/7/$releasever/$basearch/rhn-tools/os',
         '/DPS_Satellite/Library/WF-RHEL-7-CV-2018_33-OS/content/dist/rhel/server/7/7Server/$basearch/extras/os',
         '/DPS_Satellite/Library/WF-RHEL-7-CV-2018_33-OS/content/dist/rhel/server/7/7Server/$basearch/sat-tools/6.3/os'
     ]
     # Assert the lists contain the same items regardless of order
     six.assertCountEqual(self, expected, paths)
Esempio n. 8
0
 def test_match_path_listing(self):
     tree = {'foo': [{'path': [{'bar': [{PATH_END: None}]}]}]}
     data = open(DATA, 'rb').read()
     pt = PathTree(data)
     pt.path_tree = tree
     self.assertTrue(pt.match_path('/foo/path/bar/listing'))
     self.assertTrue(pt.match_path('/foo/path/listing'))
     self.assertTrue(pt.match_path('/foo/listing'))
     self.assertFalse(pt.match_path('/foo/path/alfred'))
     self.assertFalse(pt.match_path('/foo/path/listing/for/alfred'))
 def test_match_path_listing(self):
     tree = {"foo": [{"path": [{"bar": [{PATH_END: None}]}]}]}
     data = open(DATA, "rb").read()
     pt = PathTree(data)
     pt.path_tree = tree
     self.assertTrue(pt.match_path("/foo/path/bar/listing"))
     self.assertTrue(pt.match_path("/foo/path/listing"))
     self.assertTrue(pt.match_path("/foo/listing"))
     self.assertFalse(pt.match_path("/foo/path/alfred"))
     self.assertFalse(pt.match_path("/foo/path/listing/for/alfred"))
 def test_match_path(self):
     data = open(DATA, "rb").read()
     pt = PathTree(data)
     self.assertTrue(pt.match_path("/foo/path"))
     self.assertTrue(pt.match_path("/foo/path/"))
     # the '2' should match against "$releasever"
     self.assertTrue(pt.match_path("/foo/path/always/2"))
     self.assertTrue(pt.match_path("/foo/path/bar"))
     self.assertTrue(pt.match_path("/foo/path/bar/a/b/c"))
     self.assertFalse(pt.match_path("/foo"))
     self.assertFalse(pt.match_path("/bar"))
Esempio n. 11
0
 def test_match_path(self):
     data = open(DATA, 'rb').read()
     pt = PathTree(data)
     self.assertTrue(pt.match_path('/foo/path'))
     self.assertTrue(pt.match_path('/foo/path/'))
     # the '2' should match against "$releasever"
     self.assertTrue(pt.match_path('/foo/path/always/2'))
     self.assertTrue(pt.match_path('/foo/path/bar'))
     self.assertTrue(pt.match_path('/foo/path/bar/a/b/c'))
     self.assertFalse(pt.match_path('/foo'))
     self.assertFalse(pt.match_path('/bar'))
Esempio n. 12
0
 def test_unpack_data(self):
     data = open(DATA).read()
     nodes, bits = PathTree._unpack_data(data)
     self.assertEqual(len(nodes), 6)
     # first node always gets weight of 1
     self.assertEqual(nodes[0].weight, 1)
     self.assertEqual(nodes[0].value, 'never')
     self.assertEqual(nodes[5].weight, 6)
     self.assertEqual(nodes[5].value, '')
     self.assertEqual(len(bits), 6)
Esempio n. 13
0
 def test_unpack_data(self):
     data = open(DATA, 'rb').read()
     nodes, bits = PathTree._unpack_data(data)
     self.assertEqual(len(nodes), 6)
     # first node always gets weight of 1
     self.assertEqual(nodes[0].weight, 1)
     self.assertEqual(nodes[0].value, 'never')
     self.assertEqual(nodes[5].weight, 6)
     self.assertEqual(nodes[5].value, '')
     self.assertEqual(len(bits), 6)
Esempio n. 14
0
 def test_match_path_listing(self):
     tree = {'foo': [{'path': [{'bar':[{PATH_END: None}]}]}]}
     data = open(DATA).read()
     pt = PathTree(data)
     pt.path_tree = tree
     self.assertTrue(pt.match_path('/foo/path/bar/listing'))
     self.assertTrue(pt.match_path('/foo/path/listing'))
     self.assertTrue(pt.match_path('/foo/listing'))
     self.assertFalse(pt.match_path('/foo/path/alfred'))
     self.assertFalse(pt.match_path('/foo/path/listing/for/alfred'))
Esempio n. 15
0
 def test_match_path(self):
     data = open(DATA).read()
     pt = PathTree(data)
     self.assertTrue(pt.match_path('/foo/path'))
     self.assertTrue(pt.match_path('/foo/path/'))
     # the '2' should match against "$releasever"
     self.assertTrue(pt.match_path('/foo/path/always/2'))
     self.assertTrue(pt.match_path('/foo/path/bar'))
     self.assertTrue(pt.match_path('/foo/path/bar/a/b/c'))
     self.assertFalse(pt.match_path('/foo'))
     self.assertFalse(pt.match_path('/bar'))
Esempio n. 16
0
    def _path_tree(self):
        """
        :return:    PathTree object built from this cert's extensions
        :rtype:     rhsm.pathtree.PathTree

        :raise: AttributeError if self.version.major < 3
        """
        # This data was not present in certificates prior to v3.
        if self.version.major < 3:
            raise AttributeError('path tree not used for v%d certs' %
                                 self.version.major)
        if not self._path_tree_object:
            # generate and cache the tree
            data = self.extensions[EXT_ENT_PAYLOAD]
            self._path_tree_object = PathTree(data)
        return self._path_tree_object
Esempio n. 17
0
 def test_match_different_variables(self):
     tree1 = {'foo': [{'$releasever': [{'bar':[{PATH_END: None}]}],
                      'jarjar': [{'binks':[{PATH_END: None}]}]}]}
     tree2 = {'foo': [{'jarjar': [{'binks':[{PATH_END: None}]}],
                      '$releasever': [{'bar':[{PATH_END: None}]}]}]}
     tree3 = {'foo': [{'$releasever': [{'bar':[{PATH_END: None}]}]},
                      {'jarjar': [{'binks':[{PATH_END: None}]}]}]}
     tree4 = {'foo': [{'jarjar': [{'binks':[{PATH_END: None}]}]},
                      {'$releasever': [{'bar':[{PATH_END: None}]}]}]}
     trees = [tree1, tree2, tree3, tree4]
     data = open(DATA).read()
     pt = PathTree(data)
     #just swap out the pre-cooked data with out with
     for tree in trees:
         pt.path_tree = tree
         self.assertTrue(pt.match_path('/foo/path/bar'))
         self.assertFalse(pt.match_path('/foo/path/abc'))
         self.assertFalse(pt.match_path('/foo/path/abc'))
         self.assertTrue(pt.match_path('/foo/jarjar/binks'))
         self.assertTrue(pt.match_path('/foo/jarjar/bar'))
         self.assertFalse(pt.match_path('/foo/jarjar/notbinks'))
Esempio n. 18
0
 def test_match_different_variables(self):
     tree1 = {'foo': [{'$releasever': [{'bar':[{PATH_END: None}]}],
                      'jarjar': [{'binks':[{PATH_END: None}]}]}]}
     tree2 = {'foo': [{'jarjar': [{'binks':[{PATH_END: None}]}],
                      '$releasever': [{'bar':[{PATH_END: None}]}]}]}
     tree3 = {'foo': [{'$releasever': [{'bar':[{PATH_END: None}]}]},
                      {'jarjar': [{'binks':[{PATH_END: None}]}]}]}
     tree4 = {'foo': [{'jarjar': [{'binks':[{PATH_END: None}]}]},
                      {'$releasever': [{'bar':[{PATH_END: None}]}]}]}
     trees = [tree1, tree2, tree3, tree4]
     data = open(DATA).read()
     pt = PathTree(data)
     #just swap out the pre-cooked data with out with
     for tree in trees:
         pt.path_tree = tree
         self.assertTrue(pt.match_path('/foo/path/bar'))
         self.assertFalse(pt.match_path('/foo/path/abc'))
         self.assertFalse(pt.match_path('/foo/path/abc'))
         self.assertTrue(pt.match_path('/foo/jarjar/binks'))
         self.assertTrue(pt.match_path('/foo/jarjar/bar'))
         self.assertFalse(pt.match_path('/foo/jarjar/notbinks'))
Esempio n. 19
0
 def test_generate_path_tree(self):
     data = open(DATA, 'rb').read()
     pt = PathTree(data).path_tree
     self.assertTrue('foo' in pt)
     self.assertEqual(len(list(pt.keys())), 1)
 def test_match_different_variables(self):
     tree1 = {
         "foo": [{
             "$releasever": [{
                 "bar": [{
                     PATH_END: None
                 }]
             }],
             "jarjar": [{
                 "binks": [{
                     PATH_END: None
                 }]
             }]
         }]
     }
     tree2 = {
         "foo": [{
             "jarjar": [{
                 "binks": [{
                     PATH_END: None
                 }]
             }],
             "$releasever": [{
                 "bar": [{
                     PATH_END: None
                 }]
             }]
         }]
     }
     tree3 = {
         "foo": [
             {
                 "$releasever": [{
                     "bar": [{
                         PATH_END: None
                     }]
                 }]
             },
             {
                 "jarjar": [{
                     "binks": [{
                         PATH_END: None
                     }]
                 }]
             },
         ]
     }
     tree4 = {
         "foo": [
             {
                 "jarjar": [{
                     "binks": [{
                         PATH_END: None
                     }]
                 }]
             },
             {
                 "$releasever": [{
                     "bar": [{
                         PATH_END: None
                     }]
                 }]
             },
         ]
     }
     trees = [tree1, tree2, tree3, tree4]
     data = open(DATA, "rb").read()
     pt = PathTree(data)
     # just swap out the pre-cooked data with out with
     for tree in trees:
         pt.path_tree = tree
         self.assertTrue(pt.match_path("/foo/path/bar"))
         self.assertFalse(pt.match_path("/foo/path/abc"))
         self.assertFalse(pt.match_path("/foo/path/abc"))
         self.assertTrue(pt.match_path("/foo/jarjar/binks"))
         self.assertTrue(pt.match_path("/foo/jarjar/bar"))
         self.assertFalse(pt.match_path("/foo/jarjar/notbinks"))
Esempio n. 21
0
 def test_get_node_count_medium(self):
     bs = GhettoBitStream([])
     # count bigger than 127, only need 1 byte to represent it
     bs.bytes = deque([129, 150])
     ret = PathTree._get_node_count(bs)
     self.assertEqual(ret, 150)
Esempio n. 22
0
 def test_get_node_count_big(self):
     bs = GhettoBitStream([])
     # count bigger than 127, need next 2 bytes to represent it
     bs.bytes = deque([130, 1, 17])
     ret = PathTree._get_node_count(bs)
     self.assertEqual(ret, 273)
Esempio n. 23
0
 def test_get_node_count_medium(self):
     bs = GhettoBitStream([])
     # count bigger than 127, only need 1 byte to represent it
     bs.bytes = deque([129, 150])
     ret = PathTree._get_node_count(bs)
     self.assertEqual(ret, 150)
Esempio n. 24
0
 def test_get_node_count_small(self):
     bs = GhettoBitStream([])
     bs.bytes = deque([6])
     ret = PathTree._get_node_count(bs)
     self.assertEqual(ret, 6)
Esempio n. 25
0
 def test_get_leaf_from_dict(self):
     codes = {'1010': 'abc'}
     bitstream = '10101111110000'
     ret = PathTree._get_leaf_from_dict(codes, bitstream)
     self.assertEqual(ret, 'abc')
Esempio n. 26
0
 def test_get_node_count_small(self):
     bs = GhettoBitStream([])
     bs.bytes = deque([6])
     ret = PathTree._get_node_count(bs)
     self.assertEqual(ret, 6)
Esempio n. 27
0
 def test_get_node_count_big(self):
     bs = GhettoBitStream([])
     # count bigger than 127, need next 2 bytes to represent it
     bs.bytes = deque([130, 1, 17])
     ret = PathTree._get_node_count(bs)
     self.assertEqual(ret, 273)
Esempio n. 28
0
 def test_generate_path_tree(self):
     data = open(DATA).read()
     pt = PathTree(data).path_tree
     self.assertTrue('foo' in pt)
     self.assertEqual(len(pt.keys()), 1)
 def test_get_leaf_from_dict(self):
     codes = {"1010": "abc"}
     bitstream = "10101111110000"
     ret = PathTree._get_leaf_from_dict(codes, bitstream)
     self.assertEqual(ret, "abc")
Esempio n. 30
0
 def test_get_leaf_from_dict(self):
     codes = {'1010': 'abc'}
     bitstream = '10101111110000'
     ret = PathTree._get_leaf_from_dict(codes, bitstream)
     self.assertEqual(ret, 'abc')