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

testutil: fixed promrated.go #2815

Merged
merged 2 commits into from
Jan 24, 2024
Merged
Show file tree
Hide file tree
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
14 changes: 12 additions & 2 deletions testutil/promrated/promrated.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

import (
"context"
"net/url"
"time"

"github.com/prometheus/client_golang/prometheus"
Expand All @@ -27,8 +28,7 @@
// Run blocks running the promrated program until the context is canceled or a fatal error occurs.
func Run(ctx context.Context, config Config) error {
log.Info(ctx, "Promrated started",
z.Str("rated_endpoint", config.RatedEndpoint), // TODO(corver): This may contain a password
z.Str("prom_auth", config.PromAuth), // TODO(corver): This may contain a password
z.Str("rated_endpoint", redactURL(config.RatedEndpoint)),

Check warning on line 31 in testutil/promrated/promrated.go

View check run for this annotation

Codecov / codecov/patch

testutil/promrated/promrated.go#L31

Added line #L31 was not covered by tests
z.Str("monitoring_addr", config.MonitoringAddr),
)

Expand Down Expand Up @@ -131,3 +131,13 @@

return result
}

// redactURL returns a redacted version of the given URL.
func redactURL(val string) string {
u, err := url.Parse(val)
if err != nil {
return val
}

Check warning on line 140 in testutil/promrated/promrated.go

View check run for this annotation

Codecov / codecov/patch

testutil/promrated/promrated.go#L139-L140

Added lines #L139 - L140 were not covered by tests

return u.Redacted()
}
17 changes: 17 additions & 0 deletions testutil/promrated/promrated_internal_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// Copyright © 2022-2023 Obol Labs Inc. Licensed under the terms of a Business Source License 1.1

package promrated

import (
"testing"

"github.com/stretchr/testify/require"
)

func TestRedactURL(t *testing.T) {
url := "https://user:[email protected]"

redacted := redactURL(url)

require.Equal(t, "https://user:[email protected]", redacted)
}
Loading