vitess.io/vitess@v0.16.2/go/mysql/auth_server_test.go (about) 1 /* 2 copyright 2020 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 mysql 18 19 import ( 20 "testing" 21 22 "github.com/stretchr/testify/assert" 23 ) 24 25 func TestVerifyHashedMysqlNativePassword(t *testing.T) { 26 salt := []byte{10, 47, 74, 111, 75, 73, 34, 48, 88, 76, 114, 74, 37, 13, 3, 80, 82, 2, 23, 21} 27 password := "secret" 28 29 // Double SHA1 of "secret" 30 passwordHash := []byte{0x38, 0x81, 0x21, 0x9d, 0x08, 0x7d, 0xd9, 0xc6, 0x34, 0x37, 0x3f, 0xd3, 31 0x3d, 0xfa, 0x33, 0xa2, 0xcb, 0x6b, 0xfc, 0x6c, 0x52, 0x0b, 0x64, 0xb8, 32 0xbb, 0x60, 0xef, 0x2c, 0xeb, 0x53, 0x4a, 0xe7} 33 34 reply := ScrambleCachingSha2Password(salt, []byte(password)) 35 36 assert.True(t, VerifyHashedCachingSha2Password(reply, salt, passwordHash), "password hash mismatch") 37 38 passwordHash[0] = 0x00 39 assert.False(t, VerifyHashedCachingSha2Password(reply, salt, passwordHash), "password hash match") 40 } 41 42 func TestVerifyHashedCachingSha2Password(t *testing.T) { 43 salt := []byte{10, 47, 74, 111, 75, 73, 34, 48, 88, 76, 114, 74, 37, 13, 3, 80, 82, 2, 23, 21} 44 password := "secret" 45 46 // Double SHA1 of "secret" 47 passwordHash := []byte{0x14, 0xe6, 0x55, 0x67, 0xab, 0xdb, 0x51, 0x35, 0xd0, 0xcf, 0xd9, 0xa7, 48 0x0b, 0x30, 0x32, 0xc1, 0x79, 0xa4, 0x9e, 0xe7} 49 50 reply := ScrambleMysqlNativePassword(salt, []byte(password)) 51 assert.True(t, VerifyHashedMysqlNativePassword(reply, salt, passwordHash), "password hash mismatch") 52 53 passwordHash[0] = 0x00 54 assert.False(t, VerifyHashedMysqlNativePassword(reply, salt, passwordHash), "password hash match") 55 }