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

Conversation

Shaptic
Copy link
Contributor

@Shaptic Shaptic commented Dec 22, 2021

PR Checklist

PR Structure

  • This PR has reasonably narrow scope (if not, break it down into smaller PRs).
  • This PR avoids mixing refactoring changes with feature changes (split into two PRs
    otherwise).
  • This PR's title starts with name of package that is most changed in the PR, ex.
    services/friendbot, or all or doc if the changes are broad or impact many
    packages.

Thoroughness

  • This PR adds tests for the most critical parts of the new functionality or fixes.
  • I've updated any docs (developer docs, .md
    files, etc... affected by this change). Take a look in the docs folder for a given service,
    like this one.

Release planning

  • I've updated the relevant CHANGELOG (here for Horizon) if
    needed with deprecations, added features, breaking changes, and DB schema changes.
  • I've decided if this PR requires a new major/minor version according to
    semver, or if it's mainly a patch change. The PR is targeted at the next
    release branch if it's not a patch change.

What

Checks that the history archive URLs contain no meaningful values.

Specifically, because of the way strings.Split works, the returned array will always have at least one element. If the string is empty, the array will be [""], so we need to check urls[1] == "" instead of checking the length.

Why

Currently, the error is not clear; closes #4141.

Known limitations

n/a

Because of the way strings.Split works, the returned array will
*always* have at least one element. If the string is empty, the
array will be [""], so we need to check [1] == "" instead of
checking the length.
@Shaptic Shaptic requested review from bartekn and a team December 22, 2021 20:56
@Shaptic Shaptic self-assigned this Dec 22, 2021
@@ -555,7 +555,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.

@Shaptic Shaptic enabled auto-merge (squash) January 24, 2022 07:35
@Shaptic Shaptic disabled auto-merge January 24, 2022 07:35
@Shaptic Shaptic disabled auto-merge January 24, 2022 07:35
@Shaptic Shaptic enabled auto-merge (squash) January 24, 2022 07:36
@Shaptic Shaptic merged commit 8652df7 into stellar:master Jan 24, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

services/horizon: Improve error message when HISTORY_ARCHIVE_URLS is empty
3 participants