summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--client/client_test.go46
-rw-r--r--client/server.go3
-rw-r--r--cmd/cli/main.go2
-rw-r--r--exports/exports.go9
-rw-r--r--internal/discovery/discovery_test.go34
-rw-r--r--internal/verify/verify_test.go8
-rw-r--r--wrappers/python/tests.py20
7 files changed, 55 insertions, 67 deletions
diff --git a/client/client_test.go b/client/client_test.go
index b39b289..772be4b 100644
--- a/client/client_test.go
+++ b/client/client_test.go
@@ -12,7 +12,8 @@ import (
"time"
httpw "github.com/eduvpn/eduvpn-common/internal/http"
- "github.com/eduvpn/eduvpn-common/internal/oauth"
+ "github.com/eduvpn/eduvpn-common/types/protocol"
+ srvtypes "github.com/eduvpn/eduvpn-common/types/server"
"github.com/go-errors/errors"
)
@@ -80,7 +81,6 @@ func TestServer(t *testing.T) {
"org.letsconnect-vpn.app.linux",
"0.1.0-test",
"configstest",
- "en",
func(old FSMStateID, new FSMStateID, data interface{}) bool {
stateCallback(t, old, new, data, state)
return true
@@ -91,11 +91,11 @@ func TestServer(t *testing.T) {
t.Fatalf("Register error: %v", registerErr)
}
- _, addErr := state.AddCustomServer(serverURI)
+ addErr := state.AddCustomServer(serverURI)
if addErr != nil {
t.Fatalf("Add error: %v", addErr)
}
- _, configErr := state.GetConfigCustomServer(serverURI, false, oauth.Token{})
+ _, configErr := state.GetConfigCustomServer(serverURI, false, srvtypes.Tokens{})
if configErr != nil {
t.Fatalf("Connect error: %v", configErr)
}
@@ -114,7 +114,6 @@ func testConnectOAuthParameter(
"org.letsconnect-vpn.app.linux",
"0.1.0-test",
configDirectory,
- "en",
func(oldState FSMStateID, newState FSMStateID, data interface{}) bool {
if newState == StateOAuthStarted {
server, serverErr := state.Servers.GetCustomServer(serverURI)
@@ -157,7 +156,7 @@ func testConnectOAuthParameter(
t.Fatalf("Register error: %v", registerErr)
}
- _, err := state.AddCustomServer(serverURI)
+ err := state.AddCustomServer(serverURI)
if errPrefix == "" {
if err != nil {
@@ -245,7 +244,6 @@ func TestTokenExpired(t *testing.T) {
"org.letsconnect-vpn.app.linux",
"0.1.0-test",
"configsexpired",
- "en",
func(old FSMStateID, new FSMStateID, data interface{}) bool {
stateCallback(t, old, new, data, state)
return true
@@ -256,12 +254,12 @@ func TestTokenExpired(t *testing.T) {
t.Fatalf("Register error: %v", registerErr)
}
- _, addErr := state.AddCustomServer(serverURI)
+ addErr := state.AddCustomServer(serverURI)
if addErr != nil {
t.Fatalf("Add error: %v", addErr)
}
- _, configErr := state.GetConfigCustomServer(serverURI, false, oauth.Token{})
+ _, configErr := state.GetConfigCustomServer(serverURI, false, srvtypes.Tokens{})
if configErr != nil {
t.Fatalf("Connect error before expired: %v", configErr)
@@ -282,7 +280,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, oauth.Token{})
+ _, configErr = state.GetConfigCustomServer(serverURI, false, srvtypes.Tokens{})
if configErr != nil {
t.Fatalf("Connect error after expiry: %v", configErr)
@@ -308,7 +306,6 @@ func TestInvalidProfileCorrected(t *testing.T) {
"org.letsconnect-vpn.app.linux",
"0.1.0-test",
"configscancelprofile",
- "en",
func(old FSMStateID, new FSMStateID, data interface{}) bool {
stateCallback(t, old, new, data, state)
return true
@@ -319,12 +316,12 @@ func TestInvalidProfileCorrected(t *testing.T) {
t.Fatalf("Register error: %v", registerErr)
}
- _, addErr := state.AddCustomServer(serverURI)
+ addErr := state.AddCustomServer(serverURI)
if addErr != nil {
t.Fatalf("Add error: %v", addErr)
}
- _, configErr := state.GetConfigCustomServer(serverURI, false, oauth.Token{})
+ _, configErr := state.GetConfigCustomServer(serverURI, false, srvtypes.Tokens{})
if configErr != nil {
t.Fatalf("First connect error: %v", configErr)
@@ -343,8 +340,7 @@ func TestInvalidProfileCorrected(t *testing.T) {
previousProfile := base.Profiles.Current
base.Profiles.Current = "IDONOTEXIST"
- _, configErr = state.GetConfigCustomServer(serverURI, false, oauth.Token{})
-
+ _, configErr = state.GetConfigCustomServer(serverURI, false, srvtypes.Tokens{})
if configErr != nil {
t.Fatalf("Second connect error: %v", configErr)
}
@@ -367,7 +363,6 @@ func TestPreferTCP(t *testing.T) {
"org.letsconnect-vpn.app.linux",
"0.1.0-test",
"configsprefertcp",
- "en",
func(old FSMStateID, new FSMStateID, data interface{}) bool {
stateCallback(t, old, new, data, state)
return true
@@ -378,16 +373,16 @@ func TestPreferTCP(t *testing.T) {
t.Fatalf("Register error: %v", registerErr)
}
- _, addErr := state.AddCustomServer(serverURI)
+ addErr := state.AddCustomServer(serverURI)
if addErr != nil {
t.Fatalf("Add error: %v", addErr)
}
// get a config with preferTCP set to true
- config, configErr := state.GetConfigCustomServer(serverURI, true, oauth.Token{})
+ config, configErr := state.GetConfigCustomServer(serverURI, true, srvtypes.Tokens{})
// Test server should accept prefer TCP!
- if config.Type != "openvpn" {
+ if config.Protocol != protocol.OpenVPN {
t.Fatalf("Invalid protocol for prefer TCP, got: WireGuard, want: OpenVPN")
}
@@ -396,20 +391,20 @@ func TestPreferTCP(t *testing.T) {
}
// We also test for script security 0 here
- if !strings.HasSuffix(config.Config, "udp\nscript-security 0") {
- t.Fatalf("Suffix for prefer TCP is not in the right order for config: %s", config)
+ if !strings.HasSuffix(config.VPNConfig, "udp\nscript-security 0") {
+ t.Fatalf("Suffix for prefer TCP is not in the right order for config: %s", config.VPNConfig)
}
// get a config with preferTCP set to false
- config, configErr = state.GetConfigCustomServer(serverURI, false, oauth.Token{})
+ config, configErr = state.GetConfigCustomServer(serverURI, false, srvtypes.Tokens{})
if configErr != nil {
t.Fatalf("Config error: %v", configErr)
}
// We also test for script security 0 here
- if config.Type == "openvpn" &&
- !strings.HasSuffix(config.Config, "tcp\nscript-security 0") {
- t.Fatalf("Suffix for disable prefer TCP is not in the right order for config: %s", config.Config)
+ if config.Protocol == protocol.OpenVPN &&
+ !strings.HasSuffix(config.VPNConfig, "tcp\nscript-security 0") {
+ t.Fatalf("Suffix for disable prefer TCP is not in the right order for config: %s", config.VPNConfig)
}
}
@@ -429,7 +424,6 @@ func TestInvalidClientID(t *testing.T) {
k,
"0.1.0-test",
"configsclientid",
- "en",
func(old FSMStateID, new FSMStateID, data interface{}) bool {
stateCallback(t, old, new, data, state)
return true
diff --git a/client/server.go b/client/server.go
index 00e55e8..f31da2e 100644
--- a/client/server.go
+++ b/client/server.go
@@ -457,7 +457,8 @@ func (c *Client) GetConfigInstituteAccess(url string, preferTCP bool, t srvtypes
// GetConfigSecureInternet gets a configuration for a Secure Internet Server.
// It ensures that the Secure Internet Server exists by creating or using an existing one with the orgID.
// `preferTCP` indicates that the client wants to use TCP (through OpenVPN) to establish the VPN tunnel.
-func (c *Client) GetConfigSecureInternet(orgID string, preferTCP bool, t srvtypes.Tokens) (cfg *srvtypes.Configuration, err error) {
+// TODO: Check on first argument orgID
+func (c *Client) GetConfigSecureInternet(_ string, preferTCP bool, t srvtypes.Tokens) (cfg *srvtypes.Configuration, err error) {
defer func() {
if err != nil {
c.logError(err)
diff --git a/cmd/cli/main.go b/cmd/cli/main.go
index 9bf8fe4..9ff880d 100644
--- a/cmd/cli/main.go
+++ b/cmd/cli/main.go
@@ -110,7 +110,7 @@ func sendProfile(state *client.Client, data interface{}) {
for k, v := range sps.Map {
ps += fmt.Sprintf("\n%d - %s", i+1, GetLanguageMatched(v.DisplayName, "en"))
options = append(options, k)
- i += 1
+ i++
}
// Show the profiles
diff --git a/exports/exports.go b/exports/exports.go
index 19be174..fe7581e 100644
--- a/exports/exports.go
+++ b/exports/exports.go
@@ -62,7 +62,6 @@ func getReturnData(data interface{}) (string, error) {
}
func StateCallback(
- state *client.Client,
oldState client.FSMStateID,
newState client.FSMStateID,
data interface{},
@@ -97,20 +96,18 @@ func Register(
stateCallback C.StateCB,
debug C.int,
) *C.char {
- state, stateErr := getVPNState()
+ _, stateErr := getVPNState()
if stateErr == nil {
return getCError(errors.New("failed to register, a VPN state is already present"))
}
- state = &client.Client{}
+ state := &client.Client{}
VPNState = state
PStateCallback = stateCallback
registerErr := state.Register(
C.GoString(name),
C.GoString(version),
C.GoString(configDirectory),
- func(old client.FSMStateID, new client.FSMStateID, data interface{}) bool {
- return StateCallback(state, old, new, data)
- },
+ StateCallback,
debug == 1,
)
diff --git a/internal/discovery/discovery_test.go b/internal/discovery/discovery_test.go
index 2e6c38f..93ab51e 100644
--- a/internal/discovery/discovery_test.go
+++ b/internal/discovery/discovery_test.go
@@ -7,7 +7,7 @@ import (
"time"
"github.com/eduvpn/eduvpn-common/internal/test"
- "github.com/eduvpn/eduvpn-common/types"
+ discotypes "github.com/eduvpn/eduvpn-common/types/discovery"
)
// TestServers tests whether or not we can obtain discovery servers
@@ -85,9 +85,9 @@ func TestOrganizations(t *testing.T) {
// TestSecureLocationList tests the function for getting a list of secure internet servers
func TestSecureLocationList(t *testing.T) {
d := Discovery{
- ServerList: types.DiscoveryServers{
+ ServerList: discotypes.Servers{
Version: 1,
- List: []types.DiscoveryServer{
+ List: []discotypes.Server{
// institute access server, this should not be found
{CountryCode: "", Type: "institute_access"},
// secure internet servers, these should be found
@@ -110,9 +110,9 @@ func TestSecureLocationList(t *testing.T) {
// TestServerByURL tests the function for getting a server by the Base URL and type
func TestServerByURL(t *testing.T) {
d := Discovery{
- ServerList: types.DiscoveryServers{
+ ServerList: discotypes.Servers{
Version: 1,
- List: []types.DiscoveryServer{
+ List: []discotypes.Server{
// institute access server
{BaseURL: "a", Type: "institute_access"},
// secure internet servers
@@ -149,11 +149,11 @@ func TestServerByURL(t *testing.T) {
// TestServerByCountryCode tests the function for getting a server by the country code
func TestServerByCountryCode(t *testing.T) {
- s1 := types.DiscoveryServer{CountryCode: "a", Type: "secure_internet"}
+ s1 := discotypes.Server{CountryCode: "a", Type: "secure_internet"}
d := Discovery{
- ServerList: types.DiscoveryServers{
+ ServerList: discotypes.Servers{
Version: 1,
- List: []types.DiscoveryServer{
+ List: []discotypes.Server{
// secure internet server
s1,
// Unexpected types, these should not be found
@@ -184,11 +184,11 @@ func TestServerByCountryCode(t *testing.T) {
// TestOrgByID tests the function for getting an organization by ID
func TestOrgByID(t *testing.T) {
- o1 := types.DiscoveryOrganization{OrgID: "a"}
+ o1 := discotypes.Organization{OrgID: "a"}
d := Discovery{
- OrganizationList: types.DiscoveryOrganizations{
+ OrganizationList: discotypes.Organizations{
Version: 1,
- List: []types.DiscoveryOrganization{
+ List: []discotypes.Organization{
o1,
},
},
@@ -208,19 +208,19 @@ func TestOrgByID(t *testing.T) {
// TestSecureHomeArgs tests the function for getting an organization and matching secure internet server by organization ID
func TestSecureHomeArgs(t *testing.T) {
- o1 := types.DiscoveryOrganization{OrgID: "id", SecureInternetHome: "a"}
- s1 := types.DiscoveryServer{BaseURL: "a", Type: "secure_internet"}
+ o1 := discotypes.Organization{OrgID: "id", SecureInternetHome: "a"}
+ s1 := discotypes.Server{BaseURL: "a", Type: "secure_internet"}
d := Discovery{
- OrganizationList: types.DiscoveryOrganizations{
+ OrganizationList: discotypes.Organizations{
Version: 1,
- List: []types.DiscoveryOrganization{
+ List: []discotypes.Organization{
{OrgID: "id2", SecureInternetHome: "c"},
o1,
},
},
- ServerList: types.DiscoveryServers{
+ ServerList: discotypes.Servers{
Version: 1,
- List: []types.DiscoveryServer{
+ List: []discotypes.Server{
s1,
{BaseURL: "b"},
},
diff --git a/internal/verify/verify_test.go b/internal/verify/verify_test.go
index cbc6cb9..bb270a4 100644
--- a/internal/verify/verify_test.go
+++ b/internal/verify/verify_test.go
@@ -359,24 +359,24 @@ func compareResults(
t.Errorf("error not expected but returned '%s', callstr '%s'", err.Error(), callStr())
}
if !ret {
- t.Errorf("error is nil and result is false, callstr '%s'", callStr())
+ t.Errorf("error is nil and result is false, callstr: '%s'", callStr())
}
return
}
if err == nil {
// we expect an error but received nil
- t.Errorf("expected error prefix '%s' but received nil, callstr '%s'", expectedErrPrefix, callStr())
+ t.Errorf("expected error prefix '%s' but received nil, callstr: '%s'", expectedErrPrefix, callStr())
return
}
if !strings.HasPrefix(err.Error(), expectedErrPrefix) {
// wrong error
- t.Errorf("expected error prefix '%s' for error '%s', callStr '%s'", expectedErrPrefix, err.Error(), callStr())
+ t.Errorf("expected error prefix '%s' for error '%s', callstr '%s'", expectedErrPrefix, err.Error(), callStr())
return
}
if ret {
- t.Errorf("error is not nil and result is true, callStr '%s'", callStr())
+ t.Errorf("error is not nil and result is true, '%s'", callStr())
}
}
diff --git a/wrappers/python/tests.py b/wrappers/python/tests.py
index bd8b4eb..bca7b86 100644
--- a/wrappers/python/tests.py
+++ b/wrappers/python/tests.py
@@ -2,11 +2,8 @@
import unittest
import eduvpn_common.main as eduvpn
-from eduvpn_common.state import State, StateType
-import webbrowser
import sys
import os
-import json
# Import project root directory where the selenium python utility is
sys.path.append(
@@ -15,16 +12,15 @@ sys.path.append(
from selenium_eduvpn import login_eduvpn
+def handler(_old_state, new_state, data):
+ if new_state == 6:
+ login_eduvpn(data)
class ConfigTests(unittest.TestCase):
def testConfig(self):
- _eduvpn = eduvpn.EduVPN("org.letsconnect-vpn.app.linux", "0.1.0", "testconfigs", "en")
+ _eduvpn = eduvpn.EduVPN("org.letsconnect-vpn.app.linux", "0.1.0", "testconfigs")
# This can throw an exception
- _eduvpn.register()
-
- @_eduvpn.event.on(State.OAUTH_STARTED, StateType.ENTER)
- def oauth_initialized(old_state, url_json):
- login_eduvpn(url_json)
+ _eduvpn.register(handler=handler)
server_uri = os.getenv("SERVER_URI")
if not server_uri:
@@ -33,14 +29,14 @@ class ConfigTests(unittest.TestCase):
return
# This can throw an exception
- _eduvpn.add_custom_server(server_uri)
- _eduvpn.get_config_custom_server(server_uri)
+ _eduvpn.add_server(eduvpn.ServerType.CUSTOM, server_uri)
+ _eduvpn.get_config(eduvpn.ServerType.CUSTOM, server_uri)
# Deregister
_eduvpn.deregister()
def testDoubleRegister(self):
- _eduvpn = eduvpn.EduVPN("org.letsconnect-vpn.app.linux", "0.1.0", "testconfigs", "en")
+ _eduvpn = eduvpn.EduVPN("org.letsconnect-vpn.app.linux", "0.1.0", "testconfigs")
# This can throw an exception
_eduvpn.register()
# This should throw