Skip to content

Commit

Permalink
node: Fix url verification bug where <ip>:<port> is not supported (#3719
Browse files Browse the repository at this point in the history
)

* node: update url verification logic to support ip:port format

Signed-off-by: bingyuyap <[email protected]>

* node: add test case for ip:port

Signed-off-by: bingyuyap <[email protected]>

* node: change neon rpc scheme from websocket to HTTP

Signed-off-by: bingyuyap <[email protected]>

* node: update comment to be more accurate

Signed-off-by: bingyuyap <[email protected]>

* node: remove neon from devmode

Signed-off-by: bingyuyap <[email protected]>

* node: ignore internal xlabs testing file

Signed-off-by: bingyuyap <[email protected]>

* node: add ws:// prefix to Sui

Signed-off-by: bingyuyap <[email protected]>

* node: add ws:// and wss:// prefixes to Sui schemes

Signed-off-by: bingyuyap <[email protected]>

* node: update testnet yaml naming

Signed-off-by: bingyuyap <[email protected]>

---------

Signed-off-by: bingyuyap <[email protected]>
  • Loading branch information
bingyuyap authored Jan 18, 2024
1 parent c7756f8 commit 3d16cca
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 12 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,6 @@ devnet-consts.json
/ethereum/cache/
sui.log.*
sui/examples/wrapped_coin
*.prof
*.prof
# Only used for internal testing
*.testnet.yaml
2 changes: 1 addition & 1 deletion Tiltfile
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ def build_node_yaml():
"--suiMoveEventType",
"0x7f6cebb8a489654d7a759483bd653c4be3e5ccfef17a8b5fd3ba98bd072fabc3::publish_message::WormholeMessage",
"--suiWS",
"sui:9000",
"ws://sui:9000",
]

if evm2:
Expand Down
2 changes: 0 additions & 2 deletions devnet/node.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,6 @@ spec:
- ws://eth-devnet:8545
- --optimismRPC
- ws://eth-devnet:8545
- --neonRPC
- ws://eth-devnet:8545
- --baseRPC
- ws://eth-devnet:8545
- --scrollRPC
Expand Down
5 changes: 2 additions & 3 deletions node/cmd/guardiand/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ func init() {
moonbeamRPC = node.RegisterFlagWithValidationOrFail(NodeCmd, "moonbeamRPC", "Moonbeam RPC URL", "ws://eth-devnet:8545", []string{"ws", "wss"})
moonbeamContract = NodeCmd.Flags().String("moonbeamContract", "", "Moonbeam contract address")

neonRPC = node.RegisterFlagWithValidationOrFail(NodeCmd, "neonRPC", "Neon RPC URL", "ws://eth-devnet:8545", []string{"ws", "wss"})
neonRPC = node.RegisterFlagWithValidationOrFail(NodeCmd, "neonRPC", "Neon RPC URL", "http://eth-devnet:8545", []string{"http", "https"})
neonContract = NodeCmd.Flags().String("neonContract", "", "Neon contract address")

terraWS = node.RegisterFlagWithValidationOrFail(NodeCmd, "terraWS", "Path to terrad root for websocket connection", "ws://terra-terrad:26657/websocket", []string{"ws", "wss"})
Expand Down Expand Up @@ -336,7 +336,7 @@ func init() {
aptosHandle = NodeCmd.Flags().String("aptosHandle", "", "aptos handle")

suiRPC = node.RegisterFlagWithValidationOrFail(NodeCmd, "suiRPC", "Sui RPC URL", "http://sui:9000", []string{"http", "https"})
suiWS = node.RegisterFlagWithValidationOrFail(NodeCmd, "suiWS", "Sui WS URL", "sui:9000", []string{""})
suiWS = node.RegisterFlagWithValidationOrFail(NodeCmd, "suiWS", "Sui WS URL", "ws://sui:9000", []string{"ws", "wss"})
suiMoveEventType = NodeCmd.Flags().String("suiMoveEventType", "", "Sui move event type for publish_message")

solanaRPC = node.RegisterFlagWithValidationOrFail(NodeCmd, "solanaRPC", "Solana RPC URL (required)", "http://solana-devnet:8899", []string{"http", "https"})
Expand Down Expand Up @@ -521,7 +521,6 @@ func runNode(cmd *cobra.Command, args []string) {
*klaytnContract = unsafeDevModeEvmContractAddress(*klaytnContract)
*celoContract = unsafeDevModeEvmContractAddress(*celoContract)
*moonbeamContract = unsafeDevModeEvmContractAddress(*moonbeamContract)
*neonContract = unsafeDevModeEvmContractAddress(*neonContract)
*arbitrumContract = unsafeDevModeEvmContractAddress(*arbitrumContract)
*optimismContract = unsafeDevModeEvmContractAddress(*optimismContract)
*baseContract = unsafeDevModeEvmContractAddress(*baseContract)
Expand Down
11 changes: 6 additions & 5 deletions node/pkg/node/url_verification.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,18 @@ func hasKnownSchemePrefix(urlStr string) bool {
}

func validateURL(urlStr string, validSchemes []string) bool {
parsedURL, err := url.Parse(urlStr)
if err != nil {
return false
}

// If no scheme is required, validate host:port format
if len(validSchemes) == 1 && validSchemes[0] == "" {
host, port, err := net.SplitHostPort(urlStr)
return err == nil && host != "" && port != "" && !hasKnownSchemePrefix(urlStr)
}

// url.Parse() has to come later because it will fail if the scheme is empty
parsedURL, err := url.Parse(urlStr)
if err != nil {
return false
}

for _, scheme := range validSchemes {
if parsedURL.Scheme == scheme {
return true
Expand Down
1 change: 1 addition & 0 deletions node/pkg/node/url_verification_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ func TestValidateURL(t *testing.T) {
{[]string{""}, "example.com:8080", true},
{[]string{""}, "http://invalid-scheme:8080", false},
{[]string{""}, "ws://invalid-scheme:8080", false},
{[]string{""}, "170.0.0.1:8080", true},
}

for _, test := range tests {
Expand Down

0 comments on commit 3d16cca

Please sign in to comment.