Browse Source

Merge "Add tests for system member for trusts"

tags/16.0.0.0rc1
Zuul 1 month ago
parent
commit
114f23195b
1 changed files with 54 additions and 19 deletions
  1. 54
    19
      keystone/tests/unit/protection/v3/test_trusts.py

+ 54
- 19
keystone/tests/unit/protection/v3/test_trusts.py View File

@@ -284,7 +284,34 @@ class _SystemUserTests(object):
284 284
             )
285 285
 
286 286
 
287
-class SystemReaderTests(TrustTests, _SystemUserTests):
287
+class _SystemReaderMemberTests(_SystemUserTests):
288
+    """Tests for system readers and members."""
289
+
290
+    def test_user_cannot_create_trust(self):
291
+        json = {'trust': self.trust_data['trust']}
292
+        json['trust']['roles'] = self.trust_data['roles']
293
+
294
+        with self.test_client() as c:
295
+            c.post(
296
+                '/v3/OS-TRUST/trusts',
297
+                json=json,
298
+                headers=self.headers,
299
+                expected_status_code=http_client.FORBIDDEN
300
+            )
301
+
302
+    def test_user_cannot_delete_trust(self):
303
+        ref = PROVIDERS.trust_api.create_trust(
304
+            self.trust_id, **self.trust_data)
305
+
306
+        with self.test_client() as c:
307
+            c.delete(
308
+                '/v3/OS-TRUST/trusts/%s' % ref['id'],
309
+                headers=self.headers,
310
+                expected_status_code=http_client.FORBIDDEN
311
+            )
312
+
313
+
314
+class SystemReaderTests(TrustTests, _SystemReaderMemberTests):
288 315
     """Tests for system reader users."""
289 316
 
290 317
     def setUp(self):
@@ -314,28 +341,36 @@ class SystemReaderTests(TrustTests, _SystemUserTests):
314 341
             self.token_id = r.headers['X-Subject-Token']
315 342
             self.headers = {'X-Auth-Token': self.token_id}
316 343
 
317
-    def test_user_cannot_create_trust(self):
318
-        json = {'trust': self.trust_data['trust']}
319
-        json['trust']['roles'] = self.trust_data['roles']
320 344
 
321
-        with self.test_client() as c:
322
-            c.post(
323
-                '/v3/OS-TRUST/trusts',
324
-                json=json,
325
-                headers=self.headers,
326
-                expected_status_code=http_client.FORBIDDEN
327
-            )
345
+class SystemMemberTests(TrustTests, _SystemReaderMemberTests):
346
+    """Tests for system member users."""
328 347
 
329
-    def test_user_cannot_delete_trust(self):
330
-        ref = PROVIDERS.trust_api.create_trust(
331
-            self.trust_id, **self.trust_data)
348
+    def setUp(self):
349
+        super(SystemMemberTests, self).setUp()
350
+        self.config_fixture.config(group='oslo_policy', enforce_scope=True)
351
+
352
+        system_member = unit.new_user_ref(
353
+            domain_id=CONF.identity.default_domain_id
354
+        )
355
+        self.user_id = PROVIDERS.identity_api.create_user(
356
+            system_member
357
+        )['id']
358
+        PROVIDERS.assignment_api.create_system_grant_for_user(
359
+            self.user_id, self.bootstrapper.member_role_id
360
+        )
332 361
 
362
+        auth = self.build_authentication_request(
363
+            user_id=self.user_id,
364
+            password=system_member['password'],
365
+            system=True
366
+        )
367
+
368
+        # Grab a token using the persona we're testing and prepare headers
369
+        # for requests we'll be making in the tests.
333 370
         with self.test_client() as c:
334
-            c.delete(
335
-                '/v3/OS-TRUST/trusts/%s' % ref['id'],
336
-                headers=self.headers,
337
-                expected_status_code=http_client.FORBIDDEN
338
-            )
371
+            r = c.post('/v3/auth/tokens', json=auth)
372
+            self.token_id = r.headers['X-Subject-Token']
373
+            self.headers = {'X-Auth-Token': self.token_id}
339 374
 
340 375
 
341 376
 class SystemAdminTests(TrustTests, _AdminTestsMixin, _SystemUserTests):

Loading…
Cancel
Save