summaryrefslogtreecommitdiff
path: root/src/server_test.go
blob: 54c78090e45e99433f14511d7430216262db276e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
package eduvpn

import (
	"testing"
	"net/http"
	"crypto/tls"
	"os/exec"
	"strings"
)

func RunCommand(t *testing.T, name string, args ...string) {
	cmd := exec.Command(name, args...)
	var errBuffer strings.Builder

	cmd.Stderr = &errBuffer
	err := cmd.Start()
	if err != nil {
		t.Errorf("%v", err)
	}

	err = cmd.Wait()

	if err != nil {
		t.Errorf("Login OAuth with selenium script failed with error %v and stderr %s", err, errBuffer.String())
	}
}

func LoginOAuthSelenium(t* testing.T, url string) {
	// We could use the go selenium library
	// But it does not support the latest selenium v4 just yet
	RunCommand(t, "python3", "../selenium_eduvpn.py", url)
}

func StateCallback(t *testing.T, oldState string, newState string, data string) {
	if newState == "OAuthInitialized" {
		LoginOAuthSelenium(t, data)
	}
}

func TestServer(t *testing.T) {
	state := GetVPNState()

	// 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", "configs", func(old string, new string, data string) {
		StateCallback(t, old, new, data)
	})
	_, configErr := state.Connect("https://eduvpnserver")

	if configErr != nil {
		t.Errorf("Connect error: %v", configErr)
	}
}