cuba-api 0.5.1 → 0.6.0
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/lib/cuba_api/allow_session_rack.rb +16 -0
- data/lib/cuba_api/{no_session_rack.rb → allow_session_rack.rb~} +0 -0
- data/lib/cuba_api/guard.rb +73 -6
- data/lib/cuba_api/utils.rb +7 -0
- data/lib/cuba_api/write_aspect.rb +0 -6
- data/spec/accept_spec.rb +2 -0
- data/spec/allow_session_rack_spec.rb +30 -0
- data/spec/allow_session_rack_spec.rb~ +42 -0
- data/spec/guard_spec.rb +262 -0
- data/spec/guard_spec.rb~ +118 -0
- metadata +17 -10
@@ -0,0 +1,16 @@
|
|
1
|
+
module CubaApi
|
2
|
+
class AllowSessionRack
|
3
|
+
def initialize( app, *not_pattern )
|
4
|
+
@app = app
|
5
|
+
@regexp = /^\/#{not_pattern.join( '|^\/' )}/
|
6
|
+
end
|
7
|
+
|
8
|
+
def call( env )
|
9
|
+
status, headers, resp = @app.call( env )
|
10
|
+
if not( env[ 'PATH_INFO' ].match @regexp )
|
11
|
+
headers.delete( 'Set-Cookie' )
|
12
|
+
end
|
13
|
+
[ status, headers, resp ]
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
File without changes
|
data/lib/cuba_api/guard.rb
CHANGED
@@ -20,19 +20,86 @@
|
|
20
20
|
#
|
21
21
|
# -*- Coding: utf-8 -*-
|
22
22
|
|
23
|
+
require 'ixtlan/user_management/guard'
|
24
|
+
|
25
|
+
# TODO move to upstream
|
26
|
+
class Ixtlan::UserManagement::Permission
|
27
|
+
attribute :parent, Ixtlan::UserManagement::Permission
|
28
|
+
end
|
29
|
+
|
23
30
|
module CubaApi
|
24
31
|
module Guard
|
25
|
-
|
26
|
-
def allowed?( *group_names )
|
27
|
-
authenticated? && ( allowed_groups( *group_names ).size > 0 )
|
28
|
-
end
|
32
|
+
module ClassMethods
|
29
33
|
|
30
|
-
|
31
|
-
|
34
|
+
def guard( &block )
|
35
|
+
self[ :guard ] ||= block ||
|
36
|
+
begin
|
37
|
+
warn 'no guard configured. default guard denies eveythings !'
|
38
|
+
guard = Ixtlan::UserManagement::Guard.new
|
39
|
+
Proc.new do |groups|
|
40
|
+
guard
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
32
45
|
end
|
33
46
|
|
34
47
|
def current_groups
|
35
48
|
current_user.groups
|
36
49
|
end
|
50
|
+
|
51
|
+
def allowed_associations
|
52
|
+
guard.associations( @_context, @_method )
|
53
|
+
end
|
54
|
+
|
55
|
+
def on_context( name, &block )
|
56
|
+
perm = guard.permissions( name )
|
57
|
+
if perm && perm.parent &&
|
58
|
+
perm.parent.resource != @_context
|
59
|
+
raise 'parent resource is not guarded'
|
60
|
+
end
|
61
|
+
on name do
|
62
|
+
old = @_context
|
63
|
+
@_context = name
|
64
|
+
yield( *captures )
|
65
|
+
@_context = old
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
def on_association
|
70
|
+
on :association do |association|
|
71
|
+
# TODO one method in guard
|
72
|
+
asso = guard.permissions( @_context ).associations
|
73
|
+
if asso.empty? or asso.include?( association )
|
74
|
+
yield( association )
|
75
|
+
else
|
76
|
+
no_body :forbidden
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
def on_guard( method, *args)
|
82
|
+
args.insert( 0, send( method ) )
|
83
|
+
on *args do
|
84
|
+
|
85
|
+
@_method = method
|
86
|
+
|
87
|
+
warn "[CubaApi::Guard] check #{method.to_s.upcase} #{@_context}: #{guard.allow?( @_context, method )}"
|
88
|
+
# TODO guard needs no association here
|
89
|
+
if guard.allow?( @_context, method, (allowed_associations || []).first )
|
90
|
+
|
91
|
+
yield( *captures )
|
92
|
+
else
|
93
|
+
no_body :forbidden # 403
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
private
|
99
|
+
|
100
|
+
def guard
|
101
|
+
self.class.guard.call( current_groups )
|
102
|
+
end
|
103
|
+
|
37
104
|
end
|
38
105
|
end
|
data/lib/cuba_api/utils.rb
CHANGED
@@ -15,6 +15,13 @@ module CubaApi
|
|
15
15
|
req.options?
|
16
16
|
end
|
17
17
|
|
18
|
+
# convenient method for status only responses
|
19
|
+
def no_body( status )
|
20
|
+
res.status = Rack::Utils.status_code( status )
|
21
|
+
res.write Rack::Utils::HTTP_STATUS_CODES[ res.status ]
|
22
|
+
res['Content-Type' ] = 'text/plain'
|
23
|
+
end
|
24
|
+
|
18
25
|
# params
|
19
26
|
def to_float( name, default = nil )
|
20
27
|
v = req[ name ]
|
@@ -39,12 +39,6 @@ module CubaApi
|
|
39
39
|
end
|
40
40
|
end
|
41
41
|
|
42
|
-
def no_body( status )
|
43
|
-
res.status = Rack::Utils.status_code( status )
|
44
|
-
res.write Rack::Utils::HTTP_STATUS_CODES[ res.status ]
|
45
|
-
res['Content-Type' ] = 'text/plain'
|
46
|
-
end
|
47
|
-
|
48
42
|
def write( obj, options = {} )
|
49
43
|
self.res.status = options[:status] || 200
|
50
44
|
# make sure we inherit aspects and repsect the order
|
data/spec/accept_spec.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
require 'cuba_api/config'
|
3
|
+
require 'cuba_api/utils'
|
3
4
|
require 'cuba_api/write_aspect'
|
4
5
|
require 'cuba_api/accept_content'
|
5
6
|
require 'yaml'
|
@@ -15,6 +16,7 @@ describe CubaApi::AcceptContent do
|
|
15
16
|
before do
|
16
17
|
Cuba.reset!
|
17
18
|
Cuba.plugin CubaApi::Config
|
19
|
+
Cuba.plugin CubaApi::Utils
|
18
20
|
Cuba[ :aspects ] = []
|
19
21
|
Cuba.plugin CubaApi::WriteAspect
|
20
22
|
Cuba.plugin CubaApi::AcceptContent
|
@@ -0,0 +1,30 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'cuba_api/allow_session_rack'
|
3
|
+
|
4
|
+
describe CubaApi::AllowSessionRack do
|
5
|
+
|
6
|
+
before do
|
7
|
+
Cuba.reset!
|
8
|
+
Cuba.use CubaApi::AllowSessionRack, 'session', 'system'
|
9
|
+
Cuba.use Rack::Session::Cookie, :secret => 'secret'
|
10
|
+
Cuba.define do
|
11
|
+
on 'session' do
|
12
|
+
session[ 'name' ] = :me
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
it 'allows session' do
|
18
|
+
_, headers, _ = Cuba.call( { 'PATH_INFO' => '/session',
|
19
|
+
'SCRIPT_NAME' => '/session' } )
|
20
|
+
|
21
|
+
headers[ 'Set-Cookie' ].must_not.eq nil
|
22
|
+
end
|
23
|
+
|
24
|
+
it 'does NOT allows session' do
|
25
|
+
_, headers, _ = Cuba.call( { 'PATH_INFO' => '/something',
|
26
|
+
'SCRIPT_NAME' => '/something' } )
|
27
|
+
|
28
|
+
headers[ 'Set-Cookie' ].must.eq nil
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'cuba_api/config'
|
3
|
+
require 'cuba_api/write_aspect'
|
4
|
+
|
5
|
+
module Plugin
|
6
|
+
def one( obj, opts )
|
7
|
+
obj + "-one"
|
8
|
+
end
|
9
|
+
def two( obj, opts )
|
10
|
+
obj + "-two"
|
11
|
+
end
|
12
|
+
def three( obj, opts )
|
13
|
+
obj + "-three"
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
describe CubaApi::WriteAspect do
|
18
|
+
|
19
|
+
before do
|
20
|
+
Cuba.reset!
|
21
|
+
Cuba.plugin CubaApi::Config
|
22
|
+
Cuba[ :aspects ] = []
|
23
|
+
Cuba.plugin CubaApi::WriteAspect
|
24
|
+
Cuba.plugin Plugin
|
25
|
+
Cuba.append_aspect :one
|
26
|
+
Cuba.prepend_aspect :two
|
27
|
+
Cuba.append_aspect :three
|
28
|
+
Cuba.define do
|
29
|
+
on true do
|
30
|
+
write 'start'
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
after { Cuba.config.clear }
|
36
|
+
|
37
|
+
it 'should execute aspects in the right order' do
|
38
|
+
_, _, resp = Cuba.call({})
|
39
|
+
|
40
|
+
resp.join.must.eq "start-two-one-three"
|
41
|
+
end
|
42
|
+
end
|
data/spec/guard_spec.rb
ADDED
@@ -0,0 +1,262 @@
|
|
1
|
+
require File.expand_path( File.join( File.dirname( __FILE__ ),
|
2
|
+
'spec_helper.rb' ) )
|
3
|
+
require 'cuba_api/config'
|
4
|
+
require 'cuba_api/utils'
|
5
|
+
require 'cuba_api/guard'
|
6
|
+
require 'ixtlan/user_management/group_model'
|
7
|
+
|
8
|
+
describe CubaApi::Guard do
|
9
|
+
|
10
|
+
let( :root ) { Ixtlan::UserManagement::Group.new( :name => 'root' ) }
|
11
|
+
|
12
|
+
before do
|
13
|
+
Cuba.reset!
|
14
|
+
Cuba.plugin CubaApi::Config
|
15
|
+
Cuba.plugin CubaApi::Utils
|
16
|
+
Cuba.plugin CubaApi::Guard
|
17
|
+
Cuba.define do
|
18
|
+
|
19
|
+
def current_groups
|
20
|
+
@groups ||= [ root ]
|
21
|
+
end
|
22
|
+
|
23
|
+
on_context 'admins' do
|
24
|
+
res.write "admins"
|
25
|
+
end
|
26
|
+
|
27
|
+
on_context 'users' do
|
28
|
+
|
29
|
+
on_context 'accounts' do
|
30
|
+
on_guard :get do
|
31
|
+
res.write "get accounts"
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
on_association do |id|
|
36
|
+
on_guard :post do
|
37
|
+
res.write "post#{id}"
|
38
|
+
end
|
39
|
+
on_guard :get do
|
40
|
+
res.write "get#{id}"
|
41
|
+
end
|
42
|
+
on_guard :put do
|
43
|
+
res.write "put#{id}"
|
44
|
+
end
|
45
|
+
on_guard :delete do
|
46
|
+
res.write "delete#{id}"
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
on_guard :post do
|
51
|
+
res.write "post"
|
52
|
+
end
|
53
|
+
on_guard :get do
|
54
|
+
res.write "get#{allowed_associations ? allowed_associations.inspect : nil}"
|
55
|
+
end
|
56
|
+
on_guard :put do
|
57
|
+
res.write "put"
|
58
|
+
end
|
59
|
+
on_guard :delete do
|
60
|
+
res.write "delete"
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
let( :env ) do
|
67
|
+
{ 'PATH_INFO' => '/users',
|
68
|
+
'SCRIPT_NAME' => '/users',
|
69
|
+
}
|
70
|
+
end
|
71
|
+
|
72
|
+
let( :guard ) do
|
73
|
+
guard = Ixtlan::UserManagement::Guard.new
|
74
|
+
Cuba[ :guard ] = Proc.new do |groups|
|
75
|
+
guard
|
76
|
+
end
|
77
|
+
guard
|
78
|
+
end
|
79
|
+
|
80
|
+
describe 'guarded context with nested context' do
|
81
|
+
|
82
|
+
it 'should raise error' do
|
83
|
+
env = { 'PATH_INFO' => '/users/accounts',
|
84
|
+
'SCRIPT_NAME' => '/users/accounts' }
|
85
|
+
|
86
|
+
user = guard.permission( 'users' ) do |u|
|
87
|
+
u.allow_all
|
88
|
+
end
|
89
|
+
guard.permission( 'admins' ) do |a|
|
90
|
+
a.parent = user
|
91
|
+
a.allow_all
|
92
|
+
end
|
93
|
+
|
94
|
+
env[ 'REQUEST_METHOD' ] = 'GET'
|
95
|
+
lambda{ Cuba.call( env ) }.must_raise RuntimeError
|
96
|
+
end
|
97
|
+
|
98
|
+
it 'allow all' do
|
99
|
+
env = { 'PATH_INFO' => '/users/accounts',
|
100
|
+
'SCRIPT_NAME' => '/users/accounts' }
|
101
|
+
user = guard.permission( 'users' ) do |u|
|
102
|
+
u.allow_all
|
103
|
+
end
|
104
|
+
guard.permission( 'accounts' ) do |a|
|
105
|
+
a.parent = user
|
106
|
+
a.allow_all
|
107
|
+
end
|
108
|
+
|
109
|
+
env[ 'REQUEST_METHOD' ] = 'GET'
|
110
|
+
_, _, resp = Cuba.call( env )
|
111
|
+
resp.join.must.eq 'get accounts'
|
112
|
+
|
113
|
+
[ 'POST','PUT', 'DELETE' ].each do |m|
|
114
|
+
env[ 'REQUEST_METHOD' ] = m
|
115
|
+
status, _, resp = Cuba.call( env )
|
116
|
+
resp.must.be :empty?
|
117
|
+
status.must.eq 200
|
118
|
+
end
|
119
|
+
end
|
120
|
+
|
121
|
+
end
|
122
|
+
|
123
|
+
describe 'guarded context with association' do
|
124
|
+
|
125
|
+
let( :env ) do
|
126
|
+
{ 'PATH_INFO' => '/users/42',
|
127
|
+
'SCRIPT_NAME' => '/users/42',
|
128
|
+
}
|
129
|
+
end
|
130
|
+
|
131
|
+
it 'denies all requests without associated id' do
|
132
|
+
guard.permission( 'users' ) do |u|
|
133
|
+
u.allow_all
|
134
|
+
end
|
135
|
+
|
136
|
+
['GET', 'POST','PUT', 'DELETE' ].each do |m|
|
137
|
+
env[ 'REQUEST_METHOD' ] = m
|
138
|
+
_, _, resp = Cuba.call( env )
|
139
|
+
resp.join.must.eq m.downcase + '42'
|
140
|
+
end
|
141
|
+
end
|
142
|
+
|
143
|
+
it 'denies all requests with wrong associated id' do
|
144
|
+
guard.permission( 'users', 13 ) do |u|
|
145
|
+
u.allow_all
|
146
|
+
end
|
147
|
+
|
148
|
+
['GET', 'POST','PUT', 'DELETE' ].each do |m|
|
149
|
+
env[ 'REQUEST_METHOD' ] = m
|
150
|
+
_, _, resp = Cuba.call( env )
|
151
|
+
resp.join.must.eq 'Forbidden'
|
152
|
+
end
|
153
|
+
|
154
|
+
env[ 'PATH_INFO' ] = '/users'
|
155
|
+
env[ 'SCRIPT_NAME' ] = '/users'
|
156
|
+
env[ 'REQUEST_METHOD' ] = 'GET'
|
157
|
+
_, _, resp = Cuba.call( env )
|
158
|
+
resp.join.must.eq 'get["13"]'
|
159
|
+
end
|
160
|
+
|
161
|
+
it 'allows all requests with associated id' do
|
162
|
+
guard.permission( 'users', 42 ) do |u|
|
163
|
+
u.allow_all
|
164
|
+
end
|
165
|
+
|
166
|
+
['GET', 'POST','PUT', 'DELETE' ].each do |m|
|
167
|
+
env[ 'REQUEST_METHOD' ] = m
|
168
|
+
_, _, resp = Cuba.call( env )
|
169
|
+
resp.join.must.eq m.downcase + '42'
|
170
|
+
end
|
171
|
+
|
172
|
+
env[ 'PATH_INFO' ] = '/users'
|
173
|
+
env[ 'SCRIPT_NAME' ] = '/users'
|
174
|
+
env[ 'REQUEST_METHOD' ] = 'GET'
|
175
|
+
_, _, resp = Cuba.call( env )
|
176
|
+
resp.join.must.eq 'get["42"]'
|
177
|
+
end
|
178
|
+
end
|
179
|
+
|
180
|
+
describe 'guarded context' do
|
181
|
+
it 'forbids all request' do
|
182
|
+
Cuba[ :guard ] = nil
|
183
|
+
['GET', 'POST','PUT', 'DELETE' ].each do |m|
|
184
|
+
env[ 'REQUEST_METHOD' ] = m
|
185
|
+
_, _, resp = Cuba.call( env )
|
186
|
+
resp.join.must.eq 'Forbidden'
|
187
|
+
end
|
188
|
+
end
|
189
|
+
|
190
|
+
it 'allows all request' do
|
191
|
+
guard.permission( 'users' ) do |u|
|
192
|
+
u.allow_all
|
193
|
+
end
|
194
|
+
|
195
|
+
['GET', 'POST','PUT', 'DELETE' ].each do |m|
|
196
|
+
env[ 'REQUEST_METHOD' ] = m
|
197
|
+
_, _, resp = Cuba.call( env )
|
198
|
+
resp.join.must.eq m.downcase
|
199
|
+
end
|
200
|
+
end
|
201
|
+
|
202
|
+
it 'allows retrieve' do
|
203
|
+
guard.permission( 'users' ) do |u|
|
204
|
+
u.allow_retrieve
|
205
|
+
end
|
206
|
+
|
207
|
+
m = 'GET'
|
208
|
+
env[ 'REQUEST_METHOD' ] = m
|
209
|
+
_, _, resp = Cuba.call( env )
|
210
|
+
resp.join.must.eq m.downcase
|
211
|
+
|
212
|
+
['POST','PUT', 'DELETE' ].each do |m|
|
213
|
+
env[ 'REQUEST_METHOD' ] = m
|
214
|
+
_, _, resp = Cuba.call( env )
|
215
|
+
resp.join.must.eq 'Forbidden'
|
216
|
+
end
|
217
|
+
end
|
218
|
+
|
219
|
+
it 'allows retrieve and create' do
|
220
|
+
guard.permission( 'users' ) do |u|
|
221
|
+
u.allow_retrieve
|
222
|
+
u.allow_create
|
223
|
+
end
|
224
|
+
['GET','POST' ].each do |m|
|
225
|
+
env[ 'REQUEST_METHOD' ] = m
|
226
|
+
_, _, resp = Cuba.call( env )
|
227
|
+
resp.join.must.eq m.downcase
|
228
|
+
end
|
229
|
+
['PUT', 'DELETE' ].each do |m|
|
230
|
+
env[ 'REQUEST_METHOD' ] = m
|
231
|
+
_, _, resp = Cuba.call( env )
|
232
|
+
resp.join.must.eq 'Forbidden'
|
233
|
+
end
|
234
|
+
end
|
235
|
+
|
236
|
+
it 'allows retrieve and create and update' do
|
237
|
+
guard.permission( 'users' ) do |u|
|
238
|
+
u.allow_mutate
|
239
|
+
end
|
240
|
+
['GET', 'POST','PUT' ].each do |m|
|
241
|
+
env[ 'REQUEST_METHOD' ] = m
|
242
|
+
_, _, resp = Cuba.call( env )
|
243
|
+
resp.join.must.eq m.downcase
|
244
|
+
end
|
245
|
+
env[ 'REQUEST_METHOD' ] = 'DELETE'
|
246
|
+
_, _, resp = Cuba.call( env )
|
247
|
+
resp.join.must.eq 'Forbidden'
|
248
|
+
end
|
249
|
+
|
250
|
+
it 'allows retrieve and create and update and delete' do
|
251
|
+
guard.permission( 'users' ) do |u|
|
252
|
+
u.allow_mutate
|
253
|
+
u.allow_delete
|
254
|
+
end
|
255
|
+
['GET', 'POST','PUT', 'DELETE' ].each do |m|
|
256
|
+
env[ 'REQUEST_METHOD' ] = m
|
257
|
+
_, _, resp = Cuba.call( env )
|
258
|
+
resp.join.must.eq m.downcase
|
259
|
+
end
|
260
|
+
end
|
261
|
+
end
|
262
|
+
end
|
data/spec/guard_spec.rb~
ADDED
@@ -0,0 +1,118 @@
|
|
1
|
+
require File.expand_path( File.join( File.dirname( __FILE__ ),
|
2
|
+
'spec_helper.rb' ) )
|
3
|
+
require 'cuba_api/config'
|
4
|
+
require 'cuba_api/cors'
|
5
|
+
|
6
|
+
describe CubaApi::Cors do
|
7
|
+
|
8
|
+
before do
|
9
|
+
Cuba.reset!
|
10
|
+
Cuba.plugin CubaApi::Config
|
11
|
+
Cuba.plugin CubaApi::Cors
|
12
|
+
Cuba.define do
|
13
|
+
|
14
|
+
on_cors 'path/to/:who' do |who|
|
15
|
+
on post do
|
16
|
+
res.write "post from #{who}"
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
on_cors_method [:post, :get], 'office/:me' do |me|
|
21
|
+
on post do
|
22
|
+
res.write "#{me} posted"
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
on_cors_method :delete, 'something' do
|
27
|
+
res.write "delete something"
|
28
|
+
end
|
29
|
+
|
30
|
+
on_cors_method :delete, 'home/:me' do |me|
|
31
|
+
res.write "delete #{me}"
|
32
|
+
end
|
33
|
+
|
34
|
+
on_cors do
|
35
|
+
on put do
|
36
|
+
res.write "put answered"
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
let( :env ) do
|
44
|
+
{ 'REQUEST_METHOD' => 'OPTIONS',
|
45
|
+
'PATH_INFO' => '/account',
|
46
|
+
'HTTP_ORIGIN' => 'http://middleearth',
|
47
|
+
'HTTP_ACCESS_CONTROL_REQUEST_METHOD' => 'PUT',
|
48
|
+
'HTTP_ACCESS_CONTROL_REQUEST_HEADERS' => 'x-requested-with'
|
49
|
+
}
|
50
|
+
end
|
51
|
+
|
52
|
+
it 'should response with catch section' do
|
53
|
+
_, headers, _ = Cuba.call( env )
|
54
|
+
|
55
|
+
headers[ "Access-Control-Max-Age" ].must.eq "86400"
|
56
|
+
headers[ "Access-Control-Allow-Origin" ].must.eq "http://middleearth"
|
57
|
+
headers[ "Access-Control-Allow-Methods" ].must.eq "GET, HEAD, POST, PUT, DELETE"
|
58
|
+
headers[ "Access-Control-Allow-Headers" ].must.eq 'x-requested-with'
|
59
|
+
headers[ "Access-Control-Allow-Expose-Headers" ].must.eq nil
|
60
|
+
|
61
|
+
env[ 'REQUEST_METHOD' ] = 'PUT'
|
62
|
+
_, _, resp = Cuba.call( env )
|
63
|
+
resp.join.must.eq 'put answered'
|
64
|
+
end
|
65
|
+
|
66
|
+
it 'should with path/to/:me section' do
|
67
|
+
env[ 'PATH_INFO' ] = '/path/to/alf'
|
68
|
+
env[ 'SCRIPT_NAME' ] = '/path/to/alf'
|
69
|
+
|
70
|
+
_, headers, _ = Cuba.call( env )
|
71
|
+
|
72
|
+
headers[ "Access-Control-Max-Age" ].must.eq "86400"
|
73
|
+
headers[ "Access-Control-Allow-Origin" ].must.eq "http://middleearth"
|
74
|
+
headers[ "Access-Control-Allow-Methods" ].must.eq "GET, HEAD, POST, PUT, DELETE"
|
75
|
+
headers[ "Access-Control-Allow-Headers" ].must.eq 'x-requested-with'
|
76
|
+
headers[ "Access-Control-Allow-Expose-Headers" ].must.eq nil
|
77
|
+
|
78
|
+
env[ 'REQUEST_METHOD' ] = 'POST'
|
79
|
+
_, _, resp = Cuba.call( env )
|
80
|
+
resp.join.must.eq 'post from alf'
|
81
|
+
end
|
82
|
+
|
83
|
+
it 'should with home/:me section' do
|
84
|
+
env[ 'PATH_INFO' ] = '/home/gandalf'
|
85
|
+
env[ 'SCRIPT_NAME' ] = '/home/gandalf'
|
86
|
+
env[ 'HTTP_ACCESS_CONTROL_REQUEST_METHOD' ] = 'DELETE'
|
87
|
+
|
88
|
+
_, headers, _ = Cuba.call( env )
|
89
|
+
|
90
|
+
headers[ "Access-Control-Max-Age" ].must.eq "86400"
|
91
|
+
headers[ "Access-Control-Allow-Origin" ].must.eq "http://middleearth"
|
92
|
+
headers[ "Access-Control-Allow-Methods" ].must.eq "DELETE"
|
93
|
+
headers[ "Access-Control-Allow-Headers" ].must.eq 'x-requested-with'
|
94
|
+
headers[ "Access-Control-Allow-Expose-Headers" ].must.eq nil
|
95
|
+
|
96
|
+
env[ 'REQUEST_METHOD' ] = 'DELETE'
|
97
|
+
_, _, resp = Cuba.call( env )
|
98
|
+
resp.join.must.eq 'delete gandalf'
|
99
|
+
end
|
100
|
+
|
101
|
+
it 'should with office/:me section' do
|
102
|
+
env[ 'PATH_INFO' ] = '/office/frodo'
|
103
|
+
env[ 'SCRIPT_NAME' ] = '/home/frodo'
|
104
|
+
env[ 'HTTP_ACCESS_CONTROL_REQUEST_METHOD' ] = 'POST'
|
105
|
+
|
106
|
+
_, headers, _ = Cuba.call( env )
|
107
|
+
|
108
|
+
headers[ "Access-Control-Max-Age" ].must.eq "86400"
|
109
|
+
headers[ "Access-Control-Allow-Origin" ].must.eq "http://middleearth"
|
110
|
+
headers[ "Access-Control-Allow-Methods" ].must.eq "POST, GET"
|
111
|
+
headers[ "Access-Control-Allow-Headers" ].must.eq 'x-requested-with'
|
112
|
+
headers[ "Access-Control-Allow-Expose-Headers" ].must.eq nil
|
113
|
+
|
114
|
+
env[ 'REQUEST_METHOD' ] = 'POST'
|
115
|
+
_, _, resp = Cuba.call( env )
|
116
|
+
resp.join.must.eq 'frodo posted'
|
117
|
+
end
|
118
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cuba-api
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.6.0
|
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: 2013-10-
|
12
|
+
date: 2013-10-04 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: cuba
|
@@ -97,13 +97,13 @@ dependencies:
|
|
97
97
|
requirements:
|
98
98
|
- - ~>
|
99
99
|
- !ruby/object:Gem::Version
|
100
|
-
version: '10.
|
100
|
+
version: '10.1'
|
101
101
|
none: false
|
102
102
|
requirement: !ruby/object:Gem::Requirement
|
103
103
|
requirements:
|
104
104
|
- - ~>
|
105
105
|
- !ruby/object:Gem::Version
|
106
|
-
version: '10.
|
106
|
+
version: '10.1'
|
107
107
|
none: false
|
108
108
|
prerelease: false
|
109
109
|
type: :development
|
@@ -113,13 +113,13 @@ dependencies:
|
|
113
113
|
requirements:
|
114
114
|
- - ~>
|
115
115
|
- !ruby/object:Gem::Version
|
116
|
-
version: '
|
116
|
+
version: '5.0'
|
117
117
|
none: false
|
118
118
|
requirement: !ruby/object:Gem::Requirement
|
119
119
|
requirements:
|
120
120
|
- - ~>
|
121
121
|
- !ruby/object:Gem::Version
|
122
|
-
version: '
|
122
|
+
version: '5.0'
|
123
123
|
none: false
|
124
124
|
prerelease: false
|
125
125
|
type: :development
|
@@ -140,18 +140,18 @@ dependencies:
|
|
140
140
|
prerelease: false
|
141
141
|
type: :development
|
142
142
|
- !ruby/object:Gem::Dependency
|
143
|
-
name:
|
143
|
+
name: ixtlan-user-management
|
144
144
|
version_requirements: !ruby/object:Gem::Requirement
|
145
145
|
requirements:
|
146
146
|
- - ~>
|
147
147
|
- !ruby/object:Gem::Version
|
148
|
-
version: '2
|
148
|
+
version: '0.2'
|
149
149
|
none: false
|
150
150
|
requirement: !ruby/object:Gem::Requirement
|
151
151
|
requirements:
|
152
152
|
- - ~>
|
153
153
|
- !ruby/object:Gem::Version
|
154
|
-
version: '2
|
154
|
+
version: '0.2'
|
155
155
|
none: false
|
156
156
|
prerelease: false
|
157
157
|
type: :development
|
@@ -170,6 +170,7 @@ files:
|
|
170
170
|
- lib/cuba_api/config.rb~
|
171
171
|
- lib/cuba_api/reloader_rack.rb
|
172
172
|
- lib/cuba_api/utils.rb
|
173
|
+
- lib/cuba_api/allow_session_rack.rb
|
173
174
|
- lib/cuba_api/cors.rb~
|
174
175
|
- lib/cuba_api/input_filter.rb~
|
175
176
|
- lib/cuba_api/response_status.rb~
|
@@ -183,6 +184,7 @@ files:
|
|
183
184
|
- lib/cuba_api/utils.rb~
|
184
185
|
- lib/cuba_api/guard.rb
|
185
186
|
- lib/cuba_api/current_user.rb~
|
187
|
+
- lib/cuba_api/allow_session_rack.rb~
|
186
188
|
- lib/cuba_api/config.rb
|
187
189
|
- lib/cuba_api/accept_content.rb
|
188
190
|
- lib/cuba_api/ext2mime_rack.rb
|
@@ -191,19 +193,22 @@ files:
|
|
191
193
|
- lib/cuba_api/reloader_rack.rb~
|
192
194
|
- lib/cuba_api/no_session_rack.rb~
|
193
195
|
- lib/cuba_api/serializer.rb
|
194
|
-
- lib/cuba_api/no_session_rack.rb
|
195
196
|
- lib/cuba_api/guard.rb~
|
196
197
|
- lib/cuba_api/current_user.rb
|
197
198
|
- spec/serializer_spec.rb
|
198
199
|
- spec/cors_with_config_spec.rb~
|
199
200
|
- spec/accept_spec.rb
|
200
201
|
- spec/current_user_spec.rb
|
202
|
+
- spec/allow_session_rack_spec.rb
|
201
203
|
- spec/config_spec.rb
|
204
|
+
- spec/allow_session_rack_spec.rb~
|
202
205
|
- spec/input_filter_spec.rb
|
203
206
|
- spec/serializer_spec.rb~
|
207
|
+
- spec/guard_spec.rb~
|
204
208
|
- spec/aspects_spec.rb~
|
205
209
|
- spec/accept_spec.rb~
|
206
210
|
- spec/cors_with_config_spec.rb
|
211
|
+
- spec/guard_spec.rb
|
207
212
|
- spec/spec_helper.rb~
|
208
213
|
- spec/response_status_spec.rb
|
209
214
|
- spec/spec_helper.rb
|
@@ -244,9 +249,11 @@ test_files:
|
|
244
249
|
- spec/serializer_spec.rb
|
245
250
|
- spec/accept_spec.rb
|
246
251
|
- spec/current_user_spec.rb
|
252
|
+
- spec/allow_session_rack_spec.rb
|
247
253
|
- spec/config_spec.rb
|
248
254
|
- spec/input_filter_spec.rb
|
249
255
|
- spec/cors_with_config_spec.rb
|
256
|
+
- spec/guard_spec.rb
|
250
257
|
- spec/response_status_spec.rb
|
251
258
|
- spec/cors_spec.rb
|
252
259
|
- spec/aspects_spec.rb
|