strelka 0.5.0 → 0.6.0.pre.409
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data.tar.gz.sig +0 -0
- data/ChangeLog +106 -2
- data/History.rdoc +11 -0
- data/Rakefile +7 -4
- data/lib/strelka.rb +2 -2
- data/lib/strelka/app/restresources.rb +2 -0
- data/lib/strelka/httprequest.rb +14 -6
- data/lib/strelka/paramvalidator.rb +5 -1
- data/lib/strelka/session/db.rb +5 -1
- data/spec/strelka/httprequest_spec.rb +119 -60
- data/spec/strelka/paramvalidator_spec.rb +26 -1
- metadata +34 -4
- metadata.gz.sig +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 50a4d91af69f2c2c769b0083c519c0236f507de6
|
4
|
+
data.tar.gz: ea34b00f822a1844b3b71d60c3dd6ab8217d4c23
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 664324eea627f727cef57d61a5b1e8e274a55cb19fdbc1acb7a73ec7b6db70d57247ecb65acf08065b7678d6daf7d1b4607c839b4e5b1f6029884ffa95028dc2
|
7
|
+
data.tar.gz: 328780a90b04272bc1b2bdb57735bcd9b7d06a3ea651e28cee8ed0beb2d283ba719d0e599f3e265e0de7cd2be40176671c43a0d77dfb387daff4a249fae8f6b3
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
data.tar.gz.sig
CHANGED
Binary file
|
data/ChangeLog
CHANGED
@@ -1,9 +1,113 @@
|
|
1
|
+
2013-06-12 Michael Granger <ged@FaerieMUD.org>
|
2
|
+
|
3
|
+
* Rakefile:
|
4
|
+
Add Mahlon (finally) as an author
|
5
|
+
[d0a7eba63c10] [tip]
|
6
|
+
|
7
|
+
* lib/strelka/httprequest.rb, spec/strelka/httprequest_spec.rb:
|
8
|
+
Make HTTPRequest#params always return a Hash
|
9
|
+
[ad9220ddef52]
|
10
|
+
|
11
|
+
* .rvm.gems:
|
12
|
+
Bump the safe_yaml version to the latest.
|
13
|
+
[dbac1c7bdd06]
|
14
|
+
|
15
|
+
2013-06-07 Michael Granger <ged@FaerieMUD.org>
|
16
|
+
|
17
|
+
* .rvm.gems, Rakefile:
|
18
|
+
Bump dependency on Loggability and Configurability
|
19
|
+
[9ec05ec558e5]
|
20
|
+
|
21
|
+
2013-05-31 Michael Granger <ged@FaerieMUD.org>
|
22
|
+
|
23
|
+
* lib/strelka/app/restresources.rb:
|
24
|
+
Add some planned features to restresources
|
25
|
+
[c068b5d7039e]
|
26
|
+
|
27
|
+
* .rvm.gems:
|
28
|
+
Fix the rspec version in the RMV gemset
|
29
|
+
[da790bc36db7]
|
30
|
+
|
31
|
+
* .rvm.gems, Rakefile, lib/strelka/httprequest.rb,
|
32
|
+
lib/strelka/session/db.rb, spec/strelka/httprequest_spec.rb:
|
33
|
+
Use the safe_yaml gem for loading untrusted request bodies.
|
34
|
+
[ce0387824c10] [github/master]
|
35
|
+
|
36
|
+
* lib/strelka/paramvalidator.rb, spec/strelka/paramvalidator_spec.rb:
|
37
|
+
Fix validator for literal "false" (via JSON)
|
38
|
+
[b59828d371a8]
|
39
|
+
|
40
|
+
2013-05-17 Michael Granger <ged@FaerieMUD.org>
|
41
|
+
|
42
|
+
* .hgtags:
|
43
|
+
Added tag v0.5.0 for changeset 600f4e4d8f65
|
44
|
+
[762c320af7d0]
|
45
|
+
|
46
|
+
* .hgsigs:
|
47
|
+
Added signature for changeset 80db7acd42dc
|
48
|
+
[600f4e4d8f65] [v0.5.0]
|
49
|
+
|
50
|
+
* History.rdoc, lib/strelka.rb:
|
51
|
+
Bump the minor version and update history.
|
52
|
+
[80db7acd42dc]
|
53
|
+
|
54
|
+
* experiments/codeobjects.rb:
|
55
|
+
Add an experiment
|
56
|
+
[96d7a4bdc444]
|
57
|
+
|
58
|
+
* lib/strelka/paramvalidator.rb, spec/strelka/paramvalidator_spec.rb:
|
59
|
+
Add :datetime builtin validator
|
60
|
+
[54367e5f3cee]
|
61
|
+
|
62
|
+
* lib/strelka/app/restresources.rb:
|
63
|
+
Add checklist for planned features to restresource header
|
64
|
+
[a12acfcd0108]
|
65
|
+
|
66
|
+
2013-05-08 Michael Granger <ged@FaerieMUD.org>
|
67
|
+
|
68
|
+
* lib/strelka/paramvalidator.rb, spec/strelka/paramvalidator_spec.rb:
|
69
|
+
Add builtin validators for various checksums.
|
70
|
+
[6d2e2cfbd5f3]
|
71
|
+
|
72
|
+
2013-05-02 Michael Granger <ged@FaerieMUD.org>
|
73
|
+
|
74
|
+
* lib/strelka/app/negotiation.rb,
|
75
|
+
lib/strelka/httpresponse/negotiation.rb,
|
76
|
+
spec/strelka/app/negotiation_spec.rb,
|
77
|
+
spec/strelka/httpresponse/negotiation_spec.rb:
|
78
|
+
Wire up custom mediatype handlers to content negotiation. Fixes #5.
|
79
|
+
[6a0e777a42ad]
|
80
|
+
|
81
|
+
2013-03-28 Michael Granger <ged@FaerieMUD.org>
|
82
|
+
|
83
|
+
* .rvm.gems, Rakefile:
|
84
|
+
Bump Pluggability dependency
|
85
|
+
[cae6b252a20b]
|
86
|
+
|
1
87
|
2013-03-26 Michael Granger <ged@FaerieMUD.org>
|
2
88
|
|
89
|
+
* .hgtags:
|
90
|
+
Added tag v0.4.0 for changeset bf131e4f535c
|
91
|
+
[84261d71f9ac]
|
92
|
+
|
93
|
+
* .hgsigs:
|
94
|
+
Added signature for changeset 49ae27e4588e
|
95
|
+
[bf131e4f535c] [v0.4.0]
|
96
|
+
|
97
|
+
* History.rdoc, lib/strelka.rb:
|
98
|
+
Bump minor version, update history.
|
99
|
+
[49ae27e4588e]
|
100
|
+
|
101
|
+
* lib/strelka.rb, lib/strelka/app.rb, spec/strelka/app_spec.rb,
|
102
|
+
spec/strelka_spec.rb:
|
103
|
+
Handle Strelka::App subclass inheritance, add Strelka::App syntactic
|
104
|
+
sugar.
|
105
|
+
[e43f773141e5]
|
106
|
+
|
3
107
|
* bin/strelka, lib/strelka/app.rb:
|
4
108
|
Pull app finder code from bin/strelka up into a Strelka::App class
|
5
109
|
method.
|
6
|
-
[715de56560f6]
|
110
|
+
[715de56560f6]
|
7
111
|
|
8
112
|
* .rvm.gems, Rakefile:
|
9
113
|
Update deps, add fivefish doc option only in development
|
@@ -67,7 +171,7 @@
|
|
67
171
|
|
68
172
|
* .rvm.gems, Rakefile:
|
69
173
|
Update dependency for configurability.
|
70
|
-
[8e7f432be135]
|
174
|
+
[8e7f432be135]
|
71
175
|
|
72
176
|
2013-02-27 Michael Granger <ged@FaerieMUD.org>
|
73
177
|
|
data/History.rdoc
CHANGED
@@ -1,3 +1,14 @@
|
|
1
|
+
== v0.6.0 [2013-06-12] Michael Granger <ged@FaerieMUD.org>
|
2
|
+
|
3
|
+
- Bump dependency on Loggability and Configurability
|
4
|
+
- Add some planned features to restresources
|
5
|
+
- Fix the rspec version in the RMV gemset
|
6
|
+
- Use the safe_yaml gem for loading untrusted request bodies.
|
7
|
+
- Fix validator for literal "false" (via JSON)
|
8
|
+
- Change HTTPRequest#params to consistently return a Hash, regardless of
|
9
|
+
whether or not the request body is one.
|
10
|
+
|
11
|
+
|
1
12
|
== v0.5.0 [2013-05-17] Michael Granger <ged@FaerieMUD.org>
|
2
13
|
|
3
14
|
- Add :datetime builtin validator
|
data/Rakefile
CHANGED
@@ -19,22 +19,25 @@ hoespec = Hoe.spec 'strelka' do
|
|
19
19
|
self.history_file = 'History.rdoc'
|
20
20
|
self.extra_rdoc_files = FileList[ '*.rdoc' ]
|
21
21
|
|
22
|
+
self.developer 'Mahlon E. Smith', 'mahlon@martini.nu'
|
22
23
|
self.developer 'Michael Granger', 'ged@FaerieMUD.org'
|
23
24
|
|
24
25
|
self.dependency 'configurability', '~> 2.0'
|
25
26
|
self.dependency 'foreman', '~> 0.62'
|
26
27
|
self.dependency 'highline', '~> 1.6'
|
27
28
|
self.dependency 'inversion', '~> 0.12'
|
28
|
-
self.dependency 'loggability', '~> 0.
|
29
|
+
self.dependency 'loggability', '~> 0.6'
|
29
30
|
self.dependency 'mongrel2', '~> 0.36'
|
30
31
|
self.dependency 'pluggability', '~> 0.2'
|
31
32
|
self.dependency 'sysexits', '~> 1.1'
|
32
33
|
self.dependency 'trollop', '~> 2.0'
|
33
34
|
self.dependency 'uuidtools', '~> 2.1'
|
35
|
+
self.dependency 'safe_yaml', '~> 0.9'
|
34
36
|
|
35
|
-
self.dependency 'hoe-deveiate', '~> 0.1',
|
36
|
-
self.dependency '
|
37
|
-
self.dependency '
|
37
|
+
self.dependency 'hoe-deveiate', '~> 0.1', :developer
|
38
|
+
self.dependency 'rspec', '~> 0.14', :developer
|
39
|
+
self.dependency 'simplecov', '~> 0.7', :developer
|
40
|
+
self.dependency 'rdoc-generator-fivefish', '~> 0.2', :developer
|
38
41
|
|
39
42
|
self.spec_extras[:licenses] = ["BSD"]
|
40
43
|
self.spec_extras[:rdoc_options] = [
|
data/lib/strelka.rb
CHANGED
@@ -24,10 +24,10 @@ module Strelka
|
|
24
24
|
log_as :strelka
|
25
25
|
|
26
26
|
# Library version constant
|
27
|
-
VERSION = '0.
|
27
|
+
VERSION = '0.6.0'
|
28
28
|
|
29
29
|
# Version-control revision constant
|
30
|
-
REVISION = %q$Revision:
|
30
|
+
REVISION = %q$Revision: a043d61c759c $
|
31
31
|
|
32
32
|
require 'strelka/constants'
|
33
33
|
require 'strelka/exceptions'
|
@@ -47,6 +47,8 @@ require 'strelka/app' unless defined?( Strelka::App )
|
|
47
47
|
#
|
48
48
|
# [√] Composite resources generated from associations
|
49
49
|
# [ ] Honor If-unmodified-since and If-match headers
|
50
|
+
# [ ] Support the 'fields' parameter for GET /collection
|
51
|
+
# [ ] Support reverse-ordering (via '-fieldname'?)
|
50
52
|
# [ ] Caching support (ETag, If-modified-since)
|
51
53
|
# [ ] Means of tailoring responses for requests for which the response
|
52
54
|
# isn't clearly specified in the RFC (DELETE /resource)
|
data/lib/strelka/httprequest.rb
CHANGED
@@ -3,7 +3,7 @@
|
|
3
3
|
# encoding: utf-8
|
4
4
|
|
5
5
|
require 'yajl'
|
6
|
-
require '
|
6
|
+
require 'safe_yaml'
|
7
7
|
require 'uri'
|
8
8
|
require 'loggability'
|
9
9
|
|
@@ -127,24 +127,32 @@ class Strelka::HTTPRequest < Mongrel2::HTTPRequest
|
|
127
127
|
|
128
128
|
### Parse the request parameters and return them as a Hash. For GET requests, these are
|
129
129
|
### taken from the query arguments. For requests that commonly
|
130
|
-
### contain an entity-body,
|
130
|
+
### contain an entity-body, this method will attempt to parse that.
|
131
131
|
###
|
132
132
|
### # For a handler with a route of '/user', for the request:
|
133
133
|
### # "GET /user/1/profile?checkbox=1&checkbox=2&text=foo HTTP/1.1"
|
134
134
|
### # r.params
|
135
135
|
### # => {"checkbox"=>["1", "2"], "text"=>"foo"}
|
136
|
+
###
|
137
|
+
### If the request body is not a Hash, an empty Hash with the body's value as the default
|
138
|
+
### value will be returned instead.
|
136
139
|
def params
|
137
140
|
unless @params
|
141
|
+
value = nil
|
142
|
+
|
138
143
|
case self.verb
|
139
144
|
when :GET, :HEAD
|
140
|
-
|
145
|
+
value = self.parse_query_args
|
141
146
|
when :POST, :PUT
|
142
|
-
|
147
|
+
value = self.parse_form_data
|
143
148
|
when :TRACE
|
144
149
|
self.log.debug "No parameters for a TRACE request."
|
145
150
|
else
|
146
|
-
|
151
|
+
value = self.parse_form_data if self.content_type
|
147
152
|
end
|
153
|
+
|
154
|
+
value = Hash.new( value ) unless value.is_a?( Hash )
|
155
|
+
@params = value
|
148
156
|
end
|
149
157
|
|
150
158
|
return @params
|
@@ -203,7 +211,7 @@ class Strelka::HTTPRequest < Mongrel2::HTTPRequest
|
|
203
211
|
when 'application/json', 'text/javascript'
|
204
212
|
return Yajl.load( self.body )
|
205
213
|
when 'text/x-yaml', 'application/x-yaml'
|
206
|
-
return YAML.load( self.body )
|
214
|
+
return YAML.load( self.body, safe: true )
|
207
215
|
when 'multipart/form-data'
|
208
216
|
boundary = self.content_type[ /\bboundary=(\S+)/, 1 ] or
|
209
217
|
raise Strelka::ParseError, "no boundary found for form data: %p" %
|
@@ -728,6 +728,8 @@ class Strelka::ParamValidator
|
|
728
728
|
params = stringify_keys( params )
|
729
729
|
@fields = deep_copy( params )
|
730
730
|
|
731
|
+
self.log.debug "Starting validation with fields: %p" % [ @fields ]
|
732
|
+
|
731
733
|
# Use the constraints list to extract all the parameters that have corresponding
|
732
734
|
# constraints
|
733
735
|
self.constraints.each do |field, constraint|
|
@@ -751,7 +753,7 @@ class Strelka::ParamValidator
|
|
751
753
|
### the given +value+, and add the field to the appropriate field list based on the
|
752
754
|
### result.
|
753
755
|
def apply_constraint( constraint, value )
|
754
|
-
if value
|
756
|
+
if !value.nil?
|
755
757
|
result = constraint.apply( value, self.untaint_all? )
|
756
758
|
|
757
759
|
if !result.nil?
|
@@ -807,9 +809,11 @@ class Strelka::ParamValidator
|
|
807
809
|
def valid
|
808
810
|
self.validate unless self.validated?
|
809
811
|
|
812
|
+
self.log.debug "Building valid fields hash from raw data: %p" % [ @valid ]
|
810
813
|
unless @parsed_params
|
811
814
|
@parsed_params = {}
|
812
815
|
for key, value in @valid
|
816
|
+
self.log.debug " adding %s: %p" % [ key, value ]
|
813
817
|
value = [ value ] if key.to_s.end_with?( '[]' )
|
814
818
|
if key.to_s.include?( '[' )
|
815
819
|
build_deep_hash( value, @parsed_params, get_levels(key.to_s) )
|
data/lib/strelka/session/db.rb
CHANGED
@@ -87,7 +87,11 @@ class Strelka::Session::Db < Strelka::Session::Default
|
|
87
87
|
### Load a session instance from storage using the given +session_id+.
|
88
88
|
def self::load( session_id )
|
89
89
|
session_row = self.dataset.filter( :session_id => session_id ).first
|
90
|
-
session = session_row.nil?
|
90
|
+
session = if session_row.nil?
|
91
|
+
{}
|
92
|
+
else
|
93
|
+
YAML.load( session_row[:session], safe: false )
|
94
|
+
end
|
91
95
|
return new( session_id, session )
|
92
96
|
end
|
93
97
|
|
@@ -38,43 +38,43 @@ describe Strelka::HTTPRequest do
|
|
38
38
|
end
|
39
39
|
|
40
40
|
it "knows what the request's parsed URI is" do
|
41
|
-
@req.uri.
|
42
|
-
@req.uri.to_s.
|
41
|
+
expect( @req.uri ).to be_a( URI )
|
42
|
+
expect( @req.uri.to_s ).to eq( 'http://localhost:8080/directory/userinfo/ged' )
|
43
43
|
end
|
44
44
|
|
45
45
|
it "knows what the request's parsed URI is when it's an HTTPS request" do
|
46
46
|
@req.headers.url_scheme = 'https'
|
47
|
-
@req.uri.
|
48
|
-
@req.uri.to_s.
|
47
|
+
expect( @req.uri ).to be_a( URI )
|
48
|
+
expect( @req.uri.to_s ).to eq( 'https://localhost:8080/directory/userinfo/ged' )
|
49
49
|
end
|
50
50
|
|
51
51
|
it "doesn't error when run under earlier versions of Mongrel that didn't set the " +
|
52
52
|
"url-scheme header" do
|
53
53
|
@req.headers.url_scheme = nil
|
54
|
-
@req.uri.
|
55
|
-
@req.uri.to_s.
|
54
|
+
expect( @req.uri ).to be_a( URI )
|
55
|
+
expect( @req.uri.to_s ).to eq( 'http://localhost:8080/directory/userinfo/ged' )
|
56
56
|
end
|
57
57
|
|
58
58
|
it "knows what Mongrel2 route it followed" do
|
59
|
-
@req.pattern.
|
59
|
+
expect( @req.pattern ).to eq( '/directory' )
|
60
60
|
end
|
61
61
|
|
62
62
|
it "knows what the URI of the route handling the request is" do
|
63
|
-
@req.base_uri.
|
64
|
-
@req.base_uri.to_s.
|
63
|
+
expect( @req.base_uri ).to be_a( URI )
|
64
|
+
expect( @req.base_uri.to_s ).to eq( 'http://localhost:8080/directory' )
|
65
65
|
end
|
66
66
|
|
67
67
|
it "knows what the path of the request past its route is" do
|
68
|
-
@req.app_path.
|
68
|
+
expect( @req.app_path ).to eq( '/userinfo/ged' )
|
69
69
|
end
|
70
70
|
|
71
71
|
it "knows what HTTP verb the request used" do
|
72
|
-
@req.verb.
|
72
|
+
expect( @req.verb ).to eq(:GET)
|
73
73
|
end
|
74
74
|
|
75
75
|
it "can get and set notes for communication between plugins" do
|
76
|
-
@req.notes.
|
77
|
-
@req.notes[:routing].
|
76
|
+
expect( @req.notes ).to be_a( Hash )
|
77
|
+
expect( @req.notes[:routing] ).to be_a( Hash )
|
78
78
|
end
|
79
79
|
|
80
80
|
it "can redirect the request to a different URI" do
|
@@ -97,21 +97,21 @@ describe Strelka::HTTPRequest do
|
|
97
97
|
end
|
98
98
|
|
99
99
|
it "knows what the request's parsed URI is" do
|
100
|
-
@req.uri.
|
101
|
-
@req.uri.to_s.
|
100
|
+
expect( @req.uri ).to be_a( URI )
|
101
|
+
expect( @req.uri.to_s ).to eq( 'http://localhost:8080/directory/user%20info/ged%00' )
|
102
102
|
end
|
103
103
|
|
104
104
|
it "knows what Mongrel2 route it followed" do
|
105
|
-
@req.pattern.
|
105
|
+
expect( @req.pattern ).to eq('/directory')
|
106
106
|
end
|
107
107
|
|
108
108
|
it "knows what the URI of the route handling the request is" do
|
109
|
-
@req.base_uri.
|
110
|
-
@req.base_uri.to_s.
|
109
|
+
expect( @req.base_uri ).to be_a( URI )
|
110
|
+
expect( @req.base_uri.to_s ).to eq( 'http://localhost:8080/directory' )
|
111
111
|
end
|
112
112
|
|
113
113
|
it "knows what the path of the request past its route is" do
|
114
|
-
@req.app_path.
|
114
|
+
expect( @req.app_path ).to eq("/user info/ged\0")
|
115
115
|
end
|
116
116
|
|
117
117
|
end
|
@@ -124,26 +124,26 @@ describe Strelka::HTTPRequest do
|
|
124
124
|
end
|
125
125
|
|
126
126
|
it "knows what the request's parsed URI is" do
|
127
|
-
@req.uri.
|
128
|
-
@req.uri.to_s.
|
127
|
+
expect( @req.uri ).to be_a( URI )
|
128
|
+
expect( @req.uri.to_s ).to eq( 'http://localhost:8080/directory/userinfo/ged?limit=10;offset=20' )
|
129
129
|
end
|
130
130
|
|
131
131
|
it "knows what Mongrel2 route it followed" do
|
132
|
-
@req.pattern.
|
132
|
+
expect( @req.pattern ).to eq( '/directory' )
|
133
133
|
end
|
134
134
|
|
135
135
|
it "knows what the URI of the route handling the request is" do
|
136
|
-
@req.base_uri.
|
137
|
-
@req.base_uri.to_s.
|
136
|
+
expect( @req.base_uri ).to be_a( URI )
|
137
|
+
expect( @req.base_uri.to_s ).to eq( 'http://localhost:8080/directory' )
|
138
138
|
end
|
139
139
|
|
140
140
|
it "knows what the path of the request past its route is" do
|
141
|
-
@req.app_path.
|
142
|
-
@req.app_path.
|
141
|
+
expect( @req.app_path ).to eq( '/userinfo/ged' )
|
142
|
+
expect( @req.app_path ).to eq( '/userinfo/ged' ) # make sure the slice is non-destructive
|
143
143
|
end
|
144
144
|
|
145
145
|
it "knows what HTTP verb the request used" do
|
146
|
-
@req.verb.
|
146
|
+
expect( @req.verb ).to eq(:GET)
|
147
147
|
end
|
148
148
|
|
149
149
|
end
|
@@ -154,53 +154,53 @@ describe Strelka::HTTPRequest do
|
|
154
154
|
context "a GET request" do
|
155
155
|
it "has an empty params Hash if the request doesn't have a query string " do
|
156
156
|
req = @request_factory.get( '/directory/path' )
|
157
|
-
req.params.
|
157
|
+
expect( req.params ).to eq({})
|
158
158
|
end
|
159
159
|
|
160
160
|
it "has a params Hash with the key/value pair in it if the query string has " +
|
161
161
|
"one key/value pair" do
|
162
162
|
req = @request_factory.get( '/directory/path?foo=bar' )
|
163
|
-
req.params.
|
163
|
+
expect( req.params ).to eq({'foo' => 'bar'})
|
164
164
|
end
|
165
165
|
|
166
166
|
it "has a params Hash with the key/value pairs in it if the query string has " +
|
167
167
|
"two pairs seperated with a an ampersand" do
|
168
168
|
req = @request_factory.get( '/directory/path?foo=bar&chunky=pork' )
|
169
|
-
req.params.
|
169
|
+
expect( req.params ).to eq({
|
170
170
|
'foo' => 'bar',
|
171
171
|
'chunky' => 'pork',
|
172
|
-
}
|
172
|
+
})
|
173
173
|
end
|
174
174
|
|
175
175
|
it "has a params Hash with the key/value pairs in it if the query string has " +
|
176
176
|
"two pairs with a semi-colon separator" do
|
177
177
|
req = @request_factory.get( '/directory/path?potato=gun;legume=bazooka' )
|
178
|
-
req.params.
|
178
|
+
expect( req.params ).to eq({
|
179
179
|
'potato' => 'gun',
|
180
180
|
'legume' => 'bazooka',
|
181
|
-
}
|
181
|
+
})
|
182
182
|
end
|
183
183
|
|
184
184
|
it "has a params Hash with an Array of values if the query string has two values " +
|
185
185
|
"for the same key" do
|
186
186
|
req = @request_factory.get( '/directory/path?foo=bar&foo=baz' )
|
187
|
-
req.params.
|
187
|
+
expect( req.params ).to eq({
|
188
188
|
'foo' => ['bar', 'baz'],
|
189
|
-
}
|
189
|
+
})
|
190
190
|
end
|
191
191
|
|
192
192
|
it "has a params Hash with one Array of values and a scalar value if the query " +
|
193
193
|
"string has three values and two keys" do
|
194
194
|
req = @request_factory.get( '/directory/path?foo=bar&foo=pork;mirror=sequel' )
|
195
|
-
req.params.
|
195
|
+
expect( req.params ).to eq({
|
196
196
|
'foo' => ['bar', 'pork'],
|
197
197
|
'mirror' => 'sequel',
|
198
|
-
}
|
198
|
+
})
|
199
199
|
end
|
200
200
|
|
201
201
|
it "treats a malformed query string as the lack of a query" do
|
202
202
|
req = @request_factory.get( '/directory/path?foo' )
|
203
|
-
req.params.
|
203
|
+
expect( req.params ).to eq({})
|
204
204
|
end
|
205
205
|
end
|
206
206
|
|
@@ -211,8 +211,8 @@ describe Strelka::HTTPRequest do
|
|
211
211
|
end
|
212
212
|
|
213
213
|
|
214
|
-
it "
|
215
|
-
@req.params.
|
214
|
+
it "params are all nil" do
|
215
|
+
expect( @req.params[:foo] ).to be_nil
|
216
216
|
end
|
217
217
|
end
|
218
218
|
|
@@ -231,7 +231,7 @@ describe Strelka::HTTPRequest do
|
|
231
231
|
%{I really don't like this path.\r\n} +
|
232
232
|
%{----a_boundary--\r\n}
|
233
233
|
|
234
|
-
@req.params.
|
234
|
+
expect( @req.params ).to eq({'reason' => "I really don't like this path."})
|
235
235
|
end
|
236
236
|
|
237
237
|
end
|
@@ -267,46 +267,46 @@ describe Strelka::HTTPRequest do
|
|
267
267
|
|
268
268
|
it "returns an empty Hash for an empty body" do
|
269
269
|
@req.body = ''
|
270
|
-
@req.params.
|
270
|
+
expect( @req.params['foo'] ).to be_nil
|
271
271
|
end
|
272
272
|
|
273
273
|
it "has a params Hash with the key/value pair in it if the form data has " +
|
274
274
|
"one key/value pair" do
|
275
275
|
@req.body = 'foo=bar'
|
276
|
-
@req.params.
|
276
|
+
expect( @req.params ).to eq({'foo' => 'bar'})
|
277
277
|
end
|
278
278
|
|
279
279
|
it "has a params Hash with the key/value pairs in it if the form data has " +
|
280
280
|
"two pairs seperated with a an ampersand" do
|
281
281
|
@req.body = 'foo=bar&chunky=pork'
|
282
|
-
@req.params.
|
282
|
+
expect( @req.params ).to eq({
|
283
283
|
'foo' => 'bar',
|
284
284
|
'chunky' => 'pork',
|
285
|
-
}
|
285
|
+
})
|
286
286
|
end
|
287
287
|
|
288
288
|
it "has a params Hash with the key/value pairs in it if the form data has " +
|
289
289
|
"two pairs with a semi-colon separator" do
|
290
290
|
@req.body = 'potato=gun;legume=bazooka'
|
291
|
-
@req.params.
|
291
|
+
expect( @req.params ).to eq({
|
292
292
|
'potato' => 'gun',
|
293
293
|
'legume' => 'bazooka',
|
294
|
-
}
|
294
|
+
})
|
295
295
|
end
|
296
296
|
|
297
297
|
it "has a params Hash with an Array of values if the form data has two values " +
|
298
298
|
"for the same key" do
|
299
299
|
@req.body = 'foo=bar&foo=baz'
|
300
|
-
@req.params.
|
300
|
+
expect( @req.params ).to eq({ 'foo' => ['bar', 'baz'] })
|
301
301
|
end
|
302
302
|
|
303
303
|
it "has a params Hash with one Array of values and a scalar value if the form " +
|
304
304
|
"data has three values and two keys" do
|
305
305
|
@req.body = 'foo=bar&foo=pork;mirror=sequel'
|
306
|
-
@req.params.
|
306
|
+
expect( @req.params ).to eq({
|
307
307
|
'foo' => ['bar', 'pork'],
|
308
308
|
'mirror' => 'sequel',
|
309
|
-
}
|
309
|
+
})
|
310
310
|
end
|
311
311
|
end
|
312
312
|
|
@@ -324,7 +324,7 @@ describe Strelka::HTTPRequest do
|
|
324
324
|
%{An Impossible Task\r\n} +
|
325
325
|
%{----a_boundary--\r\n}
|
326
326
|
|
327
|
-
@req.params.
|
327
|
+
expect( @req.params ).to eq({'title' => 'An Impossible Task'})
|
328
328
|
end
|
329
329
|
|
330
330
|
end
|
@@ -336,18 +336,77 @@ describe Strelka::HTTPRequest do
|
|
336
336
|
'Content-type' => 'application/json' )
|
337
337
|
end
|
338
338
|
|
339
|
-
it "returns
|
339
|
+
it "returns a default params hash for an empty body" do
|
340
340
|
@req.body = ''
|
341
|
-
@req.params.
|
341
|
+
expect( @req.params[:foo] ).to be_nil
|
342
342
|
end
|
343
343
|
|
344
|
-
it "has the JSON data as the params if it has a body with JSON object in it" do
|
344
|
+
it "has the JSON data as the params if it has a body with a JSON object in it" do
|
345
345
|
data = {
|
346
346
|
'animal' => 'ducky',
|
347
347
|
'adjectives' => ['fluffy', 'puddle-ey'],
|
348
348
|
}
|
349
349
|
@req.body = Yajl.dump( data )
|
350
|
-
@req.params.
|
350
|
+
expect( @req.params ).to eq( data )
|
351
|
+
end
|
352
|
+
|
353
|
+
it "has the array as the default param value if the body has a JSON array in it" do
|
354
|
+
data = %w[an array of stuff]
|
355
|
+
@req.body = Yajl.dump( data )
|
356
|
+
expect( @req.params[:foo] ).to eq( data )
|
357
|
+
end
|
358
|
+
|
359
|
+
end
|
360
|
+
|
361
|
+
context "a POST request with a 'text/x-yaml' body" do
|
362
|
+
before( :each ) do
|
363
|
+
@req = @request_factory.post( '/directory/path', '',
|
364
|
+
'Content-type' => 'text/x-yaml' )
|
365
|
+
end
|
366
|
+
|
367
|
+
it "returns a params hash in which all values are nil for an empty body" do
|
368
|
+
@req.body = ''
|
369
|
+
expect( @req.params[:profile] ).to be_false
|
370
|
+
end
|
371
|
+
|
372
|
+
it "has the YAML data as the params if it has a body with YAML in it" do
|
373
|
+
data = {
|
374
|
+
'animal' => 'ducky',
|
375
|
+
'adjectives' => ['fluffy', 'puddle-ey'],
|
376
|
+
}
|
377
|
+
@req.body = data.to_yaml
|
378
|
+
expect( @req.params ).to eq( data )
|
379
|
+
end
|
380
|
+
|
381
|
+
it "doesn't deserialize Symbols from the YAML body" do
|
382
|
+
data = {
|
383
|
+
animal: 'horsie',
|
384
|
+
adjectives: ['cuddly', 'stompery'],
|
385
|
+
}
|
386
|
+
@req.body = data.to_yaml
|
387
|
+
|
388
|
+
expect( @req.params.keys ).not_to include( :animal, :adjectives )
|
389
|
+
end
|
390
|
+
|
391
|
+
it "doesn't deserialize unsafe objects" do
|
392
|
+
obj = OpenStruct.new
|
393
|
+
obj.foo = 'stuff'
|
394
|
+
obj.bar = 'some other stuff'
|
395
|
+
@req.body = obj.to_yaml
|
396
|
+
|
397
|
+
expect( @req.params ).not_to be_a( OpenStruct )
|
398
|
+
expect( @req.params ).to eq({
|
399
|
+
"table" => {
|
400
|
+
":foo" => "stuff",
|
401
|
+
":bar" => "some other stuff"
|
402
|
+
},
|
403
|
+
"modifiable"=>true
|
404
|
+
})
|
405
|
+
end
|
406
|
+
|
407
|
+
it "handles null entity bodies by returning an empty Hash" do
|
408
|
+
@req.body = ''
|
409
|
+
expect( @req.params ).to eq( {} )
|
351
410
|
end
|
352
411
|
|
353
412
|
end
|
@@ -364,16 +423,16 @@ describe Strelka::HTTPRequest do
|
|
364
423
|
|
365
424
|
it "parses a single cookie into a cookieset with the cookie in it" do
|
366
425
|
@req.header.cookie = 'foom=chuckUfarly'
|
367
|
-
@req.cookies.
|
368
|
-
@req.cookies['foom'].value.
|
426
|
+
expect( @req.cookies ).to have( 1 ).member
|
427
|
+
expect( @req.cookies['foom'].value ).to eq( 'chuckUfarly' )
|
369
428
|
end
|
370
429
|
|
371
430
|
it "parses multiple cookies into a cookieset with multiple cookies in it" do
|
372
431
|
@req.header.cookie = 'foom=chuckUfarly; glarn=hotchinfalcheck'
|
373
432
|
|
374
|
-
@req.cookies.
|
375
|
-
@req.cookies['foom'].value.
|
376
|
-
@req.cookies['glarn'].value.
|
433
|
+
expect( @req.cookies ).to have( 2 ).members
|
434
|
+
expect( @req.cookies['foom'].value ).to eq( 'chuckUfarly' )
|
435
|
+
expect( @req.cookies['glarn'].value ).to eq( 'hotchinfalcheck' )
|
377
436
|
end
|
378
437
|
|
379
438
|
end
|
@@ -508,7 +508,7 @@ describe Strelka::ParamValidator do
|
|
508
508
|
@validator[:enabled].should be_true()
|
509
509
|
end
|
510
510
|
|
511
|
-
it "accepts the
|
511
|
+
it "accepts the string 'false'" do
|
512
512
|
@validator.validate( 'enabled' => 'false' )
|
513
513
|
|
514
514
|
@validator.should be_okay()
|
@@ -517,6 +517,15 @@ describe Strelka::ParamValidator do
|
|
517
517
|
@validator[:enabled].should be_false()
|
518
518
|
end
|
519
519
|
|
520
|
+
it "accepts the literal false value" do
|
521
|
+
@validator.validate( 'enabled' => false )
|
522
|
+
|
523
|
+
@validator.should be_okay()
|
524
|
+
@validator.should_not have_errors()
|
525
|
+
|
526
|
+
@validator[:enabled].should be_false()
|
527
|
+
end
|
528
|
+
|
520
529
|
it "accepts the value 'f'" do
|
521
530
|
@validator.validate( 'enabled' => 'f' )
|
522
531
|
|
@@ -562,6 +571,12 @@ describe Strelka::ParamValidator do
|
|
562
571
|
@validator[:enabled].should be_nil()
|
563
572
|
end
|
564
573
|
|
574
|
+
it "includes literal false values in the hash of valid data" do
|
575
|
+
@validator.validate( 'enabled' => false )
|
576
|
+
|
577
|
+
@validator.valid.should include( enabled: false )
|
578
|
+
end
|
579
|
+
|
565
580
|
end
|
566
581
|
|
567
582
|
describe ":integer constraints" do
|
@@ -596,6 +611,16 @@ describe Strelka::ParamValidator do
|
|
596
611
|
@validator[:count].should == -407
|
597
612
|
end
|
598
613
|
|
614
|
+
it "accepts literal integers" do
|
615
|
+
@validator.add( :count, :integer )
|
616
|
+
@validator.validate( 'count' => 118 )
|
617
|
+
|
618
|
+
@validator.should be_okay()
|
619
|
+
@validator.should_not have_errors()
|
620
|
+
|
621
|
+
@validator[:count].should == 118
|
622
|
+
end
|
623
|
+
|
599
624
|
it "rejects non-integers" do
|
600
625
|
@validator.add( :count, :integer )
|
601
626
|
@validator.validate( 'count' => '11.1' )
|
metadata
CHANGED
@@ -1,9 +1,10 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: strelka
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.6.0.pre.409
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
|
+
- Mahlon E. Smith
|
7
8
|
- Michael Granger
|
8
9
|
autorequire:
|
9
10
|
bindir: bin
|
@@ -30,7 +31,7 @@ cert_chain:
|
|
30
31
|
6mKCwjpegytE0oifXfF8k75A9105cBnNiMZOe1tXiqYc/exCgWvbggurzDOcRkZu
|
31
32
|
/YSusaiDXHKU2O3Akc3htA==
|
32
33
|
-----END CERTIFICATE-----
|
33
|
-
date: 2013-
|
34
|
+
date: 2013-06-12 00:00:00.000000000 Z
|
34
35
|
dependencies:
|
35
36
|
- !ruby/object:Gem::Dependency
|
36
37
|
name: configurability
|
@@ -94,14 +95,14 @@ dependencies:
|
|
94
95
|
requirements:
|
95
96
|
- - ~>
|
96
97
|
- !ruby/object:Gem::Version
|
97
|
-
version: '0.
|
98
|
+
version: '0.6'
|
98
99
|
type: :runtime
|
99
100
|
prerelease: false
|
100
101
|
version_requirements: !ruby/object:Gem::Requirement
|
101
102
|
requirements:
|
102
103
|
- - ~>
|
103
104
|
- !ruby/object:Gem::Version
|
104
|
-
version: '0.
|
105
|
+
version: '0.6'
|
105
106
|
- !ruby/object:Gem::Dependency
|
106
107
|
name: mongrel2
|
107
108
|
requirement: !ruby/object:Gem::Requirement
|
@@ -172,6 +173,20 @@ dependencies:
|
|
172
173
|
- - ~>
|
173
174
|
- !ruby/object:Gem::Version
|
174
175
|
version: '2.1'
|
176
|
+
- !ruby/object:Gem::Dependency
|
177
|
+
name: safe_yaml
|
178
|
+
requirement: !ruby/object:Gem::Requirement
|
179
|
+
requirements:
|
180
|
+
- - ~>
|
181
|
+
- !ruby/object:Gem::Version
|
182
|
+
version: '0.9'
|
183
|
+
type: :runtime
|
184
|
+
prerelease: false
|
185
|
+
version_requirements: !ruby/object:Gem::Requirement
|
186
|
+
requirements:
|
187
|
+
- - ~>
|
188
|
+
- !ruby/object:Gem::Version
|
189
|
+
version: '0.9'
|
175
190
|
- !ruby/object:Gem::Dependency
|
176
191
|
name: hoe-mercurial
|
177
192
|
requirement: !ruby/object:Gem::Requirement
|
@@ -228,6 +243,20 @@ dependencies:
|
|
228
243
|
- - ~>
|
229
244
|
- !ruby/object:Gem::Version
|
230
245
|
version: '0.1'
|
246
|
+
- !ruby/object:Gem::Dependency
|
247
|
+
name: rspec
|
248
|
+
requirement: !ruby/object:Gem::Requirement
|
249
|
+
requirements:
|
250
|
+
- - ~>
|
251
|
+
- !ruby/object:Gem::Version
|
252
|
+
version: '0.14'
|
253
|
+
type: :development
|
254
|
+
prerelease: false
|
255
|
+
version_requirements: !ruby/object:Gem::Requirement
|
256
|
+
requirements:
|
257
|
+
- - ~>
|
258
|
+
- !ruby/object:Gem::Version
|
259
|
+
version: '0.14'
|
231
260
|
- !ruby/object:Gem::Dependency
|
232
261
|
name: simplecov
|
233
262
|
requirement: !ruby/object:Gem::Requirement
|
@@ -279,6 +308,7 @@ description: |-
|
|
279
308
|
one of the first canine space travelers to orbit the Earth and return alive.
|
280
309
|
Her name means "little arrow".
|
281
310
|
email:
|
311
|
+
- mahlon@martini.nu
|
282
312
|
- ged@FaerieMUD.org
|
283
313
|
executables:
|
284
314
|
- strelka
|
metadata.gz.sig
CHANGED
Binary file
|