From 5d2ea93307f1487da113d2b0ab50229d6db6a37c Mon Sep 17 00:00:00 2001 From: Ivan Krutov Date: Sun, 31 Dec 2023 10:54:48 +0300 Subject: [PATCH] Correctly processing extension capabilities (fixes #384) --- docs/log-files.adoc | 11 ++++++----- proxy.go | 10 +++++----- proxy_test.go | 15 +++++++++++---- 3 files changed, 22 insertions(+), 14 deletions(-) diff --git a/docs/log-files.adoc b/docs/log-files.adoc index 4e54f3c..a34ed54 100644 --- a/docs/log-files.adoc +++ b/docs/log-files.adoc @@ -1,13 +1,14 @@ == Log Files A typical log file looks like the following: -``` +---- 2017/04/18 03:52:36 [12413389] [SESSION_ATTEMPTED] [my_quota] [192.168.2.3] [firefox-42.0] [firefox42-1.example.com:4444] [1] 2017/04/18 03:52:40 [12413389] [SESSION_FAILED] [my_quota] [192.168.2.3] [firefox-42.0] [firefox42-1.example.com:4444] Error forwarding the new session Request timed out waiting for a node to become available. 2017/04/18 03:52:40 [12413390] [SESSION_ATTEMPTED] [my_quota] [192.168.2.3] [firefox-42.0] [firefox42-5.example.com:4444] [2] 2017/04/18 03:52:45 [12413390] [5.86s] [SESSION_CREATED] [my_quota] [192.168.2.3] [firefox-42.0] [firefox42-5.example.com:4444] [0c500a6f-98d2-4871-acb7-637d85e1416a] [2] .... 2017/04/18 03:53:05 [SESSION_DELETED] [192.168.2.3] [firefox42-5.example.com:4444] [0c500a6f-98d2-4871-acb7-637d85e1416a] -``` +---- + Every line contains: .Log entry contents @@ -72,7 +73,7 @@ The following statuses are available: |=== === Custom Labels in Log File -Sometimes you may need to add some custom metadata like build number or branch name to Selenium logs. Just add the following capability to your tests: +Sometimes you may need to add some custom metadata like build number or branch name to Selenium logs. Just add the following capability to your tests under `ggr:options`: .Type: map, format: "": "" ---- @@ -80,7 +81,7 @@ labels: {"buildNumber": 122, "branch": "feature-XXX"} ---- With this capability browser column will look like this: -``` +---- [firefox-42.0 buildNumber=122 branch=feature-XXX] -``` +---- Such additional metadata in logs allows to better analyze respective Selenium sessions. diff --git a/proxy.go b/proxy.go index 2a190ab..1a81e04 100644 --- a/proxy.go +++ b/proxy.go @@ -111,7 +111,7 @@ func (c caps) capabilities(fn func(m map[string]interface{}, w3c bool, extension } if match != nil { fn(match, true, false) - for k, v := range m { // Extension capabilities have ":" in key + for k, v := range match { // Extension capabilities have ":" in key if ec, ok := v.(map[string]interface{}); ok && strings.Contains(k, ":") { fn(ec, true, true) } @@ -808,10 +808,10 @@ func defaultErrorHandler(requestId uint64) func(http.ResponseWriter, *http.Reque func mux() http.Handler { mux := http.NewServeMux() - authenticator := auth.NewBasicAuthenticator( - "Selenium Grid Router", - auth.HtpasswdFileProvider(users), - ) + authenticator := &auth.BasicAuth{ + Realm: "Selenium Grid Router", + Secrets: auth.HtpasswdFileProvider(users), + } mux.HandleFunc(paths.Ping, ping) mux.HandleFunc(paths.Status, status) mux.HandleFunc(paths.Err, err) diff --git a/proxy_test.go b/proxy_test.go index b9f3cbd..7d563ff 100644 --- a/proxy_test.go +++ b/proxy_test.go @@ -1695,10 +1695,10 @@ func TestPanicGuestQuotaMissingUsersFileAuthPresent(t *testing.T) { defer func() { users = ".htpasswd" }() - authenticator := auth.NewBasicAuthenticator( - "Some Realm", - auth.HtpasswdFileProvider(users), - ) + authenticator := &auth.BasicAuth{ + Realm: "Some Realm", + Secrets: auth.HtpasswdFileProvider(users), + } mux := http.NewServeMux() mux.HandleFunc("/", WithSuitableAuthentication(authenticator, func(_ http.ResponseWriter, _ *http.Request) {})) @@ -1720,3 +1720,10 @@ func TestPlatformCapability(t *testing.T) { AssertThat(t, caps.platform(), EqualTo{"WINDOWS"}) } + +func TestLabelsCapabilityFromExtensions(t *testing.T) { + var caps caps + testCaps := `{"capabilities": {"alwaysMatch":{"ggr:options": {"labels": {"some-key": "some-value"}}}}}` + _ = json.Unmarshal([]byte(testCaps), &caps) + AssertThat(t, caps.labels(), EqualTo{"some-key=some-value"}) +}