vitess.io/vitess@v0.16.2/go/vt/mysqlctl/replication_test.go (about) 1 /* 2 Copyright 2019 The Vitess Authors. 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 mysqlctl 18 19 import ( 20 "testing" 21 ) 22 23 func testRedacted(t *testing.T, source, expected string) { 24 if r := redactPassword(source); r != expected { 25 t.Errorf("redactPassword bad result: %v\nWas expecting:%v", r, expected) 26 } 27 } 28 29 func TestRedactMasterPassword(t *testing.T) { 30 31 // regular test case 32 testRedacted(t, `CHANGE MASTER TO 33 MASTER_PASSWORD = 'AAA', 34 MASTER_CONNECT_RETRY = 1 35 `, 36 `CHANGE MASTER TO 37 MASTER_PASSWORD = '****', 38 MASTER_CONNECT_RETRY = 1 39 `) 40 41 // empty password 42 testRedacted(t, `CHANGE MASTER TO 43 MASTER_PASSWORD = '', 44 MASTER_CONNECT_RETRY = 1 45 `, 46 `CHANGE MASTER TO 47 MASTER_PASSWORD = '****', 48 MASTER_CONNECT_RETRY = 1 49 `) 50 51 // no beginning match 52 testRedacted(t, "aaaaaaaaaaaaaa", "aaaaaaaaaaaaaa") 53 54 // no end match 55 testRedacted(t, `CHANGE MASTER TO 56 MASTER_PASSWORD = 'AAA`, `CHANGE MASTER TO 57 MASTER_PASSWORD = 'AAA`) 58 } 59 60 func TestRedactPassword(t *testing.T) { 61 // regular case 62 testRedacted(t, `START xxx USER = 'vt_repl', PASSWORD = 'AAA'`, 63 `START xxx USER = 'vt_repl', PASSWORD = '****'`) 64 65 // empty password 66 testRedacted(t, `START xxx USER = 'vt_repl', PASSWORD = ''`, 67 `START xxx USER = 'vt_repl', PASSWORD = '****'`) 68 69 // no end match 70 testRedacted(t, `START xxx USER = 'vt_repl', PASSWORD = 'AAA`, 71 `START xxx USER = 'vt_repl', PASSWORD = 'AAA`) 72 73 // both primary password and password 74 testRedacted(t, `START xxx 75 MASTER_PASSWORD = 'AAA', 76 PASSWORD = 'BBB' 77 `, 78 `START xxx 79 MASTER_PASSWORD = '****', 80 PASSWORD = '****' 81 `) 82 }