╭─────────────╮ │scroll to top│ ╰─────────────╯ ╭ serve_ssh.zig ────────────────────────────────────────────────╮ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ ╰───────────────────────────────────────────────────────────────╯
╭────╮ ╭ clone ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╮ │http│ ssh │ │ ╰────╯ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╯
639 try sess.writeBytes(line); 640 try sess.exit(1); 641 } 642 643 test "parseGitCommand rejects malformed input" { 644 const allocator = std.testing.allocator; 645 try std.testing.expectError(error.InvalidCommand, parseGitCommand(allocator, "git-upload-pack")); 646 try std.testing.expectError(error.UnsupportedService, parseGitCommand(allocator, "ls -la")); 647 try std.testing.expectError(error.UnsupportedService, parseGitCommand(allocator, "git-fake-pack 'repo'")); 648 } 649 650 test "parseGitCommand happy paths" { 651 const allocator = std.testing.allocator; 652 653 { 654 const parsed = try parseGitCommand(allocator, "git-upload-pack 'some-repo'"); 655 defer parsed.deinit(allocator); 656 try std.testing.expectEqual(GitService.upload_pack, parsed.service); 657 try std.testing.expectEqualStrings("some-repo", parsed.dir); 658 } 659 { 660 const parsed = try parseGitCommand(allocator, "git-receive-pack 'user/proj'"); 661 defer parsed.deinit(allocator); 662 try std.testing.expectEqual(GitService.receive_pack, parsed.service); 663 try std.testing.expectEqualStrings("user/proj", parsed.dir); 664 } 665 { 666 const parsed = try parseGitCommand(allocator, "git-upload-pack repo"); 667 defer parsed.deinit(allocator); 668 try std.testing.expectEqual(GitService.upload_pack, parsed.service); 669 try std.testing.expectEqualStrings("repo", parsed.dir); 670 } 671 } 672