heirloom 0.9.0 → 0.10.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -3,28 +3,42 @@ require 'spec_helper'
3
3
  describe Heirloom do
4
4
  before do
5
5
  @logger_mock = mock 'logger', :info => true
6
- @logger_mock.stub :info => true
6
+ @logger_mock.stub :info => true,
7
+ :debug => true
7
8
  @config_mock = mock 'config'
8
9
  @config_mock.stub :logger => @logger_mock
9
10
  @tempfile_stub = stub 'tempfile', :path => '/path_to_encrypted_archive',
10
11
  :close! => true
11
12
  Tempfile.stub :new => @tempfile_stub
12
- @aes_mock = mock 'aes'
13
- @aes_mock.stub :random_iv => 'firstsixteenchar'
14
- OpenSSL::Cipher::AES256.should_receive(:new).
15
- with(:CBC).and_return @aes_mock
16
13
  @file = Heirloom::Cipher::File.new :config => @config_mock
17
14
  end
18
15
 
19
16
  it "should encrypt the given file" do
20
- @aes_mock.should_receive(:encrypt)
21
- @aes_mock.should_receive(:iv=).with 'firstsixteenchar'
22
- @aes_mock.should_receive(:key=).with Digest::SHA256.hexdigest 'mysecret'
23
- ::File.should_receive(:open)
17
+ @file.should_receive(:which).with('gpg').and_return true
18
+ command = 'gpg --batch --yes -c --cipher-algo AES256 --passphrase mysecret --output /path_to_encrypted_archive /file 2>&1'
19
+ @file.should_receive(:`).with command
20
+ $?.stub :success? => true
24
21
  FileUtils.should_receive(:mv).
25
22
  with('/path_to_encrypted_archive', '/file')
26
23
  @file.encrypt_file(:file => '/file',
27
24
  :secret => 'mysecret').should be_true
28
25
  end
29
26
 
27
+ it "should return false if gpg is not in the path" do
28
+ @file.should_receive(:which).with('gpg').and_return false
29
+ @logger_mock.should_receive(:error)
30
+ @file.encrypt_file(:file => '/file',
31
+ :secret => 'mysecret').should be_false
32
+ end
33
+
34
+ it "should return false if gpg returns non zero code" do
35
+ @file.should_receive(:which).with('gpg').and_return true
36
+ @logger_mock.should_receive(:error)
37
+ command = 'gpg --batch --yes -c --cipher-algo AES256 --passphrase mysecret --output /path_to_encrypted_archive /file 2>&1'
38
+ @file.should_receive(:`).with command
39
+ $?.stub :success? => false
40
+ @file.encrypt_file(:file => '/file',
41
+ :secret => 'mysecret').should be_false
42
+ end
43
+
30
44
  end
@@ -78,6 +78,7 @@ describe Heirloom do
78
78
  with(:bucket_prefix => 'bp',
79
79
  :regions => @regions,
80
80
  :public_readable => false,
81
+ :secret => 'secret12',
81
82
  :file => '/tmp/file.tar.gz')
82
83
  @upload.upload
83
84
  end
@@ -5,24 +5,28 @@ describe Heirloom::Directory do
5
5
  describe 'build_artifact_from_directory' do
6
6
  before do
7
7
  @config_mock = double 'config'
8
- @logger_stub = stub :debug => 'true', :info => 'true', :warn => 'true'
8
+ @logger_stub = stub :debug => 'true',
9
+ :info => 'true',
10
+ :warn => 'true',
11
+ :error => 'true'
9
12
  @config_mock.stub(:logger).and_return(@logger_stub)
10
13
  @directory = Heirloom::Directory.new :config => @config_mock,
11
14
  :exclude => ['.', '..', 'dont_pack_me'],
12
15
  :path => '/dir',
13
16
  :file => '/tmp/file.tar.gz'
14
- output_mock = double 'output mock'
15
- Dir.should_receive(:entries).with('/dir').
16
- exactly(2).times.
17
- and_return ['pack_me', '.hidden',
18
- 'with a space', 'dont_pack_me']
19
- Heirloom::Directory.any_instance.should_receive(:`).
20
- with("cd /dir && tar czf /tmp/file.tar.gz 'pack_me' '.hidden' 'with a space'").
21
- and_return output_mock
22
17
  end
23
18
 
24
19
  context 'when succesful' do
25
20
  before do
21
+ @directory.should_receive(:which).with('tar').and_return true
22
+ output_mock = double 'output mock'
23
+ command = "cd /dir && tar czf /tmp/file.tar.gz 'pack_me' '.hidden' 'with a space'"
24
+ files = ['pack_me', '.hidden', 'with a space', 'dont_pack_me']
25
+ Heirloom::Directory.any_instance.should_receive(:`).
26
+ with(command).
27
+ and_return output_mock
28
+ Dir.should_receive(:entries).with('/dir').
29
+ and_return files
26
30
  $?.stub :success? => true
27
31
  end
28
32
 
@@ -53,7 +57,17 @@ describe Heirloom::Directory do
53
57
  end
54
58
 
55
59
  context 'when unable to create the tar' do
56
- before { $?.stub(:success?).and_return(false) }
60
+ before do
61
+ @directory.should_receive(:which).with('tar').and_return true
62
+ output_mock = double 'output mock'
63
+ command = "cd /dir && tar czf /tmp/file.tar.gz 'pack_me' '.hidden' 'with a space'"
64
+ files = ['pack_me', '.hidden', 'with a space', 'dont_pack_me']
65
+ Heirloom::Directory.any_instance.should_receive(:`).
66
+ with(command).
67
+ and_return output_mock
68
+ Dir.should_receive(:entries).with('/dir').and_return files
69
+ $?.stub(:success?).and_return(false)
70
+ end
57
71
 
58
72
  it "build should return false" do
59
73
  @directory.build_artifact_from_directory(:secret => nil).should be_false
@@ -65,6 +79,18 @@ describe Heirloom::Directory do
65
79
  end
66
80
  end
67
81
 
82
+ context 'when required executable is missing' do
83
+ before do
84
+ files = ['pack_me', '.hidden', 'with a space', 'dont_pack_me']
85
+ Dir.should_receive(:entries).with('/dir').and_return files
86
+ end
87
+
88
+ it "should return false if tar is not in path" do
89
+ @directory.should_receive(:which).with('tar').and_return false
90
+ @directory.build_artifact_from_directory(:secret => nil).should be_false
91
+ end
92
+ end
93
+
68
94
  end
69
95
 
70
96
  end
@@ -0,0 +1,64 @@
1
+ require 'spec_helper'
2
+
3
+ describe Heirloom::Uploader::S3 do
4
+ before do
5
+ @logger_stub = stub 'logger stub', :info => true,
6
+ :warn => true,
7
+ :debug => true
8
+ @config_stub = stub 'config stub', :logger => @logger_stub
9
+ @s3 = Heirloom::Uploader::S3.new :config => @config_stub,
10
+ :logger => @logger_stub,
11
+ :region => 'us-west-1'
12
+ end
13
+
14
+ it "should upload the file to s3" do
15
+ @options = { :bucket => 'bucket',
16
+ :file => 'file',
17
+ :id => 'id',
18
+ :key_name => 'key_name',
19
+ :key_folder => 'key_folder',
20
+ :name => 'name',
21
+ :public_readable => true }
22
+ @s3_mock = mock 's3 mock'
23
+ @bucket_mock = mock 'bucket mock'
24
+ @files_mock = mock 'files mock'
25
+ @file_mock = mock 'file mock'
26
+ @body_mock = mock 'body mock'
27
+ Heirloom::AWS::S3.should_receive(:new).
28
+ with(:config => @config_stub,
29
+ :region => 'us-west-1').
30
+ and_return @s3_mock
31
+ @s3_mock.should_receive(:get_bucket).
32
+ with('bucket').
33
+ and_return @bucket_mock
34
+ @bucket_mock.should_receive(:files).and_return(@files_mock)
35
+ File.should_receive(:open).with('file').and_return @body_mock
36
+ @files_mock.should_receive(:create).
37
+ with :key => "key_folder/key_name",
38
+ :body => @body_mock,
39
+ :public => true
40
+ @body_mock.should_receive(:close)
41
+ @s3.upload_file @options
42
+ end
43
+
44
+ it "should add endpoint attributes for the file to simpledb" do
45
+ simpledb_mock = mock 'simpledb mock'
46
+ options = { :bucket => 'bucket',
47
+ :id => 'id',
48
+ :key_name => 'key_name',
49
+ :name => 'name' }
50
+ Heirloom::AWS::SimpleDB.should_receive(:new).
51
+ with(:config => @config_stub).
52
+ and_return simpledb_mock
53
+ simpledb_mock.should_receive(:put_attributes).
54
+ with("heirloom_name", "id",
55
+ { "us-west-1-s3-url" => "s3://bucket/name/key_name" } )
56
+ simpledb_mock.should_receive(:put_attributes).
57
+ with("heirloom_name", "id",
58
+ { "us-west-1-http-url" => "http://s3-us-west-1.amazonaws.com/bucket/name/key_name" } )
59
+ simpledb_mock.should_receive(:put_attributes).
60
+ with("heirloom_name", "id",
61
+ { "us-west-1-https-url" => "https://s3-us-west-1.amazonaws.com/bucket/name/key_name" } )
62
+ @s3.add_endpoint_attributes options
63
+ end
64
+ end
@@ -0,0 +1,30 @@
1
+ require 'spec_helper'
2
+
3
+ describe Heirloom::Utils::File do
4
+ before do
5
+ @object = Object.new
6
+ @object.extend Heirloom::Utils::File
7
+ end
8
+
9
+ it "should return the path to a present executable" do
10
+ @object.stub :path => '/test1:/test2'
11
+ ::File.should_receive(:executable?).
12
+ with('/test1/test1234').
13
+ and_return false
14
+ ::File.should_receive(:executable?).
15
+ with('/test2/test1234').
16
+ and_return true
17
+ @object.which('test1234').should == '/test2/test1234'
18
+ end
19
+
20
+ it "should return nil if the executable does not exist" do
21
+ @object.stub :path => '/test1:/test2'
22
+ ::File.should_receive(:executable?).
23
+ with('/test1/test1234').
24
+ and_return false
25
+ ::File.should_receive(:executable?).
26
+ with('/test2/test1234').
27
+ and_return false
28
+ @object.which('test1234').should be_nil
29
+ end
30
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: heirloom
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.0
4
+ version: 0.10.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-12-01 00:00:00.000000000 Z
12
+ date: 2012-12-14 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec
16
- requirement: &70302923492580 !ruby/object:Gem::Requirement
16
+ requirement: &70327489259240 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ~>
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: 2.11.0
22
22
  type: :development
23
23
  prerelease: false
24
- version_requirements: *70302923492580
24
+ version_requirements: *70327489259240
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: rake
27
- requirement: &70302923545380 !ruby/object:Gem::Requirement
27
+ requirement: &70327489258580 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: '0'
33
33
  type: :development
34
34
  prerelease: false
35
- version_requirements: *70302923545380
35
+ version_requirements: *70327489258580
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: fog
38
- requirement: &70302923542440 !ruby/object:Gem::Requirement
38
+ requirement: &70327489582820 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ~>
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: 1.6.0
44
44
  type: :runtime
45
45
  prerelease: false
46
- version_requirements: *70302923542440
46
+ version_requirements: *70327489582820
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: trollop
49
- requirement: &70302923623680 !ruby/object:Gem::Requirement
49
+ requirement: &70327489581740 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - =
@@ -54,10 +54,10 @@ dependencies:
54
54
  version: '2.0'
55
55
  type: :runtime
56
56
  prerelease: false
57
- version_requirements: *70302923623680
57
+ version_requirements: *70327489581740
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: xml-simple
60
- requirement: &70302923692740 !ruby/object:Gem::Requirement
60
+ requirement: &70327489581060 !ruby/object:Gem::Requirement
61
61
  none: false
62
62
  requirements:
63
63
  - - ~>
@@ -65,7 +65,7 @@ dependencies:
65
65
  version: 1.1.2
66
66
  type: :runtime
67
67
  prerelease: false
68
- version_requirements: *70302923692740
68
+ version_requirements: *70327489581060
69
69
  description: I help build and manage building tar.gz files and deploying them into
70
70
  the cloud
71
71
  email:
@@ -115,6 +115,7 @@ files:
115
115
  - lib/heirloom/cipher.rb
116
116
  - lib/heirloom/cipher/data.rb
117
117
  - lib/heirloom/cipher/file.rb
118
+ - lib/heirloom/cipher/shared.rb
118
119
  - lib/heirloom/cli.rb
119
120
  - lib/heirloom/cli/authorize.rb
120
121
  - lib/heirloom/cli/catalog.rb
@@ -137,9 +138,12 @@ files:
137
138
  - lib/heirloom/directory/directory.rb
138
139
  - lib/heirloom/downloader.rb
139
140
  - lib/heirloom/downloader/s3.rb
141
+ - lib/heirloom/exceptions.rb
140
142
  - lib/heirloom/logger.rb
141
143
  - lib/heirloom/uploader.rb
142
144
  - lib/heirloom/uploader/s3.rb
145
+ - lib/heirloom/utils.rb
146
+ - lib/heirloom/utils/file.rb
143
147
  - lib/heirloom/version.rb
144
148
  - spec/acl/s3_spec.rb
145
149
  - spec/archive/authorizer_spec.rb
@@ -186,6 +190,8 @@ files:
186
190
  - spec/downloader/s3_spec.rb
187
191
  - spec/logger_spec.rb
188
192
  - spec/spec_helper.rb
193
+ - spec/uploader/s3_spec.rb
194
+ - spec/utils/file_spec.rb
189
195
  homepage: ''
190
196
  licenses: []
191
197
  post_install_message:
@@ -200,7 +206,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
200
206
  version: '0'
201
207
  segments:
202
208
  - 0
203
- hash: -2336051542288959986
209
+ hash: -166474931629253916
204
210
  required_rubygems_version: !ruby/object:Gem::Requirement
205
211
  none: false
206
212
  requirements:
@@ -209,7 +215,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
209
215
  version: '0'
210
216
  segments:
211
217
  - 0
212
- hash: -2336051542288959986
218
+ hash: -166474931629253916
213
219
  requirements: []
214
220
  rubyforge_project: heirloom
215
221
  rubygems_version: 1.8.16
@@ -262,3 +268,5 @@ test_files:
262
268
  - spec/downloader/s3_spec.rb
263
269
  - spec/logger_spec.rb
264
270
  - spec/spec_helper.rb
271
+ - spec/uploader/s3_spec.rb
272
+ - spec/utils/file_spec.rb