Skip to content

Commit

Permalink
In debug mode, hide password from selenium url (tebeka#59)
Browse files Browse the repository at this point in the history
  • Loading branch information
llonchj authored and minusnine committed May 4, 2017
1 parent 8e171d7 commit 2094221
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
16 changes: 16 additions & 0 deletions common.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package selenium

import (
"log"
"net/url"
)

var debugFlag = false
Expand All @@ -17,3 +18,18 @@ func debugLog(format string, args ...interface{}) {
}
log.Printf(format+"\n", args...)
}

// filteredURL replaces existing password from the given URL.
func filteredURL(u string) string {
// Hide password if set in URL
m, err := url.Parse(u)
if err != nil {
return ""
}
if m.User != nil {
if _, ok := m.User.Password(); ok {
m.User = url.UserPassword(m.User.Username(), "__password__")
}
}
return m.String()
}
2 changes: 1 addition & 1 deletion remote.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ func (e *Error) Error() string {
}

func (wd *remoteWD) execute(method, url string, data []byte) ([]byte, error) {
debugLog("-> %s %s\n%s", method, url, data)
debugLog("-> %s %s\n%s", method, filteredURL(url), data)
request, err := newRequest(method, url, data)
if err != nil {
return nil, err
Expand Down

0 comments on commit 2094221

Please sign in to comment.