@@ -16,6 +16,7 @@ package ast_test
1616import (
1717 . "github.com/pingcap/check"
1818 "github.com/pingcap/parser"
19+ "github.com/pingcap/parser/ast"
1920 . "github.com/pingcap/parser/ast"
2021 "github.com/pingcap/parser/auth"
2122 "github.com/pingcap/parser/mysql"
@@ -277,3 +278,40 @@ func (ts *testMiscSuite) TestChangeStmtRestore(c *C) {
277278 }
278279 RunNodeRestoreTest (c , testCases , "%s" , extractNodeFunc )
279280}
281+
282+ func (ts * testMiscSuite ) TestBRIESecureText (c * C ) {
283+ testCases := []struct {
284+ input string
285+ secured string
286+ }{
287+ {
288+ input : "restore database * from 'local:///tmp/br01' snapshot = 23333" ,
289+ secured : `^\QRESTORE DATABASE * FROM 'local:///tmp/br01' SNAPSHOT = 23333\E$` ,
290+ },
291+ {
292+ input : "backup database * to 's3://bucket/prefix?region=us-west-2'" ,
293+ secured : `^\QBACKUP DATABASE * TO 's3://bucket/prefix?region=us-west-2'\E$` ,
294+ },
295+ {
296+ // we need to use regexp to match to avoid the random ordering since a map was used.
297+ // unfortunately Go's regexp doesn't support lookahead assertion, so the test case below
298+ // has false positives.
299+ input : "backup database * to 's3://bucket/prefix?access-key=abcdefghi&secret-access-key=123&force-path-style=true'" ,
300+ secured : `^\QBACKUP DATABASE * TO 's3://bucket/prefix?\E((access-key=xxxxxx|force-path-style=true|secret-access-key=xxxxxx)(&|'$)){3}` ,
301+ },
302+ {
303+ input : "backup database * to 'gcs://bucket/prefix?access-key=irrelevant&credentials-file=/home/user/secrets.txt'" ,
304+ secured : `^\QBACKUP DATABASE * TO 'gcs://bucket/prefix?\E((access-key=irrelevant|credentials-file=/home/user/secrets\.txt)(&|'$)){2}` ,
305+ },
306+ }
307+
308+ parser := parser .New ()
309+ for _ , tc := range testCases {
310+ comment := Commentf ("input = %s" , tc .input )
311+ node , err := parser .ParseOneStmt (tc .input , "" , "" )
312+ c .Assert (err , IsNil , comment )
313+ n , ok := node .(ast.SensitiveStmtNode )
314+ c .Assert (ok , IsTrue , comment )
315+ c .Assert (n .SecureText (), Matches , tc .secured , comment )
316+ }
317+ }
0 commit comments