vidibus-validate_uri 0.2.0 → 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.md +71 -0
- data/lib/vidibus-validate_uri.rb +3 -3
- data/lib/vidibus/validate_uri.rb +3 -3
- data/lib/vidibus/validate_uri/core.rb +5 -5
- data/lib/vidibus/validate_uri/extensions.rb +1 -1
- data/lib/vidibus/validate_uri/version.rb +1 -1
- metadata +40 -24
- data/.document +0 -5
- data/.gitignore +0 -6
- data/.rspec +0 -2
- data/.travis.yml +0 -1
- data/Gemfile +0 -4
- data/README.rdoc +0 -71
- data/spec/spec_helper.rb +0 -16
- data/spec/vidibus/validate_uri/action_controller_spec.rb +0 -14
- data/spec/vidibus/validate_uri/core_spec.rb +0 -230
- data/spec/vidibus/validate_uri/uri_validator_spec.rb +0 -55
- data/vidibus-validate_uri.gemspec +0 -36
data/README.md
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
# Vidibus::ValidateUri [](http://travis-ci.org/vidibus/vidibus-validate_uri) [](http://stillmaintained.com/vidibus/vidibus-validate_uri)
|
|
2
|
+
|
|
3
|
+
It provides validation of URIs (URLs) to ActiveModel records and ActionControllers in Rails 3.
|
|
4
|
+
|
|
5
|
+
This gem is part of [Vidibus](http://vidibus.org), an open source toolset for building distributed (video) applications.
|
|
6
|
+
|
|
7
|
+
## Installation
|
|
8
|
+
|
|
9
|
+
Add `gem "vidibus-validate_uri"` to your Gemfile. Then call `bundle install` on your console.
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
## Usage
|
|
13
|
+
|
|
14
|
+
To validate an URI in your ActiveModel record, simply add the uri validator to the field you want to validate as URI:
|
|
15
|
+
|
|
16
|
+
```ruby
|
|
17
|
+
class Model
|
|
18
|
+
include Mongoid::Document
|
|
19
|
+
field :some_uri
|
|
20
|
+
validates :some_uri, :uri => true
|
|
21
|
+
end
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
To validate an URI in any model, include ActiveModel::Validations:
|
|
25
|
+
|
|
26
|
+
```ruby
|
|
27
|
+
class Model
|
|
28
|
+
include ActiveModel::Validations
|
|
29
|
+
attr_accessor :uri
|
|
30
|
+
validates :some_uri, :uri => true
|
|
31
|
+
end
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
Just in case you'll need it, a method `valid_uri?` is available to controllers that inherit from ActionController::Base. Use it like this:
|
|
35
|
+
|
|
36
|
+
```ruby
|
|
37
|
+
valid_uri?("something") # => false
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
### Validation options
|
|
41
|
+
|
|
42
|
+
To restrict validation to a certain protocol, provide a `:protocol` option:
|
|
43
|
+
|
|
44
|
+
```ruby
|
|
45
|
+
validates :some_uri, :uri => {:protocol => :rtmp}
|
|
46
|
+
validates :some_uri, :uri => {:protocol => [:rtsp, :rtmp]}
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
To check if the uri is accessible over the network, provide an `:accessible` option:
|
|
50
|
+
|
|
51
|
+
```ruby
|
|
52
|
+
validates :some_uri, :uri => {:accessible => true}
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
Just like for any other ActiveModel validation, you may allow blank values by providing an `:allow_blank` option:
|
|
56
|
+
|
|
57
|
+
```ruby
|
|
58
|
+
validates :some_uri, :uri => {:allow_blank => true}
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
You may provide those validation options to the `valid_uri?` method as well:
|
|
62
|
+
|
|
63
|
+
```ruby
|
|
64
|
+
valid_uri?(your_uri, :accessible => true)
|
|
65
|
+
valid_uri?(your_uri, :protocol => :rtmp)
|
|
66
|
+
valid_uri?(your_uri, :protocol => [:rtsp, :rtmp])
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
## Copyright
|
|
70
|
+
|
|
71
|
+
© 2010-2011 Andre Pankratz. See LICENSE for details.
|
data/lib/vidibus-validate_uri.rb
CHANGED
data/lib/vidibus/validate_uri.rb
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
require
|
|
2
|
-
require
|
|
3
|
-
require
|
|
1
|
+
require 'vidibus/validate_uri/core'
|
|
2
|
+
require 'vidibus/validate_uri/extensions'
|
|
3
|
+
require 'vidibus/validate_uri/uri_validator'
|
|
4
4
|
|
|
5
5
|
ActiveModel::Validations.send(:include, Vidibus::ValidateUri)
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# encoding: UTF-8
|
|
2
|
-
require
|
|
3
|
-
require
|
|
2
|
+
require 'net/https'
|
|
3
|
+
require 'uri'
|
|
4
4
|
|
|
5
5
|
module Vidibus
|
|
6
6
|
module ValidateUri
|
|
@@ -25,7 +25,7 @@ module Vidibus
|
|
|
25
25
|
|
|
26
26
|
if protocol = options[:protocol]
|
|
27
27
|
protocol = [protocol] unless p.is_a?(Array)
|
|
28
|
-
protocol_regexp = /#{protocol.join(
|
|
28
|
+
protocol_regexp = /#{protocol.join('|')}/
|
|
29
29
|
else
|
|
30
30
|
protocol_regexp = /\w+/
|
|
31
31
|
end
|
|
@@ -39,10 +39,10 @@ module Vidibus
|
|
|
39
39
|
def accessible_uri?(uri)
|
|
40
40
|
return false unless valid_uri?(uri)
|
|
41
41
|
_uri = URI.parse(uri)
|
|
42
|
-
path = _uri.path.blank? ?
|
|
42
|
+
path = _uri.path.blank? ? '/' : _uri.path
|
|
43
43
|
begin
|
|
44
44
|
http = Net::HTTP.new(_uri.host, _uri.port)
|
|
45
|
-
if _uri.scheme ==
|
|
45
|
+
if _uri.scheme == 'https'
|
|
46
46
|
http.use_ssl = true
|
|
47
47
|
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
|
48
48
|
end
|
metadata
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: vidibus-validate_uri
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
+
hash: 21
|
|
4
5
|
prerelease: false
|
|
5
6
|
segments:
|
|
6
7
|
- 0
|
|
7
8
|
- 2
|
|
8
|
-
-
|
|
9
|
-
version: 0.2.
|
|
9
|
+
- 1
|
|
10
|
+
version: 0.2.1
|
|
10
11
|
platform: ruby
|
|
11
12
|
authors:
|
|
12
13
|
- Andre Pankratz
|
|
@@ -14,16 +15,18 @@ autorequire:
|
|
|
14
15
|
bindir: bin
|
|
15
16
|
cert_chain: []
|
|
16
17
|
|
|
17
|
-
date:
|
|
18
|
+
date: 2012-02-13 00:00:00 +01:00
|
|
18
19
|
default_executable:
|
|
19
20
|
dependencies:
|
|
20
21
|
- !ruby/object:Gem::Dependency
|
|
21
22
|
name: rack
|
|
22
23
|
prerelease: false
|
|
23
24
|
requirement: &id001 !ruby/object:Gem::Requirement
|
|
25
|
+
none: false
|
|
24
26
|
requirements:
|
|
25
|
-
- -
|
|
27
|
+
- - ">="
|
|
26
28
|
- !ruby/object:Gem::Version
|
|
29
|
+
hash: 29
|
|
27
30
|
segments:
|
|
28
31
|
- 1
|
|
29
32
|
- 2
|
|
@@ -35,9 +38,11 @@ dependencies:
|
|
|
35
38
|
name: activesupport
|
|
36
39
|
prerelease: false
|
|
37
40
|
requirement: &id002 !ruby/object:Gem::Requirement
|
|
41
|
+
none: false
|
|
38
42
|
requirements:
|
|
39
43
|
- - ~>
|
|
40
44
|
- !ruby/object:Gem::Version
|
|
45
|
+
hash: 5
|
|
41
46
|
segments:
|
|
42
47
|
- 3
|
|
43
48
|
version: "3"
|
|
@@ -47,9 +52,11 @@ dependencies:
|
|
|
47
52
|
name: activemodel
|
|
48
53
|
prerelease: false
|
|
49
54
|
requirement: &id003 !ruby/object:Gem::Requirement
|
|
55
|
+
none: false
|
|
50
56
|
requirements:
|
|
51
57
|
- - ~>
|
|
52
58
|
- !ruby/object:Gem::Version
|
|
59
|
+
hash: 5
|
|
53
60
|
segments:
|
|
54
61
|
- 3
|
|
55
62
|
version: "3"
|
|
@@ -59,9 +66,11 @@ dependencies:
|
|
|
59
66
|
name: bundler
|
|
60
67
|
prerelease: false
|
|
61
68
|
requirement: &id004 !ruby/object:Gem::Requirement
|
|
69
|
+
none: false
|
|
62
70
|
requirements:
|
|
63
71
|
- - ">="
|
|
64
72
|
- !ruby/object:Gem::Version
|
|
73
|
+
hash: 23
|
|
65
74
|
segments:
|
|
66
75
|
- 1
|
|
67
76
|
- 0
|
|
@@ -73,9 +82,11 @@ dependencies:
|
|
|
73
82
|
name: rake
|
|
74
83
|
prerelease: false
|
|
75
84
|
requirement: &id005 !ruby/object:Gem::Requirement
|
|
85
|
+
none: false
|
|
76
86
|
requirements:
|
|
77
87
|
- - ">="
|
|
78
88
|
- !ruby/object:Gem::Version
|
|
89
|
+
hash: 3
|
|
79
90
|
segments:
|
|
80
91
|
- 0
|
|
81
92
|
version: "0"
|
|
@@ -85,9 +96,11 @@ dependencies:
|
|
|
85
96
|
name: rdoc
|
|
86
97
|
prerelease: false
|
|
87
98
|
requirement: &id006 !ruby/object:Gem::Requirement
|
|
99
|
+
none: false
|
|
88
100
|
requirements:
|
|
89
101
|
- - ">="
|
|
90
102
|
- !ruby/object:Gem::Version
|
|
103
|
+
hash: 3
|
|
91
104
|
segments:
|
|
92
105
|
- 0
|
|
93
106
|
version: "0"
|
|
@@ -97,9 +110,11 @@ dependencies:
|
|
|
97
110
|
name: rcov
|
|
98
111
|
prerelease: false
|
|
99
112
|
requirement: &id007 !ruby/object:Gem::Requirement
|
|
113
|
+
none: false
|
|
100
114
|
requirements:
|
|
101
115
|
- - ">="
|
|
102
116
|
- !ruby/object:Gem::Version
|
|
117
|
+
hash: 3
|
|
103
118
|
segments:
|
|
104
119
|
- 0
|
|
105
120
|
version: "0"
|
|
@@ -109,9 +124,11 @@ dependencies:
|
|
|
109
124
|
name: rspec
|
|
110
125
|
prerelease: false
|
|
111
126
|
requirement: &id008 !ruby/object:Gem::Requirement
|
|
127
|
+
none: false
|
|
112
128
|
requirements:
|
|
113
129
|
- - ~>
|
|
114
130
|
- !ruby/object:Gem::Version
|
|
131
|
+
hash: 7
|
|
115
132
|
segments:
|
|
116
133
|
- 2
|
|
117
134
|
version: "2"
|
|
@@ -121,9 +138,11 @@ dependencies:
|
|
|
121
138
|
name: rr
|
|
122
139
|
prerelease: false
|
|
123
140
|
requirement: &id009 !ruby/object:Gem::Requirement
|
|
141
|
+
none: false
|
|
124
142
|
requirements:
|
|
125
143
|
- - ">="
|
|
126
144
|
- !ruby/object:Gem::Version
|
|
145
|
+
hash: 3
|
|
127
146
|
segments:
|
|
128
147
|
- 0
|
|
129
148
|
version: "0"
|
|
@@ -133,9 +152,11 @@ dependencies:
|
|
|
133
152
|
name: actionpack
|
|
134
153
|
prerelease: false
|
|
135
154
|
requirement: &id010 !ruby/object:Gem::Requirement
|
|
155
|
+
none: false
|
|
136
156
|
requirements:
|
|
137
157
|
- - ~>
|
|
138
158
|
- !ruby/object:Gem::Version
|
|
159
|
+
hash: 5
|
|
139
160
|
segments:
|
|
140
161
|
- 3
|
|
141
162
|
version: "3"
|
|
@@ -145,9 +166,11 @@ dependencies:
|
|
|
145
166
|
name: webmock
|
|
146
167
|
prerelease: false
|
|
147
168
|
requirement: &id011 !ruby/object:Gem::Requirement
|
|
169
|
+
none: false
|
|
148
170
|
requirements:
|
|
149
171
|
- - ">="
|
|
150
172
|
- !ruby/object:Gem::Version
|
|
173
|
+
hash: 3
|
|
151
174
|
segments:
|
|
152
175
|
- 0
|
|
153
176
|
version: "0"
|
|
@@ -162,29 +185,18 @@ extensions: []
|
|
|
162
185
|
extra_rdoc_files: []
|
|
163
186
|
|
|
164
187
|
files:
|
|
165
|
-
- .bundle/config
|
|
166
|
-
- .document
|
|
167
|
-
- .gitignore
|
|
168
|
-
- .rspec
|
|
169
|
-
- .travis.yml
|
|
170
|
-
- Gemfile
|
|
171
|
-
- LICENSE
|
|
172
|
-
- README.rdoc
|
|
173
|
-
- Rakefile
|
|
174
|
-
- config/locales/de.yml
|
|
175
|
-
- config/locales/en.yml
|
|
176
|
-
- lib/vidibus-validate_uri.rb
|
|
177
|
-
- lib/vidibus/validate_uri.rb
|
|
178
188
|
- lib/vidibus/validate_uri/core.rb
|
|
179
|
-
- lib/vidibus/validate_uri/extensions.rb
|
|
180
189
|
- lib/vidibus/validate_uri/extensions/controller.rb
|
|
190
|
+
- lib/vidibus/validate_uri/extensions.rb
|
|
181
191
|
- lib/vidibus/validate_uri/uri_validator.rb
|
|
182
192
|
- lib/vidibus/validate_uri/version.rb
|
|
183
|
-
-
|
|
184
|
-
-
|
|
185
|
-
-
|
|
186
|
-
-
|
|
187
|
-
-
|
|
193
|
+
- lib/vidibus/validate_uri.rb
|
|
194
|
+
- lib/vidibus-validate_uri.rb
|
|
195
|
+
- config/locales/de.yml
|
|
196
|
+
- config/locales/en.yml
|
|
197
|
+
- LICENSE
|
|
198
|
+
- README.md
|
|
199
|
+
- Rakefile
|
|
188
200
|
has_rdoc: true
|
|
189
201
|
homepage: https://github.com/vidibus/vidibus-validate_uri
|
|
190
202
|
licenses: []
|
|
@@ -195,16 +207,20 @@ rdoc_options: []
|
|
|
195
207
|
require_paths:
|
|
196
208
|
- lib
|
|
197
209
|
required_ruby_version: !ruby/object:Gem::Requirement
|
|
210
|
+
none: false
|
|
198
211
|
requirements:
|
|
199
212
|
- - ">="
|
|
200
213
|
- !ruby/object:Gem::Version
|
|
214
|
+
hash: 3
|
|
201
215
|
segments:
|
|
202
216
|
- 0
|
|
203
217
|
version: "0"
|
|
204
218
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
219
|
+
none: false
|
|
205
220
|
requirements:
|
|
206
221
|
- - ">="
|
|
207
222
|
- !ruby/object:Gem::Version
|
|
223
|
+
hash: 23
|
|
208
224
|
segments:
|
|
209
225
|
- 1
|
|
210
226
|
- 3
|
|
@@ -213,7 +229,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
213
229
|
requirements: []
|
|
214
230
|
|
|
215
231
|
rubyforge_project: vidibus-resource
|
|
216
|
-
rubygems_version: 1.3.
|
|
232
|
+
rubygems_version: 1.3.7
|
|
217
233
|
signing_key:
|
|
218
234
|
specification_version: 3
|
|
219
235
|
summary: URI validation for Rails 3
|
data/.document
DELETED
data/.gitignore
DELETED
data/.rspec
DELETED
data/.travis.yml
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
script: "bundle exec rspec spec --format progress"
|
data/Gemfile
DELETED
data/README.rdoc
DELETED
|
@@ -1,71 +0,0 @@
|
|
|
1
|
-
= Vidibus::ValidateUri
|
|
2
|
-
|
|
3
|
-
It provides validation of URIs (URLs) to ActiveModel records and ActionControllers in Rails 3.
|
|
4
|
-
|
|
5
|
-
This gem is part of {Vidibus}[http://vidibus.org], an open source toolset for building distributed (video) applications.
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
== Compatibility
|
|
9
|
-
|
|
10
|
-
http://travis-ci.org/vidibus/vidibus-validate_uri.png
|
|
11
|
-
|
|
12
|
-
Vidibus::ValidateUri is tested against Ruby 1.8.7. {Build History}[http://travis-ci.org/vidibus/vidibus-validate_uri]
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
== Installation
|
|
16
|
-
|
|
17
|
-
Add the dependency to the Gemfile of your application:
|
|
18
|
-
|
|
19
|
-
gem "vidibus-validate_uri"
|
|
20
|
-
|
|
21
|
-
Then call bundle install on your console.
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
== Usage
|
|
25
|
-
|
|
26
|
-
To validate an URI in your ActiveModel record, simply add the uri validator to the field you want to validate as URI:
|
|
27
|
-
|
|
28
|
-
class Model
|
|
29
|
-
include Mongoid::Document
|
|
30
|
-
field :some_uri
|
|
31
|
-
validates :some_uri, :uri => true
|
|
32
|
-
end
|
|
33
|
-
|
|
34
|
-
To validate an URI in any model, include ActiveModel::Validations:
|
|
35
|
-
|
|
36
|
-
class Model
|
|
37
|
-
include ActiveModel::Validations
|
|
38
|
-
attr_accessor :uri
|
|
39
|
-
validates :some_uri, :uri => true
|
|
40
|
-
end
|
|
41
|
-
|
|
42
|
-
Just in case you'll need it, a method #valid_uri? is available to controllers that inherit from ActionController::Base. Use it like this:
|
|
43
|
-
|
|
44
|
-
valid_uri?("something") # => false
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
=== Validation options
|
|
48
|
-
|
|
49
|
-
To restrict validation to a certain protocol, provide a :protocol option:
|
|
50
|
-
|
|
51
|
-
validates :some_uri, :uri => { :protocol => :rtmp }
|
|
52
|
-
validates :some_uri, :uri => { :protocol => [:rtsp, :rtmp] }
|
|
53
|
-
|
|
54
|
-
To check if the uri is accessible over the network, provide an :accessible option:
|
|
55
|
-
|
|
56
|
-
validates :some_uri, :uri => { :accessible => true }
|
|
57
|
-
|
|
58
|
-
Just like for any other ActiveModel validation, you may allow blank values by providing an :allow_blank option:
|
|
59
|
-
|
|
60
|
-
validates :some_uri, :uri => { :allow_blank => true }
|
|
61
|
-
|
|
62
|
-
You may provide those validation options to the #valid_uri? method as well:
|
|
63
|
-
|
|
64
|
-
valid_uri?(your_uri, :accessible => true)
|
|
65
|
-
valid_uri?(your_uri, :protocol => :rtmp)
|
|
66
|
-
valid_uri?(your_uri, :protocol => [:rtsp, :rtmp])
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
== Copyright
|
|
70
|
-
|
|
71
|
-
Copyright (c) 2010-2011 Andre Pankratz. See LICENSE for details.
|
data/spec/spec_helper.rb
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
|
2
|
-
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), "..", "lib"))
|
|
3
|
-
|
|
4
|
-
require "rubygems"
|
|
5
|
-
require "rspec"
|
|
6
|
-
require "ostruct"
|
|
7
|
-
require "webmock/rspec"
|
|
8
|
-
|
|
9
|
-
require "vidibus-validate_uri"
|
|
10
|
-
|
|
11
|
-
RSpec.configure do |config|
|
|
12
|
-
config.include WebMock::API
|
|
13
|
-
config.mock_with :rr
|
|
14
|
-
end
|
|
15
|
-
|
|
16
|
-
I18n.load_path += Dir[File.join('config', 'locales', '**', '*.{rb,yml}')]
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
require "spec_helper"
|
|
2
|
-
require "action_controller"
|
|
3
|
-
|
|
4
|
-
class Controller < ActionController::Base; end
|
|
5
|
-
|
|
6
|
-
describe "ActionController::Base" do
|
|
7
|
-
it "should respond to #valid_uri?" do
|
|
8
|
-
Controller.new.should respond_to(:valid_uri?)
|
|
9
|
-
end
|
|
10
|
-
|
|
11
|
-
it "should respond to #accessible_uri?" do
|
|
12
|
-
Controller.new.should respond_to(:accessible_uri?)
|
|
13
|
-
end
|
|
14
|
-
end
|
|
@@ -1,230 +0,0 @@
|
|
|
1
|
-
require "spec_helper"
|
|
2
|
-
|
|
3
|
-
class Test
|
|
4
|
-
include Vidibus::ValidateUri::Core
|
|
5
|
-
end
|
|
6
|
-
|
|
7
|
-
class Rails < OpenStruct
|
|
8
|
-
def self.logger; end
|
|
9
|
-
end
|
|
10
|
-
|
|
11
|
-
describe "Vidibus::ValidateUri::Core" do
|
|
12
|
-
let(:test) { Test.new }
|
|
13
|
-
|
|
14
|
-
describe "#valid_uri?" do
|
|
15
|
-
it "should validate http://mydomain.local" do
|
|
16
|
-
uri = "http://mydomain.local"
|
|
17
|
-
test.valid_uri?(uri).should be_true
|
|
18
|
-
end
|
|
19
|
-
|
|
20
|
-
it "should validate http://mydomain.local/" do
|
|
21
|
-
uri = "http://mydomain.local/"
|
|
22
|
-
test.valid_uri?(uri).should be_true
|
|
23
|
-
end
|
|
24
|
-
|
|
25
|
-
it "should validate http://mydomain.com" do
|
|
26
|
-
uri = "http://mydomain.com"
|
|
27
|
-
test.valid_uri?(uri).should be_true
|
|
28
|
-
end
|
|
29
|
-
|
|
30
|
-
it "should validate http://www.mydomain.com" do
|
|
31
|
-
uri = "http://www.mydomain.com"
|
|
32
|
-
test.valid_uri?(uri).should be_true
|
|
33
|
-
end
|
|
34
|
-
|
|
35
|
-
it "should validate http://mydomain.com:8080" do
|
|
36
|
-
uri = "http://mydomain.com:8080"
|
|
37
|
-
test.valid_uri?(uri).should be_true
|
|
38
|
-
end
|
|
39
|
-
|
|
40
|
-
it "should validate http://mydomain.local/" do
|
|
41
|
-
uri = "http://mydomain.local/"
|
|
42
|
-
test.valid_uri?(uri).should be_true
|
|
43
|
-
end
|
|
44
|
-
|
|
45
|
-
it "should validate http://localhost" do
|
|
46
|
-
uri = "http://localhost"
|
|
47
|
-
test.valid_uri?(uri).should be_true
|
|
48
|
-
end
|
|
49
|
-
|
|
50
|
-
it "should validate http://localhost/" do
|
|
51
|
-
uri = "http://localhost/"
|
|
52
|
-
test.valid_uri?(uri).should be_true
|
|
53
|
-
end
|
|
54
|
-
|
|
55
|
-
it "should fail for http://localhosts" do
|
|
56
|
-
uri = "http://localhosts"
|
|
57
|
-
test.valid_uri?(uri).should be_false
|
|
58
|
-
end
|
|
59
|
-
|
|
60
|
-
it "should validate http://localhost:3000" do
|
|
61
|
-
uri = "http://localhost:3000"
|
|
62
|
-
test.valid_uri?(uri).should be_true
|
|
63
|
-
end
|
|
64
|
-
|
|
65
|
-
it "should validate http://localhost:3000/" do
|
|
66
|
-
uri = "http://localhost:3000/"
|
|
67
|
-
test.valid_uri?(uri).should be_true
|
|
68
|
-
end
|
|
69
|
-
|
|
70
|
-
it "should validate http://84.191.143.127" do
|
|
71
|
-
uri = "http://84.191.199.127"
|
|
72
|
-
test.valid_uri?(uri).should be_true
|
|
73
|
-
end
|
|
74
|
-
|
|
75
|
-
it "should validate http://84.191.143.127/" do
|
|
76
|
-
uri = "http://84.191.199.127/"
|
|
77
|
-
test.valid_uri?(uri).should be_true
|
|
78
|
-
end
|
|
79
|
-
|
|
80
|
-
it "should validate http://84.191.143.127:80" do
|
|
81
|
-
uri = "http://84.191.199.127:80"
|
|
82
|
-
test.valid_uri?(uri).should be_true
|
|
83
|
-
end
|
|
84
|
-
|
|
85
|
-
it "should fail for http://84.2a.143.127" do
|
|
86
|
-
uri = "http://84.2a.143.127"
|
|
87
|
-
test.valid_uri?(uri).should be_false
|
|
88
|
-
end
|
|
89
|
-
|
|
90
|
-
it "should validate https://some.weird.sub.1.mydomain.com:10000" do
|
|
91
|
-
uri = "https://some.weird.sub.1.mydomain.com:10000"
|
|
92
|
-
test.valid_uri?(uri).should be_true
|
|
93
|
-
end
|
|
94
|
-
|
|
95
|
-
it "should validate http://mydomain.local?some=params" do
|
|
96
|
-
uri = "http://mydomain.local?some=params"
|
|
97
|
-
test.valid_uri?(uri).should be_true
|
|
98
|
-
end
|
|
99
|
-
|
|
100
|
-
it "should validate http://mydomain.local/?some=params" do
|
|
101
|
-
uri = "http://mydomain.local/?some=params"
|
|
102
|
-
test.valid_uri?(uri).should be_true
|
|
103
|
-
end
|
|
104
|
-
|
|
105
|
-
it "should validate http://mydomain.local/hello/world" do
|
|
106
|
-
uri = "http://mydomain.local/hello/world"
|
|
107
|
-
test.valid_uri?(uri).should be_true
|
|
108
|
-
end
|
|
109
|
-
|
|
110
|
-
it "should fail for http://mydomain.local/hel lo/world" do
|
|
111
|
-
uri = "http://mydomain.local/hel lo/world"
|
|
112
|
-
test.valid_uri?(uri).should be_false
|
|
113
|
-
end
|
|
114
|
-
|
|
115
|
-
it "should validate http://mydomain.local/hello/world/" do
|
|
116
|
-
uri = "http://mydomain.local/hello/world/"
|
|
117
|
-
test.valid_uri?(uri).should be_true
|
|
118
|
-
end
|
|
119
|
-
|
|
120
|
-
it "should validate http://mydomain.local/hello/world.html" do
|
|
121
|
-
uri = "http://mydomain.local/hello/world.html"
|
|
122
|
-
test.valid_uri?(uri).should be_true
|
|
123
|
-
end
|
|
124
|
-
|
|
125
|
-
it "should validate http://mydomain.local/hello/world.html#doit" do
|
|
126
|
-
uri = "http://mydomain.local/hello/world.html#doit"
|
|
127
|
-
test.valid_uri?(uri).should be_true
|
|
128
|
-
end
|
|
129
|
-
|
|
130
|
-
it "should validate http://mydomain.local/hello/world?some=params" do
|
|
131
|
-
uri = "http://mydomain.local/hello/world?some=params"
|
|
132
|
-
test.valid_uri?(uri).should be_true
|
|
133
|
-
end
|
|
134
|
-
|
|
135
|
-
it "should validate http://mydomain.local/hello/world/?some=params" do
|
|
136
|
-
uri = "http://mydomain.local/hello/world/?some=params"
|
|
137
|
-
test.valid_uri?(uri).should be_true
|
|
138
|
-
end
|
|
139
|
-
|
|
140
|
-
it "should validate http://mydomain.local?some=params&another=one" do
|
|
141
|
-
uri = "http://mydomain.local?some=params&another=one"
|
|
142
|
-
test.valid_uri?(uri).should be_true
|
|
143
|
-
end
|
|
144
|
-
|
|
145
|
-
it "should validate http://mydomain.local?some=params&another=one#withFragment" do
|
|
146
|
-
uri = "http://mydomain.local?some=params&another=one#withFragment"
|
|
147
|
-
test.valid_uri?(uri).should be_true
|
|
148
|
-
end
|
|
149
|
-
|
|
150
|
-
it "should validate https://mydomain.local" do
|
|
151
|
-
uri = "https://mydomain.local"
|
|
152
|
-
test.valid_uri?(uri).should be_true
|
|
153
|
-
end
|
|
154
|
-
|
|
155
|
-
it "should validate https://mydomain.local with protocol => :https" do
|
|
156
|
-
uri = "https://mydomain.local"
|
|
157
|
-
test.valid_uri?(uri, :protocol => :https).should be_true
|
|
158
|
-
end
|
|
159
|
-
|
|
160
|
-
it "should validate https://mydomain.local with protocol => [:http, :https]" do
|
|
161
|
-
uri = "https://mydomain.local"
|
|
162
|
-
test.valid_uri?(uri, :protocol => [:http, :https]).should be_true
|
|
163
|
-
end
|
|
164
|
-
|
|
165
|
-
it "should fail for https://mydomain.local with protocol => :http" do
|
|
166
|
-
uri = "https://mydomain.local"
|
|
167
|
-
test.valid_uri?(uri, :protocol => :http).should be_false
|
|
168
|
-
end
|
|
169
|
-
|
|
170
|
-
it "should fail for https://mydomain.local with protocol => [:http, :rtmp]" do
|
|
171
|
-
uri = "https://mydomain.local"
|
|
172
|
-
test.valid_uri?(uri, :protocol => [:http, :rtmp]).should be_false
|
|
173
|
-
end
|
|
174
|
-
|
|
175
|
-
it "should validate rtmp://mydomain.local/video/13os/pi1x/1391/sxj9/go.flv?10|12|33 with protocol => [:rtmp, :rtsp]" do
|
|
176
|
-
uri = "rtmp://mydomain.local/video/13os/pi1x/1391/sxj9/go.flv?10|12|33"
|
|
177
|
-
test.valid_uri?(uri, :protocol => [:rtmp, :rtsp]).should be_true
|
|
178
|
-
end
|
|
179
|
-
|
|
180
|
-
it "should validate http://www.ali.baba.döner.de" do
|
|
181
|
-
uri = "http://www.ali.baba.döner.de"
|
|
182
|
-
test.valid_uri?(uri).should be_true
|
|
183
|
-
end
|
|
184
|
-
|
|
185
|
-
it "should validate http://mydomain.local/WhatsUp" do
|
|
186
|
-
uri = "http://mydomain.local/WhatsUp"
|
|
187
|
-
test.valid_uri?(uri).should be_true
|
|
188
|
-
end
|
|
189
|
-
end
|
|
190
|
-
|
|
191
|
-
describe "#accessible_uri?" do
|
|
192
|
-
it "should validate http://www.vidibus.org which redirects permanently" do
|
|
193
|
-
uri = "http://www.vidibus.org"
|
|
194
|
-
stub_request(:head, uri).to_return(:status => 301)
|
|
195
|
-
test.accessible_uri?(uri).should be_true
|
|
196
|
-
end
|
|
197
|
-
|
|
198
|
-
it "should validate https://encrypted.google.com" do
|
|
199
|
-
uri = "https://encrypted.google.com"
|
|
200
|
-
stub_request(:head, uri).to_return(:status => 200)
|
|
201
|
-
test.accessible_uri?(uri).should be_true
|
|
202
|
-
end
|
|
203
|
-
|
|
204
|
-
it "should fail for http://www.vidibus.zzz which causes an SocketError" do
|
|
205
|
-
uri = "http://www.vidibus.zzz"
|
|
206
|
-
stub.any_instance_of(Net::HTTP).head {raise SocketError}
|
|
207
|
-
test.accessible_uri?(uri).should be_false
|
|
208
|
-
end
|
|
209
|
-
|
|
210
|
-
it "should fail for http://vidibus.org/invalid which does not exist" do
|
|
211
|
-
uri = "http://vidibus.org/invalid"
|
|
212
|
-
stub_request(:head, uri).to_return(:status => 404)
|
|
213
|
-
test.accessible_uri?(uri).should be_false
|
|
214
|
-
end
|
|
215
|
-
|
|
216
|
-
it "should log HTTP errors with Rails.logger, if available" do
|
|
217
|
-
uri = "http://www.vidibus.zzz"
|
|
218
|
-
stub.any_instance_of(Net::HTTP).head {raise SocketError}
|
|
219
|
-
mock(Rails).logger.any_number_of_times {true}
|
|
220
|
-
mock(Rails.logger).error.with_any_args
|
|
221
|
-
test.accessible_uri?(uri)
|
|
222
|
-
end
|
|
223
|
-
|
|
224
|
-
it "should not perform accessibility check of syntactically invalid URIs" do
|
|
225
|
-
uri = "http://invalid"
|
|
226
|
-
dont_allow(URI).parse
|
|
227
|
-
test.accessible_uri?(uri).should be_false
|
|
228
|
-
end
|
|
229
|
-
end
|
|
230
|
-
end
|
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
require "spec_helper"
|
|
2
|
-
|
|
3
|
-
class Model
|
|
4
|
-
include ActiveModel::Validations
|
|
5
|
-
attr_accessor :uri
|
|
6
|
-
validates :uri, :uri => true
|
|
7
|
-
end
|
|
8
|
-
|
|
9
|
-
class SecureModel < Model
|
|
10
|
-
validates :uri, :uri => { :protocol => "https" }
|
|
11
|
-
end
|
|
12
|
-
|
|
13
|
-
class AccessibleModel < Model
|
|
14
|
-
validates :uri, :uri => { :accessible => true }
|
|
15
|
-
end
|
|
16
|
-
|
|
17
|
-
describe "Vidibus::ValidateUri::UriValidator" do
|
|
18
|
-
let(:model) { Model.new }
|
|
19
|
-
let(:secure_model) { SecureModel.new }
|
|
20
|
-
let(:accessible_model) { AccessibleModel.new }
|
|
21
|
-
|
|
22
|
-
it "should be available as URI validator" do
|
|
23
|
-
Model.validators_on(:uri).first.should be_a_kind_of(Vidibus::ValidateUri::UriValidator)
|
|
24
|
-
end
|
|
25
|
-
|
|
26
|
-
it "should add an error to model if URI is blank" do
|
|
27
|
-
model.uri = nil
|
|
28
|
-
model.should be_invalid
|
|
29
|
-
model.errors[:uri].should eql(["is invalid"])
|
|
30
|
-
end
|
|
31
|
-
|
|
32
|
-
it "should add an error to model if URI is invalid" do
|
|
33
|
-
model.uri = "http://localhosts"
|
|
34
|
-
model.should be_invalid
|
|
35
|
-
model.errors[:uri].should eql(["is invalid"])
|
|
36
|
-
end
|
|
37
|
-
|
|
38
|
-
it "should add no error to model if URI is valid" do
|
|
39
|
-
model.uri = "http://vidibus.org"
|
|
40
|
-
model.should be_valid
|
|
41
|
-
end
|
|
42
|
-
|
|
43
|
-
it "should add an error if uri does not match provided protocols" do
|
|
44
|
-
secure_model.uri = "http://www.vidibus.org"
|
|
45
|
-
secure_model.should be_invalid
|
|
46
|
-
secure_model.errors[:uri].should have(1).error
|
|
47
|
-
end
|
|
48
|
-
|
|
49
|
-
it "should add an error to model if URI is inaccessible" do
|
|
50
|
-
accessible_model.uri = "http://vidibus.zzz"
|
|
51
|
-
stub.any_instance_of(Net::HTTP).head {raise SocketError}
|
|
52
|
-
accessible_model.should be_invalid
|
|
53
|
-
accessible_model.errors[:uri].should eql(["is inaccessible"])
|
|
54
|
-
end
|
|
55
|
-
end
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
# encoding: UTF-8
|
|
2
|
-
lib = File.expand_path("../lib/", __FILE__)
|
|
3
|
-
$:.unshift lib unless $:.include?(lib)
|
|
4
|
-
|
|
5
|
-
require "vidibus/validate_uri/version"
|
|
6
|
-
|
|
7
|
-
Gem::Specification.new do |s|
|
|
8
|
-
s.name = "vidibus-validate_uri"
|
|
9
|
-
s.version = Vidibus::ValidateUri::VERSION
|
|
10
|
-
s.platform = Gem::Platform::RUBY
|
|
11
|
-
s.authors = "Andre Pankratz"
|
|
12
|
-
s.email = "andre@vidibus.com"
|
|
13
|
-
s.homepage = "https://github.com/vidibus/vidibus-validate_uri"
|
|
14
|
-
s.summary = "URI validation for Rails 3"
|
|
15
|
-
s.description = "It provides validation of URIs (URLs) to ActiveModel records and ActionControllers in Rails 3."
|
|
16
|
-
|
|
17
|
-
s.required_rubygems_version = ">= 1.3.6"
|
|
18
|
-
s.rubyforge_project = "vidibus-resource"
|
|
19
|
-
|
|
20
|
-
s.add_dependency "rack", "~> 1.2.1"
|
|
21
|
-
s.add_dependency "activesupport", "~> 3"
|
|
22
|
-
s.add_dependency "activemodel", "~> 3"
|
|
23
|
-
|
|
24
|
-
s.add_development_dependency "bundler", ">= 1.0.0"
|
|
25
|
-
s.add_development_dependency "rake"
|
|
26
|
-
s.add_development_dependency "rdoc"
|
|
27
|
-
s.add_development_dependency "rcov"
|
|
28
|
-
s.add_development_dependency "rspec", "~> 2"
|
|
29
|
-
s.add_development_dependency "rr"
|
|
30
|
-
s.add_development_dependency "actionpack", "~> 3"
|
|
31
|
-
s.add_development_dependency "webmock"
|
|
32
|
-
|
|
33
|
-
s.files = `git ls-files`.split("\n")
|
|
34
|
-
s.executables = `git ls-files`.split("\n").map{|f| f =~ /^bin\/(.*)/ ? $1 : nil}.compact
|
|
35
|
-
s.require_path = 'lib'
|
|
36
|
-
end
|