-
Notifications
You must be signed in to change notification settings - Fork 761
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Ensure loggableDSN scrubs passwords in different ways
The previous implementation of the function was only scrubbing those passwords that were part of a basic http authentication method, which means it expected passwords to be provided as part of the URL. However, the password may also be specified as a parameter, or when using key-values, it may be specified as a password=value string. This commit ensures those passwords will also not be retained, but removed. Signed-off-by: Feike Steenbergen <feike@timescale.com>
- Loading branch information
1 parent
1b492a6
commit 326d62f
Showing
2 changed files
with
88 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
// Copyright 2021 The Prometheus Authors | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package main | ||
|
||
import ( | ||
. "gopkg.in/check.v1" | ||
) | ||
|
||
func (s *FunctionalSuite) TestLoggableDSN(c *C) { | ||
type TestCase struct { | ||
input string | ||
expected string | ||
} | ||
|
||
cases := []TestCase{ | ||
{ | ||
input: "host=host.example.com user=postgres port=5432 password=s3cr3t", | ||
expected: "host=host.example.com user=postgres port=5432 password=PASSWORD_REMOVED", | ||
}, | ||
|
||
{ | ||
input: "host=host.example.com user=postgres port=5432 password=\"s3cr 3t\"", | ||
expected: "host=host.example.com user=postgres port=5432 password=PASSWORD_REMOVED", | ||
}, | ||
|
||
{ | ||
input: "password=abcde host=host.example.com user=postgres port=5432", | ||
expected: "password=PASSWORD_REMOVED host=host.example.com user=postgres port=5432", | ||
}, | ||
|
||
{ | ||
input: "password=abcde host=host.example.com user=postgres port=5432 password=\"s3cr 3t\"", | ||
expected: "password=PASSWORD_REMOVED host=host.example.com user=postgres port=5432 password=PASSWORD_REMOVED", | ||
}, | ||
|
||
{ | ||
input: "postgresql://host.example.com:5432/tsdb?user=postgres", | ||
expected: "postgresql://host.example.com:5432/tsdb?user=postgres", | ||
}, | ||
|
||
{ | ||
input: "postgresql://user:s3cret@host.example.com:5432/tsdb?user=postgres", | ||
expected: "postgresql://user:PASSWORD_REMOVED@host.example.com:5432/tsdb?user=postgres", | ||
}, | ||
|
||
{ | ||
input: "postgresql://host.example.com:5432/tsdb?user=postgres&password=s3cr3t", | ||
expected: "postgresql://host.example.com:5432/tsdb?password=PASSWORD_REMOVED&user=postgres", | ||
}, | ||
|
||
{ | ||
input: "host=host.example.com user=postgres port=5432", | ||
expected: "host=host.example.com user=postgres port=5432", | ||
}, | ||
} | ||
|
||
for _, cs := range cases { | ||
loggable := loggableDSN(cs.input) | ||
c.Assert(loggable, Equals, cs.expected) | ||
} | ||
|
||
} |