╭─────────────╮ │scroll to top│ ╰─────────────╯ ╭ serve_ssh.zig ────────────────────────────────────────────────╮ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ ╰───────────────────────────────────────────────────────────────╯
╭────╮ ╭ clone ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╮ │http│ ssh │ │ ╰────╯ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╯
700 } 701 702 // an error line ending with the presented key's fingerprint 703 fn writeFingerprintError(sess: *ssh.SessionCtx, comptime msg: []const u8) !void { 704 const prefix = "ERR haxy ssh: " ++ msg ++ " (key "; 705 var packet: [4 + prefix.len + ssh.fingerprint_len + 1]u8 = undefined; 706 const line = try std.fmt.bufPrint(&packet, "{x:0>4}" ++ prefix ++ "{s})", .{ packet.len, &sess.fingerprint }); 707 try sess.writeBytes(line); 708 try sess.exit(1); 709 } 710 711 test "parseGitCommand rejects malformed input" { 712 const allocator = std.testing.allocator; 713 try std.testing.expectError(error.InvalidCommand, parseGitCommand(allocator, "git-upload-pack")); 714 try std.testing.expectError(error.UnsupportedService, parseGitCommand(allocator, "ls -la")); 715 try std.testing.expectError(error.UnsupportedService, parseGitCommand(allocator, "git-fake-pack 'repo'")); 716 } 717 718 test "parseGitCommand happy paths" { 719 const allocator = std.testing.allocator; 720 721 { 722 const parsed = try parseGitCommand(allocator, "git-upload-pack 'some-repo'"); 723 defer parsed.deinit(allocator); 724 try std.testing.expectEqual(GitService.upload_pack, parsed.service); 725 try std.testing.expectEqualStrings("some-repo", parsed.dir); 726 } 727 { 728 const parsed = try parseGitCommand(allocator, "git-receive-pack 'user/proj'"); 729 defer parsed.deinit(allocator); 730 try std.testing.expectEqual(GitService.receive_pack, parsed.service); 731 try std.testing.expectEqualStrings("user/proj", parsed.dir); 732 } 733 { 734 const parsed = try parseGitCommand(allocator, "git-upload-pack repo"); 735 defer parsed.deinit(allocator); 736 try std.testing.expectEqual(GitService.upload_pack, parsed.service); 737 try std.testing.expectEqualStrings("repo", parsed.dir); 738 } 739 } 740