Do not hide WebSocket API when missing permission (#6186)

This commit is contained in:
Mm2PL
2025-05-04 12:49:08 +02:00
committed by GitHub
parent f282e30f1e
commit c7e1c2e812
4 changed files with 13 additions and 7 deletions
+1 -1
View File
@@ -6,7 +6,7 @@
- Minor: Added cached emotes fallback when fetching from a provider fails. (#6125)
- Minor: Add an option for the reduced opacity of message history. (#6121)
- Minor: Make paused chat indicator more visible, and fix its zoom behavior. (#6123)
- Minor: Added WebSocket API for plugins. (#6076)
- Minor: Added WebSocket API for plugins. (#6076, #6186)
- Minor: Allow for themes to set transparent values for window background on Linux. (#6137)
- Minor: Popup overlay now only draws an outline when being interacted with. (#6140)
- Minor: Made filters searchable in the Settings dialog search bar. (#5890)
+1 -5
View File
@@ -221,16 +221,12 @@ void PluginController::initSol(sol::state_view &lua, Plugin *plugin)
lua::api::ChannelRef::createUserType(c2);
lua::api::HTTPResponse::createUserType(c2);
lua::api::HTTPRequest::createUserType(c2);
lua::api::WebSocket::createUserType(c2, plugin);
c2["ChannelType"] = lua::createEnumTable<Channel::Type>(lua);
c2["HTTPMethod"] = lua::createEnumTable<NetworkRequestType>(lua);
c2["EventType"] = lua::createEnumTable<lua::api::EventType>(lua);
c2["LogLevel"] = lua::createEnumTable<lua::api::LogLevel>(lua);
if (plugin->hasNetworkPermission())
{
lua::api::WebSocket::createUserType(c2, plugin);
}
sol::table io = g["io"];
io.set_function(
"open", sol::overload(&lua::api::io_open, &lua::api::io_open_modeless));
@@ -31,6 +31,11 @@ void WebSocket::createUserType(sol::table &c2, Plugin *plugin)
c2.new_usertype<WebSocket>(
"WebSocket",
sol::factories([plugin](const QString &spec, sol::variadic_args args) {
if (!plugin->hasNetworkPermission())
{
throw std::runtime_error(
"Plugin does not have permission to use websockets");
}
QUrl url(spec);
if (url.scheme() != "wss" && url.scheme() != "ws")
{
+6 -1
View File
@@ -786,9 +786,14 @@ TEST_F(PluginTest, testWebSocketNoPerms)
configure();
bool res = lua->script(R"lua(
return c2["WebSocket"] == nil
return c2["WebSocket"] ~= nil
)lua");
ASSERT_TRUE(res);
const char *shouldThrow = R"lua(
return c2.WebSocket.new('wss://127.0.0.1:9050/echo')
)lua";
EXPECT_ANY_THROW(lua->script(shouldThrow));
}
TEST_F(PluginTest, testWebSocketApi)