dm-sanitizer 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +18 -0
- data/LICENSE +20 -0
- data/Manifest.txt +12 -0
- data/README.txt +98 -0
- data/Rakefile +81 -0
- data/TODO +8 -0
- data/lib/dm-sanitizer.rb +111 -0
- data/lib/dm-sanitizer/version.rb +5 -0
- data/spec/dm-sanitizer_spec.rb +137 -0
- data/spec/spec.opts +1 -0
- data/spec/spec_helper.rb +32 -0
- data/tasks/hoe.rb +46 -0
- metadata +87 -0
data/History.txt
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
== 0.1.1 2009-06-01
|
2
|
+
|
3
|
+
* 2 enhancements
|
4
|
+
* Change mode options syntax
|
5
|
+
* Raise errors on undefined sanitization mode assigning
|
6
|
+
|
7
|
+
* 1 bug fix
|
8
|
+
* Don't sanitize clean values in old records
|
9
|
+
|
10
|
+
== 0.0.2 2009-05-30
|
11
|
+
|
12
|
+
* 1 bug fix:
|
13
|
+
* Don't sanitize nil and empty properties
|
14
|
+
|
15
|
+
== 0.0.1 2009-05-29
|
16
|
+
|
17
|
+
* 1 major enhancement:
|
18
|
+
* Initial release
|
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2009 Sergei Zimakov
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
'Software'), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
17
|
+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
18
|
+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
19
|
+
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
20
|
+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/Manifest.txt
ADDED
data/README.txt
ADDED
@@ -0,0 +1,98 @@
|
|
1
|
+
= dm-sanitizer
|
2
|
+
|
3
|
+
* http://github.com/pat/dm-sanitizer
|
4
|
+
|
5
|
+
== Description:
|
6
|
+
|
7
|
+
This package lets DataMapper properties be easily sanitized using Sanitize.
|
8
|
+
|
9
|
+
== Features and problems:
|
10
|
+
|
11
|
+
=== Features
|
12
|
+
|
13
|
+
* Sanitize String based properties by default
|
14
|
+
* Lets choose sanitization mode on per property basis
|
15
|
+
* Allows user defined sanitization modes
|
16
|
+
|
17
|
+
=== problems
|
18
|
+
|
19
|
+
* None known. Contact me if you find them.
|
20
|
+
|
21
|
+
== Synopsis:
|
22
|
+
|
23
|
+
require 'rubygems'
|
24
|
+
require 'dm-core'
|
25
|
+
require 'dm-sanitizer'
|
26
|
+
|
27
|
+
DataMapper.setup(:default, 'sqlite3::memory:')
|
28
|
+
|
29
|
+
class SomeModel
|
30
|
+
include DataMapper::Resource
|
31
|
+
|
32
|
+
property :id, Serial
|
33
|
+
property :title, String
|
34
|
+
property :story, Text
|
35
|
+
end
|
36
|
+
SomeModel.auto_migrate!
|
37
|
+
|
38
|
+
obj = SomeModel.new
|
39
|
+
obj.title = '<h1>Hi there</h1>'
|
40
|
+
obj.story = '<em>Some sanitization <strong>needed</strong></em>'
|
41
|
+
obj.save
|
42
|
+
puts obj.title == 'Hi there'
|
43
|
+
puts obj.story == 'Some sanitization needed'
|
44
|
+
|
45
|
+
class SomeOtherModel
|
46
|
+
include DataMapper::Resource
|
47
|
+
sanitize :default_mode => :basic, :modes => {:restricted => :title}, :exclude => [:junk]
|
48
|
+
|
49
|
+
property :id, Serial
|
50
|
+
property :title, String
|
51
|
+
property :story, Text
|
52
|
+
property :junk, Text
|
53
|
+
end
|
54
|
+
SomeOtherModel.auto_migrate!
|
55
|
+
|
56
|
+
obj = SomeOtherModel.new
|
57
|
+
obj.title = '<h1><strong>Hi</strong> <a href="#">there</a></h1>'
|
58
|
+
obj.story = '<h3><a href="#">Scince</a> knows many gitiks</h3>'
|
59
|
+
obj.junk = '<script>alert("xss")</script>'
|
60
|
+
obj.save
|
61
|
+
|
62
|
+
puts obj.title == '<strong>Hi</strong> there'
|
63
|
+
puts obj.story == '<a href="#" rel="nofollow">Scince</a> knows many gitiks'
|
64
|
+
puts obj.junk == '<script>alert("xss")</script>'
|
65
|
+
|
66
|
+
== Requirements:
|
67
|
+
|
68
|
+
* DataMapper (dm-core)
|
69
|
+
* Sanitize (sanitize)
|
70
|
+
|
71
|
+
== Installation:
|
72
|
+
|
73
|
+
sudo gem install dm-sanitizer
|
74
|
+
|
75
|
+
== License
|
76
|
+
|
77
|
+
(The MIT License)
|
78
|
+
|
79
|
+
Copyright (c) 2009 Sergei Zimakov
|
80
|
+
|
81
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
82
|
+
a copy of this software and associated documentation files (the
|
83
|
+
'Software'), to deal in the Software without restriction, including
|
84
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
85
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
86
|
+
permit persons to whom the Software is furnished to do so, subject to
|
87
|
+
the following conditions:
|
88
|
+
|
89
|
+
The above copyright notice and this permission notice shall be
|
90
|
+
included in all copies or substantial portions of the Software.
|
91
|
+
|
92
|
+
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
93
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
94
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
95
|
+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
96
|
+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
97
|
+
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
98
|
+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/Rakefile
ADDED
@@ -0,0 +1,81 @@
|
|
1
|
+
require 'pathname'
|
2
|
+
require 'rubygems'
|
3
|
+
require 'rake'
|
4
|
+
require "rake/clean"
|
5
|
+
require "rake/gempackagetask"
|
6
|
+
|
7
|
+
ROOT = Pathname(__FILE__).dirname.expand_path
|
8
|
+
JRUBY = RUBY_PLATFORM =~ /java/
|
9
|
+
WINDOWS = Gem.win_platform?
|
10
|
+
SUDO = (WINDOWS || JRUBY) ? '' : ('sudo' unless ENV['SUDOLESS'])
|
11
|
+
|
12
|
+
require ROOT + 'lib/dm-sanitizer/version'
|
13
|
+
|
14
|
+
AUTHOR = 'Sergei Zimakov'
|
15
|
+
EMAIL = 'zimakov@gmail.com'
|
16
|
+
GEM_NAME = 'dm-sanitizer'
|
17
|
+
GEM_VERSION = DataMapper::Sanitizer::VERSION
|
18
|
+
GEM_DEPENDENCIES = [['dm-core', '>= 0.9.4'], ['sanitize', '>= 1.0.0']]
|
19
|
+
GEM_CLEAN = %w[ log pkg coverage ]
|
20
|
+
GEM_EXTRAS = { :has_rdoc => true, :extra_rdoc_files => %w[ README.txt LICENSE History.txt ] }
|
21
|
+
|
22
|
+
PROJECT_NAME = 'dm-sanitizer'
|
23
|
+
PROJECT_URL = "http://github.com/pat/#{GEM_NAME}/tree/master/"
|
24
|
+
PROJECT_DESCRIPTION = PROJECT_SUMMARY = 'DataMapper plugin for automated/configurable user input sanitization.'
|
25
|
+
|
26
|
+
[ ROOT ].each do |dir|
|
27
|
+
Pathname.glob(dir.join('tasks/**/*.rb').to_s).each { |f| require f }
|
28
|
+
end
|
29
|
+
#
|
30
|
+
# spec = Gem::Specification.new do |s|
|
31
|
+
# s.name = GEM_NAME
|
32
|
+
# s.version = GEM_VERSION
|
33
|
+
# s.platform = Gem::Platform::RUBY
|
34
|
+
# s.author = AUTHOR
|
35
|
+
# s.email = EMAIL
|
36
|
+
# s.homepage = PROJECT_URL
|
37
|
+
# s.summary = PROJECT_SUMMARY
|
38
|
+
# s.description = PROJECT_DESCRIPTION
|
39
|
+
# s.require_path = 'lib'
|
40
|
+
# s.files = %w[ LICENSE README.txt Rakefile History.txt TODO ] + Dir['lib/**/*'] + Dir['spec/**/*']
|
41
|
+
# s.rubyforge_project = GEM_NAME
|
42
|
+
#
|
43
|
+
# # rdoc
|
44
|
+
# s.has_rdoc = false
|
45
|
+
# s.extra_rdoc_files = %w[ LICENSE README.txt History.txt ]
|
46
|
+
#
|
47
|
+
# # Dependencies
|
48
|
+
# GEM_DEPENDENCIES.each {|dep| s.add_dependency( dep[0], dep[1] )}
|
49
|
+
# end
|
50
|
+
#
|
51
|
+
# Rake::GemPackageTask.new(spec) do |package|
|
52
|
+
# package.gem_spec = spec
|
53
|
+
# end
|
54
|
+
#
|
55
|
+
# Specs
|
56
|
+
|
57
|
+
begin
|
58
|
+
gem 'rspec', '~>1.2'
|
59
|
+
require 'spec'
|
60
|
+
require 'spec/rake/spectask'
|
61
|
+
|
62
|
+
task :default => [ :spec ]
|
63
|
+
|
64
|
+
desc 'Run specifications'
|
65
|
+
Spec::Rake::SpecTask.new(:spec) do |t|
|
66
|
+
t.spec_opts << '--options' << 'spec/spec.opts' if File.exists?('spec/spec.opts')
|
67
|
+
t.spec_files = Pathname.glob((ROOT + 'spec/**/*_spec.rb').to_s).map { |f| f.to_s }
|
68
|
+
|
69
|
+
begin
|
70
|
+
gem 'rcov', '~>0.8'
|
71
|
+
t.rcov = JRUBY ? false : (ENV.has_key?('NO_RCOV') ? ENV['NO_RCOV'] != 'true' : true)
|
72
|
+
t.rcov_opts << '--exclude' << 'spec'
|
73
|
+
t.rcov_opts << '--text-summary'
|
74
|
+
t.rcov_opts << '--sort' << 'coverage' << '--sort-reverse'
|
75
|
+
rescue LoadError
|
76
|
+
# rcov not installed
|
77
|
+
end
|
78
|
+
end
|
79
|
+
rescue LoadError
|
80
|
+
# rspec not installed
|
81
|
+
end
|
data/TODO
ADDED
data/lib/dm-sanitizer.rb
ADDED
@@ -0,0 +1,111 @@
|
|
1
|
+
require 'pathname'
|
2
|
+
require 'rubygems'
|
3
|
+
|
4
|
+
require Pathname(__FILE__).dirname.expand_path + 'dm-sanitizer/version'
|
5
|
+
|
6
|
+
gem 'dm-core', '>= 0.9.4'
|
7
|
+
require 'dm-core'
|
8
|
+
|
9
|
+
gem 'sanitize', '>= 1.0.0'
|
10
|
+
require 'sanitize'
|
11
|
+
|
12
|
+
module DataMapper
|
13
|
+
module Sanitizer
|
14
|
+
def default_options
|
15
|
+
{
|
16
|
+
:mode_definitions => {
|
17
|
+
:default => Sanitize::Config::DEFAULT,
|
18
|
+
:restricted => Sanitize::Config::RESTRICTED,
|
19
|
+
:basic => Sanitize::Config::BASIC,
|
20
|
+
:relaxed => Sanitize::Config::RELAXED
|
21
|
+
},
|
22
|
+
:default_mode => :default
|
23
|
+
}
|
24
|
+
end
|
25
|
+
module_function :default_options
|
26
|
+
|
27
|
+
module ClassMethods
|
28
|
+
def sanitize(options={})
|
29
|
+
self.class_eval <<-RUBY, __FILE__, __LINE__ + 1
|
30
|
+
def self.sanitization_options=(options)
|
31
|
+
@sanitization_options = options
|
32
|
+
end
|
33
|
+
|
34
|
+
def self.sanitization_options
|
35
|
+
@sanitization_options
|
36
|
+
end
|
37
|
+
|
38
|
+
def sanitization_options
|
39
|
+
self.class.sanitization_options
|
40
|
+
end
|
41
|
+
RUBY
|
42
|
+
|
43
|
+
self.sanitization_options = DataMapper::Sanitizer.default_options.merge(options)
|
44
|
+
remap_sanitization_modes!
|
45
|
+
check_sanitization_modes
|
46
|
+
|
47
|
+
before :save, :sanitize! unless hooks_with_scope(:instance)[:save][:before].include?({:name => :sanitize!, :from => self})
|
48
|
+
end
|
49
|
+
|
50
|
+
def disable_sanitization
|
51
|
+
self.sanitization_options[:disabled] = true
|
52
|
+
end
|
53
|
+
|
54
|
+
private
|
55
|
+
def remap_sanitization_modes!
|
56
|
+
return unless @sanitization_options[:modes]
|
57
|
+
result = {}
|
58
|
+
@sanitization_options[:modes].each do |mode, group|
|
59
|
+
if group.class == Array
|
60
|
+
group.each {|item| result[item] = mode}
|
61
|
+
else
|
62
|
+
result[group] = mode
|
63
|
+
end
|
64
|
+
end
|
65
|
+
@sanitization_options[:modes] = result
|
66
|
+
end
|
67
|
+
|
68
|
+
def check_sanitization_modes
|
69
|
+
return unless @sanitization_options[:modes]
|
70
|
+
@sanitization_options[:modes].each do |property, mode|
|
71
|
+
raise Exception.new("Sanitization mode :#{mode} is not defined") unless @sanitization_options[:mode_definitions].has_key?(mode)
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
module InstanceMethods
|
77
|
+
def sanitize!
|
78
|
+
options = self.class.sanitization_options
|
79
|
+
return false if options[:disabled]
|
80
|
+
|
81
|
+
self.class.properties.each do |property|
|
82
|
+
property_name = property.name.to_sym
|
83
|
+
|
84
|
+
next unless property.type == String || property.type == DataMapper::Types::Text
|
85
|
+
next if !new_record? && !attribute_dirty?(property.name.to_sym)
|
86
|
+
next if options[:exclude] && options[:exclude].include?(property_name)
|
87
|
+
|
88
|
+
property_mode = options[:modes] ? options[:modes][property_name] || options[:default_mode] : options[:default_mode]
|
89
|
+
|
90
|
+
sanitize_property!(property_name, property_mode)
|
91
|
+
end
|
92
|
+
return true
|
93
|
+
end
|
94
|
+
|
95
|
+
def sanitize_property!(name, mode)
|
96
|
+
value = self.send( name )
|
97
|
+
return if value.nil? || value.empty?
|
98
|
+
sanitized_value = Sanitize.clean(value, self.class.sanitization_options[:mode_definitions][mode])
|
99
|
+
self.send( name.to_s+'=', sanitized_value)
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
103
|
+
def self.included(receiver)
|
104
|
+
receiver.extend( ClassMethods )
|
105
|
+
receiver.send( :include, InstanceMethods )
|
106
|
+
receiver.send( :sanitize )
|
107
|
+
end
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
111
|
+
DataMapper::Resource.append_inclusions DataMapper::Sanitizer
|
@@ -0,0 +1,137 @@
|
|
1
|
+
require 'pathname'
|
2
|
+
require Pathname(__FILE__).dirname.expand_path + 'spec_helper'
|
3
|
+
|
4
|
+
if HAS_SQLITE3 || HAS_MYSQL || HAS_POSTGRES
|
5
|
+
|
6
|
+
class CleanCell
|
7
|
+
include DataMapper::Resource
|
8
|
+
|
9
|
+
property :id, Serial
|
10
|
+
property :title, String
|
11
|
+
property :story, Text
|
12
|
+
end
|
13
|
+
CleanCell.auto_migrate!
|
14
|
+
|
15
|
+
class DirtyCell
|
16
|
+
include DataMapper::Resource
|
17
|
+
disable_sanitization
|
18
|
+
|
19
|
+
property :id, Serial
|
20
|
+
property :title, String
|
21
|
+
property :story, Text
|
22
|
+
end
|
23
|
+
DirtyCell.auto_migrate!
|
24
|
+
|
25
|
+
|
26
|
+
describe DataMapper::Model do
|
27
|
+
it "should have options" do
|
28
|
+
CleanCell.new.sanitization_options.should be_an_instance_of(Hash)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
describe DataMapper::Model, 'without sanitization' do
|
33
|
+
before(:each) do
|
34
|
+
@object = DirtyCell.new
|
35
|
+
end
|
36
|
+
|
37
|
+
it "should have disabling option" do
|
38
|
+
@object.sanitization_options[:disabled].should be_true
|
39
|
+
end
|
40
|
+
|
41
|
+
it "should not sanitize before save (sanitize! should return false)" do
|
42
|
+
@object.should_receive(:sanitize!).and_return(false)
|
43
|
+
@object.save
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
describe DataMapper::Model, "with sanitization" do
|
48
|
+
before(:each) do
|
49
|
+
@object = CleanCell.new
|
50
|
+
end
|
51
|
+
|
52
|
+
it "should call sanitize! once before save" do
|
53
|
+
@object.should_receive(:sanitize!).with().once.and_return(true)
|
54
|
+
@object.save
|
55
|
+
end
|
56
|
+
|
57
|
+
it "should sanitize String and Text properties by default" do
|
58
|
+
@object.should_receive(:sanitize_property!).with(:title,anything).once.ordered
|
59
|
+
@object.should_receive(:sanitize_property!).with(:story,anything).once.ordered
|
60
|
+
@object.save
|
61
|
+
end
|
62
|
+
|
63
|
+
it "should not sanitize property if its exluded" do
|
64
|
+
@object.class.sanitize :exclude => [:title]
|
65
|
+
@object.should_not_receive(:sanitize_property!).with(:title,anything)
|
66
|
+
@object.should_receive(:sanitize_property!).with(:story,anything).once.ordered
|
67
|
+
@object.save
|
68
|
+
end
|
69
|
+
|
70
|
+
it "should use changed default_mode" do
|
71
|
+
@object.class.sanitize :default_mode => :basic
|
72
|
+
@object.should_receive(:sanitize_property!).with(:title, :basic)
|
73
|
+
@object.should_receive(:sanitize_property!).with(:story, :basic)
|
74
|
+
@object.save
|
75
|
+
end
|
76
|
+
|
77
|
+
it "should use changed mode" do
|
78
|
+
@object.class.sanitize :modes => {:restricted => :title, :relaxed => :story}
|
79
|
+
@object.should_receive(:sanitize_property!).with(:title, :restricted)
|
80
|
+
@object.should_receive(:sanitize_property!).with(:story, :relaxed)
|
81
|
+
@object.save
|
82
|
+
end
|
83
|
+
|
84
|
+
it "should accept array style mode setting" do
|
85
|
+
@object.class.sanitize :modes => {:restricted => [:title, :story]}
|
86
|
+
@object.should_receive(:sanitize_property!).with(:title, :restricted)
|
87
|
+
@object.should_receive(:sanitize_property!).with(:story, :restricted)
|
88
|
+
@object.save
|
89
|
+
end
|
90
|
+
|
91
|
+
it "should raise error on undefined sanitization mode" do
|
92
|
+
lambda {
|
93
|
+
@object.class.sanitize :modes => {:desanitizedtwice => :title}
|
94
|
+
}.should raise_error
|
95
|
+
end
|
96
|
+
|
97
|
+
it "should not sanitize not dirty properties in not new records by default" do
|
98
|
+
@object.should_receive(:sanitize_property!).with(:title,anything).twice
|
99
|
+
@object.should_receive(:sanitize_property!).with(:story,anything).once
|
100
|
+
@object.save
|
101
|
+
@object.title = 'Really new <strong>value</strong>'
|
102
|
+
@object.save
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
describe "DataMapper::Model sanitize_property! method" do
|
107
|
+
before(:each) do
|
108
|
+
@object = CleanCell.new
|
109
|
+
@object.title = '<em>hi</em>'
|
110
|
+
end
|
111
|
+
|
112
|
+
it "should call Sanitize.clean with property and mode" do
|
113
|
+
Sanitize.should_receive(:clean).with(@object.title, @object.sanitization_options[:mode_definitions][:restricted])
|
114
|
+
@object.sanitize_property!(:title, :restricted)
|
115
|
+
end
|
116
|
+
|
117
|
+
it "should set property to sanitized value" do
|
118
|
+
@object.sanitize_property!(:title, :default)
|
119
|
+
@object.title.should == Sanitize.clean(@object.title, @object.sanitization_options[:mode_definitions][:default])
|
120
|
+
end
|
121
|
+
|
122
|
+
it "should not sanitize nil properties" do
|
123
|
+
@object.title = nil
|
124
|
+
Sanitize.should_not_receive(:clean)
|
125
|
+
@object.sanitize_property!(:title, :default)
|
126
|
+
@object.title.should == nil
|
127
|
+
end
|
128
|
+
|
129
|
+
it "should not sanitize empty properties" do
|
130
|
+
@object.title = ''
|
131
|
+
Sanitize.should_not_receive(:clean)
|
132
|
+
@object.sanitize_property!(:title, :default)
|
133
|
+
@object.title.should == ''
|
134
|
+
end
|
135
|
+
end
|
136
|
+
|
137
|
+
end
|
data/spec/spec.opts
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--colour
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
require 'pathname'
|
2
|
+
require 'rubygems'
|
3
|
+
|
4
|
+
gem 'rspec', '~>1.2'
|
5
|
+
require 'spec'
|
6
|
+
|
7
|
+
gem 'dm-core', '>= 0.9.4'
|
8
|
+
require 'dm-core'
|
9
|
+
|
10
|
+
gem 'sanitize', '>= 1.0.0'
|
11
|
+
require 'sanitize'
|
12
|
+
|
13
|
+
require Pathname(__FILE__).dirname.parent.expand_path + 'lib/dm-sanitizer'
|
14
|
+
|
15
|
+
def load_driver(name, default_uri)
|
16
|
+
return false if ENV['ADAPTER'] != name.to_s
|
17
|
+
|
18
|
+
begin
|
19
|
+
DataMapper.setup(name, ENV["#{name.to_s.upcase}_SPEC_URI"] || default_uri)
|
20
|
+
DataMapper::Repository.adapters[:default] = DataMapper::Repository.adapters[name]
|
21
|
+
true
|
22
|
+
rescue LoadError => e
|
23
|
+
warn "Could not load do_#{name}: #{e}"
|
24
|
+
false
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
ENV['ADAPTER'] ||= 'sqlite3'
|
29
|
+
|
30
|
+
HAS_SQLITE3 = load_driver(:sqlite3, 'sqlite3::memory:')
|
31
|
+
HAS_MYSQL = load_driver(:mysql, 'mysql://localhost/dm_core_test')
|
32
|
+
HAS_POSTGRES = load_driver(:postgres, 'postgres://postgres@localhost/dm_core_test')
|
data/tasks/hoe.rb
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
require 'hoe'
|
2
|
+
|
3
|
+
@config_file = "~/.rubyforge/user-config.yml"
|
4
|
+
@config = nil
|
5
|
+
RUBYFORGE_USERNAME = "unknown"
|
6
|
+
def rubyforge_username
|
7
|
+
unless @config
|
8
|
+
begin
|
9
|
+
@config = YAML.load(File.read(File.expand_path(@config_file)))
|
10
|
+
rescue
|
11
|
+
puts <<-EOS
|
12
|
+
ERROR: No rubyforge config file found: #{@config_file}
|
13
|
+
Run 'rubyforge setup' to prepare your env for access to Rubyforge
|
14
|
+
- See http://newgem.rubyforge.org/rubyforge.html for more details
|
15
|
+
EOS
|
16
|
+
exit
|
17
|
+
end
|
18
|
+
end
|
19
|
+
RUBYFORGE_USERNAME.replace @config["username"]
|
20
|
+
end
|
21
|
+
|
22
|
+
# Remove hoe dependency
|
23
|
+
class Hoe
|
24
|
+
def extra_dev_deps
|
25
|
+
@extra_dev_deps.reject! { |dep| dep[0] == "hoe" }
|
26
|
+
@extra_dev_deps
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
hoe = Hoe.new(GEM_NAME, GEM_VERSION) do |p|
|
31
|
+
|
32
|
+
p.developer(AUTHOR, EMAIL)
|
33
|
+
|
34
|
+
p.description = PROJECT_DESCRIPTION
|
35
|
+
p.summary = PROJECT_SUMMARY
|
36
|
+
p.url = PROJECT_URL
|
37
|
+
|
38
|
+
p.rubyforge_name = PROJECT_NAME if PROJECT_NAME
|
39
|
+
p.clean_globs |= GEM_CLEAN
|
40
|
+
p.spec_extras = GEM_EXTRAS if GEM_EXTRAS
|
41
|
+
|
42
|
+
GEM_DEPENDENCIES.each do |dep|
|
43
|
+
p.extra_deps << dep
|
44
|
+
end
|
45
|
+
|
46
|
+
end
|
metadata
ADDED
@@ -0,0 +1,87 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: dm-sanitizer
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Sergei Zimakov
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2009-06-02 00:00:00 +04:00
|
13
|
+
default_executable:
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: dm-core
|
17
|
+
type: :runtime
|
18
|
+
version_requirement:
|
19
|
+
version_requirements: !ruby/object:Gem::Requirement
|
20
|
+
requirements:
|
21
|
+
- - ">="
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: 0.9.4
|
24
|
+
version:
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: sanitize
|
27
|
+
type: :runtime
|
28
|
+
version_requirement:
|
29
|
+
version_requirements: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 1.0.0
|
34
|
+
version:
|
35
|
+
description: DataMapper plugin for automated/configurable user input sanitization.
|
36
|
+
email:
|
37
|
+
- zimakov@gmail.com
|
38
|
+
executables: []
|
39
|
+
|
40
|
+
extensions: []
|
41
|
+
|
42
|
+
extra_rdoc_files:
|
43
|
+
- README.txt
|
44
|
+
- LICENSE
|
45
|
+
- History.txt
|
46
|
+
files:
|
47
|
+
- History.txt
|
48
|
+
- LICENSE
|
49
|
+
- Manifest.txt
|
50
|
+
- Rakefile
|
51
|
+
- README.txt
|
52
|
+
- TODO
|
53
|
+
- lib/dm-sanitizer.rb
|
54
|
+
- lib/dm-sanitizer/version.rb
|
55
|
+
- spec/dm-sanitizer_spec.rb
|
56
|
+
- spec/spec.opts
|
57
|
+
- spec/spec_helper.rb
|
58
|
+
- tasks/hoe.rb
|
59
|
+
has_rdoc: true
|
60
|
+
homepage: http://github.com/pat/dm-sanitizer/tree/master/
|
61
|
+
post_install_message:
|
62
|
+
rdoc_options:
|
63
|
+
- --main
|
64
|
+
- README.txt
|
65
|
+
require_paths:
|
66
|
+
- lib
|
67
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
68
|
+
requirements:
|
69
|
+
- - ">="
|
70
|
+
- !ruby/object:Gem::Version
|
71
|
+
version: "0"
|
72
|
+
version:
|
73
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
74
|
+
requirements:
|
75
|
+
- - ">="
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: "0"
|
78
|
+
version:
|
79
|
+
requirements: []
|
80
|
+
|
81
|
+
rubyforge_project: dm-sanitizer
|
82
|
+
rubygems_version: 1.3.1
|
83
|
+
signing_key:
|
84
|
+
specification_version: 2
|
85
|
+
summary: DataMapper plugin for automated/configurable user input sanitization.
|
86
|
+
test_files: []
|
87
|
+
|