anmo 0.0.22 → 0.0.23
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/anmo/application.rb +30 -7
- data/lib/anmo/version.rb +1 -1
- data/test/anmo/application_test.rb +9 -0
- metadata +3 -2
data/lib/anmo/application.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
require "dalli"
|
2
|
+
require "uri"
|
2
3
|
|
3
4
|
module Anmo
|
4
5
|
class ApplicationDataStore
|
@@ -35,6 +36,20 @@ module Anmo
|
|
35
36
|
server.delete("requests")
|
36
37
|
end
|
37
38
|
|
39
|
+
def self.find(path, query_string)
|
40
|
+
self.objects.each do |object|
|
41
|
+
object_path = object["path"].gsub(/(\?.*)$/, "")
|
42
|
+
if path == object_path
|
43
|
+
object_query_string = Rack::Utils.parse_query(object["path"].gsub(/(.*?)\?/, ""))
|
44
|
+
|
45
|
+
if query_string == object_query_string
|
46
|
+
p object
|
47
|
+
return object
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
38
53
|
private
|
39
54
|
def self.server
|
40
55
|
@server ||= Dalli::Client.new "localhost:11211", {:namespace => Process.pid.to_s}
|
@@ -121,19 +136,27 @@ module Anmo
|
|
121
136
|
actual_request_query = Rack::Utils.parse_query(actual_request.query_string)
|
122
137
|
|
123
138
|
suspected_request = ApplicationDataStore.objects.find do |r|
|
124
|
-
r["path"]
|
139
|
+
uri = URI(r["path"])
|
140
|
+
|
141
|
+
query = Rack::Utils.parse_query(uri.query)
|
142
|
+
method = r["method"] || "GET"
|
143
|
+
|
144
|
+
if uri.query.nil?
|
145
|
+
uri.path == actual_request.path_info && method.upcase == actual_request.request_method.upcase
|
146
|
+
else
|
147
|
+
uri.path == actual_request.path_info && query == actual_request_query && method.upcase == actual_request.request_method.upcase
|
148
|
+
end
|
125
149
|
end
|
126
150
|
|
127
|
-
if suspected_request
|
128
|
-
return unless
|
129
|
-
return unless request_has_same_query actual_request, suspected_request
|
130
|
-
return unless request_has_required_headers actual_request, suspected_request
|
151
|
+
if !suspected_request.nil?
|
152
|
+
return unless request_has_required_headers(actual_request, suspected_request)
|
131
153
|
end
|
154
|
+
|
132
155
|
suspected_request
|
133
156
|
end
|
134
157
|
|
135
158
|
def request_has_same_method initial_request, suspected_request
|
136
|
-
return true if suspected_request["method"]
|
159
|
+
return true if suspected_request["method"].nil?
|
137
160
|
suspected_request["method"].upcase == initial_request.request_method
|
138
161
|
end
|
139
162
|
|
@@ -144,7 +167,7 @@ module Anmo
|
|
144
167
|
end
|
145
168
|
|
146
169
|
def request_has_required_headers initial_request, suspected_request
|
147
|
-
required_headers = suspected_request["required_headers"] ||
|
170
|
+
required_headers = suspected_request["required_headers"] || {}
|
148
171
|
required_headers.each do |name, value|
|
149
172
|
if initial_request.env[convert_header_name_to_rack_style_name(name)] != value
|
150
173
|
return false
|
data/lib/anmo/version.rb
CHANGED
@@ -72,6 +72,15 @@ module Anmo
|
|
72
72
|
assert_equal 123, last_response.status
|
73
73
|
end
|
74
74
|
|
75
|
+
def test_similar_query_string
|
76
|
+
save_object "/pulsar/assets?channel=foo.bar.baz.qux.quux.1", "Something", 200, nil, :get
|
77
|
+
save_object "/pulsar/assets?channel=foo.bar.baz.qux.quux.2", "Something else", 200, nil, :get
|
78
|
+
|
79
|
+
get "/pulsar/assets?channel=foo.bar.baz.qux.quux.1"
|
80
|
+
|
81
|
+
assert_equal 200, last_response.status
|
82
|
+
end
|
83
|
+
|
75
84
|
def test_allows_deleting_all_objects
|
76
85
|
save_object "/this/is/the/path.object", "please save this", nil, nil, nil
|
77
86
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: anmo
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.23
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-
|
12
|
+
date: 2012-10-09 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rack
|
@@ -206,3 +206,4 @@ test_files:
|
|
206
206
|
- features/step_definitions/api_steps.rb
|
207
207
|
- features/support/env.rb
|
208
208
|
- test/anmo/application_test.rb
|
209
|
+
has_rdoc:
|