summaryrefslogtreecommitdiff
path: root/src/server_test.go
diff options
context:
space:
mode:
authorjwijenbergh <jeroenwijenbergh@protonmail.com>2022-03-25 11:37:29 +0100
committerjwijenbergh <jeroenwijenbergh@protonmail.com>2022-03-25 11:37:29 +0100
commit855f1a93305d1eb95e91c29796b9112e199252f2 (patch)
tree99c4381691ab5874cf8d1fa69fbe3c5675652644 /src/server_test.go
parentd033c8bb4103179b4971b5b067d9c440f254bdd7 (diff)
Login to oauth with selenium and test
Diffstat (limited to 'src/server_test.go')
-rw-r--r--src/server_test.go54
1 files changed, 54 insertions, 0 deletions
diff --git a/src/server_test.go b/src/server_test.go
new file mode 100644
index 0000000..54c7809
--- /dev/null
+++ b/src/server_test.go
@@ -0,0 +1,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)
+ }
+}