Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

services/horizon: Properly validate the history archive URLs #4152

Merged
merged 2 commits into from
Jan 24, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion services/horizon/internal/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -559,7 +559,7 @@ func ApplyFlags(config *Config, flags support.ConfigOptions, options ApplyOption

// config.HistoryArchiveURLs contains a single empty value when empty so using
// viper.GetString is easier.
if len(config.HistoryArchiveURLs) == 0 {
if len(config.HistoryArchiveURLs) == 1 && config.HistoryArchiveURLs[0] == "" {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

since it's not really a value comparison for empty string, doing len(str) == 0 can be a bit more direct, but either way appears to be convention in go.

is there a unit test that hits this?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah both length and content checks are idiomatic; I think we use == "" most of the time.

We've started work on testing CLI parameters (see #3193 and its references), but there's a lot more to be done there. In general no, we don't have unit tests for flag parsing afaik.

return fmt.Errorf("--history-archive-urls must be set when --ingest is set")
}

Expand Down