forked from scroll-tech/go-ethereum
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ethstats: fix URL parser for '@' or ':' in node name/password (ethere…
…um#21640) Fixes the case (example below) where the value passed to --ethstats flag would be parsed wrongly because the node name and/or password value contained the special characters '@' or ':' --ethstats "ETC Labs Metrics @meowsbits":mypass@ws://mordor.dash.fault.dev:3000
- Loading branch information
Showing
2 changed files
with
97 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
package ethstats | ||
|
||
import ( | ||
"strconv" | ||
"testing" | ||
) | ||
|
||
func TestParseEthstatsURL(t *testing.T) { | ||
cases := []struct { | ||
url string | ||
node, pass, host string | ||
}{ | ||
{ | ||
url: `"debug meowsbits":mypass@ws://mordor.dash.fault.dev:3000`, | ||
node: "debug meowsbits", pass: "mypass", host: "ws://mordor.dash.fault.dev:3000", | ||
}, | ||
{ | ||
url: `"debug @meowsbits":mypass@ws://mordor.dash.fault.dev:3000`, | ||
node: "debug @meowsbits", pass: "mypass", host: "ws://mordor.dash.fault.dev:3000", | ||
}, | ||
{ | ||
url: `"debug: @meowsbits":mypass@ws://mordor.dash.fault.dev:3000`, | ||
node: "debug: @meowsbits", pass: "mypass", host: "ws://mordor.dash.fault.dev:3000", | ||
}, | ||
{ | ||
url: `name:@ws://mordor.dash.fault.dev:3000`, | ||
node: "name", pass: "", host: "ws://mordor.dash.fault.dev:3000", | ||
}, | ||
{ | ||
url: `name@ws://mordor.dash.fault.dev:3000`, | ||
node: "name", pass: "", host: "ws://mordor.dash.fault.dev:3000", | ||
}, | ||
{ | ||
url: `:mypass@ws://mordor.dash.fault.dev:3000`, | ||
node: "", pass: "mypass", host: "ws://mordor.dash.fault.dev:3000", | ||
}, | ||
{ | ||
url: `:@ws://mordor.dash.fault.dev:3000`, | ||
node: "", pass: "", host: "ws://mordor.dash.fault.dev:3000", | ||
}, | ||
} | ||
|
||
for i, c := range cases { | ||
parts, err := parseEthstatsURL(c.url) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
node, pass, host := parts[0], parts[1], parts[2] | ||
|
||
// unquote because the value provided will be used as a CLI flag value, so unescaped quotes will be removed | ||
nodeUnquote, err := strconv.Unquote(node) | ||
if err == nil { | ||
node = nodeUnquote | ||
} | ||
|
||
if node != c.node { | ||
t.Errorf("case=%d mismatch node value, got: %v ,want: %v", i, node, c.node) | ||
} | ||
if pass != c.pass { | ||
t.Errorf("case=%d mismatch pass value, got: %v ,want: %v", i, pass, c.pass) | ||
} | ||
if host != c.host { | ||
t.Errorf("case=%d mismatch host value, got: %v ,want: %v", i, host, c.host) | ||
} | ||
} | ||
|
||
} |