webspicy 0.10.2 → 0.11.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/examples/restful/Gemfile +1 -4
- data/examples/restful/Gemfile.lock +20 -23
- data/examples/restful/app.rb +25 -3
- data/examples/restful/webspicy/config.rb +15 -1
- data/examples/restful/webspicy/rack.rb +2 -1
- data/examples/restful/webspicy/real.rb +2 -1
- data/examples/restful/webspicy/support/must_be_an_admin.rb +20 -0
- data/examples/restful/webspicy/support/must_be_authenticated.rb +48 -0
- data/examples/restful/webspicy/todo/deleteTodo.yml +2 -1
- data/examples/restful/webspicy/todo/getTodo.yml +0 -2
- data/examples/restful/webspicy/todo/getTodos.yml +0 -2
- data/examples/restful/webspicy/todo/options.yml +0 -2
- data/examples/restful/webspicy/todo/patchTodo.yml +2 -1
- data/examples/restful/webspicy/todo/postCsv.yml +2 -1
- data/examples/restful/webspicy/todo/postFile.yml +2 -1
- data/examples/restful/webspicy/todo/postTodos.yml +2 -1
- data/lib/webspicy/client.rb +7 -0
- data/lib/webspicy/configuration.rb +6 -0
- data/lib/webspicy/formaldoc.fio +1 -0
- data/lib/webspicy/postcondition.rb +14 -0
- data/lib/webspicy/precondition.rb +15 -0
- data/lib/webspicy/resource/service/test_case.rb +4 -0
- data/lib/webspicy/tester.rb +1 -0
- data/lib/webspicy/version.rb +2 -2
- data/lib/webspicy.rb +2 -0
- metadata +12 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7b4b049f47d49e0353773deb3bd73a9e7781c9ff
|
4
|
+
data.tar.gz: 2092dcafacd9cdfe793add174e7e275b5626c723
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 20368b7c88e963da7731dc5f4afc1981cafdd27368735927c289b73a840ffd4693163b830f97a84911e1ab219084de272faccde7481ad37a553d2cc6fd10cbae
|
7
|
+
data.tar.gz: f68ad3769913376bb49173c19242e116fccfa95d7c221456fe171cf0a536132dcd911f45b0fe173027f8382f604c228c3f3f47a5c589d5fa15116e1d6ffc2054
|
data/examples/restful/Gemfile
CHANGED
@@ -2,7 +2,7 @@ PATH
|
|
2
2
|
remote: ../..
|
3
3
|
specs:
|
4
4
|
webspicy (0.10.2)
|
5
|
-
finitio (>= 0.
|
5
|
+
finitio (>= 0.6.1)
|
6
6
|
http (~> 2)
|
7
7
|
path (~> 1.3)
|
8
8
|
rack-robustness (~> 1.1.0)
|
@@ -16,9 +16,9 @@ GEM
|
|
16
16
|
public_suffix (>= 2.0.2, < 4.0)
|
17
17
|
citrus (3.0.2)
|
18
18
|
diff-lcs (1.3)
|
19
|
-
domain_name (0.5.
|
19
|
+
domain_name (0.5.20180417)
|
20
20
|
unf (>= 0.0.5, < 1.0.0)
|
21
|
-
finitio (0.
|
21
|
+
finitio (0.6.1)
|
22
22
|
citrus (>= 2.4, < 4.0)
|
23
23
|
http (2.2.2)
|
24
24
|
addressable (~> 2.3)
|
@@ -29,35 +29,35 @@ GEM
|
|
29
29
|
domain_name (~> 0.5)
|
30
30
|
http-form_data (1.0.3)
|
31
31
|
http_parser.rb (0.6.0)
|
32
|
-
mustermann (1.0.
|
32
|
+
mustermann (1.0.2)
|
33
33
|
path (1.3.3)
|
34
34
|
public_suffix (3.0.2)
|
35
35
|
rack (2.0.3)
|
36
|
-
rack-protection (2.0.
|
36
|
+
rack-protection (2.0.3)
|
37
37
|
rack
|
38
38
|
rack-robustness (1.1.0)
|
39
39
|
rack-test (0.6.3)
|
40
40
|
rack (>= 1.0)
|
41
41
|
rake (10.5.0)
|
42
|
-
rspec (3.
|
43
|
-
rspec-core (~> 3.
|
44
|
-
rspec-expectations (~> 3.
|
45
|
-
rspec-mocks (~> 3.
|
46
|
-
rspec-core (3.
|
47
|
-
rspec-support (~> 3.
|
48
|
-
rspec-expectations (3.
|
42
|
+
rspec (3.8.0)
|
43
|
+
rspec-core (~> 3.8.0)
|
44
|
+
rspec-expectations (~> 3.8.0)
|
45
|
+
rspec-mocks (~> 3.8.0)
|
46
|
+
rspec-core (3.8.0)
|
47
|
+
rspec-support (~> 3.8.0)
|
48
|
+
rspec-expectations (3.8.1)
|
49
49
|
diff-lcs (>= 1.2.0, < 2.0)
|
50
|
-
rspec-support (~> 3.
|
51
|
-
rspec-mocks (3.
|
50
|
+
rspec-support (~> 3.8.0)
|
51
|
+
rspec-mocks (3.8.0)
|
52
52
|
diff-lcs (>= 1.2.0, < 2.0)
|
53
|
-
rspec-support (~> 3.
|
54
|
-
rspec-support (3.
|
55
|
-
sinatra (2.0.
|
53
|
+
rspec-support (~> 3.8.0)
|
54
|
+
rspec-support (3.8.0)
|
55
|
+
sinatra (2.0.3)
|
56
56
|
mustermann (~> 1.0)
|
57
57
|
rack (~> 2.0)
|
58
|
-
rack-protection (= 2.0.
|
58
|
+
rack-protection (= 2.0.3)
|
59
59
|
tilt (~> 2.0)
|
60
|
-
tilt (2.0.
|
60
|
+
tilt (2.0.8)
|
61
61
|
unf (0.1.4)
|
62
62
|
unf_ext
|
63
63
|
unf_ext (0.0.7.5)
|
@@ -66,11 +66,8 @@ PLATFORMS
|
|
66
66
|
ruby
|
67
67
|
|
68
68
|
DEPENDENCIES
|
69
|
-
finitio (~> 0.5.2)
|
70
|
-
path (~> 1.3)
|
71
|
-
rack-robustness (~> 1.1.0)
|
72
69
|
rake (~> 10)
|
73
|
-
sinatra (~> 2.0)
|
70
|
+
sinatra (~> 2.0, >= 2.0.2)
|
74
71
|
webspicy!
|
75
72
|
|
76
73
|
BUNDLED WITH
|
data/examples/restful/app.rb
CHANGED
@@ -23,6 +23,28 @@ enable :raise_errors
|
|
23
23
|
|
24
24
|
set :todolist, TODOLIST.dup
|
25
25
|
|
26
|
+
set(:auth) do |role|
|
27
|
+
condition do
|
28
|
+
token = env['HTTP_AUTHORIZATION']
|
29
|
+
case token
|
30
|
+
when NilClass
|
31
|
+
halt [
|
32
|
+
401,
|
33
|
+
{'Content-Type' => 'application/json'},
|
34
|
+
[{ error: "Please log in first" }.to_json]
|
35
|
+
]
|
36
|
+
when "Bearer #{role}"
|
37
|
+
true
|
38
|
+
else
|
39
|
+
halt [
|
40
|
+
401,
|
41
|
+
{'Content-Type' => 'application/json'},
|
42
|
+
[{ error: "#{role.capitalize} required" }.to_json]
|
43
|
+
]
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
26
48
|
use Rack::Robustness do |g|
|
27
49
|
g.no_catch_all
|
28
50
|
g.status 400
|
@@ -47,7 +69,7 @@ get '/todo/' do
|
|
47
69
|
settings.todolist.to_json
|
48
70
|
end
|
49
71
|
|
50
|
-
post '/todo/' do
|
72
|
+
post '/todo/', :auth => :user do
|
51
73
|
content_type :json
|
52
74
|
case todos = loaded_body
|
53
75
|
when Array
|
@@ -82,7 +104,7 @@ get '/todo/:id' do |id|
|
|
82
104
|
end
|
83
105
|
end
|
84
106
|
|
85
|
-
patch '/todo/:id' do |id|
|
107
|
+
patch '/todo/:id', :auth => :user do |id|
|
86
108
|
content_type :json
|
87
109
|
todo = settings.todolist.find{|todo| todo[:id] == Integer(id) }
|
88
110
|
if todo.nil?
|
@@ -97,7 +119,7 @@ patch '/todo/:id' do |id|
|
|
97
119
|
end
|
98
120
|
end
|
99
121
|
|
100
|
-
delete '/todo/:id' do |id|
|
122
|
+
delete '/todo/:id', :auth => :admin do |id|
|
101
123
|
content_type :json
|
102
124
|
todo = settings.todolist.find{|todo| todo[:id] == Integer(id) }
|
103
125
|
if todo.nil?
|
@@ -1 +1,15 @@
|
|
1
|
-
|
1
|
+
def webspicy_config(&bl)
|
2
|
+
Webspicy::Configuration.new(Path.dir) do |c|
|
3
|
+
|
4
|
+
c.precondition MustBeAuthenticated
|
5
|
+
c.precondition MustBeAnAdmin
|
6
|
+
|
7
|
+
c.instrument do |tc, client|
|
8
|
+
role = tc.metadata[:role]
|
9
|
+
tc.headers['Authorization'] = "Bearer #{role}" if role
|
10
|
+
end
|
11
|
+
|
12
|
+
bl.call(c) if bl
|
13
|
+
end
|
14
|
+
end
|
15
|
+
webspicy_config
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require_relative 'must_be_authenticated'
|
2
|
+
class MustBeAnAdmin < MustBeAuthenticated
|
3
|
+
include Webspicy::Precondition
|
4
|
+
|
5
|
+
def self.match(service, pre)
|
6
|
+
MustBeAnAdmin.new(:admin) if pre =~ /Must be an admin/
|
7
|
+
end
|
8
|
+
|
9
|
+
def counterexamples(service)
|
10
|
+
examples = super
|
11
|
+
examples << counterexample(
|
12
|
+
"When authenticated as a normal user",
|
13
|
+
"user",
|
14
|
+
"Admin required",
|
15
|
+
401
|
16
|
+
)
|
17
|
+
examples
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
class MustBeAuthenticated
|
2
|
+
include Webspicy::Precondition
|
3
|
+
|
4
|
+
def initialize(role = :user)
|
5
|
+
@role = role
|
6
|
+
end
|
7
|
+
attr_reader :role
|
8
|
+
|
9
|
+
def self.match(service, pre)
|
10
|
+
MustBeAuthenticated.new if pre =~ /Must be authenticated/
|
11
|
+
end
|
12
|
+
|
13
|
+
def instrument(test_case, client)
|
14
|
+
return if test_case.metadata.has_key?(:role)
|
15
|
+
return if test_case.description =~ /When not authenticated at all/
|
16
|
+
test_case.metadata[:role] = role
|
17
|
+
end
|
18
|
+
|
19
|
+
def counterexamples(service)
|
20
|
+
examples = super
|
21
|
+
examples << counterexample(
|
22
|
+
"When not authenticated at all",
|
23
|
+
"~",
|
24
|
+
"Please log in first",
|
25
|
+
401
|
26
|
+
)
|
27
|
+
examples
|
28
|
+
end
|
29
|
+
|
30
|
+
def counterexample(description, role, expected, status = 401)
|
31
|
+
YAML.load <<-YML.gsub(/^\s+[#][ ]/, "")
|
32
|
+
# description: |-
|
33
|
+
# (#{self.class.name}) #{description}
|
34
|
+
# params:
|
35
|
+
# id: 1
|
36
|
+
# dress_params:
|
37
|
+
# false
|
38
|
+
# metadata:
|
39
|
+
# role: #{role}
|
40
|
+
# expected:
|
41
|
+
# content_type: application/json
|
42
|
+
# status: #{status}
|
43
|
+
# assert:
|
44
|
+
# - "pathFD('', error: '#{expected}')"
|
45
|
+
YML
|
46
|
+
end
|
47
|
+
|
48
|
+
end
|
data/lib/webspicy/client.rb
CHANGED
@@ -33,6 +33,13 @@ module Webspicy
|
|
33
33
|
end
|
34
34
|
private :_around
|
35
35
|
|
36
|
+
def instrument(*args, &bl)
|
37
|
+
args << self
|
38
|
+
config.listeners(:instrument).each do |i|
|
39
|
+
i.call(*args, &bl)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
36
43
|
def before(*args, &bl)
|
37
44
|
args << self
|
38
45
|
config.listeners(:before_each).each do |beach|
|
@@ -247,6 +247,12 @@ module Webspicy
|
|
247
247
|
register_listener(:around_each, listener)
|
248
248
|
end
|
249
249
|
|
250
|
+
# Installs a listener that will be called right after all precondition
|
251
|
+
# instrumentations.
|
252
|
+
def instrument(&instrumentor)
|
253
|
+
register_listener(:instrument, instrumentor)
|
254
|
+
end
|
255
|
+
|
250
256
|
# Allows setting the options passed at RSpec, which is used by both the runner
|
251
257
|
# and checker classes.
|
252
258
|
#
|
data/lib/webspicy/formaldoc.fio
CHANGED
data/lib/webspicy/tester.rb
CHANGED
data/lib/webspicy/version.rb
CHANGED
data/lib/webspicy.rb
CHANGED
@@ -20,6 +20,8 @@ module Webspicy
|
|
20
20
|
require 'webspicy/client/http_client'
|
21
21
|
require 'webspicy/client/rack_test_client'
|
22
22
|
require 'webspicy/resource'
|
23
|
+
require 'webspicy/precondition'
|
24
|
+
require 'webspicy/postcondition'
|
23
25
|
require 'webspicy/checker'
|
24
26
|
require 'webspicy/tester'
|
25
27
|
require 'webspicy/tester/assertions'
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: webspicy
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.11.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Bernard Lambeau
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-
|
11
|
+
date: 2018-08-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|
@@ -28,16 +28,16 @@ dependencies:
|
|
28
28
|
name: sinatra
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- - "
|
31
|
+
- - ">="
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version:
|
33
|
+
version: 2.0.2
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- - "
|
38
|
+
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version:
|
40
|
+
version: 2.0.2
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: rspec
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -72,14 +72,14 @@ dependencies:
|
|
72
72
|
requirements:
|
73
73
|
- - ">="
|
74
74
|
- !ruby/object:Gem::Version
|
75
|
-
version: 0.
|
75
|
+
version: 0.6.1
|
76
76
|
type: :runtime
|
77
77
|
prerelease: false
|
78
78
|
version_requirements: !ruby/object:Gem::Requirement
|
79
79
|
requirements:
|
80
80
|
- - ">="
|
81
81
|
- !ruby/object:Gem::Version
|
82
|
-
version: 0.
|
82
|
+
version: 0.6.1
|
83
83
|
- !ruby/object:Gem::Dependency
|
84
84
|
name: http
|
85
85
|
requirement: !ruby/object:Gem::Requirement
|
@@ -140,6 +140,8 @@ files:
|
|
140
140
|
- examples/restful/webspicy/rack.rb
|
141
141
|
- examples/restful/webspicy/real.rb
|
142
142
|
- examples/restful/webspicy/schema.fio
|
143
|
+
- examples/restful/webspicy/support/must_be_an_admin.rb
|
144
|
+
- examples/restful/webspicy/support/must_be_authenticated.rb
|
143
145
|
- examples/restful/webspicy/todo/deleteTodo.yml
|
144
146
|
- examples/restful/webspicy/todo/getTodo.yml
|
145
147
|
- examples/restful/webspicy/todo/getTodos.yml
|
@@ -157,6 +159,8 @@ files:
|
|
157
159
|
- lib/webspicy/configuration.rb
|
158
160
|
- lib/webspicy/file_upload.rb
|
159
161
|
- lib/webspicy/formaldoc.fio
|
162
|
+
- lib/webspicy/postcondition.rb
|
163
|
+
- lib/webspicy/precondition.rb
|
160
164
|
- lib/webspicy/resource.rb
|
161
165
|
- lib/webspicy/resource/service.rb
|
162
166
|
- lib/webspicy/resource/service/invocation.rb
|