summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorjwijenbergh <jeroenwijenbergh@protonmail.com>2022-04-05 11:17:22 +0200
committerjwijenbergh <jeroenwijenbergh@protonmail.com>2022-04-05 11:17:22 +0200
commitf826441dc4a72c7797fec36de5214d6524b9d6c5 (patch)
tree45de03ede795a20554ce45e3b6d367474c7b3ac6 /src
parent5113ea73d8be2f296aa97bccfd19535e2e432f57 (diff)
Correct tests for fsm
Diffstat (limited to 'src')
-rw-r--r--src/server_test.go35
1 files changed, 22 insertions, 13 deletions
diff --git a/src/server_test.go b/src/server_test.go
index 65a8747..f6de009 100644
--- a/src/server_test.go
+++ b/src/server_test.go
@@ -36,8 +36,8 @@ func LoginOAuthSelenium(t *testing.T, url string) {
}
func StateCallback(t *testing.T, oldState string, newState string, data string) {
- if newState == "OAuthInitialized" {
- LoginOAuthSelenium(t, data)
+ if newState == "SERVER_OAUTH_STARTED" {
+ go LoginOAuthSelenium(t, data)
}
}
@@ -49,7 +49,7 @@ func Test_server(t *testing.T) {
state.Register("org.eduvpn.app.linux", "configstest", func(old string, new string, data string) {
StateCallback(t, old, new, data)
- })
+ }, false)
_, configErr := state.Connect("https://eduvpnserver")
@@ -59,21 +59,22 @@ func Test_server(t *testing.T) {
}
func test_connect_oauth_parameter(t *testing.T, parameters URLParameters, expectedErr interface{}) {
- state := &VPNState{}
+ state := GetVPNState()
+ state.Deregister()
// Do not verify because during testing, the cert is self-signed
http.DefaultTransport.(*http.Transport).TLSClientConfig = &tls.Config{InsecureSkipVerify: true}
- state.Register("org.eduvpn.app.linux", "configsnologin", func(old string, new string, data string) {
- if new == "OAuthInitialized" {
+ state.Register("org.eduvpn.app.linux", "configsnologin", func(oldState string, newState string, data string) {
+ if newState == "SERVER_OAUTH_STARTED" {
baseURL := "http://127.0.0.1:8000/callback"
url, err := HTTPConstructURL(baseURL, parameters)
if err != nil {
t.Errorf("Error: Constructing url %s with parameters %s", baseURL, fmt.Sprint(parameters))
}
- _, _ = http.Get(url)
+ go http.Get(url)
}
- })
+ }, false)
_, configErr := state.Connect("https://eduvpnserver")
if !errors.As(configErr, expectedErr) {
@@ -122,7 +123,7 @@ func Test_token_expired(t *testing.T) {
state.Register("org.eduvpn.app.linux", "configstest", func(old string, new string, data string) {
StateCallback(t, old, new, data)
- })
+ }, false)
accessToken := state.Server.OAuth.Token.Access
refreshToken := state.Server.OAuth.Token.Refresh
@@ -155,9 +156,17 @@ func Test_token_invalid(t *testing.T) {
// Do not verify because during testing, the cert is self-signed
http.DefaultTransport.(*http.Transport).TLSClientConfig = &tls.Config{InsecureSkipVerify: true}
+ state.Deregister()
+
state.Register("org.eduvpn.app.linux", "configsinvalid", func(old string, new string, data string) {
StateCallback(t, old, new, data)
- })
+ }, false)
+
+ _, configErr := state.Connect("https://eduvpnserver")
+
+ if configErr != nil {
+ t.Errorf("Connect error before invalid: %v", configErr)
+ }
dummy_value := "37"
@@ -165,10 +174,10 @@ func Test_token_invalid(t *testing.T) {
state.Server.OAuth.Token.Access = dummy_value
state.Server.OAuth.Token.Refresh = dummy_value
- _, configErr := state.Connect("https://eduvpnserver")
+ infoErr := state.Server.APIInfo()
- if configErr != nil {
- t.Errorf("Connect error: %v", configErr)
+ if infoErr != nil {
+ t.Errorf("Info error after invalid: %v", infoErr)
}
if state.Server.OAuth.Token.Access == dummy_value {