corpus: add root
This commit is contained in:
parent
4daa6fd38a
commit
692d80cdd7
@ -501,6 +501,13 @@ const someMembers = @import("group.zig").someMembers;
|
||||
|
||||
fn testCorpus(allocator: Allocator) !Corpus {
|
||||
const users = [_]User{ User{
|
||||
.uid = 0,
|
||||
.gid = 0,
|
||||
.name = "root",
|
||||
.gecos = "",
|
||||
.home = "/root",
|
||||
.shell = "/bin/bash",
|
||||
}, User{
|
||||
.uid = 128,
|
||||
.gid = 128,
|
||||
.name = "vidmantas",
|
||||
@ -508,14 +515,14 @@ fn testCorpus(allocator: Allocator) !Corpus {
|
||||
.home = "/home/vidmantas",
|
||||
.shell = "/bin/bash",
|
||||
}, User{
|
||||
.uid = 0,
|
||||
.uid = 1000,
|
||||
.gid = math.maxInt(u32),
|
||||
.name = "Name" ** 8,
|
||||
.gecos = "Gecos" ** 51,
|
||||
.home = "Home" ** 16,
|
||||
.shell = "She.LllL" ** 8,
|
||||
}, User{
|
||||
.uid = 1002,
|
||||
.uid = 100000,
|
||||
.gid = 1002,
|
||||
.name = "svc-bar",
|
||||
.gecos = "",
|
||||
@ -530,6 +537,12 @@ fn testCorpus(allocator: Allocator) !Corpus {
|
||||
.shell = "/usr/sbin/nologin",
|
||||
} };
|
||||
|
||||
var members0 = try someMembers(
|
||||
allocator,
|
||||
&[_][]const u8{"root"},
|
||||
);
|
||||
defer members0.deinit();
|
||||
|
||||
var members1 = try someMembers(
|
||||
allocator,
|
||||
&[_][]const u8{"vidmantas"},
|
||||
@ -544,14 +557,15 @@ fn testCorpus(allocator: Allocator) !Corpus {
|
||||
|
||||
var members3 = try someMembers(
|
||||
allocator,
|
||||
&[_][]const u8{ "svc-bar", "Name" ** 8, "vidmantas" },
|
||||
&[_][]const u8{ "svc-bar", "Name" ** 8, "vidmantas", "root" },
|
||||
);
|
||||
defer members3.deinit();
|
||||
|
||||
const groups = [_]Group{
|
||||
Group{ .gid = 0, .name = "root", .members = members0 },
|
||||
Group{ .gid = 128, .name = "vidmantas", .members = members1 },
|
||||
Group{ .gid = 9999, .name = "all", .members = members3 },
|
||||
Group{ .gid = 0, .name = "service-account", .members = members2 },
|
||||
Group{ .gid = 100000, .name = "service-account", .members = members2 },
|
||||
};
|
||||
|
||||
return try Corpus.init(allocator, users[0..], groups[0..]);
|
||||
@ -563,20 +577,24 @@ test "test corpus" {
|
||||
|
||||
const name_name = 0;
|
||||
const nobody = 1;
|
||||
const svc_bar = 2;
|
||||
const vidmantas = 3;
|
||||
const root = 2;
|
||||
const svc_bar = 3;
|
||||
const vidmantas = 4;
|
||||
|
||||
const usernames = corpus.users.items(.name);
|
||||
try testing.expectEqualStrings(usernames[name_name], "Name" ** 8);
|
||||
try testing.expectEqualStrings(usernames[nobody], "nobody");
|
||||
try testing.expectEqualStrings(usernames[root], "root");
|
||||
try testing.expectEqualStrings(usernames[svc_bar], "svc-bar");
|
||||
try testing.expectEqualStrings(usernames[vidmantas], "vidmantas");
|
||||
|
||||
const g_service_account = 0;
|
||||
const g_root = 0;
|
||||
const g_vidmantas = 1;
|
||||
const g_all = 2;
|
||||
const g_service_account = 3;
|
||||
|
||||
const groupnames = corpus.groups.items(.name);
|
||||
try testing.expectEqualStrings(groupnames[g_root], "root");
|
||||
try testing.expectEqualStrings(groupnames[g_service_account], "service-account");
|
||||
try testing.expectEqualStrings(groupnames[g_vidmantas], "vidmantas");
|
||||
try testing.expectEqualStrings(groupnames[g_all], "all");
|
||||
@ -588,13 +606,14 @@ test "test corpus" {
|
||||
|
||||
const membersOfAll = corpus.group2users[g_all];
|
||||
try testing.expectEqual(membersOfAll[0], name_name);
|
||||
try testing.expectEqual(membersOfAll[1], svc_bar);
|
||||
try testing.expectEqual(membersOfAll[2], vidmantas);
|
||||
try testing.expectEqual(membersOfAll[1], root);
|
||||
try testing.expectEqual(membersOfAll[2], svc_bar);
|
||||
try testing.expectEqual(membersOfAll[3], vidmantas);
|
||||
|
||||
const groupsOfVidmantas = corpus.user2groups[vidmantas];
|
||||
try testing.expectEqual(groupsOfVidmantas[0], g_service_account);
|
||||
try testing.expectEqual(groupsOfVidmantas[1], g_vidmantas);
|
||||
try testing.expectEqual(groupsOfVidmantas[2], g_all);
|
||||
try testing.expectEqual(groupsOfVidmantas[0], g_vidmantas);
|
||||
try testing.expectEqual(groupsOfVidmantas[1], g_all);
|
||||
try testing.expectEqual(groupsOfVidmantas[2], g_service_account);
|
||||
}
|
||||
|
||||
test "test groups, group members and users" {
|
||||
@ -672,7 +691,8 @@ test "pack gids" {
|
||||
const k1 = bdz.search_u32(cmph_gid, 0);
|
||||
const k2 = bdz.search_u32(cmph_gid, 128);
|
||||
const k3 = bdz.search_u32(cmph_gid, 9999);
|
||||
var hashes = &[_]u32{ k1, k2, k3 };
|
||||
const k4 = bdz.search_u32(cmph_gid, 100000);
|
||||
var hashes = &[_]u32{ k1, k2, k3, k4 };
|
||||
sort.sort(u32, hashes, {}, comptime sort.asc(u32));
|
||||
for (hashes) |hash, i|
|
||||
try testing.expectEqual(i, hash);
|
||||
|
Loading…
Reference in New Issue
Block a user