diff options
| -rw-r--r-- | client/client_test.go | 23 | ||||
| -rw-r--r-- | client/fsm.go | 4 | ||||
| -rw-r--r-- | client/server.go | 4 | ||||
| -rw-r--r-- | cmd/cli/main.go | 19 |
4 files changed, 26 insertions, 24 deletions
diff --git a/client/client_test.go b/client/client_test.go index 57196e4..64c0430 100644 --- a/client/client_test.go +++ b/client/client_test.go @@ -12,6 +12,7 @@ import ( httpw "github.com/eduvpn/eduvpn-common/internal/http" "github.com/eduvpn/eduvpn-common/internal/util" + "github.com/eduvpn/eduvpn-common/internal/oauth" "github.com/go-errors/errors" ) @@ -93,7 +94,7 @@ func TestServer(t *testing.T) { if addErr != nil { t.Fatalf("Add error: %v", addErr) } - _, _, configErr := state.GetConfigCustomServer(serverURI, false) + _, configErr := state.GetConfigCustomServer(serverURI, false, oauth.Token{}) if configErr != nil { t.Fatalf("Connect error: %v", configErr) } @@ -252,7 +253,7 @@ func TestTokenExpired(t *testing.T) { t.Fatalf("Add error: %v", addErr) } - _, _, configErr := state.GetConfigCustomServer(serverURI, false) + _, configErr := state.GetConfigCustomServer(serverURI, false, oauth.Token{}) if configErr != nil { t.Fatalf("Connect error before expired: %v", configErr) @@ -273,7 +274,7 @@ func TestTokenExpired(t *testing.T) { // Wait for TTL so that the tokens expire time.Sleep(time.Duration(expiredInt) * time.Second) - _, _, configErr = state.GetConfigCustomServer(serverURI, false) + _, configErr = state.GetConfigCustomServer(serverURI, false, oauth.Token{}) if configErr != nil { t.Fatalf("Connect error after expiry: %v", configErr) @@ -314,7 +315,7 @@ func TestInvalidProfileCorrected(t *testing.T) { t.Fatalf("Add error: %v", addErr) } - _, _, configErr := state.GetConfigCustomServer(serverURI, false) + _, configErr := state.GetConfigCustomServer(serverURI, false, oauth.Token{}) if configErr != nil { t.Fatalf("First connect error: %v", configErr) @@ -333,7 +334,7 @@ func TestInvalidProfileCorrected(t *testing.T) { previousProfile := base.Profiles.Current base.Profiles.Current = "IDONOTEXIST" - _, _, configErr = state.GetConfigCustomServer(serverURI, false) + _, configErr = state.GetConfigCustomServer(serverURI, false, oauth.Token{}) if configErr != nil { t.Fatalf("Second connect error: %v", configErr) @@ -373,10 +374,10 @@ func TestPreferTCP(t *testing.T) { } // get a config with preferTCP set to true - config, configType, configErr := state.GetConfigCustomServer(serverURI, true) + config, configErr := state.GetConfigCustomServer(serverURI, true, oauth.Token{}) // Test server should accept prefer TCP! - if configType != "openvpn" { + if config.Type != "openvpn" { t.Fatalf("Invalid protocol for prefer TCP, got: WireGuard, want: OpenVPN") } @@ -384,18 +385,18 @@ func TestPreferTCP(t *testing.T) { t.Fatalf("Config error: %v", configErr) } - if !strings.HasSuffix(config, "remote eduvpnserver 1194 tcp\nremote eduvpnserver 1194 udp") { + if !strings.HasSuffix(config.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) + config, configErr = state.GetConfigCustomServer(serverURI, false, oauth.Token{}) if configErr != nil { t.Fatalf("Config error: %v", configErr) } - if configType == "openvpn" && - !strings.HasSuffix(config, "remote eduvpnserver 1194 udp\nremote eduvpnserver 1194 tcp") { + if config.Type == "openvpn" && + !strings.HasSuffix(config.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) } } diff --git a/client/fsm.go b/client/fsm.go index 76dee05..c156fba 100644 --- a/client/fsm.go +++ b/client/fsm.go @@ -212,7 +212,7 @@ func (c *Client) SetSearchServer() error { return err } - //TODO(jwijenbergh): Should we handle `false` returned value here? + // TODO(jwijenbergh): Should we handle `false` returned value here? c.FSM.GoTransition(StateSearchServer) return nil } @@ -325,7 +325,7 @@ func (c *Client) SetDisconnected(cleanup bool) error { func (c *Client) goBackInternal() { err := c.GoBack() if err != nil { - //TODO(jwijenbergh): Bit suspicious - logging level INFO, yet stacktrace logged. + // TODO(jwijenbergh): Bit suspicious - logging level INFO, yet stacktrace logged. c.Logger.Infof("failed going back: %s\nstacktrace:\n%s", err.Error(), err.(*errors.Error).ErrorStack()) } } diff --git a/client/server.go b/client/server.go index 0bb37a8..27cb79b 100644 --- a/client/server.go +++ b/client/server.go @@ -86,8 +86,8 @@ func (c *Client) getConfig(srv server.Server, preferTCP bool, t oauth.Token) (*C // Save the config if err = c.Config.Save(&c); err != nil { - //TODO(jwijenbergh): Not sure why INFO level, yet stacktrace... - //TODO(jwijenbergh): Even worse, why logging it but then return nil? The calling code will think that everything went well. + // TODO(jwijenbergh): Not sure why INFO level, yet stacktrace... + // TODO(jwijenbergh): Even worse, why logging it but then return nil? The calling code will think that everything went well. c.Logger.Infof("c.Config.Save failed: %s\nstacktrace:\n%s", err.Error(), err.(*errors.Error).ErrorStack()) } diff --git a/cmd/cli/main.go b/cmd/cli/main.go index 08c964a..599cd20 100644 --- a/cmd/cli/main.go +++ b/cmd/cli/main.go @@ -7,6 +7,7 @@ import ( "strings" "github.com/eduvpn/eduvpn-common/client" + "github.com/eduvpn/eduvpn-common/internal/oauth" "github.com/eduvpn/eduvpn-common/internal/server" "github.com/go-errors/errors" ) @@ -80,7 +81,7 @@ func stateCallback(state *client.Client, oldState client.FSMStateID, newState cl } // Get a config for Institute Access or Secure Internet Server. -func getConfig(state *client.Client, url string, srvType ServerTypes) (string, string, error) { +func getConfig(state *client.Client, url string, srvType ServerTypes) (*client.ConfigData, error) { if !strings.HasPrefix(url, "http") { url = "https://" + url } @@ -88,21 +89,21 @@ func getConfig(state *client.Client, url string, srvType ServerTypes) (string, s if srvType == ServerTypeInstituteAccess { _, err := state.AddInstituteServer(url) if err != nil { - return "", "", err + return nil, err } - return state.GetConfigInstituteAccess(url, false) + return state.GetConfigInstituteAccess(url, false, oauth.Token{}) } else if srvType == ServerTypeCustom { _, err := state.AddCustomServer(url) if err != nil { - return "", "", err + return nil, err } - return state.GetConfigCustomServer(url, false) + return state.GetConfigCustomServer(url, false, oauth.Token{}) } _, err := state.AddSecureInternetHomeServer(url) if err != nil { - return "", "", err + return nil, err } - return state.GetConfigSecureInternet(url, false) + return state.GetConfigSecureInternet(url, false, oauth.Token{}) } // Get a config for a single server, Institute Access or Secure Internet. @@ -126,7 +127,7 @@ func printConfig(url string, srvType ServerTypes) { defer c.Deregister() - cfg, _, err := getConfig(c, url, srvType) + cfg, err := getConfig(c, url, srvType) if err != nil { err1 := err.(*errors.Error) // Show the usage of tracebacks and causes @@ -135,7 +136,7 @@ func printConfig(url string, srvType ServerTypes) { return } - fmt.Println("Obtained config:", cfg) + fmt.Println("Obtained config:", cfg.Config) } // The main function |
