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