pact-support 0.3.1 → 0.4.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: a641a88b589e629a6991b1d4f03486bbf25457c8
4
- data.tar.gz: bfe932a2a9ea158088c848ddeda4eeb02d0d55dd
3
+ metadata.gz: a9d55f72d24799e4cfe2fd71d535eaf37eb70c74
4
+ data.tar.gz: e6c16b4858bd228d4a0d32b43bd11ac14b53bc6a
5
5
  SHA512:
6
- metadata.gz: 5c219a9254a8eb62cc3c3c2216dcc83e734acf4ff04bdd17f96670fa6f1d3ed7cc372d14154acda42719a4c3e142e38acd24b441d762256919009a801e6a4168
7
- data.tar.gz: 7ff96f3a742321247936a84fca00c2f33065f2558d8bafa4126981be51d96403e52988fa59576979bef0e12b82f5239a76699169e14717bf253c6b8e17934f23
6
+ metadata.gz: 70a1d305f8a0655db237cbf488118f47285f5bcd08e493b597620faf6f2cad99a2a9de0f9a71f89d9fca25422564c3b69743685cfc45df9d11206e3e9925e5e0
7
+ data.tar.gz: 121e1252a85b993bc22c7becb00b79430754e7e329459f4ec7c5141092b2a04e3587ec98b22c0d1bd8f4c2c027a25cb1cbc282fc2600de40033ebe4dfbd43cdc
data/CHANGELOG.md CHANGED
@@ -2,6 +2,11 @@ Do this to generate your change history
2
2
 
3
3
  git log --pretty=format:' * %h - %s (%an, %ad)'
4
4
 
5
+ ### 0.4.0 (20 March 2015)
6
+
7
+ * 409bde5 - support url including basic authentication info, e.g.: http://username:password@packtbroker.com (lifei zhou, Wed Mar 18 21:49:29 2015 +1100)
8
+ * d0d42bb - added http basic authentication options when open uri (lifei zhou, Thu Feb 26 22:03:21 2015 +1100)
9
+
5
10
  ### 0.3.1 (24 Februrary 2015)
6
11
 
7
12
  * e3d6d6d - Fixed bug when Content-Type is a Pact::Term. (Beth Skurrie, Tue Feb 24 17:25:10 2015 +1100)
data/RELEASING.md ADDED
@@ -0,0 +1,14 @@
1
+ # Releasing
2
+
3
+ 1. Increment the version in `lib/pact/support/version.rb`
4
+ 2. Update the `CHANGELOG.md` using:
5
+
6
+ $ git log --pretty=format:' * %h - %s (%an, %ad)'
7
+
8
+ 3. Add files to git
9
+
10
+ $ git add CHANGELOG.md lib/pact/support/version.rb
11
+
12
+ 3. Release:
13
+
14
+ $ bundle exec rake release
@@ -5,9 +5,10 @@ module Pact
5
5
  extend self
6
6
 
7
7
  def read uri, options = {}
8
- pact = open(uri.to_s) { | file | file.read }
8
+ uri_string = uri.to_s
9
+ pact = render_pact(uri_string, options)
9
10
  if options[:save_pactfile_to_tmp]
10
- save_pactfile_to_tmp pact, ::File.basename(uri.to_s)
11
+ save_pactfile_to_tmp pact, ::File.basename(uri_string)
11
12
  end
12
13
  pact
13
14
  rescue StandardError => e
@@ -20,5 +21,17 @@ module Pact
20
21
  ::FileUtils.mkdir_p Pact.configuration.tmp_dir
21
22
  ::File.open(Pact.configuration.tmp_dir + "/#{name}", "w") { |file| file << pact}
22
23
  end
24
+
25
+ def render_pact uri_string, options
26
+ uri_obj = URI(uri_string)
27
+ uri_user_info = uri_obj.userinfo
28
+ if(uri_user_info)
29
+ options[:username] = uri_obj.user unless options[:username]
30
+ options[:password] = uri_obj.password unless options[:password]
31
+ uri_string = uri_string.sub("#{uri_user_info}@", '')
32
+ end
33
+ open_options = options[:username] ? {http_basic_authentication:[options[:username],options[:password]]} : {}
34
+ open(uri_string, open_options) { | file | file.read }
35
+ end
23
36
  end
24
37
  end
@@ -1,5 +1,5 @@
1
1
  module Pact
2
2
  module Support
3
- VERSION = "0.3.1"
3
+ VERSION = "0.4.0"
4
4
  end
5
5
  end
@@ -0,0 +1,47 @@
1
+ require 'spec_helper'
2
+ require 'pact/consumer_contract/pact_file'
3
+
4
+ module Pact
5
+ describe PactFile do
6
+ describe 'render_pact' do
7
+ let(:uri_without_userinfo) { 'http://pactbroker.com'}
8
+ let(:pact_content) { 'api contract'}
9
+ context 'without basic authentication' do
10
+ it 'should open uri to get pact file content' do
11
+ expect(PactFile).to receive(:open).with(uri_without_userinfo, {}).and_return(pact_content)
12
+ expect(PactFile.render_pact(uri_without_userinfo, {})).to eq(pact_content)
13
+ end
14
+ end
15
+
16
+ context 'basic authentication' do
17
+ let(:username) { 'brokeruser'}
18
+ let(:password) { 'brokerpassword'}
19
+ let(:options) do
20
+ { username: username, password: password }
21
+ end
22
+ context 'when userinfo is specified in the option' do
23
+ it 'should open uri to get pact file content with userinfo in the options' do
24
+ expect(PactFile).to receive(:open).with(uri_without_userinfo, {http_basic_authentication:[username, password]})
25
+ .and_return(pact_content)
26
+ expect(PactFile.render_pact(uri_without_userinfo, options)).to eq(pact_content)
27
+ end
28
+ let(:uri_with_userinfo) { 'http://dummyuser:dummyps@pactbroker.com'}
29
+ it 'should use userinfo in options which overwrites userinfo in url' do
30
+ expect(PactFile).to receive(:open).with(uri_without_userinfo, {http_basic_authentication:[username, password]})
31
+ .and_return(pact_content)
32
+ expect(PactFile.render_pact(uri_with_userinfo, options)).to eq(pact_content)
33
+ end
34
+ end
35
+
36
+ context 'when user info is specified in url' do
37
+ let(:uri_with_userinfo) { "http://#{username}:#{password}@pactbroker.com"}
38
+ it 'should open uri to get pact file content with userinfo in the uri' do
39
+ expect(PactFile).to receive(:open).with(uri_without_userinfo, {http_basic_authentication:[username, password]})
40
+ .and_return(pact_content)
41
+ expect(PactFile.render_pact(uri_with_userinfo, {})).to eq(pact_content)
42
+ end
43
+ end
44
+ end
45
+ end
46
+ end
47
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pact-support
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.1
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - James Fraser
@@ -12,7 +12,7 @@ authors:
12
12
  autorequire:
13
13
  bindir: bin
14
14
  cert_chain: []
15
- date: 2015-02-24 00:00:00.000000000 Z
15
+ date: 2015-03-20 00:00:00.000000000 Z
16
16
  dependencies:
17
17
  - !ruby/object:Gem::Dependency
18
18
  name: randexp
@@ -228,6 +228,7 @@ files:
228
228
  - Gemfile
229
229
  - LICENSE.txt
230
230
  - README.md
231
+ - RELEASING.md
231
232
  - Rakefile
232
233
  - lib/pact/configuration.rb
233
234
  - lib/pact/consumer/request.rb
@@ -291,6 +292,7 @@ files:
291
292
  - spec/lib/pact/consumer_contract/consumer_contract_spec.rb
292
293
  - spec/lib/pact/consumer_contract/headers_spec.rb
293
294
  - spec/lib/pact/consumer_contract/interaction_spec.rb
295
+ - spec/lib/pact/consumer_contract/pact_file_spec.rb
294
296
  - spec/lib/pact/consumer_contract/query_hash_spec.rb
295
297
  - spec/lib/pact/consumer_contract/query_string_spec.rb
296
298
  - spec/lib/pact/consumer_contract/request_spec.rb
@@ -374,6 +376,7 @@ test_files:
374
376
  - spec/lib/pact/consumer_contract/consumer_contract_spec.rb
375
377
  - spec/lib/pact/consumer_contract/headers_spec.rb
376
378
  - spec/lib/pact/consumer_contract/interaction_spec.rb
379
+ - spec/lib/pact/consumer_contract/pact_file_spec.rb
377
380
  - spec/lib/pact/consumer_contract/query_hash_spec.rb
378
381
  - spec/lib/pact/consumer_contract/query_string_spec.rb
379
382
  - spec/lib/pact/consumer_contract/request_spec.rb