summaryrefslogtreecommitdiffstats
path: root/src/pybind/mgr/dashboard/tests/test_ceph_users.py
blob: 9e0ee525b5ca0e73ef4b91cefc735fd2c441134d (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
import unittest.mock as mock

from jsonschema import validate

from ..controllers.ceph_users import CephUser, create_form
from ..tests import ControllerTestCase

auth_dump_mock = {"auth_dump": [
    {"entity": "client.admin",
     "key": "RANDOMFi7NwMARAA7RdGqdav+BEEFDEAD0x00g==",
     "caps": {"mds": "allow *",
              "mgr": "allow *",
              "mon": "allow *",
              "osd": "allow *"}},
    {"entity": "client.bootstrap-mds",
     "key": "2RANDOMi7NwMARAA7RdGqdav+BEEFDEAD0x00g==",
     "caps": {"mds": "allow *",
              "osd": "allow *"}}
]}


class CephUsersControllerTestCase(ControllerTestCase):
    @classmethod
    def setup_server(cls):
        cls.setup_crud_controllers(CephUser)

    @mock.patch('dashboard.services.ceph_service.CephService.send_command')
    def test_get_all(self, send_command):
        send_command.return_value = auth_dump_mock
        self._get('/api/cluster/user')
        self.assertStatus(200)
        self.assertJsonBody([
            {"entity": "client.admin",
             "caps": {"mds": "allow *",
                      "mgr": "allow *",
                      "mon": "allow *",
                      "osd": "allow *"},
             "key": "***********"
             },
            {"entity": "client.bootstrap-mds",
             "caps": {"mds": "allow *",
                      "osd": "allow *"},
             "key": "***********"
             }
        ])

    def test_create_form(self):
        form_dict = create_form.to_dict()
        schema = {'schema': form_dict['control_schema'], 'layout': form_dict['ui_schema']}
        validate(instance={'user_entity': 'foo',
                           'capabilities': [{"entity": "mgr", "cap": "allow *"}]},
                 schema=schema['schema'])