forked from flike/kingshard
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutil_test.go
48 lines (41 loc) · 1.53 KB
/
util_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
// Copyright 2016 The kingshard Authors. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License"): you may
// not use this file except in compliance with the License. You may obtain
// a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
// License for the specific language governing permissions and limitations
// under the License.
package mysql
import (
"encoding/hex"
"testing"
"github.com/flike/kingshard/core/hack"
)
func TestCalcPassword(t *testing.T) {
/*
// **** JDBC ****
seed:
@jx=d_3z42;sS$YrS)p|
hex:
406a783d645f337a34323b73532459725329707c
pass:
kingshard
scramble:
fbc71db5ac3d7b51048d1a1d88c1677f34bcca11
*/
test, _ := RandomBuf(20)
hex_test := hex.EncodeToString(test)
t.Logf("rnd seed: %s, %s", hack.String(test), hex_test)
seed := hack.Slice("@jx=d_3z42;sS$YrS)p|")
hex_seed := hex.EncodeToString(seed)
t.Logf("seed: %s equal %s, pass: %v", "406a783d645f337a34323b73532459725329707c", hex_seed, "406a783d645f337a34323b73532459725329707c" == hex_seed)
scramble := CalcPassword(seed, hack.Slice("kingshard"))
hex_scramble := hex.EncodeToString(scramble)
t.Logf("scramble: %s equal %s, pass: %v", "fbc71db5ac3d7b51048d1a1d88c1677f34bcca11", hex_scramble, "fbc71db5ac3d7b51048d1a1d88c1677f34bcca11" == hex_scramble)
}