puppet-blacksmith 3.0.1 → 3.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- OTY2Yzc5NzNiM2E0ZjI3ZTk2ZjVjMjViOThhYTM4NDM1Yjg3YTRmZQ==
4
+ YzQxNDUxMzM4OGFmNmUyZTg5YjIzNjA1MDM5ZmJkZTYyYTgzNjIwMA==
5
5
  data.tar.gz: !binary |-
6
- ZTZmZjhiZDdmMDE2N2E0MDY5NWU0MjlkN2YwMDk4ZGMyNGQ2ZTk5Nw==
6
+ OWNjODg5OGY5MTI1YTI1YjY1NzRjNDZiZDJkNjZiNGI2Y2Q5NTNjMA==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- YmY4NjZjNzQ1MjY1ZDA4MDQ3YWVjZjhlNjVmMjYwZTM0ZGExYTM5NjEwNDNk
10
- MDBmMDJiMWU0ZTJhNmNkN2Q2MjkwMjMzY2UzNTQ0ZTQ1NjVmODBkYWZkZjVl
11
- ZWFhMGQ1NTZkYmY4N2MxY2EyMzYxN2EyMjJmYWE4NjI5ZWVhMDY=
9
+ ZjBlMjZkYmVkYjdhZGVkYTFmNzIwODY2OTdmZmQwZTc1NzIyY2M1NWMyMjE1
10
+ ZjFiMTU2N2E5NmQyM2M1ZDFmNjdkM2Y1YTY5MDM4YjMxNzE2YmI2NzE3M2Zi
11
+ NWEwN2YyYjJiYjc4MDE1NWUwOGNiY2ZjZDdiYTY4ZjNhMjQ3MTM=
12
12
  data.tar.gz: !binary |-
13
- MmVkNzIyMmJhZjMzOTk5YjZlMGE4YWY5OGFhODgzYzVhNDk4NzM1YTcxN2Jk
14
- MzkyY2UxOTQzMmZhYjdiNDA5NWJkNjUyYTdkOGQ2YmFiY2M5NmVlNzgxNjEw
15
- ZDAxNjQ5OTAwZTRkYWZjMTQ1NGQxOWQ2ZWEyYTEzYmY5MzQwNzM=
13
+ MDVjZDU2NTIyODM0MjMwZDFmNzI5ODg4ZWYxNGQ2YTgzMjU0ZTc1MDlmYTg0
14
+ MDRlY2E4ZTUzZjEyZjMwZGU2MTk3Y2UwYTJiYzI5NTE4Nzc0Mzg2Yzc4Y2Y3
15
+ NTNlMDlhOGI5NjFiNzJjMWFiYTU3Zjg2NzY3ZTYwYmRlOTNmMDA=
@@ -37,20 +37,28 @@ module Blacksmith
37
37
  raise Errno::ENOENT, "File does not exist: #{package}" unless File.exists?(package)
38
38
 
39
39
  # login to the puppet forge
40
- response = RestClient.post("#{url}/oauth/token", {
41
- 'client_id' => client_id,
42
- 'client_secret' => client_secret,
43
- 'username' => username,
44
- 'password' => password,
45
- 'grant_type' => 'password'
46
- }, HEADERS)
40
+ begin
41
+ response = RestClient.post("#{url}/oauth/token", {
42
+ 'client_id' => client_id,
43
+ 'client_secret' => client_secret,
44
+ 'username' => username,
45
+ 'password' => password,
46
+ 'grant_type' => 'password'
47
+ }, HEADERS)
48
+ rescue RestClient::Exception => e
49
+ raise Blacksmith::Error, "Error login to the forge #{url} as #{username} [#{e.message}]: #{e.response}"
50
+ end
47
51
  login_data = JSON.parse(response)
48
52
  access_token = login_data['access_token']
49
53
 
50
54
  # upload the file
51
- response = RestClient.post("#{url}/v2/releases",
52
- {:file => File.new(package, 'rb')},
53
- HEADERS.merge({'Authorization' => "Bearer #{access_token}"}))
55
+ begin
56
+ response = RestClient.post("#{url}/v2/releases",
57
+ {:file => File.new(package, 'rb')},
58
+ HEADERS.merge({'Authorization' => "Bearer #{access_token}"}))
59
+ rescue RestClient::Exception => e
60
+ raise Blacksmith::Error, "Error uploading #{package} to the forge #{url} [#{e.message}]: #{e.response}"
61
+ end
54
62
  end
55
63
 
56
64
  private
@@ -62,7 +70,7 @@ module Blacksmith
62
70
  Could not find Puppet Forge credentials file '#{credentials_file}'
63
71
  Please create it
64
72
  ---
65
- url: https://forge.puppetlabs.com
73
+ url: https://forgeapi.puppetlabs.com
66
74
  username: myuser
67
75
  password: mypassword
68
76
  eos
@@ -1,3 +1,3 @@
1
1
  module Blacksmith
2
- VERSION = '3.0.1'
2
+ VERSION = '3.0.2'
3
3
  end
@@ -0,0 +1,14 @@
1
+ require 'spec_helper'
2
+ require_relative 'forge_shared'
3
+ require 'fileutils'
4
+
5
+ # Run tests against the real Forge staging API
6
+ describe 'Blacksmith::Forge', :live => true do
7
+ include_context 'forge'
8
+ let(:username) { nil }
9
+
10
+ describe 'push' do
11
+ before { create_tarball }
12
+ include_examples 'forge_push'
13
+ end
14
+ end
@@ -0,0 +1,37 @@
1
+ require 'spec_helper'
2
+ require 'fileutils'
3
+
4
+ RSpec.shared_examples 'forge_push' do |collection_class|
5
+ it "should push the module" do
6
+ subject.push!(module_name, package)
7
+ end
8
+ end
9
+
10
+ RSpec.shared_context "forge" do
11
+ subject { Blacksmith::Forge.new(username, password, forge) }
12
+ let(:username) { 'johndoe' }
13
+ let(:password) { 'secret' }
14
+ let(:forge) { "https://forgestagingapi.puppetlabs.com" }
15
+ let(:module_name) { "test" }
16
+ let(:version) { "1.0.0" }
17
+ let(:module_name) { "maestrodev-test" }
18
+ let(:spec_data) { File.join(File.dirname(__FILE__), '/../data') }
19
+ let(:spec_module) { File.join(spec_data, module_name) }
20
+ let(:target) { File.expand_path(File.join(__FILE__, "../../..", "pkg", module_name)) }
21
+ let(:package) { "#{target}.tar.gz" }
22
+
23
+ let(:headers) { { 'User-Agent' => %r{^Blacksmith/#{Blacksmith::VERSION} Ruby/.* \(.*\)$} } }
24
+
25
+ def create_tarball
26
+ FileUtils.mkdir_p(target)
27
+
28
+ # update version
29
+ f = File.join(spec_module, "metadata.json")
30
+ metadata = JSON.parse File.read(f)
31
+ metadata['version'] = "1.0.#{Random.rand(9999999)}"
32
+ File.open(File.join(target, "metadata.json"),"w") do |file|
33
+ file.write(JSON.pretty_generate(metadata))
34
+ end
35
+ `cd #{target}/..; tar -czf #{module_name}.tar.gz #{module_name}`
36
+ end
37
+ end
@@ -1,20 +1,10 @@
1
1
  require 'spec_helper'
2
+ require_relative 'forge_shared'
2
3
  require 'fileutils'
3
4
  require 'webmock/rspec'
4
5
 
5
6
  describe 'Blacksmith::Forge' do
6
-
7
- subject { Blacksmith::Forge.new(username, password, forge) }
8
- let(:username) { 'johndoe' }
9
- let(:password) { 'secret' }
10
- let(:forge) { "https://forgestagingapi.puppetlabs.com" }
11
- let(:module_name) { "test" }
12
- let(:version) { "1.0.0" }
13
- let(:module_name) { "maestrodev-test" }
14
- let(:spec_data) { File.join(File.dirname(__FILE__), '/../data') }
15
- let(:spec_module) { File.join(spec_data, module_name) }
16
- let(:target) { File.expand_path(File.join(__FILE__, "../../..", "pkg", module_name)) }
17
- let(:package) { "#{target}.tar.gz" }
7
+ include_context 'forge'
18
8
 
19
9
  describe 'missing credentials file' do
20
10
  before do
@@ -27,39 +17,27 @@ describe 'Blacksmith::Forge' do
27
17
  end
28
18
 
29
19
  it "should raise an error" do
30
- expect { foo = Blacksmith::Forge.new(nil, password, forge) }.to raise_error(/Could not find Puppet Forge credentials file '\/home\/mr\_puppet\/.puppetforge.yml'\s*Please create it\s*---\s*url: https:\/\/forge.puppetlabs.com\s*username: myuser\s*password: mypassword/)
20
+ expect { foo = Blacksmith::Forge.new(nil, password, forge) }.to raise_error(/Could not find Puppet Forge credentials file '\/home\/mr\_puppet\/.puppetforge.yml'\s*Please create it\s*---\s*url: https:\/\/forgeapi.puppetlabs.com\s*username: myuser\s*password: mypassword/)
31
21
  end
32
22
  end
33
23
 
34
24
  end
35
25
 
36
- describe 'push', :credentials => true do
37
- let(:headers) { { 'User-Agent' => %r{^Blacksmith/#{Blacksmith::VERSION} Ruby/.* \(.*\)$} } }
26
+ describe 'push' do
27
+ let(:login_body) {{
28
+ "client_id"=>"b93eb708fd942cfc7b4ed71db6ce219b814954619dbe537ddfd208584e8cff8d",
29
+ "client_secret"=>"216648059ad4afec3e4d77bd9e67817c095b2dcf94cdec18ac3d00584f863180",
30
+ "grant_type"=>"password",
31
+ "password"=>"secret",
32
+ "username"=>"johndoe"
33
+ }}
38
34
 
39
- before do
40
- FileUtils.mkdir_p(target)
41
-
42
- # update version
43
- f = File.join(spec_module, "metadata.json")
44
- metadata = JSON.parse File.read(f)
45
- metadata['version'] = "1.0.#{Random.rand(9999999)}"
46
- File.open(File.join(target, "metadata.json"),"w") do |file|
47
- file.write(JSON.pretty_generate(metadata))
48
- end
49
- `cd #{target}/..; tar -czf #{module_name}.tar.gz #{module_name}`
50
- end
35
+ before { create_tarball }
51
36
 
52
37
  context "when using username and password" do
53
38
  before do
54
-
55
39
  stub_request(:post, "#{forge}/oauth/token").with(
56
- :body => {
57
- "client_id"=>"b93eb708fd942cfc7b4ed71db6ce219b814954619dbe537ddfd208584e8cff8d",
58
- "client_secret"=>"216648059ad4afec3e4d77bd9e67817c095b2dcf94cdec18ac3d00584f863180",
59
- "grant_type"=>"password",
60
- "password"=>"secret",
61
- "username"=>"johndoe"
62
- },
40
+ :body => login_body,
63
41
  :headers => headers
64
42
  ).to_return(
65
43
  :status => 200,
@@ -71,14 +49,27 @@ describe 'Blacksmith::Forge' do
71
49
  :headers => headers.merge({'Accept'=>'*/*; q=0.5, application/xml', 'Accept-Encoding'=>'gzip, deflate', 'Authorization'=>'Bearer e52f78b62e97cb8d8db6659a73aa522cca0f5c74d4714e0ed0bdd10000000000', 'Content-Type'=>%r{multipart/form-data;}})
72
50
  ).to_return(:status => 200, :body => File.read(File.join(spec_data, "response.json")), :headers => {})
73
51
 
74
- subject.push!(module_name, package)
75
52
  end
76
53
 
77
- it "should push the module" do
54
+ include_examples 'forge_push'
55
+ end
78
56
 
57
+ context "when using bad credentials" do
58
+ before do
59
+ stub_request(:post, "#{forge}/oauth/token").with(
60
+ :body => login_body,
61
+ :headers => headers
62
+ ).to_return(
63
+ :status => 400,
64
+ :body => {"error"=>"invalid_grant","error_description"=>"Username/password do not match"}.to_json,
65
+ :headers => {})
79
66
  end
80
- end
81
67
 
68
+ it "should push the module" do
69
+ expect { subject.push!(module_name, package) }.to raise_error(Blacksmith::Error, "Error login to the forge #{forge} as #{username} [400 Bad Request]: {\"error\":\"invalid_grant\",\"error_description\":\"Username/password do not match\"}")
70
+ end
71
+
72
+ end
82
73
  end
83
74
  end
84
75
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: puppet-blacksmith
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.0.1
4
+ version: 3.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - MaestroDev
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-09-19 00:00:00.000000000 Z
11
+ date: 2014-09-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rest-client
@@ -142,6 +142,8 @@ files:
142
142
  - spec/data/maestrodev-test/metadata.json
143
143
  - spec/data/metadata.json
144
144
  - spec/data/response.json
145
+ - spec/puppet_blacksmith/forge_live_spec.rb
146
+ - spec/puppet_blacksmith/forge_shared.rb
145
147
  - spec/puppet_blacksmith/forge_spec.rb
146
148
  - spec/puppet_blacksmith/git_spec.rb
147
149
  - spec/puppet_blacksmith/modulefile_spec.rb
@@ -176,5 +178,7 @@ test_files:
176
178
  - spec/data/Modulefile
177
179
  - spec/data/maestrodev-test/metadata.json
178
180
  - spec/puppet_blacksmith/forge_spec.rb
181
+ - spec/puppet_blacksmith/forge_shared.rb
182
+ - spec/puppet_blacksmith/forge_live_spec.rb
179
183
  - spec/puppet_blacksmith/modulefile_spec.rb
180
184
  - spec/puppet_blacksmith/git_spec.rb