soaspec 0.0.68 → 0.0.69

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: 598e32d75616543432d61150ecdd1105a255b172
4
- data.tar.gz: eeeeb60b9f49ec979dada1b46caf83ba77523455
3
+ metadata.gz: 14727008606cfec7f58866ea5528db6e761927dd
4
+ data.tar.gz: 9da88c13d311e5d2f1e920fbe6c5ce219362f871
5
5
  SHA512:
6
- metadata.gz: cc58120c84d46e6bcf688c35c19508e5bf0130bd83c33e80fe146720c4c33cf20f599b0126fcfc05a5e233911407a5dad75e2eec2dbb63409e874dec7f27d4ac
7
- data.tar.gz: c58d409768534149f900b6b9314181ac548f5b1699540e496901ff26c4007ea607897535b9d0dc6928e4a0888f608cce5e83adf8a9a000e78baafc9f819feb3f
6
+ metadata.gz: ce39bb65f5aa62ab0df66a454eaa690e85253a3974c2d9739140fbe1a67c5f8e96a473772623c8943356a0b8e9eb5a0576ae4e59edea95450140b9616bdb1458
7
+ data.tar.gz: aeab0b613c8217aa71f3a02ac459d3b3187ced396e7f6f9a03994c863edafb4a7fc7f563363c5c62a4d8065b898a1f2959e3bb34e567d4f568c15257a48bfe78
data/ChangeLog CHANGED
@@ -1,3 +1,10 @@
1
+ Version 0.0.69
2
+ * Enhancements
3
+ * Calculate base_url ERB at time of handler's first request (Rather than when initialised).
4
+ - Important for where base url uses ERB and so does oauth whose user may change
5
+ * Demonstrate using oauth via spec
6
+ * Demonstrate using basic auth via spec
7
+
1
8
  Version 0.0.68
2
9
  * Enhancements
3
10
  * Use ERB to calculate base_url for dynamic bases
data/Rakefile CHANGED
@@ -21,6 +21,6 @@ desc 'Start virtual web service'
21
21
  task :start_test_server do
22
22
  mkdir_p 'logs'
23
23
  ENV['test_server_pid'] = Process.spawn('ruby', 'exe/soaspec-virtual-server', err: %w[logs/test_server.log w]).to_s
24
- sleep 1 # Wait a little for virtual server to start up
24
+ sleep 2 # Wait a little for virtual server to start up
25
25
  puts 'Running test server at pid ' + ENV['test_server_pid']
26
26
  end
@@ -5,6 +5,7 @@
5
5
  $LOAD_PATH.unshift File.join(File.dirname(__FILE__), *%w[.. lib])
6
6
  require 'soaspec'
7
7
  require 'sinatra'
8
+ require 'sinatra/basic_auth'
8
9
  require 'nokogiri'
9
10
  require 'erb'
10
11
  require 'json'
@@ -27,12 +28,27 @@ get '/BLZService' do
27
28
  [200, { 'Content-Type' => 'text/xml' }, Soaspec::TestServer::GetBank.test_wsdl]
28
29
  end
29
30
 
30
- get '/as/token.oauth2' do
31
+ # Simulate retrieving an ouath token. Passed to '/invoices'
32
+ post '/as/token.oauth2' do
33
+ [200, Soaspec::TestServer::Invoices.oauth_headers, JSON.generate(Soaspec::TestServer::Invoices.oauth_body) ] #Soaspec::TestServer::Invoices.oauth_headers, ]# JSON.generate(Soaspec::TestServer::Invoices.oauth_body)]
34
+ end
35
+
36
+ get '/invoice/:id' do |id|
37
+ JSON.generate(customer_id: id, oauth: request.env['HTTP_AUTHORIZATION'])
38
+ end
39
+
40
+ authorize do |username, password|
41
+ username == 'admin' && password == 'secret'
42
+ end
31
43
 
44
+ protect do
45
+ get '/basic_secrets' do
46
+ 'Secret data'
47
+ end
32
48
  end
33
49
 
34
50
  # Used for testing storage of data
35
- post '/test/name' do
51
+ post '/test/puppy' do
36
52
  request_hash = JSON.parse(request.body.string)
37
53
  id = Soaspec::TestServer::PuppyService.new_id
38
54
  Soaspec::TestServer::PuppyService.data[id][:Name] = request_hash['Name']
@@ -42,12 +58,12 @@ post '/test/name' do
42
58
  end
43
59
 
44
60
  # Used for testing retrieving storage of data
45
- get '/test/name/:id' do |id|
61
+ get '/test/puppy/:id' do |id|
46
62
  result = Soaspec::TestServer::PuppyService.data[id.to_i]
47
63
  JSON.generate result
48
64
  end
49
65
 
50
- patch '/test/name/:id' do |id|
66
+ patch '/test/puppy/:id' do |id|
51
67
  request_hash = JSON.parse(request.body.string)
52
68
  Soaspec::TestServer::PuppyService.data[id.to_i][:Name] = request_hash['Name']
53
69
  response_hash = { result: { Status: 'updated', With: request_hash['Name'] } }
data/lib/soaspec.rb CHANGED
@@ -25,6 +25,7 @@ require 'soaspec/not_found_errors'
25
25
  require 'soaspec/test_server/get_bank'
26
26
  require 'soaspec/test_server/test_attribute'
27
27
  require 'soaspec/test_server/puppy_service'
28
+ require 'soaspec/test_server/invoices'
28
29
 
29
30
  # Gem for handling SOAP and REST api tests
30
31
  module Soaspec
@@ -50,12 +50,15 @@ module Soaspec
50
50
  Soaspec::SpecLogger.add_to 'request_params: ' + payload.to_s
51
51
  response = RestClient.post(token_url, payload, cache_control: 'no_cache', verify_ssl: false)
52
52
  rescue RestClient::Exception => e
53
+ Soaspec::SpecLogger.add_to("oauth_error: #{e.message}")
54
+ Soaspec::SpecLogger.add_to("oauth_error: #{e.response}")
53
55
  retry_count += 1
54
56
  retry if retry_count < 3
55
57
  raise e
56
58
  end
57
59
  Soaspec::SpecLogger.add_to("response_headers: #{response.headers}")
58
60
  Soaspec::SpecLogger.add_to("response_body: #{response.body}")
61
+ Soaspec::SpecLogger.add_to("response: #{response}")
59
62
  JSON.parse(response)
60
63
  end
61
64
 
@@ -138,11 +141,7 @@ module Soaspec
138
141
  end
139
142
  super
140
143
  set_remove_key(options, :default_hash)
141
- merged_options = rest_resource_options
142
- merged_options[:headers] ||= {}
143
- merged_options[:headers].merge! parse_headers
144
- merged_options.merge!(options)
145
- @resource = RestClient::Resource.new(ERB.new(base_url_value).result(binding), merged_options)
144
+ @init_options = options
146
145
  end
147
146
 
148
147
  # Convert snakecase to PascalCase
@@ -168,18 +167,30 @@ module Soaspec
168
167
  end
169
168
  end
170
169
 
170
+ # Initialize value of merged options
171
+ def init_merge_options
172
+ options = rest_resource_options
173
+ options[:headers] ||= {}
174
+ options[:headers].merge! parse_headers
175
+ options.merge(@init_options)
176
+ end
177
+
171
178
  # Used in together with Exchange request that passes such override parameters
172
179
  # @param [Hash] override_parameters Params to characterize REST request
173
180
  # @param_value [params] Extra parameters (E.g. headers)
174
181
  # @param_value [suburl] URL appended to base_url of class
175
- # @param_value [method] REST method (get, post, etc)
182
+ # @param_value [method] REST method (:get, :post, etc)
176
183
  def make_request(override_parameters)
184
+ @merged_options ||= init_merge_options
177
185
  test_values = override_parameters
178
186
  test_values[:params] ||= {}
179
187
  test_values[:method] ||= :post
180
188
  test_values[:suburl] = test_values[:suburl].to_s if test_values[:suburl]
181
189
  test_values[:params][:params] = test_values[:q] if test_values[:q] # Use q for query parameters. Nested :params is ugly and long
182
190
 
191
+ # In order for ERB to be calculated at correct time, the first time request is made, the resource should be created
192
+ @resource ||= RestClient::Resource.new(ERB.new(base_url_value).result(binding), @merged_options)
193
+
183
194
  @resource_used = test_values[:suburl] ? @resource[test_values[:suburl]] : @resource
184
195
 
185
196
  begin
@@ -0,0 +1,23 @@
1
+ module Soaspec
2
+ module TestServer
3
+ # Used to simulate requests requiring oauth authentication
4
+ class Invoices
5
+ class << self
6
+ def oauth_headers
7
+ {
8
+ 'Content-Type' => 'application/json;charset=UTF-8'
9
+ }
10
+ end
11
+
12
+ def oauth_body
13
+ {
14
+ access_token: 'TEST_TOKENiIsImtpZCI6IlRFU1QifQ.AAAABBBBRfaWQiOiJhYWQ5MjY3SIMULATE_LARGE_TOKEN3MmM5OGQ5NGE2YTU5YSIsImV4cCI6MTUyNzU3MTY4Mywic2NvcGUiOltdfQ.3OmCdW7fLZMUST_BE_ABLE_TO_HANDLEgAGaJB0lFYyhaw',
15
+ token_type: 'Bearer',
16
+ expires_in: '86399'
17
+ }
18
+ end
19
+
20
+ end
21
+ end
22
+ end
23
+ end
@@ -1,5 +1,6 @@
1
1
  module Soaspec
2
2
  module TestServer
3
+ # Simulates ordering a new puppy. Used for testing REST storing, retrieving and updating data
3
4
  class PuppyService
4
5
  @data = {}
5
6
  @current_id = 1
@@ -1,3 +1,3 @@
1
1
  module Soaspec
2
- VERSION = '0.0.68'.freeze
2
+ VERSION = '0.0.69'.freeze
3
3
  end
data/soaspec.gemspec CHANGED
@@ -38,6 +38,7 @@ the same configuration "
38
38
  spec.add_dependency 'rspec-its', '>= 1.2.0'
39
39
  spec.add_dependency 'savon', '>= 2' # SOAP
40
40
  spec.add_dependency 'sinatra'
41
+ spec.add_dependency 'sinatra-basic-auth'
41
42
  spec.add_dependency 'xml-simple', '>= 1.1.5'
42
43
 
43
44
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: soaspec
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.68
4
+ version: 0.0.69
5
5
  platform: ruby
6
6
  authors:
7
7
  - SamuelGarrattIQA
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-05-28 00:00:00.000000000 Z
11
+ date: 2018-05-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -234,6 +234,20 @@ dependencies:
234
234
  - - ">="
235
235
  - !ruby/object:Gem::Version
236
236
  version: '0'
237
+ - !ruby/object:Gem::Dependency
238
+ name: sinatra-basic-auth
239
+ requirement: !ruby/object:Gem::Requirement
240
+ requirements:
241
+ - - ">="
242
+ - !ruby/object:Gem::Version
243
+ version: '0'
244
+ type: :runtime
245
+ prerelease: false
246
+ version_requirements: !ruby/object:Gem::Requirement
247
+ requirements:
248
+ - - ">="
249
+ - !ruby/object:Gem::Version
250
+ version: '0'
237
251
  - !ruby/object:Gem::Dependency
238
252
  name: xml-simple
239
253
  requirement: !ruby/object:Gem::Requirement
@@ -292,6 +306,7 @@ files:
292
306
  - lib/soaspec/spec_logger.rb
293
307
  - lib/soaspec/test_server/bank.wsdl
294
308
  - lib/soaspec/test_server/get_bank.rb
309
+ - lib/soaspec/test_server/invoices.rb
295
310
  - lib/soaspec/test_server/note.xml
296
311
  - lib/soaspec/test_server/puppy_service.rb
297
312
  - lib/soaspec/test_server/test_attribute.rb