Skip to content

Commit 011b7d0

Browse files
committed
test(auth): fix DataTables Forbidden alert by preventing API_TOKEN cache desync
- Prevented test_ui_login fixture from accidentally stripping API_TOKEN from app.conf, which was triggering random token regeneration mid-test. - Added explicit invalidation of SETTINGS_SECONDARYCACHE in server/initialise.py to ensure the Python GraphQL backend immediately respects regenerated API_TOKENs. - Fixed getSettingValue fallback logic in PHP auth layers to reliably use the token generated by the backend rather than mismatching.
1 parent 442ea13 commit 011b7d0

5 files changed

Lines changed: 19 additions & 3 deletions

File tree

front/php/server/query_graphql.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@
1212
// Helper function to get GraphQL URL (you can replace this with environment variables)
1313
function getGraphQLUrl() {
1414
$port = getSettingValue("GRAPHQL_PORT"); // Port for the GraphQL server
15+
if (empty($port) || !is_numeric($port)) {
16+
$port = 20211;
17+
}
1518
return "0.0.0.0:$port/graphql"; // Full URL to the GraphQL endpoint
1619
}
1720

front/php/templates/auth.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
}
3030

3131
$config_file_lines = file($config_file);
32-
$config_file_lines_pw = array_values(preg_grep('/^SETPWD_password.*=/', $config_file_lines ?: []));
32+
$config_file_lines_pw = array_values(preg_grep('/^SETPWD_password\s*=/', $config_file_lines ?: []));
3333
if (empty($config_file_lines_pw) || substr_count($config_file_lines_pw[0], "'") < 2) {
3434
http_response_code(401);
3535
echo 'Unauthorized 401';
@@ -38,9 +38,12 @@
3838
$password_line = explode("'", $config_file_lines_pw[0], 3);
3939
$nax_Password = $password_line[1];
4040

41-
$config_file_lines_token = array_values(preg_grep('/^API_TOKEN.*=/', $config_file_lines ?: []));
41+
$config_file_lines_token = array_values(preg_grep('/^API_TOKEN\s*=/', $config_file_lines ?: []));
4242
$token_line = !empty($config_file_lines_token) ? explode("'", $config_file_lines_token[0], 3) : [];
4343
$api_token = $token_line[1] ?? '';
44+
if (empty($api_token)) {
45+
$api_token = getenv('API_TOKEN') ?: '';
46+
}
4447
if ($api_token === '') {
4548
http_response_code(401);
4649
echo 'Unauthorized 401';

front/php/templates/security.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,9 @@ function redirect($url) {
9393
}
9494
$nax_Password = getConfigValue('/^SETPWD_password\s*=/', $configLines);
9595
$api_token = getConfigValue('/^API_TOKEN\s*=/', $configLines, "'");
96+
if (empty($api_token)) {
97+
$api_token = getenv('API_TOKEN') ?: '';
98+
}
9699

97100
$expectedToken = 'Bearer ' . $api_token;
98101

server/initialise.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,13 @@ def importConfigs(pm, db, all_plugins):
227227
mylog("debug", ["[Import Config] importing config file"])
228228
conf.mySettings = [] # reset settings
229229
conf.mySettingsSQLsafe = [] # same as above but safe to be passed into a SQL query
230+
231+
# Invalidate secondary cache from helper since conf.mySettings changed
232+
try:
233+
import helper
234+
helper.SETTINGS_SECONDARYCACHE = {}
235+
except Exception:
236+
pass
230237

231238
# User values loaded from now
232239
c_d = read_config_file(config_file)

test/ui/test_ui_login.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ def ensure_web_protection():
4343
f.write(line)
4444
f.write("\nSETPWD_enable_password='true'\n")
4545
f.write("SETPWD_password='8d969eef6ecad3c29a3a629280e686cf0c3f5d5a86aff3ca12020c923adc6c92'\n")
46-
time.sleep(1) # Let disk sync catch up
46+
time.sleep(2) # Let disk sync catch up
4747

4848
yield
4949

0 commit comments

Comments
 (0)