File: test_federation.py

package info (click to toggle)
python-keystoneclient 1%3A3.17.0-2
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 2,416 kB
  • sloc: python: 21,389; sh: 192; xml: 149; makefile: 105
file content (106 lines) | stat: -rw-r--r-- 4,124 bytes parent folder | download | duplicates (5)
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
# 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 keystoneauth1.exceptions import http

from keystoneclient.tests.functional import base


class TestIdentityProviders(base.V3ClientTestCase):

    def test_idp_create(self):
        idp_id = uuid.uuid4().hex
        # Create an identity provider just passing an ID
        idp = self.client.federation.identity_providers.create(id=idp_id)
        self.addCleanup(
            self.client.federation.identity_providers.delete, idp_id)

        self.assertEqual(idp_id, idp.id)
        self.assertEqual([], idp.remote_ids)
        self.assertFalse(idp.enabled)

    def test_idp_create_enabled_true(self):
        # Create an enabled identity provider
        idp_id = uuid.uuid4().hex
        idp = self.client.federation.identity_providers.create(
            id=idp_id, enabled=True)
        self.addCleanup(
            self.client.federation.identity_providers.delete, idp_id)

        self.assertEqual(idp_id, idp.id)
        self.assertEqual([], idp.remote_ids)
        self.assertTrue(idp.enabled)

    def test_idp_create_with_remote_ids(self):
        # Create an enabled identity provider with remote IDs
        idp_id = uuid.uuid4().hex
        remote_ids = [uuid.uuid4().hex, uuid.uuid4().hex]
        idp = self.client.federation.identity_providers.create(
            id=idp_id, enabled=True, remote_ids=remote_ids)
        self.addCleanup(
            self.client.federation.identity_providers.delete, idp_id)

        self.assertEqual(idp_id, idp.id)
        self.assertIn(remote_ids[0], idp.remote_ids)
        self.assertIn(remote_ids[1], idp.remote_ids)
        self.assertTrue(idp.enabled)

    def test_idp_list(self):
        idp_ids = []
        for _ in range(3):
            idp_id = uuid.uuid4().hex
            self.client.federation.identity_providers.create(id=idp_id)
            self.addCleanup(
                self.client.federation.identity_providers.delete, idp_id)
            idp_ids.append(idp_id)

        idp_list = self.client.federation.identity_providers.list()
        fetched_ids = [fetched_idp.id for fetched_idp in idp_list]
        for idp_id in idp_ids:
            self.assertIn(idp_id, fetched_ids)

    def test_idp_get(self):
        idp_id = uuid.uuid4().hex
        remote_ids = [uuid.uuid4().hex, uuid.uuid4().hex]
        idp_create = self.client.federation.identity_providers.create(
            id=idp_id, enabled=True, remote_ids=remote_ids)
        self.addCleanup(
            self.client.federation.identity_providers.delete, idp_id)

        idp_get = self.client.federation.identity_providers.get(idp_id)
        self.assertEqual(idp_create.id, idp_get.id)
        self.assertEqual(idp_create.enabled, idp_get.enabled)
        self.assertIn(idp_create.remote_ids[0], idp_get.remote_ids)
        self.assertIn(idp_create.remote_ids[1], idp_get.remote_ids)

    def test_idp_delete(self):
        idp_id = uuid.uuid4().hex
        self.client.federation.identity_providers.create(id=idp_id)

        # Get should not raise an error
        self.client.federation.identity_providers.get(idp_id)

        # Delete it
        self.client.federation.identity_providers.delete(idp_id)

        # Now get should raise an error
        self.assertRaises(
            http.NotFound,
            self.client.federation.identity_providers.get,
            idp_id)

        # Should not be present in the identity provider list
        idp_list = self.client.federation.identity_providers.list()
        fetched_ids = [fetched_idp.id for fetched_idp in idp_list]
        self.assertNotIn(idp_id, fetched_ids)