╭─────────────╮ │scroll to top│ ╰─────────────╯ ╭ serve_ssh.zig ────────────────────────────────────────────────╮ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ ╰───────────────────────────────────────────────────────────────╯
╭ find file ─ ─ ─ ─ ─ ─ ─ ─ ─ ─╮ ╭────╮ ╭ clone ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─╮ │ │ │http│ ssh │ │ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─╯ ╰────╯ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─╯
672 line[key_type.len] = ' '; 673 _ = encoder.encode(line[key_type.len + 1 ..], blob); 674 return line; 675 } 676 677 fn writeError(sess: *ssh.SessionCtx, comptime msg: []const u8) !void { 678 const body = "ERR haxy ssh: " ++ msg; 679 var packet: [body.len + 4]u8 = undefined; 680 const line = try std.fmt.bufPrint(&packet, "{x:0>4}{s}", .{ packet.len, body }); 681 try sess.writeBytes(line); 682 try sess.exit(1); 683 } 684 685 test "parseGitCommand rejects malformed input" { 686 const allocator = std.testing.allocator; 687 try std.testing.expectError(error.InvalidCommand, parseGitCommand(allocator, "git-upload-pack")); 688 try std.testing.expectError(error.UnsupportedService, parseGitCommand(allocator, "ls -la")); 689 try std.testing.expectError(error.UnsupportedService, parseGitCommand(allocator, "git-fake-pack 'repo'")); 690 } 691 692 test "parseGitCommand happy paths" { 693 const allocator = std.testing.allocator; 694 695 { 696 const parsed = try parseGitCommand(allocator, "git-upload-pack 'some-repo'"); 697 defer parsed.deinit(allocator); 698 try std.testing.expectEqual(GitService.upload_pack, parsed.service); 699 try std.testing.expectEqualStrings("some-repo", parsed.dir); 700 } 701 { 702 const parsed = try parseGitCommand(allocator, "git-receive-pack 'user/proj'"); 703 defer parsed.deinit(allocator); 704 try std.testing.expectEqual(GitService.receive_pack, parsed.service); 705 try std.testing.expectEqualStrings("user/proj", parsed.dir); 706 } 707 { 708 const parsed = try parseGitCommand(allocator, "git-upload-pack repo"); 709 defer parsed.deinit(allocator); 710 try std.testing.expectEqual(GitService.upload_pack, parsed.service); 711 try std.testing.expectEqualStrings("repo", parsed.dir); 712 } 713 } 714