Skip to content

Commit 535e9c8

Browse files
committed
Merge branch 'master' of git://github.com/neoryan/rails-sqlserver-adapter
2 parents cc51f28 + 8909869 commit 535e9c8

12 files changed

+554
-105
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
debug.log

RUNNING_UNIT_TESTS

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,5 +40,20 @@ you can do so with:
4040

4141
That'll run the base suite using the SQLServer-Ruby adapter.
4242

43+
== Expected Errors
4344

45+
Currently we expect the following errors from running the test suite:
4446

47+
1. test_add_limit_offset_should_sanitize_sql_injection_for_limit_with_comas
48+
from
49+
activerecord/test/cases/adapter_test.rb
50+
51+
2. test_add_limit_offset_should_sanitize_sql_injection_for_limit_without_comas
52+
from
53+
activerecord/test/cases/adapter_test.rb
54+
55+
1. & 2. error because we treat the possible values for offset and limit much more
56+
aggressively than the intention of the tests. Rails expects that limit => '1,7 bad sql'
57+
would turn into ' limit 1,7' but that's not valid SQL Server syntax so why should we
58+
bother? So we just deny non-integer limit / offset params entirely rather than trying
59+
to sanitize them. It's a hard-line to take on sql injection, but probably a safer one.

autotest/discover.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
2+
Autotest.add_discovery do
3+
'sqlserveradapter'
4+
end
5+
6+

autotest/sqlserveradapter.rb

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
require 'autotest'
2+
3+
class Autotest::Sqlserveradapter < Autotest
4+
5+
def initialize
6+
super
7+
8+
odbc_mode = true
9+
10+
clear_mappings
11+
12+
self.libs = [
13+
"lib",
14+
"test",
15+
"test/connections/native_sqlserver#{odbc_mode ? '_odbc' : ''}",
16+
"../../../rails/activerecord/test/"
17+
].join(File::PATH_SEPARATOR)
18+
19+
self.extra_files = ['../../../rails/activerecord/test/']
20+
21+
self.add_mapping %r%^test/.*/.*_test_sqlserver.rb$% do |filename, _|
22+
filename
23+
end
24+
25+
self.add_mapping %r%../../../rails/activerecord/test/.*/.*_test.rb$% do |filename, _|
26+
filename
27+
end
28+
29+
end
30+
31+
# Have to use a custom reorder method since the normal :alpha for Autotest would put the
32+
# files with ../ in the path before others.
33+
def reorder(files_to_test)
34+
ar_tests, sqlsvr_tests = files_to_test.partition { |k,v| k.start_with?('../../../') }
35+
ar_tests.sort! { |a,b| a[0] <=> b[0] }
36+
sqlsvr_tests.sort! { |a,b| a[0] <=> b[0] }
37+
sqlsvr_tests + ar_tests
38+
end
39+
40+
end
41+

0 commit comments

Comments
 (0)