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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9aa4e36d2bd121fc10a478253ed1670e8c77bad2
4
- data.tar.gz: a0bee8049568070cb32ad4e2069e6cf6b0f23b04
3
+ metadata.gz: 7b4b049f47d49e0353773deb3bd73a9e7781c9ff
4
+ data.tar.gz: 2092dcafacd9cdfe793add174e7e275b5626c723
5
5
  SHA512:
6
- metadata.gz: 80bd1389d546f45be39f0c5298f5d3f0ef0b8f717feceaf5d6e4022e1d35e6bf1c48c58e0523b5186251e9fab1ce363617af453cadcdcc03336c03626e700a46
7
- data.tar.gz: 5e1791bf8cdb6992d2e1835bf6e0f91b33f7f4d53353275b0aa47e97792ddb290cca6066ef994ea913f19cd21c957c6b8899e62c8b761ee24bfe7cd422e8fa32
6
+ metadata.gz: 20368b7c88e963da7731dc5f4afc1981cafdd27368735927c289b73a840ffd4693163b830f97a84911e1ab219084de272faccde7481ad37a553d2cc6fd10cbae
7
+ data.tar.gz: f68ad3769913376bb49173c19242e116fccfa95d7c221456fe171cf0a536132dcd911f45b0fe173027f8382f604c228c3f3f47a5c589d5fa15116e1d6ffc2054
@@ -1,8 +1,5 @@
1
1
  source "https://rubygems.org"
2
2
 
3
3
  gem "rake", "~> 10"
4
- gem 'sinatra', "~> 2.0"
5
- gem "path", "~> 1.3"
6
- gem "finitio", "~> 0.5.2"
4
+ gem 'sinatra', "~> 2.0", ">= 2.0.2"
7
5
  gem "webspicy", path: "../.."
8
- gem "rack-robustness", "~> 1.1.0"
@@ -2,7 +2,7 @@ PATH
2
2
  remote: ../..
3
3
  specs:
4
4
  webspicy (0.10.2)
5
- finitio (>= 0.5.2)
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.20170404)
19
+ domain_name (0.5.20180417)
20
20
  unf (>= 0.0.5, < 1.0.0)
21
- finitio (0.5.2)
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.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.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.7.0)
43
- rspec-core (~> 3.7.0)
44
- rspec-expectations (~> 3.7.0)
45
- rspec-mocks (~> 3.7.0)
46
- rspec-core (3.7.1)
47
- rspec-support (~> 3.7.0)
48
- rspec-expectations (3.7.0)
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.7.0)
51
- rspec-mocks (3.7.0)
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.7.0)
54
- rspec-support (3.7.1)
55
- sinatra (2.0.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.0)
58
+ rack-protection (= 2.0.3)
59
59
  tilt (~> 2.0)
60
- tilt (2.0.7)
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
@@ -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
- Webspicy::Configuration.new(Path.dir)
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
@@ -1,4 +1,5 @@
1
- Webspicy::Configuration.inherits(Path.dir) do |c|
1
+ require_relative 'config'
2
+ webspicy_config do |c|
2
3
  c.client = Webspicy::RackTestClient.for(::Sinatra::Application)
3
4
  c.before_each do |_,client|
4
5
  client.api.post "/reset"
@@ -1,4 +1,5 @@
1
- Webspicy::Configuration.inherits(Path.dir) do |c|
1
+ require_relative 'config'
2
+ webspicy_config do |c|
2
3
  c.host = "http://127.0.0.1:4567"
3
4
  c.client = Webspicy::HttpClient
4
5
  c.before_each do |_,client|
@@ -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
@@ -12,7 +12,8 @@ services:
12
12
  description: |-
13
13
  Deletes a single todo item
14
14
 
15
- preconditions: |-
15
+ preconditions:
16
+ - Must be an admin
16
17
 
17
18
  input_schema: |-
18
19
  {
@@ -12,8 +12,6 @@ services:
12
12
  description: |-
13
13
  Returns a single todo item
14
14
 
15
- preconditions: |-
16
-
17
15
  input_schema: |-
18
16
  {
19
17
  id: Integer
@@ -12,8 +12,6 @@ services:
12
12
  description: |-
13
13
  Returns the list of todo items
14
14
 
15
- preconditions: |-
16
-
17
15
  input_schema: |-
18
16
  {
19
17
  }
@@ -12,8 +12,6 @@ services:
12
12
  description: |-
13
13
  Returns options about the web service
14
14
 
15
- preconditions: |-
16
-
17
15
  input_schema: |-
18
16
  {
19
17
  }
@@ -12,7 +12,8 @@ services:
12
12
  description: |-
13
13
  Patches a single Todo item
14
14
 
15
- preconditions: |-
15
+ preconditions:
16
+ - Must be authenticated
16
17
 
17
18
  input_schema: |-
18
19
  TodoPatch
@@ -12,7 +12,8 @@ services:
12
12
  description: |-
13
13
  Creates new todo items through a CSV import
14
14
 
15
- preconditions: |-
15
+ preconditions:
16
+ - Must be authenticated
16
17
 
17
18
  input_schema: |-
18
19
  {}
@@ -12,7 +12,8 @@ services:
12
12
  description: |-
13
13
  Creates new todo items through a CSV file upload
14
14
 
15
- preconditions: |-
15
+ preconditions:
16
+ - Must be authenticated
16
17
 
17
18
  input_schema: |-
18
19
  .
@@ -12,7 +12,8 @@ services:
12
12
  description: |-
13
13
  Creates a new todo item
14
14
 
15
- preconditions: |-
15
+ preconditions:
16
+ - Must be authenticated
16
17
 
17
18
  input_schema: |-
18
19
  Todo
@@ -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
  #
@@ -44,6 +44,7 @@ TestCase =
44
44
  file_upload :? FileUpload
45
45
  seeds :? String
46
46
  requester :? String
47
+ metadata :? { ...: .Object }
47
48
  expected: {
48
49
  status : Integer
49
50
  content_type :? String|Nil
@@ -0,0 +1,14 @@
1
+ module Webspicy
2
+ module Postcondition
3
+
4
+ def self.match(service, descr)
5
+ end
6
+
7
+ def instrument(test_case, client)
8
+ end
9
+
10
+ def check(invocation)
11
+ end
12
+
13
+ end # module Postcondition
14
+ end # module Webspicy
@@ -0,0 +1,15 @@
1
+ module Webspicy
2
+ module Precondition
3
+
4
+ def self.match(service, pre)
5
+ end
6
+
7
+ def instrument(test_case, client)
8
+ end
9
+
10
+ def counterexamples(service)
11
+ []
12
+ end
13
+
14
+ end # module Precondition
15
+ end # module Webspicy
@@ -28,6 +28,10 @@ module Webspicy
28
28
  @raw[:headers] ||= {}
29
29
  end
30
30
 
31
+ def metadata
32
+ @raw[:metadata] ||= {}
33
+ end
34
+
31
35
  def dress_params
32
36
  @raw.fetch(:dress_params){ true }
33
37
  end
@@ -60,6 +60,7 @@ module Webspicy
60
60
  client.around(test_case) do
61
61
  client.before(test_case)
62
62
  test_case.instrument(client)
63
+ client.instrument(test_case)
63
64
  @invocation = client.call(test_case)
64
65
  example.run
65
66
  client.after(test_case)
@@ -1,8 +1,8 @@
1
1
  module Webspicy
2
2
  module Version
3
3
  MAJOR = 0
4
- MINOR = 10
5
- TINY = 2
4
+ MINOR = 11
5
+ TINY = 0
6
6
  end
7
7
  VERSION = "#{Version::MAJOR}.#{Version::MINOR}.#{Version::TINY}"
8
8
  end
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.10.2
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-05-25 00:00:00.000000000 Z
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: '2.0'
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: '2.0'
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.5.2
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.5.2
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