fix: enable wss connections and add certificate verification toggle in WebSocket Client (#1823)
* fix: enable wss connections and add certificate verification toggle in WebSocket Client Previous behavior: the WebSocket Client only supported unencrypted ws:// connections; wss:// URLs were not handled and would fail to connect, providing no option to disable TLS certificate validation for development or self-signed certificates. Fixed behavior: secure WebSocket connections (wss://) are now fully supported. A verifyCertificate configuration option has been introduced, defaulting to true. When set to false, certificate errors (e.g., self-signed certificates) are ignored, enabling safe local testing while maintaining strict validation by default for production. * fix: improve wss certificate verification and add tests Previous behavior: wsOptions used 'any' type without type safety, verifyCertificate was added to napcat-protocol without implementation, and no tests existed for the new config option. Fixed behavior: wsOptions now uses proper WebSocket.ClientOptions type for compile-time safety, verifyCertificate removed from napcat-protocol (no WebSocket client implementation exists there), and comprehensive tests added to validate config loading and default values.
This commit is contained in:
1 parent
25db6f0835
commit
8996b35dd1
5 files changed
+72
-5
No files matched your search
@@ -2,11 +2,11 @@ import GenericForm, { random_token } from './generic_form';
|
||||
import type { Field } from './generic_form';
|
||||
|
||||
export interface WebsocketClientFormProps {
|
||||
data?: OneBotConfig['network']['websocketClients'][0]
|
||||
onClose: () => void
|
||||
data?: OneBotConfig['network']['websocketClients'][0];
|
||||
onClose: () => void;
|
||||
onSubmit: (
|
||||
data: OneBotConfig['network']['websocketClients'][0]
|
||||
) => Promise<void>
|
||||
) => Promise<void>;
|
||||
}
|
||||
|
||||
type WebsocketClientFormType = OneBotConfig['network']['websocketClients'];
|
||||
@@ -26,6 +26,7 @@ const WebsocketClientForm: React.FC<WebsocketClientFormProps> = ({
|
||||
debug: false,
|
||||
heartInterval: 30000,
|
||||
reconnectInterval: 30000,
|
||||
verifyCertificate: true,
|
||||
};
|
||||
|
||||
const fields: Field<'websocketClients'>[] = [
|
||||
@@ -99,6 +100,13 @@ const WebsocketClientForm: React.FC<WebsocketClientFormProps> = ({
|
||||
isRequired: true,
|
||||
colSpan: 1,
|
||||
},
|
||||
{
|
||||
name: 'verifyCertificate',
|
||||
label: 'SSL证书验证',
|
||||
type: 'switch',
|
||||
description: '是否验证SSL证书(wss连接)。关闭后可连接自签名证书的服务器,但会降低安全性',
|
||||
colSpan: 2,
|
||||
},
|
||||
];
|
||||
|
||||
return (
|
||||
|
||||
Reference in new issue
Block a user