github.com/snowflakedb/gosnowflake@v1.9.0/secret_detector_test.go (about) 1 // Copyright (c) 2021-2022 Snowflake Computing Inc. All rights reserved. 2 3 package gosnowflake 4 5 import ( 6 "strings" 7 "testing" 8 ) 9 10 const ( 11 longToken = "_Y1ZNETTn5/qfUWj3Jedby7gipDzQs=UKyJH9DS=nFzzWnfZKGV+C7GopWC" + 12 "GD4LjOLLFZKOE26LXHDt3pTi4iI1qwKuSpf/FmClCMBSissVsU3Ei590FP0lPQQhcSG" + 13 "cDu69ZL_1X6e9h5z62t/iY7ZkII28n2qU=nrBJUgPRCIbtJQkVJXIuOHjX4G5yUEKjZ" + 14 "BAx4w6=_lqtt67bIA=o7D=oUSjfywsRFoloNIkBPXCwFTv+1RVUHgVA2g8A9Lw5XdJY" + 15 "uI8vhg=f0bKSq7AhQ2Bh" 16 randomPassword = `Fh[+2J~AcqeqW%?` 17 ) 18 19 func TestMaskToken(t *testing.T) { 20 if text := maskSecrets("Token =" + longToken); strings.Compare(text, "Token =****") != 0 { 21 t.Errorf("mask unsuccessful. expected: Token=****, got: %v", text) 22 } 23 if text := maskSecrets("idToken : " + longToken); strings.Compare(text, "idToken : ****") != 0 { 24 t.Errorf("mask unsuccessful. expected: idToken : ****, got: %v", text) 25 } 26 if text := maskSecrets("sessionToken : " + longToken); strings.Compare(text, "sessionToken : ****") != 0 { 27 t.Errorf("mask unsuccessful. expected: sessionToken : ****, got: %v", text) 28 } 29 if text := maskSecrets("masterToken : " + longToken); strings.Compare(text, "masterToken : ****") != 0 { 30 t.Errorf("mask unsuccessful. expected: masterToken : ****, got: %v", text) 31 } 32 33 falsePositiveToken := "2020-04-30 23:06:04,069 - MainThread auth.py:397" + 34 " - write_temporary_credential() - DEBUG - no ID token is given when " + 35 "try to store temporary credential" 36 if text := maskSecrets(falsePositiveToken); strings.Compare(text, falsePositiveToken) != 0 { 37 t.Errorf("mask token %v should not have changed value. got: %v", falsePositiveToken, text) 38 } 39 } 40 41 func TestMaskPassword(t *testing.T) { 42 if text := maskSecrets("password:" + randomPassword); strings.Compare(text, "password:****") != 0 { 43 t.Errorf("mask unsuccessful. expected: password:****, got: %v", text) 44 } 45 if text := maskSecrets("PASSWORD:" + randomPassword); strings.Compare(text, "PASSWORD:****") != 0 { 46 t.Errorf("mask unsuccessful. expected: PASSWORD:****, got: %v", text) 47 } 48 if text := maskSecrets("PaSsWoRd:" + randomPassword); strings.Compare(text, "PaSsWoRd:****") != 0 { 49 t.Errorf("mask unsuccessful. expected: PaSsWoRd:****, got: %v", text) 50 } 51 if text := maskSecrets("password = " + randomPassword); strings.Compare(text, "password = ****") != 0 { 52 t.Errorf("mask unsuccessful. expected: password = ****, got: %v", text) 53 } 54 if text := maskSecrets("pwd:" + randomPassword); strings.Compare(text, "pwd:****") != 0 { 55 t.Errorf("mask unsuccessful. expected: pwd:****, got: %v", text) 56 } 57 } 58 59 func TestTokenPassword(t *testing.T) { 60 text := maskSecrets("token=" + longToken + " foo bar baz " + "password:" + randomPassword) 61 expected := "token=**** foo bar baz password:****" 62 if strings.Compare(text, expected) != 0 { 63 t.Errorf("mask unsuccessful. expected: %v, got: %v", expected, text) 64 } 65 text = maskSecrets("PWD = " + randomPassword + " blah blah blah " + "TOKEN:" + longToken) 66 expected = "PWD = **** blah blah blah TOKEN:****" 67 if strings.Compare(text, expected) != 0 { 68 t.Errorf("mask unsuccessful. expected: %v, got: %v", expected, text) 69 } 70 }