a73x

ce7a9218

test: xdg refusal test re-reads by path, not by kept fd

a73x   2026-08-09 11:55

Commit message
test: xdg refusal test re-reads by path, not by kept fd

src/xdg.zig
Old New
@@ -112,9 +112,15 @@ test "writeNewKey: creates 0600 with 32 bytes, refuses to overwrite" {
112 try std.testing.expectEqual(@as(usize, 32), try f.preadAll(&first, 0)); 112 try std.testing.expectEqual(@as(usize, 32), try f.preadAll(&first, 0));
113 113
114 // Refusal leaves the file byte-identical: a credential is never 114 // Refusal leaves the file byte-identical: a credential is never
115 // silently replaced. 115 // silently replaced. Re-opened by PATH rather than read through `f`,
116 // because the kept fd follows the inode: an implementation that
117 // unlinked and rewrote the key would still hand the old fd the old
118 // bytes, and this assertion would pass while the credential on disk
119 // had been replaced.
116 try std.testing.expectError(error.KeyExists, writeNewKey(path)); 120 try std.testing.expectError(error.KeyExists, writeNewKey(path));
121 const f2 = try std.fs.cwd().openFile(path, .{});
122 defer f2.close();
117 var second: [32]u8 = undefined; 123 var second: [32]u8 = undefined;
118 try std.testing.expectEqual(@as(usize, 32), try f.preadAll(&second, 0)); 124 try std.testing.expectEqual(@as(usize, 32), try f2.preadAll(&second, 0));
119 try std.testing.expectEqualSlices(u8, &first, &second); 125 try std.testing.expectEqualSlices(u8, &first, &second);
120 } 126 }