╭──────────╮ │← previous│ ╰──────────╯ ╭ changed ───────╮ │src/test/net.zig│ ╰────────────────╯ ╭──────────────────────────────────────────────────────────────────────────────────────────────────────╮ │177 // add a tag │ │178 _ = try server_repo.addTag(io, allocator, .{ .name = "1.0.0", .message = "hi" }); │ │179 │ │180 + const cwd_path = try std.process.currentPathAlloc(io, allocator); │ │181 + defer allocator.free(cwd_path); │ │182 + │ │183 const client_path = try std.fs.path.join(allocator, &.{ cwd_path, temp_dir_name, "client" });│ │184 defer allocator.free(client_path); │ │185 │ ╰──────────────────────────────────────────────────────────────────────────────────────────────────────╯ ╭──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮ │188 │ │189 // add remote │ │190 { │ │188 - if (.windows == builtin.os.tag) { │ │189 - std.mem.replaceScalar(u8, server_path, '\\', '/'); │ │190 - } │ │191 - const separator = if (server_path[0] == '/') "" else "/"; │ │192 - │ │193 - const remote_url = switch (transport_def) { │ │194 - //.file => try std.fmt.allocPrint(allocator, "file://{s}{s}", .{ separator, server_path }), │ │195 - .file => try std.fmt.allocPrint(allocator, "../server", .{}), // relative file paths work too │ │196 - .wire => |wire_kind| switch (wire_kind) { │ │197 - .http => try std.fmt.allocPrint(allocator, "http://localhost:{}/server", .{http_port}), │ │198 - .raw => try std.fmt.allocPrint(allocator, "git://localhost:{}/server", .{http_port}), │ │199 - .ssh => try std.fmt.allocPrint(allocator, "ssh://localhost:{}{s}{s}", .{ ssh_port, separator, server_path }),│ │200 - }, │ │201 - }; │ │191 + const remote_url = try remoteUrl(transport_def, allocator, "testrepo"); │ │192 defer allocator.free(remote_url); │ │193 │ │194 try client_repo.addRemote(io, allocator, .{ .name = "origin", .value = remote_url }); │ ╰──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯ ╭──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮ │208 .file => false, │ │209 .wire => |wire_kind| .ssh == wire_kind, │ │210 }; │ │221 - // haxy generates a fresh host key on every run, so don't try to record │ │222 - // it. accept the unknown host and skip writing to known_hosts. the key │ │223 - // identity flag picks the ed25519 key created in runServer. │ │224 - const ssh_cmd_maybe: ?[]const u8 = if (is_ssh) blk: { │ │225 - const priv_key_path = try std.fs.path.join(allocator, &.{ cwd_path, temp_dir_name, "key" }); │ │226 - defer allocator.free(priv_key_path); │ │227 - │ │228 - break :blk try std.fmt.allocPrint(allocator, "ssh -o BatchMode=yes -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -o IdentitiesOnly=yes -o IdentityFile=\"{s}\"", .{priv_key_path});│ │229 - } else null; │ │211 + const ssh_cmd_maybe = try sshCommand(is_ssh, allocator, cwd_path, temp_dir_name); │ │212 defer if (ssh_cmd_maybe) |ssh_cmd| allocator.free(ssh_cmd); │ │213 │ │214 try client_repo.fetch( │ ╰──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯ ╭─────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮ │289 var server_process = try runServer(io, allocator, temp_dir_name); │ │290 defer _ = server_process.kill(io); │ │291 │ │310 - const cwd_path = try std.process.currentPathAlloc(io, allocator); │ │311 - defer allocator.free(cwd_path); │ │312 - │ │313 - const server_path = try std.fs.path.join(allocator, &.{ cwd_path, temp_dir_name, "repos", "server" }); │ │292 + // register the repo under admin and locate its on-disk directory │ │293 + const server_path = (try repoOnDiskPath(io, allocator, temp_dir_name, "testrepo", true)).?; │ │294 defer allocator.free(server_path); │ │295 │ │296 var server_repo = try rp.Repo(.xit, .{ .is_test = true }).init(io, allocator, .{ .path = server_path });│ ╰─────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯ ╭──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮ │297 defer server_repo.deinit(io, allocator); │ │298 │ │299 // add config │ │320 - switch (transport_def) { │ │321 - .file => try server_repo.addConfig(io, allocator, .{ .name = "core.bare", .value = "true" }), │ │322 - .wire => { │ │323 - try server_repo.addConfig(io, allocator, .{ .name = "core.bare", .value = "false" }); │ │324 - try server_repo.addConfig(io, allocator, .{ .name = "receive.denycurrentbranch", .value = "updateinstead" });│ │325 - }, │ │326 - } │ │300 + try server_repo.addConfig(io, allocator, .{ .name = "core.bare", .value = "false" }); │ │301 + try server_repo.addConfig(io, allocator, .{ .name = "receive.denycurrentbranch", .value = "updateinstead" }); │ │302 try server_repo.addConfig(io, allocator, .{ .name = "http.receivepack", .value = "true" }); │ │303 │ │304 // export server repo │ ╰──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯ ╭───────────────────────────────────────────────────────────────────────────────────────────────────────────╮ │306 const export_file = try server_repo.core.repo_dir.createFile(io, "git-daemon-export-ok", .{});│ │307 defer export_file.close(io); │ │308 } │ │309 + │ │310 + const cwd_path = try std.process.currentPathAlloc(io, allocator); │ │311 + defer allocator.free(cwd_path); │ │312 │ │313 const client_path = try std.fs.path.join(allocator, &.{ cwd_path, temp_dir_name, "client" }); │ │314 defer allocator.free(client_path); │ ╰───────────────────────────────────────────────────────────────────────────────────────────────────────────╯ ╭──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮ │330 │ │331 // add remote │ │332 { │ │355 - if (.windows == builtin.os.tag) { │ │356 - std.mem.replaceScalar(u8, server_path, '\\', '/'); │ │357 - } │ │358 - const separator = if (server_path[0] == '/') "" else "/"; │ │359 - │ │360 - const remote_url = switch (transport_def) { │ │361 - //.file => try std.fmt.allocPrint(allocator, "file://{s}{s}", .{ separator, server_path }), │ │362 - .file => try std.fmt.allocPrint(allocator, "../server", .{}), // relative file paths work too │ │363 - .wire => |wire_kind| switch (wire_kind) { │ │364 - .http => try std.fmt.allocPrint(allocator, "http://localhost:{}/server", .{http_port}), │ │365 - .raw => try std.fmt.allocPrint(allocator, "git://localhost:{}/server", .{http_port}), │ │366 - .ssh => try std.fmt.allocPrint(allocator, "ssh://localhost:{}{s}{s}", .{ ssh_port, separator, server_path }),│ │367 - }, │ │368 - }; │ │333 + const remote_url = try remoteUrl(transport_def, allocator, "testrepo"); │ │334 defer allocator.free(remote_url); │ │335 │ │336 try client_repo.addRemote(io, allocator, .{ .name = "origin", .value = remote_url }); │ ╰──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯ ╭──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮ │345 .file => false, │ │346 .wire => |wire_kind| .ssh == wire_kind, │ │347 }; │ │383 - // haxy generates a fresh host key on every run, so don't try to record │ │384 - // it. accept the unknown host and skip writing to known_hosts. the key │ │385 - // identity flag picks the ed25519 key created in runServer. │ │386 - const ssh_cmd_maybe: ?[]const u8 = if (is_ssh) blk: { │ │387 - const priv_key_path = try std.fs.path.join(allocator, &.{ cwd_path, temp_dir_name, "key" }); │ │388 - defer allocator.free(priv_key_path); │ │389 - │ │390 - break :blk try std.fmt.allocPrint(allocator, "ssh -o BatchMode=yes -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -o IdentitiesOnly=yes -o IdentityFile=\"{s}\"", .{priv_key_path});│ │391 - } else null; │ │348 + const ssh_cmd_maybe = try sshCommand(is_ssh, allocator, cwd_path, temp_dir_name); │ │349 defer if (ssh_cmd_maybe) |ssh_cmd| allocator.free(ssh_cmd); │ │350 │ │351 try client_repo.push( │ ╰──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯ ╭───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮ │440 } } }, │ │441 )); │ │442 │ │486 - // test denyNonFastForwards (only for wire transports, file transport bypasses receive-pack) │ │487 - switch (transport_def) { │ │488 - .file => {}, │ │489 - .wire => { │ │490 - // set denyNonFastForwards on server │ │491 - try server_repo.addConfig(io, allocator, .{ .name = "receive.denynonfastforwards", .value = "true" });│ │443 + // test denyNonFastForwards │ │444 + { │ │445 + // set denyNonFastForwards on server │ │446 + try server_repo.addConfig(io, allocator, .{ .name = "receive.denynonfastforwards", .value = "true" }); │ │447 │ │493 - // save the server's current master ref │ │494 - const oid_before_denied_push = (try server_repo.readRef(io, .{ .kind = .head, .name = "master" })).?; │ │448 + // save the server's current master ref │ │449 + const oid_before_denied_push = (try server_repo.readRef(io, .{ .kind = .head, .name = "master" })).?; │ │450 │ │496 - // force push should be rejected by server due to denyNonFastForwards │ │497 - try client_repo.push( │ │498 - io, │ │499 - allocator, │ │500 - "origin", │ │501 - "master", │ │502 - true, │ │503 - .{ .wire = .{ .ssh = .{ │ │504 - .command = ssh_cmd_maybe, │ │505 - } } }, │ │506 - ); │ │451 + // force push should be rejected by server due to denyNonFastForwards │ │452 + try client_repo.push( │ │453 + io, │ │454 + allocator, │ │455 + "origin", │ │456 + "master", │ │457 + true, │ │458 + .{ .wire = .{ .ssh = .{ │ │459 + .command = ssh_cmd_maybe, │ │460 + } } }, │ │461 + ); │ │462 │ │508 - // verify the server ref was not updated (push was denied) │ │509 - { │ │510 - const oid_master = (try server_repo.readRef(io, .{ .kind = .head, .name = "master" })).?; │ │511 - try std.testing.expectEqualStrings(&oid_before_denied_push, &oid_master); │ │512 - } │ │463 + // verify the server ref was not updated (push was denied) │ │464 + { │ │465 + const oid_master = (try server_repo.readRef(io, .{ .kind = .head, .name = "master" })).?; │ │466 + try std.testing.expectEqualStrings(&oid_before_denied_push, &oid_master); │ │467 + } │ │468 │ │514 - // remove denyNonFastForwards from server │ │515 - try server_repo.removeConfig(io, allocator, .{ .name = "receive.denynonfastforwards" }); │ │516 - }, │ │469 + // remove denyNonFastForwards from server │ │470 + try server_repo.removeConfig(io, allocator, .{ .name = "receive.denynonfastforwards" }); │ │471 } │ │472 │ │473 // force push │ ╰───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯ ╭───────────────────────────────────────────────────────────────────────────────────────────────────────────────╮ │527 │ │528 const cwd_path = try std.process.currentPathAlloc(io, allocator); │ │529 defer allocator.free(cwd_path); │ │576 - │ │577 - const server_path = try std.fs.path.join(allocator, &.{ cwd_path, temp_dir_name, "repos", "server" });│ │578 - defer allocator.free(server_path); │ │530 │ │531 const client_path = try std.fs.path.join(allocator, &.{ cwd_path, temp_dir_name, "client" }); │ │532 defer allocator.free(client_path); │ ╰───────────────────────────────────────────────────────────────────────────────────────────────────────────────╯ ╭──────╮ │next →│ ╰──────╯