|
| 1 | +// Copyright 2021 The Prometheus Authors |
| 2 | +// Licensed under the Apache License, Version 2.0 (the "License"); |
| 3 | +// you may not use this file except in compliance with the License. |
| 4 | +// You may obtain a copy of the License at |
| 5 | +// |
| 6 | +// http://www.apache.org/licenses/LICENSE-2.0 |
| 7 | +// |
| 8 | +// Unless required by applicable law or agreed to in writing, software |
| 9 | +// distributed under the License is distributed on an "AS IS" BASIS, |
| 10 | +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 11 | +// See the License for the specific language governing permissions and |
| 12 | +// limitations under the License. |
| 13 | + |
| 14 | +package main |
| 15 | + |
| 16 | +import ( |
| 17 | + . "gopkg.in/check.v1" |
| 18 | +) |
| 19 | + |
| 20 | +func (s *FunctionalSuite) TestLoggableDSN(c *C) { |
| 21 | + type TestCase struct { |
| 22 | + input string |
| 23 | + expected string |
| 24 | + } |
| 25 | + |
| 26 | + cases := []TestCase{ |
| 27 | + { |
| 28 | + input: "host=host.example.com user=postgres port=5432 password=s3cr3t", |
| 29 | + expected: "host=host.example.com user=postgres port=5432 password=PASSWORD_REMOVED", |
| 30 | + }, |
| 31 | + |
| 32 | + { |
| 33 | + input: "host=host.example.com user=postgres port=5432 password=\"s3cr 3t\"", |
| 34 | + expected: "host=host.example.com user=postgres port=5432 password=PASSWORD_REMOVED", |
| 35 | + }, |
| 36 | + |
| 37 | + { |
| 38 | + input: "password=abcde host=host.example.com user=postgres port=5432", |
| 39 | + expected: "password=PASSWORD_REMOVED host=host.example.com user=postgres port=5432", |
| 40 | + }, |
| 41 | + |
| 42 | + { |
| 43 | + input: "password=abcde host=host.example.com user=postgres port=5432 password=\"s3cr 3t\"", |
| 44 | + expected: "password=PASSWORD_REMOVED host=host.example.com user=postgres port=5432 password=PASSWORD_REMOVED", |
| 45 | + }, |
| 46 | + |
| 47 | + { |
| 48 | + input: "postgresql://host.example.com:5432/tsdb?user=postgres", |
| 49 | + expected: "postgresql://host.example.com:5432/tsdb?user=postgres", |
| 50 | + }, |
| 51 | + |
| 52 | + { |
| 53 | + input: "postgresql://user:[email protected]:5432/tsdb?user=postgres", |
| 54 | + expected: "postgresql://user:[email protected]:5432/tsdb?user=postgres", |
| 55 | + }, |
| 56 | + |
| 57 | + { |
| 58 | + input: "postgresql://host.example.com:5432/tsdb?user=postgres&password=s3cr3t", |
| 59 | + expected: "postgresql://host.example.com:5432/tsdb?password=PASSWORD_REMOVED&user=postgres", |
| 60 | + }, |
| 61 | + |
| 62 | + { |
| 63 | + input: "host=host.example.com user=postgres port=5432", |
| 64 | + expected: "host=host.example.com user=postgres port=5432", |
| 65 | + }, |
| 66 | + } |
| 67 | + |
| 68 | + for _, cs := range cases { |
| 69 | + loggable := loggableDSN(cs.input) |
| 70 | + c.Assert(loggable, Equals, cs.expected) |
| 71 | + } |
| 72 | + |
| 73 | +} |
0 commit comments