hyperion-mysql 0.0.1.alpha5 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/hyperion/mysql.rb +1 -1
- data/lib/hyperion/mysql/db_strategy.rb +2 -2
- data/spec/hyperion/mysql_spec.rb +45 -33
- metadata +8 -9
data/lib/hyperion/mysql.rb
CHANGED
@@ -8,7 +8,7 @@ module Hyperion
|
|
8
8
|
module Mysql
|
9
9
|
|
10
10
|
def self.new(opts={})
|
11
|
-
Sql::Datastore.new(DbStrategy.new, QueryExecutorStrategy.new, QueryBuilderStrategy.new)
|
11
|
+
Sql::Datastore.new(opts[:connection_url], DbStrategy.new, QueryExecutorStrategy.new, QueryBuilderStrategy.new)
|
12
12
|
end
|
13
13
|
|
14
14
|
end
|
@@ -1,11 +1,11 @@
|
|
1
|
-
require 'hyperion
|
1
|
+
require 'hyperion'
|
2
2
|
|
3
3
|
module Hyperion
|
4
4
|
module Mysql
|
5
5
|
class DbStrategy
|
6
6
|
|
7
7
|
def process_result(given_record, result)
|
8
|
-
if
|
8
|
+
if Hyperion.new?(given_record)
|
9
9
|
given_record.merge('id' => result.insert_id)
|
10
10
|
else
|
11
11
|
given_record
|
data/spec/hyperion/mysql_spec.rb
CHANGED
@@ -5,6 +5,8 @@ require 'hyperion/mysql'
|
|
5
5
|
|
6
6
|
describe Hyperion::Mysql do
|
7
7
|
|
8
|
+
CONNECTION_URL = 'mysql://localhost/hyperion_ruby'
|
9
|
+
|
8
10
|
def execute(query)
|
9
11
|
Hyperion::Sql.connection.create_command(query).execute_non_query
|
10
12
|
end
|
@@ -25,54 +27,64 @@ describe Hyperion::Mysql do
|
|
25
27
|
execute "DROP TABLE IF EXISTS #{table_name};"
|
26
28
|
end
|
27
29
|
|
30
|
+
TABLES = ['testing', 'other_testing']
|
31
|
+
|
28
32
|
around :each do |example|
|
29
|
-
Hyperion
|
33
|
+
Hyperion.with_datastore(:mysql, :connection_url => CONNECTION_URL) do
|
30
34
|
example.run
|
31
35
|
end
|
32
36
|
end
|
33
37
|
|
34
|
-
|
38
|
+
before :each do |example|
|
39
|
+
Hyperion::Sql.with_connection(CONNECTION_URL) do
|
40
|
+
TABLES.each { |table| create_table(table) }
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
after :each do |example|
|
45
|
+
Hyperion::Sql.with_connection(CONNECTION_URL) do
|
46
|
+
TABLES.each { |table| drop_table(table) }
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
include_examples 'Datastore'
|
51
|
+
|
52
|
+
context 'Transactions' do
|
35
53
|
around :each do |example|
|
36
|
-
|
37
|
-
begin
|
38
|
-
tables.each { |table| create_table(table) }
|
54
|
+
Hyperion::Sql.with_connection(CONNECTION_URL) do
|
39
55
|
example.run
|
40
|
-
ensure
|
41
|
-
tables.each { |table| drop_table(table) }
|
42
56
|
end
|
43
57
|
end
|
44
58
|
|
45
|
-
include_examples '
|
59
|
+
include_examples 'Sql Transactions'
|
60
|
+
end
|
46
61
|
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
62
|
+
context 'Sql Injection' do
|
63
|
+
it 'escapes strings to be inserted' do
|
64
|
+
evil_name = "my evil name' --"
|
65
|
+
record = Hyperion.save(:kind => 'testing', :name => evil_name)
|
66
|
+
found_record = Hyperion.find_by_key(record[:key])
|
67
|
+
found_record[:name].should == evil_name
|
68
|
+
end
|
54
69
|
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
end
|
62
|
-
error_message.should include("Table 'hyperion_ruby.my_evil_name`___' doesn't exist")
|
70
|
+
it 'escapes table names' do
|
71
|
+
error_message = ""
|
72
|
+
begin
|
73
|
+
Hyperion.save(:kind => 'my evil name` --', :name => 'value')
|
74
|
+
rescue Exception => e
|
75
|
+
error_message = e.message
|
63
76
|
end
|
77
|
+
error_message.should include("Table 'hyperion_ruby.my_evil_name`___' doesn't exist")
|
78
|
+
end
|
64
79
|
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
end
|
72
|
-
error_message.should include("Unknown column 'my_evil_name`___' in 'field list'")
|
80
|
+
it 'escapes column names' do
|
81
|
+
error_message = ""
|
82
|
+
begin
|
83
|
+
Hyperion.save(:kind => 'testing', 'my evil name` --' => 'value')
|
84
|
+
rescue Exception => e
|
85
|
+
error_message = e.message
|
73
86
|
end
|
87
|
+
error_message.should include("Unknown column 'my_evil_name`___' in 'field list'")
|
74
88
|
end
|
75
89
|
end
|
76
|
-
|
77
|
-
it_behaves_like 'Sql Transactions'
|
78
90
|
end
|
metadata
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hyperion-mysql
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
5
|
-
prerelease:
|
4
|
+
version: 0.1.0
|
5
|
+
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
|
-
-
|
8
|
+
- Myles Megyesi
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-
|
12
|
+
date: 2012-10-17 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rspec
|
@@ -34,7 +34,7 @@ dependencies:
|
|
34
34
|
requirements:
|
35
35
|
- - '='
|
36
36
|
- !ruby/object:Gem::Version
|
37
|
-
version: 0.
|
37
|
+
version: 0.1.0
|
38
38
|
type: :runtime
|
39
39
|
prerelease: false
|
40
40
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -42,7 +42,7 @@ dependencies:
|
|
42
42
|
requirements:
|
43
43
|
- - '='
|
44
44
|
- !ruby/object:Gem::Version
|
45
|
-
version: 0.
|
45
|
+
version: 0.1.0
|
46
46
|
- !ruby/object:Gem::Dependency
|
47
47
|
name: do_mysql
|
48
48
|
requirement: !ruby/object:Gem::Requirement
|
@@ -62,7 +62,6 @@ dependencies:
|
|
62
62
|
description: MySQL Datastore for Hyperion
|
63
63
|
email:
|
64
64
|
- myles@8thlight.com
|
65
|
-
- skim@8thlight.com
|
66
65
|
executables: []
|
67
66
|
extensions: []
|
68
67
|
extra_rdoc_files: []
|
@@ -88,9 +87,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
88
87
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
89
88
|
none: false
|
90
89
|
requirements:
|
91
|
-
- - ! '
|
90
|
+
- - ! '>='
|
92
91
|
- !ruby/object:Gem::Version
|
93
|
-
version:
|
92
|
+
version: '0'
|
94
93
|
requirements: []
|
95
94
|
rubyforge_project:
|
96
95
|
rubygems_version: 1.8.24
|