diff options
| author | James O'Doherty <james@theodohertyfamily.com> | 2026-05-29 19:30:26 -0400 |
|---|---|---|
| committer | James O'Doherty <james@theodohertyfamily.com> | 2026-05-29 19:30:26 -0400 |
| commit | b1b68a4aa441d9ce39d05f85338e371a704dd601 (patch) | |
| tree | 63491b88a18522eafddbd4b7525bb89bc2a04732 /internal/cli/profile_test.go | |
| parent | 70096b533d42b684ab13651aaae884047e01e43d (diff) | |
feat(cli,parser): support custom profile names and overhaul WireGuard .conf parser for robustness
- CLI:
- Add optional `[name]` argument to `wg-wrap profile import <path> [name]` to allow overriding the imported profile name. If not provided, it falls back to the derived filename.
- Update `README.md` command documentation to reflect custom profile names and list the `wg-wrap profile stop <name>` subcommand.
- Expand `internal/cli/profile_test.go` to cover derived vs custom-named profile imports.
- WG Configuration Parser:
- Overhaul `pkg/wgconf/wgconf.go` to support case-insensitivity on section headers (e.g. `[peer]`, `[interface]`) and key names (e.g. `privatekey`, `allowedips`).
- Implement robust trailing comment stripping (both `#` and `;`) while preserving inline comment-like characters in cryptographic keys (e.g. `key-with-hash-inside#123`) using whitespace-padded match logic.
- Clean up and normalize leading/trailing spaces/tabs on parsed keys, values, and list elements (e.g. `AllowedIPs` and `DNS` fields).
- Gracefully ignore unrecognized keys (e.g. `MTU`, `ListenPort`, `PresharedKey`) without returning errors.
- Add comprehensive tests in `pkg/wgconf/wgconf_test.go` covering inline/block comments, formatting variations, unrecognized keys, and case-insensitivity.
Diffstat (limited to 'internal/cli/profile_test.go')
| -rw-r--r-- | internal/cli/profile_test.go | 18 |
1 files changed, 17 insertions, 1 deletions
diff --git a/internal/cli/profile_test.go b/internal/cli/profile_test.go index 17a5bc6..c9b1274 100644 --- a/internal/cli/profile_test.go +++ b/internal/cli/profile_test.go @@ -41,6 +41,7 @@ func TestProfileImport(t *testing.T) { t.Fatalf("failed to create source conf: %v", err) } + // 1. Test importing with derived name (no explicit name argument) app := NewApp([]string{"wg-wrap", "profile", "import", srcFile}) app.ConfigDir = profilesDir @@ -49,11 +50,26 @@ func TestProfileImport(t *testing.T) { t.Errorf("expected no error, got %v", err) } - // Verify the file was actually copied + // Verify the file was actually copied to derived name destFile := filepath.Join(profilesDir, "source.conf") if _, err := os.Stat(destFile); os.IsNotExist(err) { t.Errorf("expected profile to be imported to %s", destFile) } + + // 2. Test importing with explicit name argument + customName := "custom-vpn" + appCustom := NewApp([]string{"wg-wrap", "profile", "import", srcFile, customName}) + appCustom.ConfigDir = profilesDir + + err = appCustom.Route() + if err != nil { + t.Errorf("expected no error for custom name import, got %v", err) + } + + destCustomFile := filepath.Join(profilesDir, customName+".conf") + if _, err := os.Stat(destCustomFile); os.IsNotExist(err) { + t.Errorf("expected profile to be imported to %s", destCustomFile) + } } func TestProfileDelete(t *testing.T) { |
