summaryrefslogtreecommitdiff
path: root/internal/wireguard/wireguard_test.go
diff options
context:
space:
mode:
authorjwijenbergh <jeroenwijenbergh@protonmail.com>2024-02-07 13:43:52 +0100
committerJeroen Wijenbergh <46386452+jwijenbergh@users.noreply.github.com>2024-02-19 14:15:07 +0100
commitc8e7424f0b9ca963c7454e3297a8d001d67d729d (patch)
tree979341ca6b67badc451aa58d3790704b3bf04386 /internal/wireguard/wireguard_test.go
parenta912257ad6d4260fbea9c0e3e3fb9bbefa92bb6e (diff)
WireGuard: TCP support using proxyguard
Diffstat (limited to 'internal/wireguard/wireguard_test.go')
-rw-r--r--internal/wireguard/wireguard_test.go93
1 files changed, 72 insertions, 21 deletions
diff --git a/internal/wireguard/wireguard_test.go b/internal/wireguard/wireguard_test.go
index 026658e..ddb9d56 100644
--- a/internal/wireguard/wireguard_test.go
+++ b/internal/wireguard/wireguard_test.go
@@ -3,12 +3,36 @@ package wireguard
import (
"fmt"
"testing"
+
+ "github.com/eduvpn/eduvpn-common/internal/test"
+ "golang.zx2c4.com/wireguard/wgctrl/wgtypes"
)
-func Test_ConfigAddKey(t *testing.T) {
- config := `
-[Interface]
+func TestConfigReplace(t *testing.T) {
+ k, err := wgtypes.GeneratePrivateKey()
+ if err != nil {
+ t.Fatalf("Failed to generate key for wg config replace: %v", err)
+ }
+ cases := []struct {
+ config string
+ proxy string
+ want string
+ wantep string
+ werr string
+ }{
+ {
+ config: `
+`,
+ want: "",
+ wantep: "",
+ proxy: "",
+ werr: "parsed ini is empty",
+ },
+ {
+ config: `
+[Interface]
+PrivateKey = bla
[interface]
[interface2]
@@ -18,29 +42,56 @@ interface
[Interface]
[Interface]test
-`
- wgKey, wgKeyErr := GenerateKey()
-
- if wgKeyErr != nil {
- t.Fatalf("WireGuard config add key, generate key error: %v", wgKeyErr)
- }
- expectedConfig := fmt.Sprintf(`
-[Interface]
+`,
+ want: fmt.Sprintf(`[Interface]
PrivateKey = %s
-
[interface]
-
[interface2]
+`, k.String()),
+ wantep: "",
+ proxy: "",
+ werr: "",
+ },
+ {
+ config: `
+[Interface]
+MTU = 1392
+PrivateKey =
+Address = 10.146.176.5/24,fdee:1ead:29e8:22a2::5/64
+DNS = 9.9.9.9,2620:fe::fe
-interface
-
- [Interface]
+[Peer]
+PublicKey =
+AllowedIPs = 0.0.0.0/0,::/0
+# TCPEndpoint is a proprietary eduVPN / Let's Connect! extension
+# See https://docs.eduvpn.org/server/v3/proxyguard.html#client on how to use the TCP proxy
+TCPEndpoint = vpn.example.org:51820
+`,
+ want: fmt.Sprintf(`[Interface]
+MTU = 1392
+PrivateKey = %s
+Address = 10.146.176.5/24,fdee:1ead:29e8:22a2::5/64
+DNS = 9.9.9.9,2620:fe::fe
+[Peer]
+PublicKey =
+AllowedIPs = 0.0.0.0/0,::/0
+Endpoint = 127.0.0.1:1337
+`, k.String()),
+ wantep: "vpn.example.org:51820",
+ proxy: "127.0.0.1:1337",
+ werr: "",
+ },
+ }
-[Interface]test
-`, wgKey.String())
- gotConfig := ConfigAddKey(config, wgKey)
+ for _, c := range cases {
+ gcfg, gep, err := configReplace(c.config, k, c.proxy)
+ test.AssertError(t, err, c.werr)
+ if gcfg != c.want {
+ t.Fatalf("Got config: %s, not equal to config: %s", gcfg, c.want)
+ }
- if gotConfig != expectedConfig {
- t.Fatalf("Got: %s, Want: %s", gotConfig, expectedConfig)
+ if gep != c.wantep {
+ t.Fatalf("Got endpoint: %s, not equal to endpoint: %s", gep, c.wantep)
+ }
}
}