1
0
mirror of https://github.com/weechat/weechat.git synced 2026-07-07 18:23:13 +02:00

relay/api: return an error 401 when header "x-weechat-totp" is received with empty value

This commit is contained in:
Sébastien Helleu
2025-10-26 10:11:10 +01:00
parent 0009732f78
commit d05b83d03f
2 changed files with 61 additions and 39 deletions
+14 -7
View File
@@ -713,13 +713,6 @@ TEST(RelayHttp, GetAuthStatus)
hashtable_set (client->http_req->headers, "authorization", "Basic \u26c4");
LONGS_EQUAL(-2, relay_http_get_auth_status (client));
/* test invalid TOTP */
hashtable_set (client->http_req->headers, "x-weechat-totp", "abcdef");
LONGS_EQUAL(-4, relay_http_get_auth_status (client));
hashtable_set (client->http_req->headers, "x-weechat-totp", "1234567");
LONGS_EQUAL(-4, relay_http_get_auth_status (client));
hashtable_remove (client->http_req->headers, "x-weechat-totp");
/* test invalid plain-text password ("test") */
hashtable_set (client->http_req->headers, "authorization", "Basic cGxhaW46dGVzdA==");
LONGS_EQUAL(-2, relay_http_get_auth_status (client));
@@ -898,6 +891,20 @@ TEST(RelayHttp, GetAuthStatus)
hashtable_set (client->http_req->headers, "authorization", auth_header);
LONGS_EQUAL(0, relay_http_get_auth_status (client));
/* test invalid TOTP */
hashtable_set (client->http_req->headers, "x-weechat-totp", "");
LONGS_EQUAL(-4, relay_http_get_auth_status (client));
hashtable_set (client->http_req->headers, "x-weechat-totp", "abcdef");
LONGS_EQUAL(-4, relay_http_get_auth_status (client));
hashtable_set (client->http_req->headers, "x-weechat-totp", "1234567");
LONGS_EQUAL(-4, relay_http_get_auth_status (client));
hashtable_remove (client->http_req->headers, "x-weechat-totp");
/* test valid TOTP without TOTP configuration */
hashtable_set (client->http_req->headers, "x-weechat-totp", "123456");
LONGS_EQUAL(-4, relay_http_get_auth_status (client));
hashtable_remove (client->http_req->headers, "x-weechat-totp");
/* test missing/invalid TOTP */
config_file_option_set (relay_config_network_totp_secret, "secretbase32", 1);
config_file_option_set (relay_config_network_totp_window, "1", 1);