github.com/XiaoMi/Gaea@v1.2.5/mysql/util_test.go (about) 1 // Copyright 2016 The kingshard Authors. All rights reserved. 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"): you may 4 // not use this file except in compliance with the License. You may obtain 5 // a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 11 // WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 12 // License for the specific language governing permissions and limitations 13 // under the License. 14 15 // Copyright 2019 The Gaea Authors. All Rights Reserved. 16 // 17 // Licensed under the Apache License, Version 2.0 (the "License"); 18 // you may not use this file except in compliance with the License. 19 // You may obtain a copy of the License at 20 // 21 // http://www.apache.org/licenses/LICENSE-2.0 22 // 23 // Unless required by applicable law or agreed to in writing, software 24 // distributed under the License is distributed on an "AS IS" BASIS, 25 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 26 // See the License for the specific language governing permissions and 27 // limitations under the License. 28 29 package mysql 30 31 import ( 32 "encoding/hex" 33 "testing" 34 35 "github.com/XiaoMi/Gaea/util/hack" 36 ) 37 38 func TestCalcPassword(t *testing.T) { 39 /* 40 // **** JDBC **** 41 seed: 42 @jx=d_3z42;sS$YrS)p| 43 hex: 44 406a783d645f337a34323b73532459725329707c 45 pass: 46 kingshard 47 scramble: 48 fbc71db5ac3d7b51048d1a1d88c1677f34bcca11 49 */ 50 test, _ := RandomBuf(20) 51 hexTest := hex.EncodeToString(test) 52 t.Logf("rnd seed: %s, %s", hack.String(test), hexTest) 53 54 seed := hack.Slice("@jx=d_3z42;sS$YrS)p|") 55 hexSeed := hex.EncodeToString(seed) 56 57 t.Logf("seed: %s equal %s, pass: %v", "406a783d645f337a34323b73532459725329707c", hexSeed, "406a783d645f337a34323b73532459725329707c" == hexSeed) 58 scramble := CalcPassword(seed, hack.Slice("kingshard")) 59 60 hexScramble := hex.EncodeToString(scramble) 61 t.Logf("scramble: %s equal %s, pass: %v", "fbc71db5ac3d7b51048d1a1d88c1677f34bcca11", hexScramble, "fbc71db5ac3d7b51048d1a1d88c1677f34bcca11" == hexScramble) 62 } 63 64 func TestCalcPassword2(t *testing.T) { 65 seed := hack.Slice("D?Y.SZC@v,P${ GdT0e{") 66 hexSeed := hex.EncodeToString(seed) 67 t.Logf("seed: %s equal %s, pass: %v", "443f592e535a4340762c50247b2047645430657b", hexSeed, "443f592e535a4340762c50247b2047645430657b" == hexSeed) 68 scramble := CalcCachingSha2Password(seed, "123456") 69 70 hexScramble := hex.EncodeToString(scramble) 71 t.Logf("scramble: %s equal %s, pass: %v", "896d208c92429f5d1d5cb67f1ca3a639d7abdf335b05f58894e7f11d90608ca4", hexScramble, "896d208c92429f5d1d5cb67f1ca3a639d7abdf335b05f58894e7f11d90608ca4" == hexScramble) 72 }