This file is indexed.

/usr/lib/python3/dist-packages/keystoneclient/tests/unit/test_fixtures.py is in python3-keystoneclient 1:3.15.0-0ubuntu1.

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
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
# 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


from keystoneclient import fixture
from keystoneclient.tests.unit import utils


class V2TokenTests(utils.TestCase):

    def test_unscoped(self):
        token_id = uuid.uuid4().hex
        user_id = uuid.uuid4().hex
        user_name = uuid.uuid4().hex

        token = fixture.V2Token(token_id=token_id,
                                user_id=user_id,
                                user_name=user_name)

        self.assertEqual(token_id, token.token_id)
        self.assertEqual(token_id, token['access']['token']['id'])
        self.assertEqual(user_id, token.user_id)
        self.assertEqual(user_id, token['access']['user']['id'])
        self.assertEqual(user_name, token.user_name)
        self.assertEqual(user_name, token['access']['user']['name'])
        self.assertIsNone(token.trust_id)

    def test_tenant_scoped(self):
        tenant_id = uuid.uuid4().hex
        tenant_name = uuid.uuid4().hex

        token = fixture.V2Token(tenant_id=tenant_id,
                                tenant_name=tenant_name)

        self.assertEqual(tenant_id, token.tenant_id)
        self.assertEqual(tenant_id, token['access']['token']['tenant']['id'])
        self.assertEqual(tenant_name, token.tenant_name)
        tn = token['access']['token']['tenant']['name']
        self.assertEqual(tenant_name, tn)
        self.assertIsNone(token.trust_id)

    def test_trust_scoped(self):
        trust_id = uuid.uuid4().hex
        trustee_user_id = uuid.uuid4().hex

        token = fixture.V2Token(trust_id=trust_id,
                                trustee_user_id=trustee_user_id)
        trust = token['access']['trust']

        self.assertEqual(trust_id, token.trust_id)
        self.assertEqual(trust_id, trust['id'])
        self.assertEqual(trustee_user_id, token.trustee_user_id)
        self.assertEqual(trustee_user_id, trust['trustee_user_id'])

    def test_roles(self):
        role_id1 = uuid.uuid4().hex
        role_name1 = uuid.uuid4().hex
        role_id2 = uuid.uuid4().hex
        role_name2 = uuid.uuid4().hex

        token = fixture.V2Token()
        token.add_role(id=role_id1, name=role_name1)
        token.add_role(id=role_id2, name=role_name2)

        role_names = token['access']['user']['roles']
        role_ids = token['access']['metadata']['roles']

        self.assertEqual(set([role_id1, role_id2]), set(role_ids))
        for r in (role_name1, role_name2):
            self.assertIn({'name': r}, role_names)

    def test_services(self):
        service_type = uuid.uuid4().hex
        service_name = uuid.uuid4().hex
        endpoint_id = uuid.uuid4().hex
        region = uuid.uuid4().hex

        public = uuid.uuid4().hex
        admin = uuid.uuid4().hex
        internal = uuid.uuid4().hex

        token = fixture.V2Token()
        svc = token.add_service(type=service_type, name=service_name)

        svc.add_endpoint(public=public,
                         admin=admin,
                         internal=internal,
                         region=region,
                         id=endpoint_id)

        self.assertEqual(1, len(token['access']['serviceCatalog']))
        service = token['access']['serviceCatalog'][0]['endpoints'][0]

        self.assertEqual(public, service['publicURL'])
        self.assertEqual(internal, service['internalURL'])
        self.assertEqual(admin, service['adminURL'])
        self.assertEqual(region, service['region'])
        self.assertEqual(endpoint_id, service['id'])


class V3TokenTests(utils.TestCase):

    def test_unscoped(self):
        user_id = uuid.uuid4().hex
        user_name = uuid.uuid4().hex
        user_domain_id = uuid.uuid4().hex
        user_domain_name = uuid.uuid4().hex

        token = fixture.V3Token(user_id=user_id,
                                user_name=user_name,
                                user_domain_id=user_domain_id,
                                user_domain_name=user_domain_name)

        self.assertEqual(user_id, token.user_id)
        self.assertEqual(user_id, token['token']['user']['id'])
        self.assertEqual(user_name, token.user_name)
        self.assertEqual(user_name, token['token']['user']['name'])

        user_domain = token['token']['user']['domain']

        self.assertEqual(user_domain_id, token.user_domain_id)
        self.assertEqual(user_domain_id, user_domain['id'])
        self.assertEqual(user_domain_name, token.user_domain_name)
        self.assertEqual(user_domain_name, user_domain['name'])

    def test_project_scoped(self):
        project_id = uuid.uuid4().hex
        project_name = uuid.uuid4().hex
        project_domain_id = uuid.uuid4().hex
        project_domain_name = uuid.uuid4().hex

        token = fixture.V3Token(project_id=project_id,
                                project_name=project_name,
                                project_domain_id=project_domain_id,
                                project_domain_name=project_domain_name)

        self.assertEqual(project_id, token.project_id)
        self.assertEqual(project_id, token['token']['project']['id'])
        self.assertEqual(project_name, token.project_name)
        self.assertEqual(project_name, token['token']['project']['name'])

        project_domain = token['token']['project']['domain']

        self.assertEqual(project_domain_id, token.project_domain_id)
        self.assertEqual(project_domain_id, project_domain['id'])
        self.assertEqual(project_domain_name, token.project_domain_name)
        self.assertEqual(project_domain_name, project_domain['name'])

    def test_domain_scoped(self):
        domain_id = uuid.uuid4().hex
        domain_name = uuid.uuid4().hex

        token = fixture.V3Token(domain_id=domain_id,
                                domain_name=domain_name)

        self.assertEqual(domain_id, token.domain_id)
        self.assertEqual(domain_id, token['token']['domain']['id'])
        self.assertEqual(domain_name, token.domain_name)
        self.assertEqual(domain_name, token['token']['domain']['name'])

    def test_roles(self):
        role1 = {'id': uuid.uuid4().hex, 'name': uuid.uuid4().hex}
        role2 = {'id': uuid.uuid4().hex, 'name': uuid.uuid4().hex}

        token = fixture.V3Token()
        token.add_role(**role1)
        token.add_role(**role2)

        self.assertEqual(2, len(token['token']['roles']))

        self.assertIn(role1, token['token']['roles'])
        self.assertIn(role2, token['token']['roles'])

    def test_trust_scoped(self):
        trust_id = uuid.uuid4().hex
        trustee_user_id = uuid.uuid4().hex
        trustor_user_id = uuid.uuid4().hex
        impersonation = True

        token = fixture.V3Token(trust_id=trust_id,
                                trustee_user_id=trustee_user_id,
                                trustor_user_id=trustor_user_id,
                                trust_impersonation=impersonation)

        trust = token['token']['OS-TRUST:trust']
        self.assertEqual(trust_id, token.trust_id)
        self.assertEqual(trust_id, trust['id'])
        self.assertEqual(trustee_user_id, token.trustee_user_id)
        self.assertEqual(trustee_user_id, trust['trustee_user']['id'])
        self.assertEqual(trustor_user_id, token.trustor_user_id)
        self.assertEqual(trustor_user_id, trust['trustor_user']['id'])
        self.assertEqual(impersonation, token.trust_impersonation)
        self.assertEqual(impersonation, trust['impersonation'])

    def test_oauth_scoped(self):
        access_id = uuid.uuid4().hex
        consumer_id = uuid.uuid4().hex

        token = fixture.V3Token(oauth_access_token_id=access_id,
                                oauth_consumer_id=consumer_id)

        oauth = token['token']['OS-OAUTH1']

        self.assertEqual(access_id, token.oauth_access_token_id)
        self.assertEqual(access_id, oauth['access_token_id'])
        self.assertEqual(consumer_id, token.oauth_consumer_id)
        self.assertEqual(consumer_id, oauth['consumer_id'])

    def test_catalog(self):
        service_type = uuid.uuid4().hex
        service_name = uuid.uuid4().hex
        service_id = uuid.uuid4().hex
        region = uuid.uuid4().hex
        endpoints = {'public': uuid.uuid4().hex,
                     'internal': uuid.uuid4().hex,
                     'admin': uuid.uuid4().hex}

        token = fixture.V3Token()
        svc = token.add_service(type=service_type,
                                name=service_name,
                                id=service_id)
        svc.add_standard_endpoints(region=region, **endpoints)

        self.assertEqual(1, len(token['token']['catalog']))
        service = token['token']['catalog'][0]
        self.assertEqual(3, len(service['endpoints']))

        self.assertEqual(service_name, service['name'])
        self.assertEqual(service_type, service['type'])
        self.assertEqual(service_id, service['id'])

        for endpoint in service['endpoints']:
            # assert an id exists for each endpoint, remove it to make testing
            # the endpoint content below easier.
            self.assertTrue(endpoint.pop('id'))

        for interface, url in endpoints.items():
            endpoint = {'interface': interface, 'url': url,
                        'region': region, 'region_id': region}
            self.assertIn(endpoint, service['endpoints'])