|
| 1 | +/* |
| 2 | +Copyright 2016 The Kubernetes Authors All rights reserved. |
| 3 | +
|
| 4 | +Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | +you may not use this file except in compliance with the License. |
| 6 | +You may obtain a copy of the License at |
| 7 | +
|
| 8 | + http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | +
|
| 10 | +Unless required by applicable law or agreed to in writing, software |
| 11 | +distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | +See the License for the specific language governing permissions and |
| 14 | +limitations under the License. |
| 15 | +*/ |
| 16 | + |
| 17 | +package node |
| 18 | + |
| 19 | +import ( |
| 20 | + "testing" |
| 21 | +) |
| 22 | + |
| 23 | +func Test_maskProxyPassword(t *testing.T) { |
| 24 | + type dockerOptTest struct { |
| 25 | + input string |
| 26 | + output string |
| 27 | + } |
| 28 | + var tests = []dockerOptTest{ |
| 29 | + { |
| 30 | + input: "cats", |
| 31 | + output: "cats", |
| 32 | + }, |
| 33 | + { |
| 34 | + input: "myDockerOption=value", |
| 35 | + output: "myDockerOption=value", |
| 36 | + }, |
| 37 | + { |
| 38 | + input: "http_proxy=http://minikube.sigs.k8s.io", |
| 39 | + output: "HTTP_PROXY=http://minikube.sigs.k8s.io", |
| 40 | + }, |
| 41 | + { |
| 42 | + input: "https_proxy=http://[email protected]:8080", |
| 43 | + output: "HTTPS_PROXY=http://[email protected]:8080", |
| 44 | + }, |
| 45 | + { |
| 46 | + input: "https_proxy=https://mary:[email protected]:8080", |
| 47 | + output: "HTTPS_PROXY=https://mary:*****@minikube.sigs.k8s.io:8080", |
| 48 | + }, |
| 49 | + { |
| 50 | + input: "http_proxy=http://jdoe:%n0tRe@al:[email protected]:8080", |
| 51 | + output: "HTTP_PROXY=http://jdoe:*****@minikube.sigs.k8s.io:8080", |
| 52 | + }, |
| 53 | + { |
| 54 | + input: "http_proxy=http://jo@han:n0tRe@al:&[email protected]:8080", |
| 55 | + output: "HTTP_PROXY=http://jo@han:*****@minikube.sigs.k8s.io:8080", |
| 56 | + }, |
| 57 | + { |
| 58 | + input: "http_proxy=http://k@r3n!:an0th3erF@akeP@[email protected]", |
| 59 | + output: "HTTP_PROXY=http://k@r3n!:*****@minikube.sigs.k8s.io", |
| 60 | + }, |
| 61 | + { |
| 62 | + input: "https_proxy=https://fr@ank5t3in:an0th3erF@akeP@[email protected]", |
| 63 | + output: "HTTPS_PROXY=https://fr@ank5t3in:*****@minikube.sigs.k8s.io", |
| 64 | + }, |
| 65 | + } |
| 66 | + for _, test := range tests { |
| 67 | + got := maskProxyPassword(test.input) |
| 68 | + if got != test.output { |
| 69 | + t.Errorf("maskProxyPassword(\"%v\"): got %v, expected %v", test.input, got, test.output) |
| 70 | + } |
| 71 | + } |
| 72 | +} |
0 commit comments