Skip to content

Commit 6c1c68f

Browse files
authored
Merge pull request #36 from knep/chore/remove-dead-webpack-auth-code
chore: remove dead pre-Vite webpack whitelist in auth utils
2 parents dcb753c + b917b1a commit 6c1c68f

2 files changed

Lines changed: 6 additions & 77 deletions

File tree

src/tests/web/web_auth_utils_test.py

Lines changed: 5 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -3,54 +3,21 @@
33
from parameterized import parameterized
44

55
from tests.test_utils import mock_request_handler
6-
from web.web_auth_utils import remove_webpack_suffixes, is_allowed_during_login
7-
8-
9-
class WebpackSuffixesTest(TestCase):
10-
def test_remove_webpack_suffixes_when_css(self):
11-
normalized = remove_webpack_suffixes('js/chunk-login-vendors.59040343.css')
12-
self.assertEqual('js/chunk-login-vendors.css', normalized)
13-
14-
def test_remove_webpack_suffixes_when_js(self):
15-
normalized = remove_webpack_suffixes('js/login.be16f278.js')
16-
self.assertEqual('js/login.js', normalized)
17-
18-
def test_remove_webpack_suffixes_when_js_map(self):
19-
normalized = remove_webpack_suffixes('js/login.be16f278.js.map')
20-
self.assertEqual('js/login.js.map', normalized)
21-
22-
def test_remove_webpack_suffixes_when_favicon(self):
23-
normalized = remove_webpack_suffixes('favicon.123.ico')
24-
self.assertEqual('favicon.123.ico', normalized)
25-
26-
def test_remove_webpack_suffixes_when_no_suffixes(self):
27-
normalized = remove_webpack_suffixes('css/chunk-login-vendors.css')
28-
self.assertEqual('css/chunk-login-vendors.css', normalized)
29-
30-
def test_remove_webpack_suffixes_when_no_extension(self):
31-
normalized = remove_webpack_suffixes('data/some_file')
32-
self.assertEqual('data/some_file', normalized)
6+
from web.web_auth_utils import is_allowed_during_login
337

348

359
class LoginResourcesTest(TestCase):
3610
@parameterized.expand([
3711
('/favicon.ico'),
3812
('login.html'),
39-
('/js/login.be16f278.js'),
40-
('/js/login.be16f278.js.map'),
41-
('/js/chunk-login-vendors.18e22e7f.js'),
42-
('/js/chunk-login-vendors.18e22e7f.js.map'),
43-
('/img/titleBackground_login.a6c36d4c.jpg'),
44-
('/css/login.8e74be0f.css'),
45-
('/fonts/roboto-latin-400.60fa3c06.woff'),
46-
('/fonts/roboto-latin-400.479970ff.woff2'),
47-
('/fonts/roboto-latin-500.020c97dc.woff2'),
48-
('/fonts/roboto-latin-500.87284894.woff'),
4913
# Vite-built hashed bundles served from /assets/ (used by the login page)
5014
('/assets/login-jEjOHyEw.js'),
5115
('/assets/css-Bn4Yn0er.css'),
5216
('/assets/theme-C3Leg-oT.css'),
53-
('/assets/MaterialIcons-Regular-Bnsxcfr1.woff')
17+
('/assets/MaterialIcons-Regular-Bnsxcfr1.woff'),
18+
# Custom theme assets (conf/theme/...)
19+
('/theme/theme.css'),
20+
('/theme/logo.png')
5421
])
5522
def test_is_allowed_during_login_when_allowed(self, resource):
5623
request_handler = mock_request_handler(method='GET')

src/web/web_auth_utils.py

Lines changed: 1 addition & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@
1414

1515
LOGGER = logging.getLogger('web_server')
1616

17-
webpack_prefixed_extensions = ['.css', '.js.map', '.js', '.jpg', '.woff', '.woff2', '.png']
18-
1917

2018
def check_authorization_sync(func):
2119
wrapper = check_authorization(func)
@@ -101,21 +99,6 @@ def is_allowed_during_login(request_path, login_url, request_handler):
10199

102100
if request_path == login_url:
103101
return True
104-
request_path = remove_webpack_suffixes(request_path)
105-
106-
login_resources = ['/js/login.js',
107-
'/js/login.js.map',
108-
'/js/chunk-login-vendors.js',
109-
'/js/chunk-login-vendors.js.map',
110-
'/favicon.ico',
111-
'/css/login.css',
112-
'/css/chunk-login-vendors.css',
113-
'/fonts/roboto-latin-500.woff2',
114-
'/fonts/roboto-latin-500.woff',
115-
'/fonts/roboto-latin-400.woff2',
116-
'/fonts/roboto-latin-400.woff',
117-
'/img/titleBackground_login.jpg',
118-
'/img/gitlab-icon-rgb.png']
119102

120103
# Vite emits the bundled JS/CSS/fonts/images (used by the login page too,
121104
# often as hashed and shared chunks) under /assets/. These are static client
@@ -124,25 +107,4 @@ def is_allowed_during_login(request_path, login_url, request_handler):
124107
if request_path.startswith('/assets/'):
125108
return True
126109

127-
return (request_path in login_resources) or (request_path.startswith('/theme/'))
128-
129-
130-
def remove_webpack_suffixes(request_path):
131-
if request_path.endswith('.js.map'):
132-
extension_start = len(request_path) - 7
133-
else:
134-
extension_start = request_path.rfind('.')
135-
136-
extension = request_path[extension_start:]
137-
138-
if extension not in webpack_prefixed_extensions:
139-
return request_path
140-
141-
if extension_start < 0:
142-
return request_path
143-
144-
prefix_start = request_path.rfind('.', 0, extension_start)
145-
if prefix_start < 0:
146-
return request_path
147-
148-
return request_path[:prefix_start] + extension
110+
return request_path.startswith('/theme/')

0 commit comments

Comments
 (0)