Skip to content
This repository has been archived by the owner on Dec 17, 2024. It is now read-only.

Commit

Permalink
Correctly processing extension capabilities (fixes #384)
Browse files Browse the repository at this point in the history
  • Loading branch information
vania-pooh committed Dec 31, 2023
1 parent 271eb4f commit 5d2ea93
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 14 deletions.
11 changes: 6 additions & 5 deletions docs/log-files.adoc
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -72,15 +73,15 @@ 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: "<key>": "<value>"
----
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.
10 changes: 5 additions & 5 deletions proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down Expand Up @@ -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)
Expand Down
15 changes: 11 additions & 4 deletions proxy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {}))
Expand All @@ -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"})
}

0 comments on commit 5d2ea93

Please sign in to comment.