forked from go-sql-driver/mysql
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathauth_test.go
72 lines (55 loc) · 1.66 KB
/
auth_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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
package mysql
import "testing"
import "bytes"
func TestAuthPlugin_Cleartext(t *testing.T) {
cfg := &Config{
Passwd: "funny",
}
plugin := authPluginFactories[mysqlClearPassword](cfg)
_, err := plugin.Next(nil)
if err == nil {
t.Fatalf("expected error when AllowCleartextPasswords is false")
}
cfg.AllowCleartextPasswords = true
actual, err := plugin.Next(nil)
if err != nil {
t.Fatalf("expected no error but got: %s", err)
}
expected := append([]byte("funny"), 0)
if bytes.Compare(actual, expected) != 0 {
t.Fatalf("expected data to be %v, but got: %v", expected, actual)
}
}
func TestAuthPlugin_NativePassword(t *testing.T) {
cfg := &Config{
Passwd: "pass ",
}
plugin := authPluginFactories[mysqlNativePassword](cfg)
actual, err := plugin.Next([]byte{9, 8, 7, 6, 5, 4, 3, 2})
if err != nil {
t.Fatalf("expected no error but got: %s", err)
}
expected := []byte{195, 146, 3, 213, 111, 95, 252, 192, 97, 226, 173, 176, 91, 175, 131, 138, 89, 45, 75, 179}
if bytes.Compare(actual, expected) != 0 {
t.Fatalf("expected data to be %v, but got: %v", expected, actual)
}
}
func TestAuthPlugin_OldPassword(t *testing.T) {
cfg := &Config{
Passwd: "pass ",
}
plugin := authPluginFactories[mysqlOldPassword](cfg)
_, err := plugin.Next(nil)
if err == nil {
t.Fatalf("expected error when AllowOldPasswords is false")
}
cfg.AllowOldPasswords = true
actual, err := plugin.Next([]byte{9, 8, 7, 6, 5, 4, 3, 2})
if err != nil {
t.Fatalf("expected no error but got: %s", err)
}
expected := []byte{71, 87, 92, 90, 67, 91, 66, 81, 0}
if bytes.Compare(actual, expected) != 0 {
t.Fatalf("expected data to be %v, but got: %v", expected, actual)
}
}