summaryrefslogtreecommitdiff
path: root/keystone/tests/protection/v3/test_application_credential.py
blob: 5807d7f90d158e98e87ece51dde56ffbc55e1f61 (plain)
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
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
#    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 datetime
import uuid

import http.client
from oslo_serialization import jsonutils

from keystone.common.policies import base as base_policy
from keystone.common import provider_api
import keystone.conf
from keystone.tests.common import auth as common_auth
from keystone.tests import unit
from keystone.tests.unit import base_classes
from keystone.tests.unit import ksfixtures
from keystone.tests.unit.ksfixtures import temporaryfile

CONF = keystone.conf.CONF
PROVIDERS = provider_api.ProviderAPIs


class _TestAppCredBase(base_classes.TestCaseWithBootstrap):
    """Base class for application credential tests."""

    def _new_app_cred_data(self, user_id=None, project_id=None, name=None,
                           expires=None, system=None):
        if not user_id:
            user_id = self.app_cred_user_id
        if not name:
            name = uuid.uuid4().hex
        if not expires:
            expires = datetime.datetime.utcnow() + datetime.timedelta(days=365)
        if not system:
            system = uuid.uuid4().hex
        if not project_id:
            project_id = self.app_cred_project_id
        app_cred_data = {
            'id': uuid.uuid4().hex,
            'name': name,
            'description': uuid.uuid4().hex,
            'user_id': user_id,
            'project_id': project_id,
            'system': system,
            'expires_at': expires,
            'roles': [
                {'id': self.bootstrapper.member_role_id},
            ],
            'secret': uuid.uuid4().hex,
            'unrestricted': False
        }
        return app_cred_data

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

        # create a user and project for app cred testing
        new_user_ref = unit.new_user_ref(
            domain_id=CONF.identity.default_domain_id
        )
        app_cred_user_ref = PROVIDERS.identity_api.create_user(
            new_user_ref
        )
        self.app_cred_user_id = app_cred_user_ref['id']
        self.app_cred_user_password = new_user_ref['password']
        app_cred_project_ref = PROVIDERS.resource_api.create_project(
            uuid.uuid4().hex,
            unit.new_project_ref(domain_id=CONF.identity.default_domain_id)
        )
        self.app_cred_project_id = app_cred_project_ref['id']
        PROVIDERS.assignment_api.create_grant(
            self.bootstrapper.member_role_id,
            user_id=self.app_cred_user_id,
            project_id=self.app_cred_project_id
        )

    def _create_application_credential(self):
        app_cred = self._new_app_cred_data()
        return \
            PROVIDERS.application_credential_api.create_application_credential(
                app_cred)

    def _override_policy(self):
        # TODO(gyee): Remove this once the deprecated policies in
        # keystone.common.policies.application_credential have been removed.
        # This is only here to make sure we test the new policies instead of
        # the deprecated ones. Oslo.policy will OR deprecated policies with
        # new policies to maintain compatibility and give operators a chance to
        # update permissions or update policies without breaking users.
        # This will cause these specific tests to fail since we're trying to
        # correct this broken behavior with better scope checking.
        with open(self.policy_file_name, 'w') as f:
            overridden_policies = {
                'identity:get_application_credential': (
                    base_policy.RULE_SYSTEM_READER_OR_OWNER),
                'identity:list_application_credentials': (
                    base_policy.RULE_SYSTEM_READER_OR_OWNER),
                'identity:create_application_credential': (
                    base_policy.RULE_OWNER),
                'identity:delete_application_credential': (
                    base_policy.RULE_SYSTEM_ADMIN_OR_OWNER),
            }
            f.write(jsonutils.dumps(overridden_policies))


class _DomainAndProjectUserTests(object):
    """Domain and project user tests.

    Domain and project users should not be able to manage application
    credentials other then their own.
    """

    def test_user_cannot_list_application_credentials(self):
        # create a couple of application credentials
        self._create_application_credential()
        self._create_application_credential()

        with self.test_client() as c:
            c.get('/v3/users/%s/application_credentials' % (
                  self.app_cred_user_id),
                  expected_status_code=http.client.FORBIDDEN,
                  headers=self.headers)

    def test_user_cannot_get_application_credential(self):
        app_cred = self._create_application_credential()

        with self.test_client() as c:
            c.get('/v3/users/%s/application_credentials/%s' % (
                  self.app_cred_user_id,
                  app_cred['id']),
                  expected_status_code=http.client.FORBIDDEN,
                  headers=self.headers)

    def test_user_cannot_lookup_application_credential(self):
        app_cred = self._create_application_credential()

        with self.test_client() as c:
            c.get('/v3/users/%s/application_credentials?name=%s' % (
                  self.app_cred_user_id,
                  app_cred['name']),
                  expected_status_code=http.client.FORBIDDEN,
                  headers=self.headers)

    def test_user_cannot_delete_application_credential(self):
        app_cred = self._create_application_credential()

        with self.test_client() as c:
            c.delete(
                '/v3/users/%s/application_credentials/%s' % (
                    self.app_cred_user_id,
                    app_cred['id']),
                expected_status_code=http.client.FORBIDDEN,
                headers=self.headers)

    def test_user_cannot_lookup_non_existent_application_credential(self):
        with self.test_client() as c:
            c.get('/v3/users/%s/application_credentials?name=%s' % (
                  self.app_cred_user_id,
                  uuid.uuid4().hex),
                  expected_status_code=http.client.FORBIDDEN,
                  headers=self.headers)

    def test_user_cannot_create_app_credential_for_another_user(self):
        # create another user
        another_user = unit.new_user_ref(
            domain_id=CONF.identity.default_domain_id
        )
        another_user_id = PROVIDERS.identity_api.create_user(
            another_user
        )['id']

        app_cred_body = {
            'application_credential': unit.new_application_credential_ref(
                roles=[{'id': self.bootstrapper.member_role_id}])
        }

        with self.test_client() as c:
            c.post(
                '/v3/users/%s/application_credentials' % another_user_id,
                json=app_cred_body,
                expected_status_code=http.client.FORBIDDEN,
                headers=self.headers)


class _SystemUserAndOwnerTests(object):
    """Common default functionality for all system users and owner."""

    def test_user_can_list_application_credentials(self):
        # create a couple of application credentials
        self._create_application_credential()
        self._create_application_credential()

        with self.test_client() as c:
            r = c.get(
                '/v3/users/%s/application_credentials' % (
                    self.app_cred_user_id),
                headers=self.headers)
            self.assertEqual(2, len(r.json['application_credentials']))

    def test_user_can_get_application_credential(self):
        app_cred = self._create_application_credential()

        with self.test_client() as c:
            r = c.get(
                '/v3/users/%s/application_credentials/%s' % (
                    self.app_cred_user_id,
                    app_cred['id']),
                headers=self.headers)
            actual_app_cred = r.json['application_credential']
            self.assertEqual(app_cred['id'], actual_app_cred['id'])

    def test_user_can_lookup_application_credential(self):
        app_cred = self._create_application_credential()

        with self.test_client() as c:
            r = c.get(
                '/v3/users/%s/application_credentials?name=%s' % (
                    self.app_cred_user_id,
                    app_cred['name']),
                headers=self.headers)
            self.assertEqual(1, len(r.json['application_credentials']))
            actual_app_cred = r.json['application_credentials'][0]
            self.assertEqual(app_cred['id'], actual_app_cred['id'])

    def _test_delete_application_credential(
            self,
            expected_status_code=http.client.NO_CONTENT):
        app_cred = self._create_application_credential()

        with self.test_client() as c:
            c.delete(
                '/v3/users/%s/application_credentials/%s' % (
                    self.app_cred_user_id,
                    app_cred['id']),
                expected_status_code=expected_status_code,
                headers=self.headers)

    def test_user_cannot_create_app_credential_for_another_user(self):
        # create another user
        another_user = unit.new_user_ref(
            domain_id=CONF.identity.default_domain_id
        )
        another_user_id = PROVIDERS.identity_api.create_user(
            another_user
        )['id']

        app_cred_body = {
            'application_credential': unit.new_application_credential_ref(
                roles=[{'id': self.bootstrapper.member_role_id}])
        }

        with self.test_client() as c:
            c.post(
                '/v3/users/%s/application_credentials' % another_user_id,
                json=app_cred_body,
                expected_status_code=http.client.FORBIDDEN,
                headers=self.headers)


class SystemReaderTests(_TestAppCredBase,
                        common_auth.AuthTestMixin,
                        _SystemUserAndOwnerTests):

    def setUp(self):
        super(SystemReaderTests, self).setUp()
        self.loadapp()
        self.useFixture(ksfixtures.Policy(self.config_fixture))
        self.config_fixture.config(group='oslo_policy', enforce_scope=True)

        system_reader = unit.new_user_ref(
            domain_id=CONF.identity.default_domain_id
        )
        self.user_id = PROVIDERS.identity_api.create_user(
            system_reader
        )['id']
        PROVIDERS.assignment_api.create_system_grant_for_user(
            self.user_id, self.bootstrapper.reader_role_id
        )

        auth = self.build_authentication_request(
            user_id=self.user_id, password=system_reader['password'],
            system=True
        )

        # Grab a token using the persona we're testing and prepare headers
        # for requests we'll be making in the tests.
        with self.test_client() as c:
            r = c.post('/v3/auth/tokens', json=auth)
            self.token_id = r.headers['X-Subject-Token']
            self.headers = {'X-Auth-Token': self.token_id}

    def test_system_reader_cannot_delete_application_credential_for_user(self):
        self._test_delete_application_credential(
            expected_status_code=http.client.FORBIDDEN)


class SystemMemberTests(_TestAppCredBase,
                        common_auth.AuthTestMixin,
                        _SystemUserAndOwnerTests):

    def setUp(self):
        super(SystemMemberTests, self).setUp()
        self.loadapp()
        self.useFixture(ksfixtures.Policy(self.config_fixture))
        self.config_fixture.config(group='oslo_policy', enforce_scope=True)

        system_member = unit.new_user_ref(
            domain_id=CONF.identity.default_domain_id
        )
        self.user_id = PROVIDERS.identity_api.create_user(
            system_member
        )['id']
        PROVIDERS.assignment_api.create_system_grant_for_user(
            self.user_id, self.bootstrapper.member_role_id
        )

        auth = self.build_authentication_request(
            user_id=self.user_id, password=system_member['password'],
            system=True
        )

        # Grab a token using the persona we're testing and prepare headers
        # for requests we'll be making in the tests.
        with self.test_client() as c:
            r = c.post('/v3/auth/tokens', json=auth)
            self.token_id = r.headers['X-Subject-Token']
            self.headers = {'X-Auth-Token': self.token_id}

    def test_system_reader_cannot_delete_application_credential_for_user(self):
        self._test_delete_application_credential(
            expected_status_code=http.client.FORBIDDEN)


class SystemAdminTests(_TestAppCredBase,
                       common_auth.AuthTestMixin,
                       _SystemUserAndOwnerTests):

    def setUp(self):
        super(SystemAdminTests, self).setUp()
        self.loadapp()
        self.useFixture(ksfixtures.Policy(self.config_fixture))
        self.config_fixture.config(group='oslo_policy', enforce_scope=True)

        self.user_id = self.bootstrapper.admin_user_id
        auth = self.build_authentication_request(
            user_id=self.user_id,
            password=self.bootstrapper.admin_password,
            system=True
        )

        # Grab a token using the persona we're testing and prepare headers
        # for requests we'll be making in the tests.
        with self.test_client() as c:
            r = c.post('/v3/auth/tokens', json=auth)
            self.token_id = r.headers['X-Subject-Token']
            self.headers = {'X-Auth-Token': self.token_id}

    def test_system_admin_can_delete_application_credential_for_user(self):
        self._test_delete_application_credential()


class OwnerTests(_TestAppCredBase,
                 common_auth.AuthTestMixin,
                 _SystemUserAndOwnerTests):

    def setUp(self):
        super(OwnerTests, self).setUp()
        self.loadapp()

        self.policy_file = self.useFixture(temporaryfile.SecureTempFile())
        self.policy_file_name = self.policy_file.file_name
        self.useFixture(
            ksfixtures.Policy(
                self.config_fixture, policy_file=self.policy_file_name
            )
        )

        self._override_policy()
        self.config_fixture.config(group='oslo_policy', enforce_scope=True)

        # in this case app_cred_user_id and user_id are the same since we
        # are testing the owner
        self.user_id = self.app_cred_user_id
        auth = self.build_authentication_request(
            user_id=self.user_id,
            password=self.app_cred_user_password,
            project_id=self.app_cred_project_id
        )

        # Grab a token using the persona we're testing and prepare headers
        # for requests we'll be making in the tests.
        with self.test_client() as c:
            r = c.post('/v3/auth/tokens', json=auth)
            self.token_id = r.headers['X-Subject-Token']
            self.headers = {'X-Auth-Token': self.token_id}

    def test_create_application_credential_by_owner(self):
        app_cred_body = {
            'application_credential': unit.new_application_credential_ref()
        }

        with self.test_client() as c:
            c.post(
                '/v3/users/%s/application_credentials' % self.user_id,
                json=app_cred_body,
                expected_status_code=http.client.CREATED,
                headers=self.headers)

    def test_owner_can_delete_application_credential(self):
        self._test_delete_application_credential()


class DomainAdminTests(_TestAppCredBase,
                       common_auth.AuthTestMixin,
                       _DomainAndProjectUserTests):

    def setUp(self):
        super(DomainAdminTests, self).setUp()
        self.loadapp()

        self.policy_file = self.useFixture(temporaryfile.SecureTempFile())
        self.policy_file_name = self.policy_file.file_name
        self.useFixture(
            ksfixtures.Policy(
                self.config_fixture, policy_file=self.policy_file_name
            )
        )

        self._override_policy()
        self.config_fixture.config(group='oslo_policy', enforce_scope=True)

        domain_admin = unit.new_user_ref(
            domain_id=CONF.identity.default_domain_id)
        self.user_id = PROVIDERS.identity_api.create_user(domain_admin)['id']
        PROVIDERS.assignment_api.create_grant(
            self.bootstrapper.admin_role_id, user_id=self.user_id,
            domain_id=CONF.identity.default_domain_id
        )

        auth = self.build_authentication_request(
            user_id=self.user_id, password=domain_admin['password'],
            domain_id=CONF.identity.default_domain_id
        )

        # Grab a token using the persona we're testing and prepare headers
        # for requests we'll be making in the tests.
        with self.test_client() as c:
            r = c.post('/v3/auth/tokens', json=auth)
            self.token_id = r.headers['X-Subject-Token']
            self.headers = {'X-Auth-Token': self.token_id}


class DomainReaderTests(_TestAppCredBase,
                        common_auth.AuthTestMixin,
                        _DomainAndProjectUserTests):

    def setUp(self):
        super(DomainReaderTests, self).setUp()
        self.loadapp()

        self.policy_file = self.useFixture(temporaryfile.SecureTempFile())
        self.policy_file_name = self.policy_file.file_name
        self.useFixture(
            ksfixtures.Policy(
                self.config_fixture, policy_file=self.policy_file_name
            )
        )

        self._override_policy()
        self.config_fixture.config(group='oslo_policy', enforce_scope=True)

        domain_admin = unit.new_user_ref(
            domain_id=CONF.identity.default_domain_id)
        self.user_id = PROVIDERS.identity_api.create_user(domain_admin)['id']
        PROVIDERS.assignment_api.create_grant(
            self.bootstrapper.reader_role_id, user_id=self.user_id,
            domain_id=CONF.identity.default_domain_id
        )

        auth = self.build_authentication_request(
            user_id=self.user_id, password=domain_admin['password'],
            domain_id=CONF.identity.default_domain_id
        )

        # Grab a token using the persona we're testing and prepare headers
        # for requests we'll be making in the tests.
        with self.test_client() as c:
            r = c.post('/v3/auth/tokens', json=auth)
            self.token_id = r.headers['X-Subject-Token']
            self.headers = {'X-Auth-Token': self.token_id}


class DomainMemberTests(_TestAppCredBase,
                        common_auth.AuthTestMixin,
                        _DomainAndProjectUserTests):

    def setUp(self):
        super(DomainMemberTests, self).setUp()
        self.loadapp()

        self.policy_file = self.useFixture(temporaryfile.SecureTempFile())
        self.policy_file_name = self.policy_file.file_name
        self.useFixture(
            ksfixtures.Policy(
                self.config_fixture, policy_file=self.policy_file_name
            )
        )

        self._override_policy()
        self.config_fixture.config(group='oslo_policy', enforce_scope=True)

        domain_admin = unit.new_user_ref(
            domain_id=CONF.identity.default_domain_id)
        self.user_id = PROVIDERS.identity_api.create_user(domain_admin)['id']
        PROVIDERS.assignment_api.create_grant(
            self.bootstrapper.member_role_id, user_id=self.user_id,
            domain_id=CONF.identity.default_domain_id
        )

        auth = self.build_authentication_request(
            user_id=self.user_id, password=domain_admin['password'],
            domain_id=CONF.identity.default_domain_id
        )

        # Grab a token using the persona we're testing and prepare headers
        # for requests we'll be making in the tests.
        with self.test_client() as c:
            r = c.post('/v3/auth/tokens', json=auth)
            self.token_id = r.headers['X-Subject-Token']
            self.headers = {'X-Auth-Token': self.token_id}


class ProjectAdminTests(_TestAppCredBase,
                        common_auth.AuthTestMixin,
                        _DomainAndProjectUserTests):

    def setUp(self):
        super(ProjectAdminTests, self).setUp()
        self.loadapp()

        self.policy_file = self.useFixture(temporaryfile.SecureTempFile())
        self.policy_file_name = self.policy_file.file_name
        self.useFixture(
            ksfixtures.Policy(
                self.config_fixture, policy_file=self.policy_file_name
            )
        )

        self._override_policy()
        self.config_fixture.config(group='oslo_policy', enforce_scope=True)

        project_admin = unit.new_user_ref(
            domain_id=CONF.identity.default_domain_id)
        self.user_id = PROVIDERS.identity_api.create_user(project_admin)['id']
        # even project admin of project where the app credential
        # is intended for cannot perform app credential operations
        PROVIDERS.assignment_api.create_grant(
            self.bootstrapper.admin_role_id,
            user_id=self.user_id,
            project_id=self.app_cred_project_id
        )
        auth = self.build_authentication_request(
            user_id=self.user_id, password=project_admin['password'],
            project_id=self.app_cred_project_id
        )

        # Grab a token using the persona we're testing and prepare headers
        # for requests we'll be making in the tests.
        with self.test_client() as c:
            r = c.post('/v3/auth/tokens', json=auth)
            self.token_id = r.headers['X-Subject-Token']
            self.headers = {'X-Auth-Token': self.token_id}


class ProjectReaderTests(_TestAppCredBase,
                         common_auth.AuthTestMixin,
                         _DomainAndProjectUserTests):

    def setUp(self):
        super(ProjectReaderTests, self).setUp()
        self.loadapp()

        self.policy_file = self.useFixture(temporaryfile.SecureTempFile())
        self.policy_file_name = self.policy_file.file_name
        self.useFixture(
            ksfixtures.Policy(
                self.config_fixture, policy_file=self.policy_file_name
            )
        )

        self._override_policy()
        self.config_fixture.config(group='oslo_policy', enforce_scope=True)

        project_admin = unit.new_user_ref(
            domain_id=CONF.identity.default_domain_id)
        self.user_id = PROVIDERS.identity_api.create_user(project_admin)['id']
        # even project admin of project where the app credential
        # is intended for cannot perform app credential operations
        PROVIDERS.assignment_api.create_grant(
            self.bootstrapper.reader_role_id,
            user_id=self.user_id,
            project_id=self.app_cred_project_id
        )
        auth = self.build_authentication_request(
            user_id=self.user_id, password=project_admin['password'],
            project_id=self.app_cred_project_id
        )

        # Grab a token using the persona we're testing and prepare headers
        # for requests we'll be making in the tests.
        with self.test_client() as c:
            r = c.post('/v3/auth/tokens', json=auth)
            self.token_id = r.headers['X-Subject-Token']
            self.headers = {'X-Auth-Token': self.token_id}


class ProjectMemberTests(_TestAppCredBase,
                         common_auth.AuthTestMixin,
                         _DomainAndProjectUserTests):

    def setUp(self):
        super(ProjectMemberTests, self).setUp()
        self.loadapp()

        self.policy_file = self.useFixture(temporaryfile.SecureTempFile())
        self.policy_file_name = self.policy_file.file_name
        self.useFixture(
            ksfixtures.Policy(
                self.config_fixture, policy_file=self.policy_file_name
            )
        )

        self._override_policy()
        self.config_fixture.config(group='oslo_policy', enforce_scope=True)

        project_admin = unit.new_user_ref(
            domain_id=CONF.identity.default_domain_id)
        self.user_id = PROVIDERS.identity_api.create_user(project_admin)['id']
        # even project admin of project where the app credential
        # is intended for cannot perform app credential operations
        PROVIDERS.assignment_api.create_grant(
            self.bootstrapper.member_role_id,
            user_id=self.user_id,
            project_id=self.app_cred_project_id
        )
        auth = self.build_authentication_request(
            user_id=self.user_id, password=project_admin['password'],
            project_id=self.app_cred_project_id
        )

        # Grab a token using the persona we're testing and prepare headers
        # for requests we'll be making in the tests.
        with self.test_client() as c:
            r = c.post('/v3/auth/tokens', json=auth)
            self.token_id = r.headers['X-Subject-Token']
            self.headers = {'X-Auth-Token': self.token_id}