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