summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjwijenbergh <jeroenwijenbergh@protonmail.com>2022-05-06 13:49:48 +0200
committerjwijenbergh <jeroenwijenbergh@protonmail.com>2022-05-06 13:49:48 +0200
commit851d2e331cb2a8313529254d119fb0c9ae78c873 (patch)
tree77e082e8830958051bc6c21057ff78fc505a35a4
parentf82f65084b77d2e8f9e8be323fedf169270a9824 (diff)
Well known: Add override for local server path using env var
-rw-r--r--internal/server.go5
-rw-r--r--state_test.go15
2 files changed, 19 insertions, 1 deletions
diff --git a/internal/server.go b/internal/server.go
index 7500a26..9d27907 100644
--- a/internal/server.go
+++ b/internal/server.go
@@ -252,8 +252,11 @@ type ServerEndpoints struct {
V string `json:"v"`
}
+// Make this a var which we can overwrite in the tests
+var WellKnownPath string = ".well-known/vpn-user-portal"
+
func getEndpoints(baseURL string) (*ServerEndpoints, error) {
- url := fmt.Sprintf("%s/.well-known/vpn-user-portal", baseURL)
+ url := fmt.Sprintf("%s/%s", baseURL, WellKnownPath)
_, body, bodyErr := HTTPGet(url)
if bodyErr != nil {
diff --git a/state_test.go b/state_test.go
index 6b05091..59b4f02 100644
--- a/state_test.go
+++ b/state_test.go
@@ -14,6 +14,14 @@ import (
"github.com/jwijenbergh/eduvpn-common/internal"
)
+func ensureLocalWellKnown() {
+ wellKnown := os.Getenv("SERVER_IS_LOCAL")
+
+ if wellKnown == "1" {
+ internal.WellKnownPath = "well-known.php"
+ }
+}
+
func getServerURI(t *testing.T) string {
serverURI := os.Getenv("SERVER_URI")
if serverURI == "" {
@@ -54,6 +62,7 @@ func stateCallback(t *testing.T, oldState string, newState string, data string,
func Test_server(t *testing.T) {
serverURI := getServerURI(t)
state := &VPNState{}
+ ensureLocalWellKnown()
state.Register("org.eduvpn.app.linux", "configstest", func(old string, new string, data string) {
stateCallback(t, old, new, data, state)
@@ -132,6 +141,8 @@ func Test_connect_oauth_parameters(t *testing.T) {
{&failedCallbackStateMatchError, internal.URLParameters{"code": "42", "state": "21"}},
}
+ ensureLocalWellKnown()
+
for _, test := range tests {
test_connect_oauth_parameter(t, test.parameters, test.expectedErr)
}
@@ -145,6 +156,8 @@ func Test_token_expired(t *testing.T) {
return
}
+ ensureLocalWellKnown()
+
// Convert the env variable to an int and signal error if it is not possible
expiredInt, expiredErr := strconv.Atoi(expiredTTL)
if expiredErr != nil {
@@ -200,6 +213,8 @@ func Test_token_invalid(t *testing.T) {
serverURI := getServerURI(t)
state := &VPNState{}
+ ensureLocalWellKnown()
+
state.Register("org.eduvpn.app.linux", "configsinvalid", func(old string, new string, data string) {
stateCallback(t, old, new, data, state)
}, false)