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

Commit

Permalink
Merge pull request #96 from vania-pooh/master
Browse files Browse the repository at this point in the history
Added ability to set custom downstream server password (fixes #93)
  • Loading branch information
aandryashin authored Jul 10, 2017
2 parents 23b7cb3 + 9420b0a commit afce666
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 4 deletions.
10 changes: 6 additions & 4 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,12 @@ type Region struct {

// Host - just a hostname
type Host struct {
Name string `xml:"name,attr"`
Port int `xml:"port,attr"`
Count int `xml:"count,attr"`
region string
Name string `xml:"name,attr"`
Port int `xml:"port,attr"`
Count int `xml:"count,attr"`
Username string `xml:"username,attr,omitempty"`
Password string `xml:"password,attr,omitempty"`
region string
}
type set interface {
contains(el string) bool
Expand Down
3 changes: 3 additions & 0 deletions proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,9 @@ func (h *Host) session(ctx context.Context, header http.Header, c caps) (map[str
req.Header.Add(key, value)
}
}
if h.Username != "" && h.Password != "" {
req.SetBasicAuth(h.Username, h.Password)
}
ctx, cancel := context.WithTimeout(ctx, timeout)
defer cancel()
req = req.WithContext(ctx)
Expand Down
27 changes: 27 additions & 0 deletions proxy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,33 @@ func TestStartSessionWithJsonSpecChars(t *testing.T) {
testStartSession(t, mux, browsersProvider, "{browser}", "1.0")
}

func TestStartSessionWithOverriddenBasicAuth(t *testing.T) {
mux := http.NewServeMux()
mux.HandleFunc("/wd/hub/session", postOnly(func(w http.ResponseWriter, r *http.Request) {
username, password, ok := r.BasicAuth()
if ok && username == "test" && password == "test-password" {
w.Write([]byte(`{"sessionId":"123"}`))
} else {
w.WriteHeader(http.StatusUnauthorized)
}
}))

browsersProvider := func(node Host) Browsers {
node.Username = "test"
node.Password = "test-password"
return Browsers{Browsers: []Browser{
{Name: "browser", DefaultVersion: "1.0", Versions: []Version{
{Number: "1.0", Regions: []Region{
{Hosts: Hosts{
node,
}},
}},
}}}}
}

testStartSession(t, mux, browsersProvider, "browser", "1.0")
}

func TestStartSessionWithPrefixVersion(t *testing.T) {
mux := http.NewServeMux()
mux.HandleFunc("/wd/hub/session", postOnly(func(w http.ResponseWriter, r *http.Request) {
Expand Down

0 comments on commit afce666

Please sign in to comment.