xref: /unit/test/test_static.py (revision 2109:8a068eaba1e7)
11184Szelenkov@nginx.comimport os
21986Szelenkov@nginx.comimport shutil
31204Szelenkov@nginx.comimport socket
41477Szelenkov@nginx.com
51635Szelenkov@nginx.comimport pytest
62066Szelenkov@nginx.comfrom conftest import unit_run
72066Szelenkov@nginx.comfrom conftest import unit_stop
81184Szelenkov@nginx.comfrom unit.applications.proto import TestApplicationProto
91730Szelenkov@nginx.comfrom unit.option import option
101735Szelenkov@nginx.comfrom unit.utils import waitforfiles
111184Szelenkov@nginx.com
121184Szelenkov@nginx.com
131184Szelenkov@nginx.comclass TestStatic(TestApplicationProto):
141184Szelenkov@nginx.com    prerequisites = {}
151184Szelenkov@nginx.com
161596Szelenkov@nginx.com    def setup_method(self):
171654Szelenkov@nginx.com        os.makedirs(option.temp_dir + '/assets/dir')
181654Szelenkov@nginx.com        with open(option.temp_dir + '/assets/index.html', 'w') as index, open(
191654Szelenkov@nginx.com            option.temp_dir + '/assets/README', 'w'
201654Szelenkov@nginx.com        ) as readme, open(
211654Szelenkov@nginx.com            option.temp_dir + '/assets/log.log', 'w'
221654Szelenkov@nginx.com        ) as log, open(
231654Szelenkov@nginx.com            option.temp_dir + '/assets/dir/file', 'w'
241596Szelenkov@nginx.com        ) as file:
251184Szelenkov@nginx.com            index.write('0123456789')
261184Szelenkov@nginx.com            readme.write('readme')
271184Szelenkov@nginx.com            log.write('[debug]')
281184Szelenkov@nginx.com            file.write('blah')
291184Szelenkov@nginx.com
301184Szelenkov@nginx.com        self._load_conf(
311184Szelenkov@nginx.com            {
321184Szelenkov@nginx.com                "listeners": {"*:7080": {"pass": "routes"}},
331960Sz.hong@f5.com                "routes": [
341960Sz.hong@f5.com                    {"action": {"share": option.temp_dir + "/assets$uri"}}
351960Sz.hong@f5.com                ],
361184Szelenkov@nginx.com                "settings": {
371184Szelenkov@nginx.com                    "http": {
381184Szelenkov@nginx.com                        "static": {
391184Szelenkov@nginx.com                            "mime_types": {"text/plain": [".log", "README"]}
401184Szelenkov@nginx.com                        }
411184Szelenkov@nginx.com                    }
421184Szelenkov@nginx.com                },
431184Szelenkov@nginx.com            }
441184Szelenkov@nginx.com        )
451184Szelenkov@nginx.com
461986Szelenkov@nginx.com    def test_static_migration(self, skip_fds_check, temp_dir):
471986Szelenkov@nginx.com        skip_fds_check(True, True, True)
481986Szelenkov@nginx.com
491986Szelenkov@nginx.com        def set_conf_version(path, version):
501986Szelenkov@nginx.com            with open(path, 'w+') as f:
511986Szelenkov@nginx.com                f.write(str(version))
521986Szelenkov@nginx.com
531986Szelenkov@nginx.com        with open(temp_dir + '/state/version', 'r') as f:
541986Szelenkov@nginx.com            assert int(f.read().rstrip()) > 12500, 'current version'
551986Szelenkov@nginx.com
561986Szelenkov@nginx.com        assert 'success' in self.conf(
571986Szelenkov@nginx.com            {"share": temp_dir + "/assets"}, 'routes/0/action'
581986Szelenkov@nginx.com        ), 'configure migration 12500'
591986Szelenkov@nginx.com
601986Szelenkov@nginx.com        shutil.copytree(temp_dir + '/state', temp_dir + '/state_copy_12500')
611986Szelenkov@nginx.com        set_conf_version(temp_dir + '/state_copy_12500/version', 12500)
621986Szelenkov@nginx.com
631986Szelenkov@nginx.com        assert 'success' in self.conf(
641986Szelenkov@nginx.com            {"share": temp_dir + "/assets$uri"}, 'routes/0/action'
651986Szelenkov@nginx.com        ), 'configure migration 12600'
661986Szelenkov@nginx.com        shutil.copytree(temp_dir + '/state', temp_dir + '/state_copy_12600')
671986Szelenkov@nginx.com        set_conf_version(temp_dir + '/state_copy_12600/version', 12600)
681986Szelenkov@nginx.com
691986Szelenkov@nginx.com        assert 'success' in self.conf(
701986Szelenkov@nginx.com            {"share": temp_dir + "/assets"}, 'routes/0/action'
711986Szelenkov@nginx.com        ), 'configure migration no version'
721986Szelenkov@nginx.com        shutil.copytree(
731986Szelenkov@nginx.com            temp_dir + '/state', temp_dir + '/state_copy_no_version'
741986Szelenkov@nginx.com        )
751986Szelenkov@nginx.com        os.remove(temp_dir + '/state_copy_no_version/version')
761986Szelenkov@nginx.com
771986Szelenkov@nginx.com        unit_stop()
781986Szelenkov@nginx.com        unit_run(temp_dir + '/state_copy_12500')
791986Szelenkov@nginx.com        assert self.get(url='/')['body'] == '0123456789', 'before 1.26.0'
801986Szelenkov@nginx.com
811986Szelenkov@nginx.com        unit_stop()
821986Szelenkov@nginx.com        unit_run(temp_dir + '/state_copy_12600')
831986Szelenkov@nginx.com        assert self.get(url='/')['body'] == '0123456789', 'after 1.26.0'
841986Szelenkov@nginx.com
851986Szelenkov@nginx.com        unit_stop()
861986Szelenkov@nginx.com        unit_run(temp_dir + '/state_copy_no_version')
871986Szelenkov@nginx.com        assert self.get(url='/')['body'] == '0123456789', 'before 1.26.0 2'
881986Szelenkov@nginx.com
891184Szelenkov@nginx.com    def test_static_index(self):
90*2109Salx.manpages@gmail.com        def set_index(index):
91*2109Salx.manpages@gmail.com            assert 'success' in self.conf(
92*2109Salx.manpages@gmail.com                {"share": option.temp_dir + "/assets$uri", "index": index},
93*2109Salx.manpages@gmail.com                'routes/0/action',
94*2109Salx.manpages@gmail.com            ), 'configure index'
95*2109Salx.manpages@gmail.com
96*2109Salx.manpages@gmail.com        set_index('README')
97*2109Salx.manpages@gmail.com        assert self.get()['body'] == 'readme', 'index'
98*2109Salx.manpages@gmail.com
99*2109Salx.manpages@gmail.com        self.conf_delete('routes/0/action/index')
100*2109Salx.manpages@gmail.com        assert self.get()['body'] == '0123456789', 'delete index'
101*2109Salx.manpages@gmail.com
102*2109Salx.manpages@gmail.com        set_index('')
103*2109Salx.manpages@gmail.com        assert self.get()['status'] == 404, 'index empty'
104*2109Salx.manpages@gmail.com
105*2109Salx.manpages@gmail.com    def test_static_index_default(self):
1061596Szelenkov@nginx.com        assert self.get(url='/index.html')['body'] == '0123456789', 'index'
1071596Szelenkov@nginx.com        assert self.get(url='/')['body'] == '0123456789', 'index 2'
1081596Szelenkov@nginx.com        assert self.get(url='//')['body'] == '0123456789', 'index 3'
1091596Szelenkov@nginx.com        assert self.get(url='/.')['body'] == '0123456789', 'index 4'
1101596Szelenkov@nginx.com        assert self.get(url='/./')['body'] == '0123456789', 'index 5'
1111596Szelenkov@nginx.com        assert self.get(url='/?blah')['body'] == '0123456789', 'index vars'
1121596Szelenkov@nginx.com        assert self.get(url='/#blah')['body'] == '0123456789', 'index anchor'
1131596Szelenkov@nginx.com        assert self.get(url='/dir/')['status'] == 404, 'index not found'
1141184Szelenkov@nginx.com
1151184Szelenkov@nginx.com        resp = self.get(url='/index.html/')
1161596Szelenkov@nginx.com        assert resp['status'] == 404, 'index not found 2 status'
1171596Szelenkov@nginx.com        assert (
1181596Szelenkov@nginx.com            resp['headers']['Content-Type'] == 'text/html'
1191596Szelenkov@nginx.com        ), 'index not found 2 Content-Type'
1201184Szelenkov@nginx.com
121*2109Salx.manpages@gmail.com    def test_static_index_invalid(self, skip_alert):
122*2109Salx.manpages@gmail.com        skip_alert(r'failed to apply new conf')
123*2109Salx.manpages@gmail.com
124*2109Salx.manpages@gmail.com        def check_index(index):
125*2109Salx.manpages@gmail.com            assert 'error' in self.conf(
126*2109Salx.manpages@gmail.com                {"share": option.temp_dir + "/assets$uri", "index": index},
127*2109Salx.manpages@gmail.com                'routes/0/action',
128*2109Salx.manpages@gmail.com            )
129*2109Salx.manpages@gmail.com
130*2109Salx.manpages@gmail.com        check_index({})
131*2109Salx.manpages@gmail.com        check_index(['index.html', '$blah'])
132*2109Salx.manpages@gmail.com
1331654Szelenkov@nginx.com    def test_static_large_file(self, temp_dir):
1341184Szelenkov@nginx.com        file_size = 32 * 1024 * 1024
1351654Szelenkov@nginx.com        with open(temp_dir + '/assets/large', 'wb') as f:
1361184Szelenkov@nginx.com            f.seek(file_size - 1)
1371184Szelenkov@nginx.com            f.write(b'\0')
1381184Szelenkov@nginx.com
1391596Szelenkov@nginx.com        assert (
1401596Szelenkov@nginx.com            len(self.get(url='/large', read_buffer_size=1024 * 1024)['body'])
1411596Szelenkov@nginx.com            == file_size
1421596Szelenkov@nginx.com        ), 'large file'
1431184Szelenkov@nginx.com
1441654Szelenkov@nginx.com    def test_static_etag(self, temp_dir):
1451184Szelenkov@nginx.com        etag = self.get(url='/')['headers']['ETag']
1461184Szelenkov@nginx.com        etag_2 = self.get(url='/README')['headers']['ETag']
1471184Szelenkov@nginx.com
1481596Szelenkov@nginx.com        assert etag != etag_2, 'different ETag'
1491596Szelenkov@nginx.com        assert etag == self.get(url='/')['headers']['ETag'], 'same ETag'
1501184Szelenkov@nginx.com
1511654Szelenkov@nginx.com        with open(temp_dir + '/assets/index.html', 'w') as f:
1521184Szelenkov@nginx.com            f.write('blah')
1531184Szelenkov@nginx.com
1541596Szelenkov@nginx.com        assert etag != self.get(url='/')['headers']['ETag'], 'new ETag'
1551184Szelenkov@nginx.com
1561184Szelenkov@nginx.com    def test_static_redirect(self):
1571184Szelenkov@nginx.com        resp = self.get(url='/dir')
1581596Szelenkov@nginx.com        assert resp['status'] == 301, 'redirect status'
1591596Szelenkov@nginx.com        assert resp['headers']['Location'] == '/dir/', 'redirect Location'
1601596Szelenkov@nginx.com        assert 'Content-Type' not in resp['headers'], 'redirect Content-Type'
1611184Szelenkov@nginx.com
1621654Szelenkov@nginx.com    def test_static_space_in_name(self, temp_dir):
1631184Szelenkov@nginx.com        os.rename(
1642073Szelenkov@nginx.com            temp_dir + '/assets/dir/file',
1652073Szelenkov@nginx.com            temp_dir + '/assets/dir/fi le',
1661184Szelenkov@nginx.com        )
1671654Szelenkov@nginx.com        assert waitforfiles(temp_dir + '/assets/dir/fi le')
1681596Szelenkov@nginx.com        assert self.get(url='/dir/fi le')['body'] == 'blah', 'file name'
1691184Szelenkov@nginx.com
1701654Szelenkov@nginx.com        os.rename(temp_dir + '/assets/dir', temp_dir + '/assets/di r')
1711654Szelenkov@nginx.com        assert waitforfiles(temp_dir + '/assets/di r/fi le')
1721596Szelenkov@nginx.com        assert self.get(url='/di r/fi le')['body'] == 'blah', 'dir name'
1731184Szelenkov@nginx.com
1741848Szelenkov@nginx.com        os.rename(temp_dir + '/assets/di r', temp_dir + '/assets/ di r ')
1751654Szelenkov@nginx.com        assert waitforfiles(temp_dir + '/assets/ di r /fi le')
1761596Szelenkov@nginx.com        assert (
1771596Szelenkov@nginx.com            self.get(url='/ di r /fi le')['body'] == 'blah'
1781596Szelenkov@nginx.com        ), 'dir name enclosing'
1791596Szelenkov@nginx.com
1801596Szelenkov@nginx.com        assert (
1811596Szelenkov@nginx.com            self.get(url='/%20di%20r%20/fi le')['body'] == 'blah'
1821596Szelenkov@nginx.com        ), 'dir encoded'
1831596Szelenkov@nginx.com        assert (
1841596Szelenkov@nginx.com            self.get(url='/ di r %2Ffi le')['body'] == 'blah'
1851596Szelenkov@nginx.com        ), 'slash encoded'
1862073Szelenkov@nginx.com        assert self.get(url='/ di r /fi%20le')['body'] == 'blah', 'file encoded'
1871596Szelenkov@nginx.com        assert (
1881596Szelenkov@nginx.com            self.get(url='/%20di%20r%20%2Ffi%20le')['body'] == 'blah'
1891596Szelenkov@nginx.com        ), 'encoded'
1901596Szelenkov@nginx.com        assert (
1911596Szelenkov@nginx.com            self.get(url='/%20%64%69%20%72%20%2F%66%69%20%6C%65')['body']
1921596Szelenkov@nginx.com            == 'blah'
1931596Szelenkov@nginx.com        ), 'encoded 2'
1941184Szelenkov@nginx.com
1951184Szelenkov@nginx.com        os.rename(
1961654Szelenkov@nginx.com            temp_dir + '/assets/ di r /fi le',
1971654Szelenkov@nginx.com            temp_dir + '/assets/ di r / fi le ',
1981184Szelenkov@nginx.com        )
1991654Szelenkov@nginx.com        assert waitforfiles(temp_dir + '/assets/ di r / fi le ')
2001596Szelenkov@nginx.com        assert (
2011596Szelenkov@nginx.com            self.get(url='/%20di%20r%20/%20fi%20le%20')['body'] == 'blah'
2021596Szelenkov@nginx.com        ), 'file name enclosing'
2031184Szelenkov@nginx.com
2041184Szelenkov@nginx.com        try:
2051654Szelenkov@nginx.com            open(temp_dir + '/ф а', 'a').close()
2061184Szelenkov@nginx.com            utf8 = True
2071184Szelenkov@nginx.com
2081706Smax.romanov@nginx.com        except KeyboardInterrupt:
2091706Smax.romanov@nginx.com            raise
2101706Smax.romanov@nginx.com
2111184Szelenkov@nginx.com        except:
2121184Szelenkov@nginx.com            utf8 = False
2131184Szelenkov@nginx.com
2141184Szelenkov@nginx.com        if utf8:
2151184Szelenkov@nginx.com            os.rename(
2161654Szelenkov@nginx.com                temp_dir + '/assets/ di r / fi le ',
2171654Szelenkov@nginx.com                temp_dir + '/assets/ di r /фа йл',
2181184Szelenkov@nginx.com            )
2191654Szelenkov@nginx.com            assert waitforfiles(temp_dir + '/assets/ di r /фа йл')
2201596Szelenkov@nginx.com            assert (
2211596Szelenkov@nginx.com                self.get(url='/ di r /фа йл')['body'] == 'blah'
2221596Szelenkov@nginx.com            ), 'file name 2'
2231184Szelenkov@nginx.com
2241184Szelenkov@nginx.com            os.rename(
2252073Szelenkov@nginx.com                temp_dir + '/assets/ di r ',
2262073Szelenkov@nginx.com                temp_dir + '/assets/ди ректория',
2271184Szelenkov@nginx.com            )
2281654Szelenkov@nginx.com            assert waitforfiles(temp_dir + '/assets/ди ректория/фа йл')
2291596Szelenkov@nginx.com            assert (
2301596Szelenkov@nginx.com                self.get(url='/ди ректория/фа йл')['body'] == 'blah'
2311596Szelenkov@nginx.com            ), 'dir name 2'
2321184Szelenkov@nginx.com
2331654Szelenkov@nginx.com    def test_static_unix_socket(self, temp_dir):
2341204Szelenkov@nginx.com        sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
2351654Szelenkov@nginx.com        sock.bind(temp_dir + '/assets/unix_socket')
2361204Szelenkov@nginx.com
2371596Szelenkov@nginx.com        assert self.get(url='/unix_socket')['status'] == 404, 'socket'
2381204Szelenkov@nginx.com
2391204Szelenkov@nginx.com        sock.close()
2401204Szelenkov@nginx.com
2411654Szelenkov@nginx.com    def test_static_unix_fifo(self, temp_dir):
2421654Szelenkov@nginx.com        os.mkfifo(temp_dir + '/assets/fifo')
2431204Szelenkov@nginx.com
2441596Szelenkov@nginx.com        assert self.get(url='/fifo')['status'] == 404, 'fifo'
2451204Szelenkov@nginx.com
2461368Szelenkov@nginx.com    def test_static_method(self):
2471368Szelenkov@nginx.com        resp = self.head()
2481596Szelenkov@nginx.com        assert resp['status'] == 200, 'HEAD status'
2491596Szelenkov@nginx.com        assert resp['body'] == '', 'HEAD empty body'
2501368Szelenkov@nginx.com
2511596Szelenkov@nginx.com        assert self.delete()['status'] == 405, 'DELETE'
2521596Szelenkov@nginx.com        assert self.post()['status'] == 405, 'POST'
2531596Szelenkov@nginx.com        assert self.put()['status'] == 405, 'PUT'
2541368Szelenkov@nginx.com
2551368Szelenkov@nginx.com    def test_static_path(self):
2561596Szelenkov@nginx.com        assert self.get(url='/dir/../dir/file')['status'] == 200, 'relative'
2571368Szelenkov@nginx.com
2581596Szelenkov@nginx.com        assert self.get(url='./')['status'] == 400, 'path invalid'
2591596Szelenkov@nginx.com        assert self.get(url='../')['status'] == 400, 'path invalid 2'
2601596Szelenkov@nginx.com        assert self.get(url='/..')['status'] == 400, 'path invalid 3'
2611596Szelenkov@nginx.com        assert self.get(url='../assets/')['status'] == 400, 'path invalid 4'
2621596Szelenkov@nginx.com        assert self.get(url='/../assets/')['status'] == 400, 'path invalid 5'
2631184Szelenkov@nginx.com
2641184Szelenkov@nginx.com    def test_static_two_clients(self):
2651184Szelenkov@nginx.com        _, sock = self.get(url='/', start=True, no_recv=True)
2661184Szelenkov@nginx.com        _, sock2 = self.get(url='/', start=True, no_recv=True)
2671184Szelenkov@nginx.com
2681596Szelenkov@nginx.com        assert sock.recv(1) == b'H', 'client 1'
2691596Szelenkov@nginx.com        assert sock2.recv(1) == b'H', 'client 2'
2701596Szelenkov@nginx.com        assert sock.recv(1) == b'T', 'client 1 again'
2711596Szelenkov@nginx.com        assert sock2.recv(1) == b'T', 'client 2 again'
2721184Szelenkov@nginx.com
2731184Szelenkov@nginx.com        sock.close()
2741184Szelenkov@nginx.com        sock2.close()
2751184Szelenkov@nginx.com
2761184Szelenkov@nginx.com    def test_static_mime_types(self):
2771596Szelenkov@nginx.com        assert 'success' in self.conf(
2781596Szelenkov@nginx.com            {
2791596Szelenkov@nginx.com                "text/x-code/x-blah/x-blah": "readme",
2801596Szelenkov@nginx.com                "text/plain": [".html", ".log", "file"],
2811596Szelenkov@nginx.com            },
2821596Szelenkov@nginx.com            'settings/http/static/mime_types',
2831596Szelenkov@nginx.com        ), 'configure mime_types'
2841184Szelenkov@nginx.com
2851596Szelenkov@nginx.com        assert (
2861596Szelenkov@nginx.com            self.get(url='/README')['headers']['Content-Type']
2871596Szelenkov@nginx.com            == 'text/x-code/x-blah/x-blah'
2881596Szelenkov@nginx.com        ), 'mime_types string case insensitive'
2891596Szelenkov@nginx.com        assert (
2901596Szelenkov@nginx.com            self.get(url='/index.html')['headers']['Content-Type']
2911596Szelenkov@nginx.com            == 'text/plain'
2921596Szelenkov@nginx.com        ), 'mime_types html'
2931596Szelenkov@nginx.com        assert (
2941596Szelenkov@nginx.com            self.get(url='/')['headers']['Content-Type'] == 'text/plain'
2951596Szelenkov@nginx.com        ), 'mime_types index default'
2961596Szelenkov@nginx.com        assert (
2972073Szelenkov@nginx.com            self.get(url='/dir/file')['headers']['Content-Type'] == 'text/plain'
2981596Szelenkov@nginx.com        ), 'mime_types file in dir'
2991184Szelenkov@nginx.com
3001184Szelenkov@nginx.com    def test_static_mime_types_partial_match(self):
3011596Szelenkov@nginx.com        assert 'success' in self.conf(
3022073Szelenkov@nginx.com            {
3032073Szelenkov@nginx.com                "text/x-blah": ["ile", "fil", "f", "e", ".file"],
3042073Szelenkov@nginx.com            },
3051596Szelenkov@nginx.com            'settings/http/static/mime_types',
3061596Szelenkov@nginx.com        ), 'configure mime_types'
3071596Szelenkov@nginx.com        assert 'Content-Type' not in self.get(url='/dir/file'), 'partial match'
3081184Szelenkov@nginx.com
3091184Szelenkov@nginx.com    def test_static_mime_types_reconfigure(self):
3101596Szelenkov@nginx.com        assert 'success' in self.conf(
3111596Szelenkov@nginx.com            {
3121596Szelenkov@nginx.com                "text/x-code": "readme",
3131596Szelenkov@nginx.com                "text/plain": [".html", ".log", "file"],
3141596Szelenkov@nginx.com            },
3151596Szelenkov@nginx.com            'settings/http/static/mime_types',
3161596Szelenkov@nginx.com        ), 'configure mime_types'
3171184Szelenkov@nginx.com
3181596Szelenkov@nginx.com        assert self.conf_get('settings/http/static/mime_types') == {
3191596Szelenkov@nginx.com            'text/x-code': 'readme',
3201596Szelenkov@nginx.com            'text/plain': ['.html', '.log', 'file'],
3211596Szelenkov@nginx.com        }, 'mime_types get'
3221596Szelenkov@nginx.com        assert (
3231596Szelenkov@nginx.com            self.conf_get('settings/http/static/mime_types/text%2Fx-code')
3241596Szelenkov@nginx.com            == 'readme'
3251596Szelenkov@nginx.com        ), 'mime_types get string'
3261596Szelenkov@nginx.com        assert self.conf_get(
3271596Szelenkov@nginx.com            'settings/http/static/mime_types/text%2Fplain'
3281596Szelenkov@nginx.com        ) == ['.html', '.log', 'file'], 'mime_types get array'
3291596Szelenkov@nginx.com        assert (
3301596Szelenkov@nginx.com            self.conf_get('settings/http/static/mime_types/text%2Fplain/1')
3311596Szelenkov@nginx.com            == '.log'
3321596Szelenkov@nginx.com        ), 'mime_types get array element'
3331184Szelenkov@nginx.com
3341596Szelenkov@nginx.com        assert 'success' in self.conf_delete(
3351596Szelenkov@nginx.com            'settings/http/static/mime_types/text%2Fplain/2'
3361596Szelenkov@nginx.com        ), 'mime_types remove array element'
3371596Szelenkov@nginx.com        assert (
3381596Szelenkov@nginx.com            'Content-Type' not in self.get(url='/dir/file')['headers']
3391596Szelenkov@nginx.com        ), 'mime_types removed'
3401596Szelenkov@nginx.com
3411596Szelenkov@nginx.com        assert 'success' in self.conf_post(
3421596Szelenkov@nginx.com            '"file"', 'settings/http/static/mime_types/text%2Fplain'
3431596Szelenkov@nginx.com        ), 'mime_types add array element'
3441596Szelenkov@nginx.com        assert (
3452073Szelenkov@nginx.com            self.get(url='/dir/file')['headers']['Content-Type'] == 'text/plain'
3461596Szelenkov@nginx.com        ), 'mime_types reverted'
3471184Szelenkov@nginx.com
3481596Szelenkov@nginx.com        assert 'success' in self.conf(
3491596Szelenkov@nginx.com            '"file"', 'settings/http/static/mime_types/text%2Fplain'
3501596Szelenkov@nginx.com        ), 'configure mime_types update'
3511596Szelenkov@nginx.com        assert (
3522073Szelenkov@nginx.com            self.get(url='/dir/file')['headers']['Content-Type'] == 'text/plain'
3531596Szelenkov@nginx.com        ), 'mime_types updated'
3541596Szelenkov@nginx.com        assert (
3551596Szelenkov@nginx.com            'Content-Type' not in self.get(url='/log.log')['headers']
3561596Szelenkov@nginx.com        ), 'mime_types updated 2'
3571184Szelenkov@nginx.com
3581596Szelenkov@nginx.com        assert 'success' in self.conf(
3591596Szelenkov@nginx.com            '".log"', 'settings/http/static/mime_types/text%2Fblahblahblah'
3601596Szelenkov@nginx.com        ), 'configure mime_types create'
3611596Szelenkov@nginx.com        assert (
3621596Szelenkov@nginx.com            self.get(url='/log.log')['headers']['Content-Type']
3631596Szelenkov@nginx.com            == 'text/blahblahblah'
3641596Szelenkov@nginx.com        ), 'mime_types create'
3651184Szelenkov@nginx.com
3661184Szelenkov@nginx.com    def test_static_mime_types_correct(self):
3671596Szelenkov@nginx.com        assert 'error' in self.conf(
3681596Szelenkov@nginx.com            {"text/x-code": "readme", "text/plain": "readme"},
3691596Szelenkov@nginx.com            'settings/http/static/mime_types',
3701596Szelenkov@nginx.com        ), 'mime_types same extensions'
3711596Szelenkov@nginx.com        assert 'error' in self.conf(
3721596Szelenkov@nginx.com            {"text/x-code": [".h", ".c"], "text/plain": ".c"},
3731596Szelenkov@nginx.com            'settings/http/static/mime_types',
3741596Szelenkov@nginx.com        ), 'mime_types same extensions array'
3751596Szelenkov@nginx.com        assert 'error' in self.conf(
3762073Szelenkov@nginx.com            {
3772073Szelenkov@nginx.com                "text/x-code": [".h", ".c", "readme"],
3782073Szelenkov@nginx.com                "text/plain": "README",
3792073Szelenkov@nginx.com            },
3801596Szelenkov@nginx.com            'settings/http/static/mime_types',
3811596Szelenkov@nginx.com        ), 'mime_types same extensions case insensitive'
3821184Szelenkov@nginx.com
3831596Szelenkov@nginx.com    @pytest.mark.skip('not yet')
3841654Szelenkov@nginx.com    def test_static_mime_types_invalid(self, temp_dir):
3851596Szelenkov@nginx.com        assert 'error' in self.http(
3861596Szelenkov@nginx.com            b"""PUT /config/settings/http/static/mime_types/%0%00% HTTP/1.1\r
3871184Szelenkov@nginx.comHost: localhost\r
3881184Szelenkov@nginx.comConnection: close\r
3891184Szelenkov@nginx.comContent-Length: 6\r
3901184Szelenkov@nginx.com\r
3911184Szelenkov@nginx.com\"blah\"""",
3921596Szelenkov@nginx.com            raw_resp=True,
3931596Szelenkov@nginx.com            raw=True,
3941596Szelenkov@nginx.com            sock_type='unix',
3951654Szelenkov@nginx.com            addr=temp_dir + '/control.unit.sock',
3961596Szelenkov@nginx.com        ), 'mime_types invalid'
397