Skip to content

Lightpanda: the headless browser designed for AI and automation

add --user-agent unit test

Pierre Tachoireca4726c1cd5f
diff --git a/src/Config.zig b/src/Config.zig
index 1eb09a480..097911bc4 100644
--- a/src/Config.zig
+++ b/src/Config.zig
@@ -1051,6 +1051,20 @@ test "Config: advertiseHost preserves concrete host when not a wildcard" {
try std.testing.expectEqualStrings("127.0.0.1", config.advertiseHost());
}
+test "Config: parseArgs refuses a mozilla user-agent" {
+ log.expectLog(&.{.app});
+ const argv = [_][*:0]const u8{ "lightpanda", "fetch", "--user-agent", "mozilla/1.0" };
+ const proc_args: std.process.Args = .{ .vector = &argv };
+ try std.testing.expectError(error.InvalidArgument, parseArgs(std.testing.allocator, proc_args));
+}
+
+test "Config: validateUserAgent" {
+ try validateUserAgent("Lightpanda/1.0");
+ try std.testing.expectError(error.Reserved, validateUserAgent("mozilla/1.0"));
+ try std.testing.expectError(error.Reserved, validateUserAgent("Mozilla/5.0"));
+ try std.testing.expectError(error.NonPrintable, validateUserAgent("bad\x01ua"));
+}
+
fn userAgentValidator(allocator: Allocator, args: *std.process.Args.Iterator, ua: *?[]const u8) !void {
const str = args.next() orelse return error.MissingArgument;
validateUserAgent(str) catch {