diff options
author | 2023-06-14 23:29:36 -0300 | |
---|---|---|
committer | 2023-06-14 19:29:36 -0700 | |
commit | e6d4b3a89ac6631f54276a21d82d41f91fd41c76 (patch) | |
tree | 17308fa0b27544c5590d111ceea7b46d79803681 /src | |
parent | 0f131a976e637669ab3ac44f53af6227a24f6900 (diff) | |
download | bun-e6d4b3a89ac6631f54276a21d82d41f91fd41c76.tar.gz bun-e6d4b3a89ac6631f54276a21d82d41f91fd41c76.tar.zst bun-e6d4b3a89ac6631f54276a21d82d41f91fd41c76.zip |
[Bun.serve] fix `Bun.serve` argument check (#3314)
* fixup checks
* throw when tls is not a object also fix socket
* fix error message
* null or undefined on tls option in Bun.serve or sockets should not throw
* add tests
* fix tests and socket validation
* remove unnecessary check
* add listen tests
Diffstat (limited to 'src')
-rw-r--r-- | src/bun.js/api/bun/socket.zig | 16 | ||||
-rw-r--r-- | src/bun.js/api/server.zig | 10 |
2 files changed, 16 insertions, 10 deletions
diff --git a/src/bun.js/api/bun/socket.zig b/src/bun.js/api/bun/socket.zig index 780bfcb14..48bfe4218 100644 --- a/src/bun.js/api/bun/socket.zig +++ b/src/bun.js/api/bun/socket.zig @@ -254,19 +254,17 @@ pub const SocketConfig = struct { var ssl: ?JSC.API.ServerConfig.SSLConfig = null; var default_data = JSValue.zero; - if (opts.getTruthy(globalObject, "tls")) |tls| outer: { + if (opts.getTruthy(globalObject, "tls")) |tls| { if (tls.isBoolean()) { if (tls.toBoolean()) { ssl = JSC.API.ServerConfig.SSLConfig.zero; } - - break :outer; - } - - if (JSC.API.ServerConfig.SSLConfig.inJS(globalObject, tls, exception)) |ssl_config| { - ssl = ssl_config; - } else if (exception.* != null) { - return null; + } else { + if (JSC.API.ServerConfig.SSLConfig.inJS(globalObject, tls, exception)) |ssl_config| { + ssl = ssl_config; + } else if (exception.* != null) { + return null; + } } } diff --git a/src/bun.js/api/server.zig b/src/bun.js/api/server.zig index 8fd9acde7..37bc601a5 100644 --- a/src/bun.js/api/server.zig +++ b/src/bun.js/api/server.zig @@ -270,6 +270,11 @@ pub const ServerConfig = struct { pub fn inJS(global: *JSC.JSGlobalObject, obj: JSC.JSValue, exception: JSC.C.ExceptionRef) ?SSLConfig { var result = zero; + if (!obj.isObject()) { + JSC.throwInvalidArguments("tls option expects an object", .{}, global, exception); + return null; + } + var any = false; // Required @@ -688,7 +693,7 @@ pub const ServerConfig = struct { } if (arguments.next()) |arg| { - if (arg.isUndefinedOrNull() or !arg.isObject()) { + if (!arg.isObject()) { JSC.throwInvalidArguments("Bun.serve expects an object", .{}, global, exception); return args; } @@ -812,6 +817,9 @@ pub const ServerConfig = struct { } return args; } + } else { + JSC.throwInvalidArguments("Bun.serve expects an object", .{}, global, exception); + return args; } if (args.base_uri.len > 0) { |