╭─────────────╮ │scroll to top│ ╰─────────────╯ ╭ serve_ssh.zig ────────────────────────────────────────────────╮ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ ╰───────────────────────────────────────────────────────────────╯
╭────╮ ╭ clone ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╮ │http│ ssh │ │ ╰────╯ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╯
536 decoder.decode(blob_buf[0..blob_len], blob_b64) catch return null; 537 538 return ssh.formatFingerprint(blob_buf[0..blob_len]); 539 } 540 541 fn writeError(sess: *ssh.SessionCtx, comptime msg: []const u8) !void { 542 const body = "ERR haxy ssh: " ++ msg; 543 var packet: [body.len + 4]u8 = undefined; 544 const line = try std.fmt.bufPrint(&packet, "{x:0>4}{s}", .{ packet.len, body }); 545 try sess.writeBytes(line); 546 try sess.exit(1); 547 } 548 549 test "parseGitCommand rejects malformed input" { 550 const allocator = std.testing.allocator; 551 try std.testing.expectError(error.InvalidCommand, parseGitCommand(allocator, "git-upload-pack")); 552 try std.testing.expectError(error.UnsupportedService, parseGitCommand(allocator, "ls -la")); 553 try std.testing.expectError(error.UnsupportedService, parseGitCommand(allocator, "git-fake-pack 'repo'")); 554 } 555 556 test "parseGitCommand happy paths" { 557 const allocator = std.testing.allocator; 558 559 { 560 const parsed = try parseGitCommand(allocator, "git-upload-pack 'some-repo'"); 561 defer parsed.deinit(allocator); 562 try std.testing.expectEqual(GitService.upload_pack, parsed.service); 563 try std.testing.expectEqualStrings("some-repo", parsed.dir); 564 } 565 { 566 const parsed = try parseGitCommand(allocator, "git-receive-pack 'user/proj'"); 567 defer parsed.deinit(allocator); 568 try std.testing.expectEqual(GitService.receive_pack, parsed.service); 569 try std.testing.expectEqualStrings("user/proj", parsed.dir); 570 } 571 { 572 const parsed = try parseGitCommand(allocator, "git-upload-pack repo"); 573 defer parsed.deinit(allocator); 574 try std.testing.expectEqual(GitService.upload_pack, parsed.service); 575 try std.testing.expectEqualStrings("repo", parsed.dir); 576 } 577 } 578