Skip to content

Commit e3e81cc

Browse files
committed
feat: Implement user profile editing feature
1 parent fc999d6 commit e3e81cc

File tree

8 files changed

+514
-22
lines changed

8 files changed

+514
-22
lines changed

bin/vine.zig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ fn dispatch(command: Command, args: []const []const u8) !void {
105105
.counters => try libvine.cli.runtime.runCounters(args, default_config_path),
106106
.snapshot => try libvine.cli.runtime.runSnapshot(args, default_config_path, default_runtime_state_path),
107107
.ping => try libvine.cli.runtime.runPing(args, default_config_path),
108-
.diagnostics => std.debug.print("vine diagnostics: not implemented yet\n", .{}),
108+
.diagnostics => try libvine.cli.runtime.runDiagnostics(args, default_config_path, default_runtime_state_path),
109109
}
110110
}
111111

lib/cli/config.zig

Lines changed: 108 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
const std = @import("std");
22
const file_config = @import("../config/file.zig");
33
const identity_store = @import("../config/identity_store.zig");
4+
const runtime = @import("../runtime/runtime.zig");
45

56
const Subcommand = enum {
67
validate,
@@ -35,10 +36,18 @@ fn handleValidate(args: []const []const u8, default_config_path: []const u8) !vo
3536
var cfg = try file_config.parse(allocator, raw);
3637
defer cfg.deinit(allocator);
3738
try validateFilesystem(config_path, cfg.node.identity_path);
39+
var runtime_cfg = try runtime.runtime_config.load(allocator, config_path);
40+
defer runtime_cfg.deinit(allocator);
3841

3942
std.debug.print(
40-
"config valid\npath={s}\nnetwork_id={s}\ntun={s}\n",
41-
.{ config_path, cfg.node.network_id, cfg.tun.name },
43+
"config valid\npath={s}\nnetwork_id={s}\ntun={s}\nallowed_peers={d}\nbootstrap_peers={d}\n",
44+
.{
45+
config_path,
46+
cfg.node.network_id,
47+
cfg.tun.name,
48+
runtime_cfg.enrolled_peers.len,
49+
runtime_cfg.startup_bootstrap_peers.len,
50+
},
4251
);
4352
}
4453

@@ -146,6 +155,103 @@ test "validate accepts a well formed config file" {
146155
try handleValidate(&.{ "-c", config_path }, "/etc/libvine/vine.toml");
147156
}
148157

158+
test "validate rejects tun names that cannot be loaded into runtime state" {
159+
var tmp = std.testing.tmpDir(.{});
160+
defer tmp.cleanup();
161+
162+
const dir_path = try tmp.dir.realpathAlloc(std.testing.allocator, ".");
163+
defer std.testing.allocator.free(dir_path);
164+
165+
const identity_path = try std.fmt.allocPrint(std.testing.allocator, "{s}/identity", .{dir_path});
166+
defer std.testing.allocator.free(identity_path);
167+
_ = try identity_store.generateAndWrite(identity_path);
168+
169+
const config_body = try std.fmt.allocPrint(
170+
std.testing.allocator,
171+
\\[node]
172+
\\name = "alpha"
173+
\\network_id = "home-net"
174+
\\identity_path = "{s}"
175+
\\
176+
\\[tun]
177+
\\name = "vine-interface-too-long"
178+
\\address = "10.42.0.1"
179+
\\prefix_len = 24
180+
\\mtu = 1400
181+
,
182+
.{identity_path},
183+
);
184+
defer std.testing.allocator.free(config_body);
185+
186+
const config_file = try tmp.dir.createFile("vine.toml", .{ .truncate = true, .mode = 0o600 });
187+
defer config_file.close();
188+
try config_file.writeAll(config_body);
189+
190+
const config_path = try std.fmt.allocPrint(std.testing.allocator, "{s}/vine.toml", .{dir_path});
191+
defer std.testing.allocator.free(config_path);
192+
193+
try std.testing.expectError(
194+
error.InvalidConfig,
195+
handleValidate(&.{ "-c", config_path }, "/etc/libvine/vine.toml"),
196+
);
197+
}
198+
199+
test "validate rejects overlapping allowed peer prefixes before startup" {
200+
var tmp = std.testing.tmpDir(.{});
201+
defer tmp.cleanup();
202+
203+
const dir_path = try tmp.dir.realpathAlloc(std.testing.allocator, ".");
204+
defer std.testing.allocator.free(dir_path);
205+
206+
const identity_path = try std.fmt.allocPrint(std.testing.allocator, "{s}/identity", .{dir_path});
207+
defer std.testing.allocator.free(identity_path);
208+
_ = try identity_store.generateAndWrite(identity_path);
209+
210+
const peer_a = [_]u8{0x41} ** 32;
211+
const peer_b = [_]u8{0x42} ** 32;
212+
const peer_a_hex = std.fmt.bytesToHex(peer_a, .lower);
213+
const peer_b_hex = std.fmt.bytesToHex(peer_b, .lower);
214+
215+
const config_body = try std.fmt.allocPrint(
216+
std.testing.allocator,
217+
\\[node]
218+
\\name = "alpha"
219+
\\network_id = "home-net"
220+
\\identity_path = "{s}"
221+
\\
222+
\\[tun]
223+
\\name = "vine0"
224+
\\address = "10.42.0.1"
225+
\\prefix_len = 24
226+
\\mtu = 1400
227+
\\
228+
\\[[allowed_peers]]
229+
\\peer_id = "{s}"
230+
\\prefix = "10.42.1.0/24"
231+
\\relay_capable = false
232+
\\
233+
\\[[allowed_peers]]
234+
\\peer_id = "{s}"
235+
\\prefix = "10.42.1.128/25"
236+
\\relay_capable = false
237+
,
238+
.{ identity_path, &peer_a_hex, &peer_b_hex },
239+
);
240+
defer std.testing.allocator.free(config_body);
241+
242+
const config_file = try tmp.dir.createFile("vine.toml", .{ .truncate = true, .mode = 0o600 });
243+
defer config_file.close();
244+
try config_file.writeAll(config_body);
245+
246+
const config_path = try std.fmt.allocPrint(std.testing.allocator, "{s}/vine.toml", .{dir_path});
247+
defer std.testing.allocator.free(config_path);
248+
249+
try std.testing.expectError(
250+
error.InvalidConfig,
251+
handleValidate(&.{ "-c", config_path }, "/etc/libvine/vine.toml"),
252+
);
253+
}
254+
149255
test "validate rejects relative config paths before daemon startup" {
150256
try std.testing.expectError(
151257
ConfigError.InvalidConfigPath,

0 commit comments

Comments
 (0)