[CI] Add ability to customise the chromedriver port (#1467)

The development workflow expects chromedriver to be run on the host on port 4444.
There is currently no mechanism to modify this behaviour at runtime, so if another service is running on 4444 tests will just fail silently.

This change introduces the `CHROMEDRIVER_PORT` environment variable which can be utilised to set a custom port.
This commit is contained in:
Amir Zarrinkafsh 2020-11-16 21:59:24 +11:00 committed by GitHub
parent f2e0f16d39
commit 8e32a4b65f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 26 additions and 3 deletions

View File

@ -48,6 +48,7 @@ var DuoBaseURL = "https://duo.example.com"
var AutheliaBaseURL = "https://authelia.example.com:9091" var AutheliaBaseURL = "https://authelia.example.com:9091"
const stringTrue = "true" const stringTrue = "true"
const defaultChromeDriverPort = "4444"
const testUsername = "john" const testUsername = "john"
const testPassword = "password" const testPassword = "password"

View File

@ -3,6 +3,8 @@ package suites
import ( import (
"context" "context"
"fmt" "fmt"
"os"
"strconv"
"testing" "testing"
"time" "time"
@ -39,7 +41,13 @@ func (s *NetworkACLSuite) TestShouldAccessSecretUpon1FA() {
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second) ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
defer cancel() defer cancel()
wds, err := StartWebDriverWithProxy("http://proxy-client1.example.com:3128", 4444) driverPort := os.Getenv("CHROMEDRIVER_PORT")
if driverPort == "" {
driverPort = defaultChromeDriverPort
}
p, _ := strconv.Atoi(driverPort)
wds, err := StartWebDriverWithProxy("http://proxy-client1.example.com:3128", p)
s.Require().NoError(err) s.Require().NoError(err)
defer wds.Stop() //nolint:errcheck // TODO: Legacy code, consider refactoring time permitting. defer wds.Stop() //nolint:errcheck // TODO: Legacy code, consider refactoring time permitting.
@ -58,7 +66,13 @@ func (s *NetworkACLSuite) TestShouldAccessSecretUpon0FA() {
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second) ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
defer cancel() defer cancel()
wds, err := StartWebDriverWithProxy("http://proxy-client2.example.com:3128", 4444) driverPort := os.Getenv("CHROMEDRIVER_PORT")
if driverPort == "" {
driverPort = defaultChromeDriverPort
}
p, _ := strconv.Atoi(driverPort)
wds, err := StartWebDriverWithProxy("http://proxy-client2.example.com:3128", p)
s.Require().NoError(err) s.Require().NoError(err)
defer wds.Stop() //nolint:errcheck // TODO: Legacy code, consider refactoring time permitting. defer wds.Stop() //nolint:errcheck // TODO: Legacy code, consider refactoring time permitting.

View File

@ -5,6 +5,7 @@ import (
"errors" "errors"
"fmt" "fmt"
"os" "os"
"strconv"
"strings" "strings"
"testing" "testing"
@ -69,7 +70,14 @@ func StartWebDriverWithProxy(proxy string, port int) (*WebDriverSession, error)
// StartWebDriver create a selenium session. // StartWebDriver create a selenium session.
func StartWebDriver() (*WebDriverSession, error) { func StartWebDriver() (*WebDriverSession, error) {
return StartWebDriverWithProxy("", 4444) driverPort := os.Getenv("CHROMEDRIVER_PORT")
if driverPort == "" {
driverPort = defaultChromeDriverPort
}
p, _ := strconv.Atoi(driverPort)
return StartWebDriverWithProxy("", p)
} }
// Stop stop the selenium session. // Stop stop the selenium session.