This file is indexed.

/usr/lib/python2.7/dist-packages/magnum/tests/unit/common/test_short_id.py is in python-magnum 3.1.1-5.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#
#    Licensed under the Apache License, Version 2.0 (the "License"); you may
#    not use this file except in compliance with the License. You may obtain
#    a copy of the License at
#
#         http://www.apache.org/licenses/LICENSE-2.0
#
#    Unless required by applicable law or agreed to in writing, software
#    distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
#    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
#    License for the specific language governing permissions and limitations
#    under the License.

import uuid

import testtools

from magnum.common import short_id


class ShortIdTest(testtools.TestCase):

    def test_byte_string_8(self):
        self.assertEqual('\xab', short_id._to_byte_string(0xab, 8))
        self.assertEqual('\x05', short_id._to_byte_string(0x05, 8))

    def test_byte_string_16(self):
        self.assertEqual('\xab\xcd', short_id._to_byte_string(0xabcd, 16))
        self.assertEqual('\x0a\xbc', short_id._to_byte_string(0xabc, 16))

    def test_byte_string_12(self):
        self.assertEqual('\xab\xc0', short_id._to_byte_string(0xabc, 12))
        self.assertEqual('\x0a\xb0', short_id._to_byte_string(0x0ab, 12))

    def test_byte_string_60(self):
        val = 0x111111111111111
        byte_string = short_id._to_byte_string(val, 60)
        self.assertEqual('\x11\x11\x11\x11\x11\x11\x11\x10', byte_string)

    def test_get_id_string(self):
        id = short_id.get_id('11111111-1111-4111-bfff-ffffffffffff')
        self.assertEqual('ceirceirceir', id)

    def test_get_id_uuid_1(self):
        source = uuid.UUID('11111111-1111-4111-bfff-ffffffffffff')
        self.assertEqual(0x111111111111111, source.time)
        self.assertEqual('ceirceirceir', short_id.get_id(source))

    def test_get_id_uuid_f(self):
        source = uuid.UUID('ffffffff-ffff-4fff-8000-000000000000')
        self.assertEqual('777777777777', short_id.get_id(source))

    def test_get_id_uuid_0(self):
        source = uuid.UUID('00000000-0000-4000-bfff-ffffffffffff')
        self.assertEqual('aaaaaaaaaaaa', short_id.get_id(source))

    def test_get_id_uuid_endianness(self):
        source = uuid.UUID('ffffffff-00ff-4000-aaaa-aaaaaaaaaaaa')
        self.assertEqual('aaaa77777777', short_id.get_id(source))

    def test_get_id_uuid1(self):
        source = uuid.uuid1()
        self.assertRaises(ValueError, short_id.get_id, source)

    def test_generate_ids(self):
        allowed_chars = 'abcdefghijklmnopqrstuvwxyz234567'
        ids = [short_id.generate_id() for i in range(25)]

        for id in ids:
            self.assertEqual(12, len(id))
            s = ''.join(ch for ch in id if ch not in allowed_chars)
            self.assertEqual(s, '')
            self.assertEqual(1, ids.count(id))