╭─────────────╮ │scroll to top│ ╰─────────────╯ ╭ serve_ssh.zig ────────────────────────────────────────────────╮ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ ╰───────────────────────────────────────────────────────────────╯
╭────╮ ╭ clone ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─╮ │http│ ssh │ │ ╰────╯ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─╯
614 const line = try std.fmt.bufPrint(&packet, "{x:0>4}{s}", .{ packet.len, body }); 615 try sess.writeBytes(line); 616 try sess.exit(1); 617 } 618 619 test "parseGitCommand rejects malformed input" { 620 const allocator = std.testing.allocator; 621 try std.testing.expectError(error.InvalidCommand, parseGitCommand(allocator, "git-upload-pack")); 622 try std.testing.expectError(error.UnsupportedService, parseGitCommand(allocator, "ls -la")); 623 try std.testing.expectError(error.UnsupportedService, parseGitCommand(allocator, "git-fake-pack 'repo'")); 624 } 625 626 test "parseGitCommand happy paths" { 627 const allocator = std.testing.allocator; 628 629 { 630 const parsed = try parseGitCommand(allocator, "git-upload-pack 'some-repo'"); 631 defer parsed.deinit(allocator); 632 try std.testing.expectEqual(GitService.upload_pack, parsed.service); 633 try std.testing.expectEqualStrings("some-repo", parsed.dir); 634 } 635 { 636 const parsed = try parseGitCommand(allocator, "git-receive-pack 'user/proj'"); 637 defer parsed.deinit(allocator); 638 try std.testing.expectEqual(GitService.receive_pack, parsed.service); 639 try std.testing.expectEqualStrings("user/proj", parsed.dir); 640 } 641 { 642 const parsed = try parseGitCommand(allocator, "git-upload-pack repo"); 643 defer parsed.deinit(allocator); 644 try std.testing.expectEqual(GitService.upload_pack, parsed.service); 645 try std.testing.expectEqualStrings("repo", parsed.dir); 646 } 647 } 648