-
Notifications
You must be signed in to change notification settings - Fork 84
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Cherry-picks audit fixes tagged with `qs-audit` on `main-v0.19` category: misc ticket: none
- Loading branch information
Showing
41 changed files
with
566 additions
and
250 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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,13 @@ | ||
// Copyright © 2022-2023 Obol Labs Inc. Licensed under the terms of a Business Source License 1.1 | ||
|
||
package cmd | ||
|
||
import ( | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
// bindDebugMonitoringFlags binds Prometheus monitoring and debug address CLI flags. The debug address defaults to an empty address. | ||
func bindDebugMonitoringFlags(cmd *cobra.Command, monitorAddr, debugAddr *string, defaultMonitorAddr string) { | ||
cmd.Flags().StringVar(monitorAddr, "monitoring-address", defaultMonitorAddr, "Listening address (ip and port) for the monitoring API (prometheus).") | ||
cmd.Flags().StringVar(debugAddr, "debug-address", "", "Listening address (ip and port) for the pprof and QBFT debug API. It is not enabled by default.") | ||
} |
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,110 @@ | ||
// Copyright © 2022-2023 Obol Labs Inc. Licensed under the terms of a Business Source License 1.1 | ||
|
||
package cmd | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/spf13/cobra" | ||
"github.com/stretchr/testify/require" | ||
|
||
"github.com/obolnetwork/charon/app" | ||
) | ||
|
||
func genTestCmd(t *testing.T, f func(config app.Config)) *cobra.Command { | ||
t.Helper() | ||
|
||
var conf app.Config | ||
|
||
cmd := &cobra.Command{ | ||
Use: "test", | ||
Short: "test", | ||
} | ||
|
||
cmd.Run = func(cmd *cobra.Command, args []string) { | ||
f(conf) | ||
} | ||
|
||
bindDebugMonitoringFlags(cmd, &conf.MonitoringAddr, &conf.DebugAddr, "") | ||
|
||
return cmd | ||
} | ||
|
||
func Test_bindDebugMonitoringFlags(t *testing.T) { | ||
cmd := &cobra.Command{ | ||
Use: "testcmd", | ||
} | ||
|
||
t.Run("both present", func(t *testing.T) { | ||
var ( | ||
mAddr = "127.0.0.1:9999" | ||
dAddr = "127.0.0.1:8888" | ||
) | ||
|
||
cmd.ResetCommands() | ||
|
||
testCmd := genTestCmd(t, func(config app.Config) { | ||
require.Equal(t, mAddr, config.MonitoringAddr) | ||
require.Equal(t, dAddr, config.DebugAddr) | ||
}) | ||
|
||
cmd.AddCommand(testCmd) | ||
|
||
cmd.SetArgs([]string{ | ||
"test", | ||
"--monitoring-address", | ||
mAddr, | ||
"--debug-address", | ||
dAddr, | ||
}) | ||
|
||
require.NoError(t, cmd.Execute()) | ||
}) | ||
|
||
t.Run("only monitor", func(t *testing.T) { | ||
var ( | ||
mAddr = "127.0.0.1:9999" | ||
dAddr = "" | ||
) | ||
cmd.ResetCommands() | ||
|
||
testCmd := genTestCmd(t, func(config app.Config) { | ||
require.Equal(t, mAddr, config.MonitoringAddr) | ||
require.Equal(t, dAddr, config.DebugAddr) | ||
}) | ||
|
||
cmd.AddCommand(testCmd) | ||
|
||
cmd.SetArgs([]string{ | ||
"test", | ||
"--monitoring-address", | ||
mAddr, | ||
}) | ||
|
||
require.NoError(t, cmd.Execute()) | ||
}) | ||
|
||
t.Run("only debug", func(t *testing.T) { | ||
var ( | ||
mAddr = "" | ||
dAddr = "127.0.0.1:8888" | ||
) | ||
|
||
cmd.ResetCommands() | ||
|
||
testCmd := genTestCmd(t, func(config app.Config) { | ||
require.Equal(t, mAddr, config.MonitoringAddr) | ||
require.Equal(t, dAddr, config.DebugAddr) | ||
}) | ||
|
||
cmd.AddCommand(testCmd) | ||
|
||
cmd.SetArgs([]string{ | ||
"test", | ||
"--debug-address", | ||
dAddr, | ||
}) | ||
|
||
require.NoError(t, cmd.Execute()) | ||
}) | ||
} |
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
Oops, something went wrong.