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