╭─────────────╮ │scroll to top│ ╰─────────────╯ ╭ serve_ssh.zig ────────────────────────────────────────────────╮ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ ╰───────────────────────────────────────────────────────────────╯
╭────╮ ╭ clone ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╮ │http│ ssh │ │ ╰────╯ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╯
643 644 return ssh.formatFingerprint(blob_buf[0..blob_len]); 645 } 646 647 fn writeError(sess: *ssh.SessionCtx, comptime msg: []const u8) !void { 648 const body = "ERR haxy ssh: " ++ msg; 649 var packet: [body.len + 4]u8 = undefined; 650 const line = try std.fmt.bufPrint(&packet, "{x:0>4}{s}", .{ packet.len, body }); 651 try sess.writeBytes(line); 652 try sess.exit(1); 653 } 654 655 test "parseGitCommand rejects malformed input" { 656 const allocator = std.testing.allocator; 657 try std.testing.expectError(error.InvalidCommand, parseGitCommand(allocator, "git-upload-pack")); 658 try std.testing.expectError(error.UnsupportedService, parseGitCommand(allocator, "ls -la")); 659 try std.testing.expectError(error.UnsupportedService, parseGitCommand(allocator, "git-fake-pack 'repo'")); 660 } 661 662 test "parseGitCommand happy paths" { 663 const allocator = std.testing.allocator; 664 665 { 666 const parsed = try parseGitCommand(allocator, "git-upload-pack 'some-repo'"); 667 defer parsed.deinit(allocator); 668 try std.testing.expectEqual(GitService.upload_pack, parsed.service); 669 try std.testing.expectEqualStrings("some-repo", parsed.dir); 670 } 671 { 672 const parsed = try parseGitCommand(allocator, "git-receive-pack 'user/proj'"); 673 defer parsed.deinit(allocator); 674 try std.testing.expectEqual(GitService.receive_pack, parsed.service); 675 try std.testing.expectEqualStrings("user/proj", parsed.dir); 676 } 677 { 678 const parsed = try parseGitCommand(allocator, "git-upload-pack repo"); 679 defer parsed.deinit(allocator); 680 try std.testing.expectEqual(GitService.upload_pack, parsed.service); 681 try std.testing.expectEqualStrings("repo", parsed.dir); 682 } 683 } 684