╭─────────────╮ │scroll to top│ ╰─────────────╯ ╭ serve_ssh.zig ────────────────────────────────────────────────╮ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ ╰───────────────────────────────────────────────────────────────╯
╭────╮ ╭ clone ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╮ │http│ ssh │ │ ╰────╯ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╯
582 const body = "ERR haxy ssh: " ++ msg; 583 var packet: [body.len + 4]u8 = undefined; 584 const line = try std.fmt.bufPrint(&packet, "{x:0>4}{s}", .{ packet.len, body }); 585 try sess.writeBytes(line); 586 try sess.exit(1); 587 } 588 589 test "parseGitCommand rejects malformed input" { 590 const allocator = std.testing.allocator; 591 try std.testing.expectError(error.InvalidCommand, parseGitCommand(allocator, "git-upload-pack")); 592 try std.testing.expectError(error.UnsupportedService, parseGitCommand(allocator, "ls -la")); 593 try std.testing.expectError(error.UnsupportedService, parseGitCommand(allocator, "git-fake-pack 'repo'")); 594 } 595 596 test "parseGitCommand happy paths" { 597 const allocator = std.testing.allocator; 598 599 { 600 const parsed = try parseGitCommand(allocator, "git-upload-pack 'some-repo'"); 601 defer parsed.deinit(allocator); 602 try std.testing.expectEqual(GitService.upload_pack, parsed.service); 603 try std.testing.expectEqualStrings("some-repo", parsed.dir); 604 } 605 { 606 const parsed = try parseGitCommand(allocator, "git-receive-pack 'user/proj'"); 607 defer parsed.deinit(allocator); 608 try std.testing.expectEqual(GitService.receive_pack, parsed.service); 609 try std.testing.expectEqualStrings("user/proj", parsed.dir); 610 } 611 { 612 const parsed = try parseGitCommand(allocator, "git-upload-pack repo"); 613 defer parsed.deinit(allocator); 614 try std.testing.expectEqual(GitService.upload_pack, parsed.service); 615 try std.testing.expectEqualStrings("repo", parsed.dir); 616 } 617 } 618