diff options
| author | jwijenbergh <jeroenwijenbergh@protonmail.com> | 2022-10-04 14:53:58 +0200 |
|---|---|---|
| committer | jwijenbergh <jeroenwijenbergh@protonmail.com> | 2022-10-04 14:53:58 +0200 |
| commit | 762a034cc1af55d09dc0a174947356e36bf15569 (patch) | |
| tree | 4c29d0ebd131a919accc944599d3c10ba61b09d2 /state_test.go | |
| parent | 0096d0471fef972e305a61435623d64b7da4f0d9 (diff) | |
Server: Implement `prefer_tcp` according to spec
Diffstat (limited to 'state_test.go')
| -rw-r--r-- | state_test.go | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/state_test.go b/state_test.go index 5647b12..82d88e2 100644 --- a/state_test.go +++ b/state_test.go @@ -350,3 +350,49 @@ func Test_invalid_profile_corrected(t *testing.T) { ) } } + +// Test if an invalid profile will be corrected +func Test_prefer_tcp(t *testing.T) { + serverURI := getServerURI(t) + state := &VPNState{} + + ensureLocalWellKnown() + + registerErr := state.Register( + "org.eduvpn.app.linux", + "configsprefertcp", + func(old FSMStateID, new FSMStateID, data interface{}) { + stateCallback(t, old, new, data, state) + }, + false, + ) + if registerErr != nil { + t.Fatalf("Register error: %v", registerErr) + } + + // get a config with preferTCP set to true + config, configType, configErr := state.GetConfigCustomServer(serverURI, true) + + // Test server should accept prefer TCP! + if configType != "openvpn" { + t.Fatalf("Invalid protocol for prefer TCP, got: WireGuard, want: OpenVPN") + } + + if configErr != nil { + t.Fatalf("Config error: %v", configErr) + } + + if !strings.HasSuffix(config, "remote eduvpnserver 1194 tcp\nremote eduvpnserver 1194 udp") { + t.Fatalf("Suffix for prefer TCP is not in the right order for config: %s", config) + } + + // get a config with preferTCP set to false + config, configType, configErr = state.GetConfigCustomServer(serverURI, false) + if configErr != nil { + t.Fatalf("Config error: %v", configErr) + } + + if configType == "openvpn" && !strings.HasSuffix(config, "remote eduvpnserver 1194 udp\nremote eduvpnserver 1194 tcp") { + t.Fatalf("Suffix for disable prefer TCP is not in the right order for config: %s", config) + } +} |
