╭─────────────╮ │scroll to top│ ╰─────────────╯ ╭ serve_ssh.zig ────────────────────────────────────────────────╮ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ ╰───────────────────────────────────────────────────────────────╯
╭────╮ ╭ clone ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╮ │http│ ssh │ │ ╰────╯ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╯
621 _ = encoder.encode(line[key_type.len + 1 ..], blob); 622 return line; 623 } 624 625 fn writeError(sess: *ssh.SessionCtx, comptime msg: []const u8) !void { 626 const body = "ERR haxy ssh: " ++ msg; 627 var packet: [body.len + 4]u8 = undefined; 628 const line = try std.fmt.bufPrint(&packet, "{x:0>4}{s}", .{ packet.len, body }); 629 try sess.writeBytes(line); 630 try sess.exit(1); 631 } 632 633 test "parseGitCommand rejects malformed input" { 634 const allocator = std.testing.allocator; 635 try std.testing.expectError(error.InvalidCommand, parseGitCommand(allocator, "git-upload-pack")); 636 try std.testing.expectError(error.UnsupportedService, parseGitCommand(allocator, "ls -la")); 637 try std.testing.expectError(error.UnsupportedService, parseGitCommand(allocator, "git-fake-pack 'repo'")); 638 } 639 640 test "parseGitCommand happy paths" { 641 const allocator = std.testing.allocator; 642 643 { 644 const parsed = try parseGitCommand(allocator, "git-upload-pack 'some-repo'"); 645 defer parsed.deinit(allocator); 646 try std.testing.expectEqual(GitService.upload_pack, parsed.service); 647 try std.testing.expectEqualStrings("some-repo", parsed.dir); 648 } 649 { 650 const parsed = try parseGitCommand(allocator, "git-receive-pack 'user/proj'"); 651 defer parsed.deinit(allocator); 652 try std.testing.expectEqual(GitService.receive_pack, parsed.service); 653 try std.testing.expectEqualStrings("user/proj", parsed.dir); 654 } 655 { 656 const parsed = try parseGitCommand(allocator, "git-upload-pack repo"); 657 defer parsed.deinit(allocator); 658 try std.testing.expectEqual(GitService.upload_pack, parsed.service); 659 try std.testing.expectEqualStrings("repo", parsed.dir); 660 } 661 } 662