This file is indexed.

/usr/lib/python2.7/dist-packages/keystoneauth1/tests/unit/loading/test_v3.py is in python-keystoneauth1 3.4.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
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
# 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 random
import uuid

from keystoneauth1 import exceptions
from keystoneauth1 import loading
from keystoneauth1.tests.unit.loading import utils


class V3PasswordTests(utils.TestCase):

    def setUp(self):
        super(V3PasswordTests, self).setUp()

        self.auth_url = uuid.uuid4().hex

    def create(self, **kwargs):
        kwargs.setdefault('auth_url', self.auth_url)
        loader = loading.get_plugin_loader('v3password')
        return loader.load_from_options(**kwargs)

    def test_basic(self):
        username = uuid.uuid4().hex
        user_domain_id = uuid.uuid4().hex
        password = uuid.uuid4().hex
        project_name = uuid.uuid4().hex
        project_domain_id = uuid.uuid4().hex

        p = self.create(username=username,
                        user_domain_id=user_domain_id,
                        project_name=project_name,
                        project_domain_id=project_domain_id,
                        password=password)

        pw_method = p.auth_methods[0]

        self.assertEqual(username, pw_method.username)
        self.assertEqual(user_domain_id, pw_method.user_domain_id)
        self.assertEqual(password, pw_method.password)

        self.assertEqual(project_name, p.project_name)
        self.assertEqual(project_domain_id, p.project_domain_id)

    def test_without_user_domain(self):
        self.assertRaises(exceptions.OptionError,
                          self.create,
                          username=uuid.uuid4().hex,
                          password=uuid.uuid4().hex)

    def test_without_project_domain(self):
        self.assertRaises(exceptions.OptionError,
                          self.create,
                          username=uuid.uuid4().hex,
                          password=uuid.uuid4().hex,
                          user_domain_id=uuid.uuid4().hex,
                          project_name=uuid.uuid4().hex)


class TOTPTests(utils.TestCase):

    def setUp(self):
        super(TOTPTests, self).setUp()

        self.auth_url = uuid.uuid4().hex

    def create(self, **kwargs):
        kwargs.setdefault('auth_url', self.auth_url)
        loader = loading.get_plugin_loader('v3totp')
        return loader.load_from_options(**kwargs)

    def test_basic(self):
        username = uuid.uuid4().hex
        user_domain_id = uuid.uuid4().hex
        # passcode is 6 digits
        passcode = ''.join(str(random.randint(0, 9)) for x in range(6))
        project_name = uuid.uuid4().hex
        project_domain_id = uuid.uuid4().hex

        p = self.create(username=username,
                        user_domain_id=user_domain_id,
                        project_name=project_name,
                        project_domain_id=project_domain_id,
                        passcode=passcode)

        totp_method = p.auth_methods[0]

        self.assertEqual(username, totp_method.username)
        self.assertEqual(user_domain_id, totp_method.user_domain_id)
        self.assertEqual(passcode, totp_method.passcode)

        self.assertEqual(project_name, p.project_name)
        self.assertEqual(project_domain_id, p.project_domain_id)

    def test_without_user_domain(self):
        self.assertRaises(exceptions.OptionError,
                          self.create,
                          username=uuid.uuid4().hex,
                          passcode=uuid.uuid4().hex)

    def test_without_project_domain(self):
        self.assertRaises(exceptions.OptionError,
                          self.create,
                          username=uuid.uuid4().hex,
                          passcode=uuid.uuid4().hex,
                          user_domain_id=uuid.uuid4().hex,
                          project_name=uuid.uuid4().hex)


class OpenIDConnectBaseTests(object):

    plugin_name = None

    def setUp(self):
        super(OpenIDConnectBaseTests, self).setUp()

        self.auth_url = uuid.uuid4().hex

    def create(self, **kwargs):
        kwargs.setdefault('auth_url', self.auth_url)
        loader = loading.get_plugin_loader(self.plugin_name)
        return loader.load_from_options(**kwargs)

    def test_base_options_are_there(self):
        options = loading.get_plugin_loader(self.plugin_name).get_options()
        self.assertTrue(
            set(['client-id', 'client-secret', 'access-token-endpoint',
                 'access-token-type', 'openid-scope',
                 'discovery-endpoint']).issubset(
                     set([o.name for o in options]))
        )
        # openid-scope gets renamed into "scope"
        self.assertIn('scope', [o.dest for o in options])


class OpenIDConnectClientCredentialsTests(OpenIDConnectBaseTests,
                                          utils.TestCase):

    plugin_name = "v3oidcclientcredentials"

    def test_options(self):
        options = loading.get_plugin_loader(self.plugin_name).get_options()
        self.assertTrue(
            set(['openid-scope']).issubset(
                set([o.name for o in options]))
        )

    def test_basic(self):
        access_token_endpoint = uuid.uuid4().hex
        scope = uuid.uuid4().hex
        identity_provider = uuid.uuid4().hex
        protocol = uuid.uuid4().hex
        scope = uuid.uuid4().hex
        client_id = uuid.uuid4().hex
        client_secret = uuid.uuid4().hex

        oidc = self.create(identity_provider=identity_provider,
                           protocol=protocol,
                           access_token_endpoint=access_token_endpoint,
                           client_id=client_id,
                           client_secret=client_secret,
                           scope=scope)

        self.assertEqual(scope, oidc.scope)
        self.assertEqual(identity_provider, oidc.identity_provider)
        self.assertEqual(protocol, oidc.protocol)
        self.assertEqual(access_token_endpoint, oidc.access_token_endpoint)
        self.assertEqual(client_id, oidc.client_id)
        self.assertEqual(client_secret, oidc.client_secret)


class OpenIDConnectPasswordTests(OpenIDConnectBaseTests, utils.TestCase):

    plugin_name = "v3oidcpassword"

    def test_options(self):
        options = loading.get_plugin_loader(self.plugin_name).get_options()
        self.assertTrue(
            set(['username', 'password', 'openid-scope']).issubset(
                set([o.name for o in options]))
        )

    def test_basic(self):
        access_token_endpoint = uuid.uuid4().hex
        username = uuid.uuid4().hex
        password = uuid.uuid4().hex
        scope = uuid.uuid4().hex
        identity_provider = uuid.uuid4().hex
        protocol = uuid.uuid4().hex
        scope = uuid.uuid4().hex
        client_id = uuid.uuid4().hex
        client_secret = uuid.uuid4().hex

        oidc = self.create(username=username,
                           password=password,
                           identity_provider=identity_provider,
                           protocol=protocol,
                           access_token_endpoint=access_token_endpoint,
                           client_id=client_id,
                           client_secret=client_secret,
                           scope=scope)

        self.assertEqual(username, oidc.username)
        self.assertEqual(password, oidc.password)
        self.assertEqual(scope, oidc.scope)
        self.assertEqual(identity_provider, oidc.identity_provider)
        self.assertEqual(protocol, oidc.protocol)
        self.assertEqual(access_token_endpoint, oidc.access_token_endpoint)
        self.assertEqual(client_id, oidc.client_id)
        self.assertEqual(client_secret, oidc.client_secret)


class OpenIDConnectAuthCodeTests(OpenIDConnectBaseTests, utils.TestCase):

    plugin_name = "v3oidcauthcode"

    def test_options(self):
        options = loading.get_plugin_loader(self.plugin_name).get_options()
        self.assertTrue(
            set(['redirect-uri', 'code']).issubset(
                set([o.name for o in options]))
        )

    def test_basic(self):
        access_token_endpoint = uuid.uuid4().hex
        redirect_uri = uuid.uuid4().hex
        authorization_code = uuid.uuid4().hex
        scope = uuid.uuid4().hex
        identity_provider = uuid.uuid4().hex
        protocol = uuid.uuid4().hex
        client_id = uuid.uuid4().hex
        client_secret = uuid.uuid4().hex

        oidc = self.create(code=authorization_code,
                           redirect_uri=redirect_uri,
                           identity_provider=identity_provider,
                           protocol=protocol,
                           access_token_endpoint=access_token_endpoint,
                           client_id=client_id,
                           client_secret=client_secret,
                           scope=scope)

        self.assertEqual(redirect_uri, oidc.redirect_uri)
        self.assertEqual(authorization_code, oidc.code)
        self.assertEqual(scope, oidc.scope)
        self.assertEqual(identity_provider, oidc.identity_provider)
        self.assertEqual(protocol, oidc.protocol)
        self.assertEqual(access_token_endpoint, oidc.access_token_endpoint)
        self.assertEqual(client_id, oidc.client_id)
        self.assertEqual(client_secret, oidc.client_secret)


class OpenIDConnectAccessToken(utils.TestCase):

    plugin_name = "v3oidcaccesstoken"

    def setUp(self):
        super(OpenIDConnectAccessToken, self).setUp()

        self.auth_url = uuid.uuid4().hex

    def create(self, **kwargs):
        kwargs.setdefault('auth_url', self.auth_url)
        loader = loading.get_plugin_loader(self.plugin_name)
        return loader.load_from_options(**kwargs)

    def test_options(self):
        options = loading.get_plugin_loader(self.plugin_name).get_options()
        self.assertTrue(
            set(['access-token']).issubset(
                set([o.name for o in options]))
        )

    def test_basic(self):
        access_token = uuid.uuid4().hex
        identity_provider = uuid.uuid4().hex
        protocol = uuid.uuid4().hex

        oidc = self.create(access_token=access_token,
                           identity_provider=identity_provider,
                           protocol=protocol)

        self.assertEqual(identity_provider, oidc.identity_provider)
        self.assertEqual(protocol, oidc.protocol)
        self.assertEqual(access_token, oidc.access_token)


class V3TokenlessAuthTests(utils.TestCase):

    def setUp(self):
        super(V3TokenlessAuthTests, self).setUp()

        self.auth_url = uuid.uuid4().hex

    def create(self, **kwargs):
        kwargs.setdefault('auth_url', self.auth_url)
        loader = loading.get_plugin_loader('v3tokenlessauth')
        return loader.load_from_options(**kwargs)

    def test_basic(self):
        domain_id = uuid.uuid4().hex
        domain_name = uuid.uuid4().hex
        project_id = uuid.uuid4().hex
        project_name = uuid.uuid4().hex
        project_domain_id = uuid.uuid4().hex
        project_domain_name = uuid.uuid4().hex

        tla = self.create(domain_id=domain_id,
                          domain_name=domain_name,
                          project_id=project_id,
                          project_name=project_name,
                          project_domain_id=project_domain_id,
                          project_domain_name=project_domain_name)

        self.assertEqual(domain_id, tla.domain_id)
        self.assertEqual(domain_name, tla.domain_name)
        self.assertEqual(project_id, tla.project_id)
        self.assertEqual(project_name, tla.project_name)
        self.assertEqual(project_domain_id, tla.project_domain_id)
        self.assertEqual(project_domain_name, tla.project_domain_name)

    def test_missing_parameters(self):
        self.assertRaises(exceptions.OptionError,
                          self.create,
                          domain_id=None)
        self.assertRaises(exceptions.OptionError,
                          self.create,
                          domain_name=None)
        self.assertRaises(exceptions.OptionError,
                          self.create,
                          project_id=None)
        self.assertRaises(exceptions.OptionError,
                          self.create,
                          project_name=None)
        self.assertRaises(exceptions.OptionError,
                          self.create,
                          project_domain_id=None)
        self.assertRaises(exceptions.OptionError,
                          self.create,
                          project_domain_name=None)
        # only when a project_name is provided, project_domain_id will
        # be use to uniquely identify the project. It's an invalid
        # option when it's just by itself.
        self.assertRaises(exceptions.OptionError,
                          self.create,
                          project_domain_id=uuid.uuid4().hex)
        # only when a project_name is provided, project_domain_name will
        # be use to uniquely identify the project. It's an invalid
        # option when it's just by itself.
        self.assertRaises(exceptions.OptionError,
                          self.create,
                          project_domain_name=uuid.uuid4().hex)
        self.assertRaises(exceptions.OptionError,
                          self.create,
                          project_name=uuid.uuid4().hex)


class V3ApplicationCredentialTests(utils.TestCase):

    def setUp(self):
        super(V3ApplicationCredentialTests, self).setUp()

        self.auth_url = uuid.uuid4().hex

    def create(self, **kwargs):
        kwargs.setdefault('auth_url', self.auth_url)
        loader = loading.get_plugin_loader('v3applicationcredential')
        return loader.load_from_options(**kwargs)

    def test_basic(self):
        id = uuid.uuid4().hex
        secret = uuid.uuid4().hex

        app_cred = self.create(application_credential_id=id,
                               application_credential_secret=secret)

        ac_method = app_cred.auth_methods[0]

        self.assertEqual(id, ac_method.application_credential_id)
        self.assertEqual(secret, ac_method.application_credential_secret)

    def test_with_name(self):
        name = uuid.uuid4().hex
        secret = uuid.uuid4().hex
        username = uuid.uuid4().hex
        user_domain_id = uuid.uuid4().hex

        app_cred = self.create(application_credential_name=name,
                               application_credential_secret=secret,
                               username=username,
                               user_domain_id=user_domain_id)

        ac_method = app_cred.auth_methods[0]

        self.assertEqual(name, ac_method.application_credential_name)
        self.assertEqual(secret, ac_method.application_credential_secret)
        self.assertEqual(username, ac_method.username)
        self.assertEqual(user_domain_id, ac_method.user_domain_id)

    def test_without_user_domain(self):
        self.assertRaises(exceptions.OptionError,
                          self.create,
                          application_credential_name=uuid.uuid4().hex,
                          username=uuid.uuid4().hex,
                          application_credential_secret=uuid.uuid4().hex)

    def test_without_name_or_id(self):
        self.assertRaises(exceptions.OptionError,
                          self.create,
                          username=uuid.uuid4().hex,
                          user_domain_id=uuid.uuid4().hex,
                          application_credential_secret=uuid.uuid4().hex)

    def test_without_secret(self):
        self.assertRaises(exceptions.OptionError,
                          self.create,
                          application_credential_id=uuid.uuid4().hex,
                          username=uuid.uuid4().hex,
                          user_domain_id=uuid.uuid4().hex)