ruby-mysql 2.9.12 → 2.11.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/README.rdoc +4 -3
- data/lib/mysql/authenticator/caching_sha2_password.rb +62 -0
- data/lib/mysql/authenticator/mysql_native_password.rb +37 -0
- data/lib/mysql/authenticator/sha256_password.rb +40 -0
- data/lib/mysql/authenticator.rb +84 -0
- data/lib/mysql/charset.rb +379 -256
- data/lib/mysql/constants.rb +154 -70
- data/lib/mysql/error.rb +13 -7
- data/lib/mysql/protocol.rb +191 -92
- data/lib/mysql.rb +55 -33
- data/test/test_mysql.rb +1899 -0
- data/test/test_mysql_packet.rb +149 -0
- metadata +21 -20
- data/spec/mysql/packet_spec.rb +0 -120
- data/spec/mysql_spec.rb +0 -1789
@@ -0,0 +1,149 @@
|
|
1
|
+
# coding: binary
|
2
|
+
require 'test/unit'
|
3
|
+
require 'test/unit/rr'
|
4
|
+
begin
|
5
|
+
require 'test/unit/notify'
|
6
|
+
rescue LoadError
|
7
|
+
# ignore
|
8
|
+
end
|
9
|
+
|
10
|
+
require 'mysql'
|
11
|
+
|
12
|
+
class TestMysqlPacket < Test::Unit::TestCase
|
13
|
+
def self._(s)
|
14
|
+
s.unpack('H*').first
|
15
|
+
end
|
16
|
+
|
17
|
+
def subject
|
18
|
+
Mysql::Packet.new(data)
|
19
|
+
end
|
20
|
+
|
21
|
+
sub_test_case '#lcb' do
|
22
|
+
[
|
23
|
+
["\xfb", nil],
|
24
|
+
["\xfc\x01\x02", 0x0201],
|
25
|
+
["\xfd\x01\x02\x03", 0x030201],
|
26
|
+
["\xfe\x01\x02\x03\x04\x05\x06\x07\x08", 0x0807060504030201],
|
27
|
+
["\x01", 0x01],
|
28
|
+
].each do |data, result|
|
29
|
+
sub_test_case "for '#{_ data}'" do
|
30
|
+
define_method(:data){ data }
|
31
|
+
test '' do
|
32
|
+
assert{ subject.lcb == result }
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
sub_test_case '#lcs' do
|
39
|
+
[
|
40
|
+
["\x03\x41\x42\x43", 'ABC'],
|
41
|
+
["\x01", ''],
|
42
|
+
["", nil],
|
43
|
+
].each do |data, result|
|
44
|
+
sub_test_case "for '#{_ data}'" do
|
45
|
+
define_method(:data){ data }
|
46
|
+
test '' do
|
47
|
+
assert{ subject.lcs == result }
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
sub_test_case '#read' do
|
54
|
+
define_method(:data){'ABCDEFGHI'}
|
55
|
+
test '' do
|
56
|
+
assert{ subject.read(7) == 'ABCDEFG' }
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
sub_test_case '#string' do
|
61
|
+
define_method(:data){"ABC\0DEF"}
|
62
|
+
test 'should NUL terminated String' do
|
63
|
+
assert{ subject.string == 'ABC' }
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
sub_test_case '#utiny' do
|
68
|
+
[
|
69
|
+
["\x01", 0x01],
|
70
|
+
["\xFF", 0xff],
|
71
|
+
].each do |data, result|
|
72
|
+
sub_test_case "for '#{_ data}'" do
|
73
|
+
define_method(:data){data}
|
74
|
+
test '' do
|
75
|
+
assert{ subject.utiny == result }
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
sub_test_case '#ushort' do
|
82
|
+
[
|
83
|
+
["\x01\x02", 0x0201],
|
84
|
+
["\xFF\xFE", 0xfeff],
|
85
|
+
].each do |data, result|
|
86
|
+
sub_test_case "for '#{_ data}'" do
|
87
|
+
define_method(:data){data}
|
88
|
+
test '' do
|
89
|
+
assert{ subject.ushort == result }
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
sub_test_case '#ulong' do
|
96
|
+
[
|
97
|
+
["\x01\x02\x03\x04", 0x04030201],
|
98
|
+
["\xFF\xFE\xFD\xFC", 0xfcfdfeff],
|
99
|
+
].each do |data, result|
|
100
|
+
sub_test_case "for '#{_ data}'" do
|
101
|
+
define_method(:data){data}
|
102
|
+
test '' do
|
103
|
+
assert{ subject.ulong == result }
|
104
|
+
end
|
105
|
+
end
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
109
|
+
sub_test_case '#eof?' do
|
110
|
+
[
|
111
|
+
["\xfe\x00\x00\x00\x00", true],
|
112
|
+
["ABCDE", false],
|
113
|
+
].each do |data, result|
|
114
|
+
sub_test_case "for '#{_ data}'" do
|
115
|
+
define_method(:data){data}
|
116
|
+
test '' do
|
117
|
+
assert{ subject.eof? == result }
|
118
|
+
end
|
119
|
+
end
|
120
|
+
end
|
121
|
+
end
|
122
|
+
|
123
|
+
sub_test_case 'Mysql::Packet.lcb' do
|
124
|
+
[
|
125
|
+
[nil, "\xfb"],
|
126
|
+
[1, "\x01"],
|
127
|
+
[250, "\xfa"],
|
128
|
+
[251, "\xfc\xfb\x00"],
|
129
|
+
[65535, "\xfc\xff\xff"],
|
130
|
+
[65536, "\xfd\x00\x00\x01"],
|
131
|
+
[16777215, "\xfd\xff\xff\xff"],
|
132
|
+
[16777216, "\xfe\x00\x00\x00\x01\x00\x00\x00\x00"],
|
133
|
+
[0xffffffffffffffff, "\xfe\xff\xff\xff\xff\xff\xff\xff\xff"],
|
134
|
+
].each do |val, result|
|
135
|
+
sub_test_case "with #{val}" do
|
136
|
+
test '' do
|
137
|
+
assert{ Mysql::Packet.lcb(val) == result }
|
138
|
+
end
|
139
|
+
end
|
140
|
+
end
|
141
|
+
end
|
142
|
+
|
143
|
+
sub_test_case 'Mysql::Packet.lcs' do
|
144
|
+
test '' do
|
145
|
+
assert{ Mysql::Packet.lcs("hoge") == "\x04hoge" }
|
146
|
+
assert{ Mysql::Packet.lcs("あいう".force_encoding("UTF-8")) == "\x09\xe3\x81\x82\xe3\x81\x84\xe3\x81\x86" }
|
147
|
+
end
|
148
|
+
end
|
149
|
+
end
|
metadata
CHANGED
@@ -1,15 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ruby-mysql
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
5
|
-
prerelease:
|
4
|
+
version: 2.11.0
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Tomita Masahiro
|
9
|
-
autorequire:
|
8
|
+
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date:
|
11
|
+
date: 2021-10-31 00:00:00.000000000 Z
|
13
12
|
dependencies: []
|
14
13
|
description: This is MySQL connector. pure Ruby version
|
15
14
|
email: tommy@tmtm.org
|
@@ -20,38 +19,40 @@ extra_rdoc_files:
|
|
20
19
|
files:
|
21
20
|
- README.rdoc
|
22
21
|
- lib/mysql.rb
|
23
|
-
- lib/mysql/
|
24
|
-
- lib/mysql/
|
22
|
+
- lib/mysql/authenticator.rb
|
23
|
+
- lib/mysql/authenticator/caching_sha2_password.rb
|
24
|
+
- lib/mysql/authenticator/mysql_native_password.rb
|
25
|
+
- lib/mysql/authenticator/sha256_password.rb
|
25
26
|
- lib/mysql/charset.rb
|
27
|
+
- lib/mysql/constants.rb
|
26
28
|
- lib/mysql/error.rb
|
27
29
|
- lib/mysql/packet.rb
|
28
|
-
-
|
29
|
-
-
|
30
|
+
- lib/mysql/protocol.rb
|
31
|
+
- test/test_mysql.rb
|
32
|
+
- test/test_mysql_packet.rb
|
30
33
|
homepage: http://github.com/tmtm/ruby-mysql
|
31
34
|
licenses:
|
32
|
-
- Ruby
|
33
|
-
|
35
|
+
- Ruby
|
36
|
+
metadata: {}
|
37
|
+
post_install_message:
|
34
38
|
rdoc_options: []
|
35
39
|
require_paths:
|
36
40
|
- lib
|
37
41
|
required_ruby_version: !ruby/object:Gem::Requirement
|
38
|
-
none: false
|
39
42
|
requirements:
|
40
|
-
- -
|
43
|
+
- - ">="
|
41
44
|
- !ruby/object:Gem::Version
|
42
45
|
version: '0'
|
43
46
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
44
|
-
none: false
|
45
47
|
requirements:
|
46
|
-
- -
|
48
|
+
- - ">="
|
47
49
|
- !ruby/object:Gem::Version
|
48
50
|
version: '0'
|
49
51
|
requirements: []
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
specification_version: 3
|
52
|
+
rubygems_version: 3.2.22
|
53
|
+
signing_key:
|
54
|
+
specification_version: 4
|
54
55
|
summary: MySQL connector
|
55
56
|
test_files:
|
56
|
-
-
|
57
|
-
-
|
57
|
+
- test/test_mysql.rb
|
58
|
+
- test/test_mysql_packet.rb
|
data/spec/mysql/packet_spec.rb
DELETED
@@ -1,120 +0,0 @@
|
|
1
|
-
# coding: binary
|
2
|
-
require 'mysql/packet'
|
3
|
-
|
4
|
-
describe Mysql::Packet do
|
5
|
-
def self._(s)
|
6
|
-
s.unpack('H*').first
|
7
|
-
end
|
8
|
-
subject{Mysql::Packet.new(data)}
|
9
|
-
describe '#lcb' do
|
10
|
-
[
|
11
|
-
["\xfb", nil],
|
12
|
-
["\xfc\x01\x02", 0x0201],
|
13
|
-
["\xfd\x01\x02\x03", 0x030201],
|
14
|
-
["\xfe\x01\x02\x03\x04\x05\x06\x07\x08", 0x0807060504030201],
|
15
|
-
["\x01", 0x01],
|
16
|
-
].each do |data, result|
|
17
|
-
context "for '#{_ data}'" do
|
18
|
-
let(:data){data}
|
19
|
-
it{subject.lcb.should == result}
|
20
|
-
end
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
describe '#lcs' do
|
25
|
-
[
|
26
|
-
["\x03\x41\x42\x43", 'ABC'],
|
27
|
-
["\x01", ''],
|
28
|
-
["", nil],
|
29
|
-
].each do |data, result|
|
30
|
-
context "for '#{_ data}'" do
|
31
|
-
let(:data){data}
|
32
|
-
it{subject.lcs.should == result}
|
33
|
-
end
|
34
|
-
end
|
35
|
-
end
|
36
|
-
|
37
|
-
describe '#read' do
|
38
|
-
let(:data){'ABCDEFGHI'}
|
39
|
-
it{subject.read(7).should == 'ABCDEFG'}
|
40
|
-
end
|
41
|
-
|
42
|
-
describe '#string' do
|
43
|
-
let(:data){"ABC\0DEF"}
|
44
|
-
it 'should NUL terminated String' do
|
45
|
-
subject.string.should == 'ABC'
|
46
|
-
end
|
47
|
-
end
|
48
|
-
|
49
|
-
describe '#utiny' do
|
50
|
-
[
|
51
|
-
["\x01", 0x01],
|
52
|
-
["\xFF", 0xff],
|
53
|
-
].each do |data, result|
|
54
|
-
context "for '#{_ data}'" do
|
55
|
-
let(:data){data}
|
56
|
-
it{subject.utiny.should == result}
|
57
|
-
end
|
58
|
-
end
|
59
|
-
end
|
60
|
-
|
61
|
-
describe '#ushort' do
|
62
|
-
[
|
63
|
-
["\x01\x02", 0x0201],
|
64
|
-
["\xFF\xFE", 0xfeff],
|
65
|
-
].each do |data, result|
|
66
|
-
context "for '#{_ data}'" do
|
67
|
-
let(:data){data}
|
68
|
-
it{subject.ushort.should == result}
|
69
|
-
end
|
70
|
-
end
|
71
|
-
end
|
72
|
-
|
73
|
-
describe '#ulong' do
|
74
|
-
[
|
75
|
-
["\x01\x02\x03\x04", 0x04030201],
|
76
|
-
["\xFF\xFE\xFD\xFC", 0xfcfdfeff],
|
77
|
-
].each do |data, result|
|
78
|
-
context "for '#{_ data}'" do
|
79
|
-
let(:data){data}
|
80
|
-
it{subject.ulong.should == result}
|
81
|
-
end
|
82
|
-
end
|
83
|
-
end
|
84
|
-
|
85
|
-
describe '#eof?' do
|
86
|
-
[
|
87
|
-
["\xfe\x00\x00\x00\x00", true],
|
88
|
-
["ABCDE", false],
|
89
|
-
].each do |data, result|
|
90
|
-
context "for '#{_ data}'" do
|
91
|
-
let(:data){data}
|
92
|
-
it{subject.eof?.should == result}
|
93
|
-
end
|
94
|
-
end
|
95
|
-
end
|
96
|
-
|
97
|
-
end
|
98
|
-
|
99
|
-
describe 'Mysql::Packet.lcb' do
|
100
|
-
[
|
101
|
-
[nil, "\xfb"],
|
102
|
-
[1, "\x01"],
|
103
|
-
[250, "\xfa"],
|
104
|
-
[251, "\xfc\xfb\x00"],
|
105
|
-
[65535, "\xfc\xff\xff"],
|
106
|
-
[65536, "\xfd\x00\x00\x01"],
|
107
|
-
[16777215, "\xfd\xff\xff\xff"],
|
108
|
-
[16777216, "\xfe\x00\x00\x00\x01\x00\x00\x00\x00"],
|
109
|
-
[0xffffffffffffffff, "\xfe\xff\xff\xff\xff\xff\xff\xff\xff"],
|
110
|
-
].each do |val, result|
|
111
|
-
context "with #{val}" do
|
112
|
-
it{Mysql::Packet.lcb(val).should == result}
|
113
|
-
end
|
114
|
-
end
|
115
|
-
end
|
116
|
-
|
117
|
-
describe 'Mysql::Packet.lcs' do
|
118
|
-
it{Mysql::Packet.lcs("hoge").should == "\x04hoge"}
|
119
|
-
it{Mysql::Packet.lcs("あいう".force_encoding("UTF-8")).should == "\x09\xe3\x81\x82\xe3\x81\x84\xe3\x81\x86"}
|
120
|
-
end
|