]>
git.proxmox.com Git - ceph.git/blob - ceph/src/pybind/mgr/dashboard/tests/test_home.py
1 from __future__
import absolute_import
9 import unittest
.mock
as mock
11 from . import ControllerTestCase
, FakeFsMixin
14 from ..controllers
.home
import HomeController
, LanguageMixin
16 logger
= logging
.getLogger()
19 class HomeTest(ControllerTestCase
, FakeFsMixin
):
21 def setup_server(cls
):
22 frontend_path
= mgr
.get_frontend_path()
24 cls
.fs
.create_dir(frontend_path
)
26 os
.path
.join(frontend_path
, '..', 'package.json'),
27 contents
='{"config":{"locale": "en-US"}}')
28 with mock
.patch(cls
.builtins_open
, new
=cls
.f_open
),\
29 mock
.patch('os.listdir', new
=cls
.f_os
.listdir
):
30 lang
= LanguageMixin()
32 os
.path
.join(lang
.DEFAULT_LANGUAGE_PATH
, 'index.html'),
33 contents
='<!doctype html><html lang="en"><body></body></html>')
34 cls
.setup_controllers([HomeController
])
36 @mock.patch(FakeFsMixin
.builtins_open
, new
=FakeFsMixin
.f_open
)
37 @mock.patch('os.stat', new
=FakeFsMixin
.f_os
.stat
)
38 @mock.patch('os.listdir', new
=FakeFsMixin
.f_os
.listdir
)
39 def test_home_default_lang(self
):
41 self
.assertStatus(200)
42 logger
.info(self
.body
)
43 self
.assertIn('<html lang="en">', self
.body
.decode('utf-8'))
45 @mock.patch(FakeFsMixin
.builtins_open
, new
=FakeFsMixin
.f_open
)
46 @mock.patch('os.stat', new
=FakeFsMixin
.f_os
.stat
)
47 @mock.patch('os.listdir', new
=FakeFsMixin
.f_os
.listdir
)
48 def test_home_uplevel_check(self
):
49 self
._get
('/../../../../../../etc/shadow')
50 self
.assertStatus(403)
52 @mock.patch(FakeFsMixin
.builtins_open
, new
=FakeFsMixin
.f_open
)
53 @mock.patch('os.stat', new
=FakeFsMixin
.f_os
.stat
)
54 @mock.patch('os.listdir', new
=FakeFsMixin
.f_os
.listdir
)
55 def test_home_en_us(self
):
56 self
._get
('/', headers
=[('Accept-Language', 'en-US')])
57 self
.assertStatus(200)
58 logger
.info(self
.body
)
59 self
.assertIn('<html lang="en">', self
.body
.decode('utf-8'))
61 @mock.patch(FakeFsMixin
.builtins_open
, new
=FakeFsMixin
.f_open
)
62 @mock.patch('os.stat', new
=FakeFsMixin
.f_os
.stat
)
63 @mock.patch('os.listdir', new
=FakeFsMixin
.f_os
.listdir
)
64 def test_home_non_supported_lang(self
):
65 self
._get
('/', headers
=[('Accept-Language', 'NO-NO')])
66 self
.assertStatus(200)
67 logger
.info(self
.body
)
68 self
.assertIn('<html lang="en">', self
.body
.decode('utf-8'))