backup 3.0.20 → 3.0.21
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +1 -5
- data/Gemfile.lock +46 -50
- data/README.md +54 -27
- data/lib/backup.rb +16 -39
- data/lib/backup/archive.rb +42 -18
- data/lib/backup/cleaner.rb +110 -25
- data/lib/backup/cli/helpers.rb +17 -32
- data/lib/backup/cli/utility.rb +46 -107
- data/lib/backup/compressor/base.rb +14 -2
- data/lib/backup/compressor/bzip2.rb +10 -24
- data/lib/backup/compressor/gzip.rb +10 -24
- data/lib/backup/compressor/lzma.rb +10 -23
- data/lib/backup/compressor/pbzip2.rb +12 -32
- data/lib/backup/config.rb +171 -0
- data/lib/backup/configuration/compressor/base.rb +1 -2
- data/lib/backup/configuration/compressor/pbzip2.rb +4 -4
- data/lib/backup/configuration/database/base.rb +2 -1
- data/lib/backup/configuration/database/mongodb.rb +8 -0
- data/lib/backup/configuration/database/mysql.rb +4 -0
- data/lib/backup/configuration/database/postgresql.rb +4 -0
- data/lib/backup/configuration/database/redis.rb +4 -0
- data/lib/backup/configuration/database/riak.rb +5 -1
- data/lib/backup/configuration/encryptor/base.rb +1 -2
- data/lib/backup/configuration/encryptor/open_ssl.rb +1 -1
- data/lib/backup/configuration/helpers.rb +7 -2
- data/lib/backup/configuration/notifier/base.rb +4 -28
- data/lib/backup/configuration/storage/base.rb +1 -1
- data/lib/backup/configuration/storage/dropbox.rb +14 -4
- data/lib/backup/configuration/syncer/base.rb +10 -0
- data/lib/backup/configuration/syncer/rsync/base.rb +28 -0
- data/lib/backup/configuration/syncer/rsync/local.rb +11 -0
- data/lib/backup/configuration/syncer/rsync/pull.rb +11 -0
- data/lib/backup/configuration/syncer/rsync/push.rb +31 -0
- data/lib/backup/configuration/syncer/s3.rb +0 -4
- data/lib/backup/database/base.rb +25 -7
- data/lib/backup/database/mongodb.rb +112 -75
- data/lib/backup/database/mysql.rb +54 -29
- data/lib/backup/database/postgresql.rb +60 -42
- data/lib/backup/database/redis.rb +61 -39
- data/lib/backup/database/riak.rb +35 -11
- data/lib/backup/dependency.rb +4 -5
- data/lib/backup/encryptor/base.rb +13 -1
- data/lib/backup/encryptor/gpg.rb +39 -39
- data/lib/backup/encryptor/open_ssl.rb +28 -38
- data/lib/backup/logger.rb +20 -11
- data/lib/backup/model.rb +206 -163
- data/lib/backup/notifier/base.rb +27 -25
- data/lib/backup/notifier/campfire.rb +7 -13
- data/lib/backup/notifier/hipchat.rb +28 -28
- data/lib/backup/notifier/mail.rb +24 -26
- data/lib/backup/notifier/presently.rb +10 -18
- data/lib/backup/notifier/prowl.rb +9 -17
- data/lib/backup/notifier/twitter.rb +11 -18
- data/lib/backup/package.rb +47 -0
- data/lib/backup/packager.rb +81 -16
- data/lib/backup/splitter.rb +48 -35
- data/lib/backup/storage/base.rb +44 -172
- data/lib/backup/storage/cloudfiles.rb +31 -46
- data/lib/backup/storage/cycler.rb +117 -0
- data/lib/backup/storage/dropbox.rb +92 -76
- data/lib/backup/storage/ftp.rb +30 -40
- data/lib/backup/storage/local.rb +44 -45
- data/lib/backup/storage/ninefold.rb +55 -49
- data/lib/backup/storage/rsync.rb +49 -56
- data/lib/backup/storage/s3.rb +33 -44
- data/lib/backup/storage/scp.rb +21 -48
- data/lib/backup/storage/sftp.rb +26 -40
- data/lib/backup/syncer/base.rb +7 -0
- data/lib/backup/syncer/rsync/base.rb +78 -0
- data/lib/backup/syncer/rsync/local.rb +53 -0
- data/lib/backup/syncer/rsync/pull.rb +38 -0
- data/lib/backup/syncer/rsync/push.rb +113 -0
- data/lib/backup/syncer/s3.rb +42 -32
- data/lib/backup/version.rb +1 -1
- data/spec/archive_spec.rb +235 -69
- data/spec/cleaner_spec.rb +304 -0
- data/spec/cli/helpers_spec.rb +142 -1
- data/spec/cli/utility_spec.rb +338 -13
- data/spec/compressor/base_spec.rb +31 -0
- data/spec/compressor/bzip2_spec.rb +60 -35
- data/spec/compressor/gzip_spec.rb +60 -35
- data/spec/compressor/lzma_spec.rb +60 -35
- data/spec/compressor/pbzip2_spec.rb +98 -37
- data/spec/config_spec.rb +321 -0
- data/spec/configuration/base_spec.rb +4 -4
- data/spec/configuration/compressor/bzip2_spec.rb +1 -0
- data/spec/configuration/compressor/gzip_spec.rb +1 -0
- data/spec/configuration/compressor/lzma_spec.rb +1 -0
- data/spec/configuration/compressor/pbzip2_spec.rb +32 -0
- data/spec/configuration/database/base_spec.rb +2 -1
- data/spec/configuration/database/mongodb_spec.rb +26 -16
- data/spec/configuration/database/mysql_spec.rb +4 -0
- data/spec/configuration/database/postgresql_spec.rb +4 -0
- data/spec/configuration/database/redis_spec.rb +4 -0
- data/spec/configuration/database/riak_spec.rb +4 -0
- data/spec/configuration/encryptor/gpg_spec.rb +1 -0
- data/spec/configuration/encryptor/open_ssl_spec.rb +1 -0
- data/spec/configuration/notifier/base_spec.rb +32 -0
- data/spec/configuration/notifier/campfire_spec.rb +1 -0
- data/spec/configuration/notifier/hipchat_spec.rb +1 -0
- data/spec/configuration/notifier/mail_spec.rb +1 -0
- data/spec/configuration/notifier/presently_spec.rb +1 -0
- data/spec/configuration/notifier/prowl_spec.rb +1 -0
- data/spec/configuration/notifier/twitter_spec.rb +1 -0
- data/spec/configuration/storage/cloudfiles_spec.rb +1 -0
- data/spec/configuration/storage/dropbox_spec.rb +4 -3
- data/spec/configuration/storage/ftp_spec.rb +1 -0
- data/spec/configuration/storage/local_spec.rb +1 -0
- data/spec/configuration/storage/ninefold_spec.rb +1 -0
- data/spec/configuration/storage/rsync_spec.rb +3 -1
- data/spec/configuration/storage/s3_spec.rb +1 -0
- data/spec/configuration/storage/scp_spec.rb +1 -0
- data/spec/configuration/storage/sftp_spec.rb +1 -0
- data/spec/configuration/syncer/rsync/base_spec.rb +33 -0
- data/spec/configuration/syncer/rsync/local_spec.rb +10 -0
- data/spec/configuration/syncer/rsync/pull_spec.rb +10 -0
- data/spec/configuration/syncer/{rsync_spec.rb → rsync/push_spec.rb} +12 -15
- data/spec/configuration/syncer/s3_spec.rb +2 -3
- data/spec/database/base_spec.rb +35 -20
- data/spec/database/mongodb_spec.rb +298 -119
- data/spec/database/mysql_spec.rb +147 -72
- data/spec/database/postgresql_spec.rb +155 -100
- data/spec/database/redis_spec.rb +200 -97
- data/spec/database/riak_spec.rb +82 -24
- data/spec/dependency_spec.rb +49 -0
- data/spec/encryptor/base_spec.rb +30 -0
- data/spec/encryptor/gpg_spec.rb +105 -28
- data/spec/encryptor/open_ssl_spec.rb +85 -114
- data/spec/logger_spec.rb +74 -8
- data/spec/model_spec.rb +528 -220
- data/spec/notifier/base_spec.rb +89 -0
- data/spec/notifier/campfire_spec.rb +147 -119
- data/spec/notifier/hipchat_spec.rb +140 -145
- data/spec/notifier/mail_spec.rb +190 -248
- data/spec/notifier/presently_spec.rb +147 -282
- data/spec/notifier/prowl_spec.rb +79 -111
- data/spec/notifier/twitter_spec.rb +87 -106
- data/spec/package_spec.rb +61 -0
- data/spec/packager_spec.rb +154 -0
- data/spec/spec_helper.rb +36 -13
- data/spec/splitter_spec.rb +90 -41
- data/spec/storage/base_spec.rb +95 -239
- data/spec/storage/cloudfiles_spec.rb +185 -75
- data/spec/storage/cycler_spec.rb +239 -0
- data/spec/storage/dropbox_spec.rb +318 -87
- data/spec/storage/ftp_spec.rb +165 -152
- data/spec/storage/local_spec.rb +206 -54
- data/spec/storage/ninefold_spec.rb +264 -128
- data/spec/storage/rsync_spec.rb +244 -163
- data/spec/storage/s3_spec.rb +175 -64
- data/spec/storage/scp_spec.rb +156 -150
- data/spec/storage/sftp_spec.rb +153 -135
- data/spec/syncer/base_spec.rb +22 -0
- data/spec/syncer/rsync/base_spec.rb +118 -0
- data/spec/syncer/rsync/local_spec.rb +121 -0
- data/spec/syncer/rsync/pull_spec.rb +90 -0
- data/spec/syncer/rsync/push_spec.rb +327 -0
- data/spec/syncer/s3_spec.rb +180 -91
- data/templates/cli/utility/config +1 -1
- data/templates/cli/utility/database/mongodb +4 -0
- data/templates/cli/utility/database/mysql +3 -0
- data/templates/cli/utility/database/postgresql +3 -0
- data/templates/cli/utility/database/redis +3 -0
- data/templates/cli/utility/database/riak +3 -0
- data/templates/cli/utility/storage/dropbox +4 -1
- data/templates/cli/utility/syncer/rsync_local +12 -0
- data/templates/cli/utility/syncer/{rsync → rsync_pull} +2 -2
- data/templates/cli/utility/syncer/rsync_push +17 -0
- data/templates/storage/dropbox/authorization_url.erb +1 -1
- metadata +42 -17
- data/lib/backup/configuration/syncer/rsync.rb +0 -45
- data/lib/backup/finder.rb +0 -87
- data/lib/backup/storage/object.rb +0 -47
- data/lib/backup/syncer/rsync.rb +0 -152
- data/spec/backup_spec.rb +0 -11
- data/spec/finder_spec.rb +0 -91
- data/spec/storage/object_spec.rb +0 -74
- data/spec/syncer/rsync_spec.rb +0 -195
@@ -0,0 +1,49 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require File.expand_path('../spec_helper.rb', __FILE__)
|
4
|
+
|
5
|
+
describe Backup::Dependency do
|
6
|
+
before do
|
7
|
+
Backup::Dependency.stubs(:all).returns(
|
8
|
+
'net-sftp' => {
|
9
|
+
:require => 'net/sftp',
|
10
|
+
:version => '~> 2.0.5',
|
11
|
+
:for => 'SFTP Protocol (SFTP Storage)'
|
12
|
+
})
|
13
|
+
end
|
14
|
+
|
15
|
+
describe ".load" do
|
16
|
+
it "should load and require given dependency" do
|
17
|
+
Backup::Dependency.expects(:gem).with("net-sftp", "~> 2.0.5")
|
18
|
+
Backup::Dependency.expects(:require).with("net/sftp")
|
19
|
+
Backup::Dependency.load("net-sftp")
|
20
|
+
end
|
21
|
+
|
22
|
+
context "on a missing dependency" do
|
23
|
+
before do
|
24
|
+
Backup::Dependency.stubs(:gem).raises(LoadError)
|
25
|
+
end
|
26
|
+
|
27
|
+
it "should display error message" do
|
28
|
+
Backup::Logger.expects(:error).with do |exception|
|
29
|
+
exception.message.should == "Dependency::LoadError: Dependency missing
|
30
|
+
Dependency required for:
|
31
|
+
SFTP Protocol (SFTP Storage)
|
32
|
+
To install the gem, issue the following command:
|
33
|
+
> gem install net-sftp -v '~> 2.0.5'
|
34
|
+
Please try again after installing the missing dependency."
|
35
|
+
end
|
36
|
+
|
37
|
+
expect do
|
38
|
+
Backup::Dependency.load("net-sftp")
|
39
|
+
end.to raise_error(SystemExit)
|
40
|
+
end
|
41
|
+
|
42
|
+
it "should exit with status code 1" do
|
43
|
+
expect do
|
44
|
+
Backup::Dependency.load("net-sftp")
|
45
|
+
end.to raise_error { |exit| exit.status.should be(1) }
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require File.expand_path('../../spec_helper.rb', __FILE__)
|
4
|
+
|
5
|
+
describe Backup::Encryptor::Base do
|
6
|
+
let(:base) { Backup::Encryptor::Base.new }
|
7
|
+
|
8
|
+
describe '#initialize' do
|
9
|
+
it 'should load defaults' do
|
10
|
+
Backup::Encryptor::Base.any_instance.expects(:load_defaults!)
|
11
|
+
base
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
describe '#encryptor_name' do
|
16
|
+
it 'should return class name with Backup namespace removed' do
|
17
|
+
base.send(:encryptor_name).should == 'Encryptor::Base'
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
describe '#log!' do
|
22
|
+
it 'should log a message' do
|
23
|
+
base.expects(:encryptor_name).returns('Encryptor Name')
|
24
|
+
Backup::Logger.expects(:message).with(
|
25
|
+
'Using Encryptor Name to encrypt the archive.'
|
26
|
+
)
|
27
|
+
base.send(:log!)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
data/spec/encryptor/gpg_spec.rb
CHANGED
@@ -3,12 +3,113 @@
|
|
3
3
|
require File.expand_path('../../spec_helper.rb', __FILE__)
|
4
4
|
|
5
5
|
describe Backup::Encryptor::GPG do
|
6
|
-
|
7
6
|
let(:encryptor) do
|
8
7
|
Backup::Encryptor::GPG.new do |e|
|
9
|
-
e.key =
|
8
|
+
e.key = 'gpg_key'
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
describe '#initialize' do
|
13
|
+
it 'should read the adapter details correctly' do
|
14
|
+
encryptor.key.should == 'gpg_key'
|
15
|
+
end
|
16
|
+
|
17
|
+
context 'when options are not set' do
|
18
|
+
it 'should use default values' do
|
19
|
+
encryptor = Backup::Encryptor::GPG.new
|
20
|
+
encryptor.key.should be_nil
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
context 'when configuration defaults have been set' do
|
25
|
+
after { Backup::Configuration::Encryptor::GPG.clear_defaults! }
|
26
|
+
|
27
|
+
it 'should use configuration defaults' do
|
28
|
+
Backup::Configuration::Encryptor::GPG.defaults do |encryptor|
|
29
|
+
encryptor.key = 'my_key'
|
30
|
+
end
|
31
|
+
|
32
|
+
encryptor = Backup::Encryptor::GPG.new
|
33
|
+
encryptor.key.should == 'my_key'
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end # describe '#initialize'
|
37
|
+
|
38
|
+
describe '#encrypt_with' do
|
39
|
+
it 'should yield the encryption command and extension' do
|
40
|
+
encryptor.expects(:log!)
|
41
|
+
encryptor.expects(:extract_encryption_key_email!)
|
42
|
+
encryptor.expects(:utility).with(:gpg).returns('gpg')
|
43
|
+
encryptor.expects(:options).returns('command options')
|
44
|
+
|
45
|
+
encryptor.encrypt_with do |command, ext|
|
46
|
+
command.should == 'gpg command options'
|
47
|
+
ext.should == '.gpg'
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
describe '#extract_encryption_key_email!' do
|
53
|
+
it 'should extract the encryption_key_email' do
|
54
|
+
encryptor.expects(:utility).with(:gpg).returns('gpg')
|
55
|
+
encryptor.expects(:with_tmp_key_file).yields('/path/to/tmpfile')
|
56
|
+
encryptor.expects(:run).with("gpg --import '/path/to/tmpfile' 2>&1").
|
57
|
+
returns('gpg: key A1B2C3D4: "User Name (Comment) <user@host>" not changed')
|
58
|
+
|
59
|
+
encryptor.send(:extract_encryption_key_email!)
|
60
|
+
encryptor.instance_variable_get(:@encryption_key_email).should == 'user@host'
|
61
|
+
end
|
62
|
+
|
63
|
+
it 'should use the cached key email if already extracted' do
|
64
|
+
encryptor.instance_variable_set(:@encryption_key_email, 'foo@host')
|
65
|
+
encryptor.expects(:utility).never
|
66
|
+
encryptor.expects(:with_tmp_key_file).never
|
67
|
+
encryptor.expects(:run).never
|
68
|
+
|
69
|
+
encryptor.send(:extract_encryption_key_email!)
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
describe '#options' do
|
74
|
+
it 'should return the option string for the gpg command' do
|
75
|
+
encryptor.instance_variable_set(:@encryption_key_email, 'user@host')
|
76
|
+
encryptor.send(:options).should == "-e --trust-model always -r 'user@host'"
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
describe '#with_tmp_key_file' do
|
81
|
+
let(:tmp_file) { mock }
|
82
|
+
let(:s) { sequence '' }
|
83
|
+
|
84
|
+
before do
|
85
|
+
tmp_file.stubs(:path).returns('/path/to/tmp_file')
|
86
|
+
encryptor.stubs(:encryption_key).returns('provided key')
|
87
|
+
end
|
88
|
+
|
89
|
+
it 'should provide a tempfile with the provided key' do
|
90
|
+
Tempfile.expects(:new).in_sequence(s).
|
91
|
+
with('backup.pub').
|
92
|
+
returns(tmp_file)
|
93
|
+
FileUtils.expects(:chown).in_sequence(s).
|
94
|
+
with(Backup::Config.user, nil, '/path/to/tmp_file')
|
95
|
+
FileUtils.expects(:chmod).in_sequence(s).
|
96
|
+
with(0600, '/path/to/tmp_file')
|
97
|
+
tmp_file.expects(:write).in_sequence(s).
|
98
|
+
with('provided key')
|
99
|
+
tmp_file.expects(:close).in_sequence(s)
|
100
|
+
tmp_file.expects(:delete).in_sequence(s)
|
101
|
+
|
102
|
+
encryptor.send(:with_tmp_key_file) do |tmp_file|
|
103
|
+
tmp_file.should == '/path/to/tmp_file'
|
104
|
+
end
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
describe '#encryption_key' do
|
109
|
+
it 'should strip leading whitespace from the given key' do
|
110
|
+
encryptor.key = <<-KEY
|
10
111
|
-----BEGIN PGP PUBLIC KEY BLOCK-----
|
11
|
-
|
112
|
+
\tVersion: GnuPG v1.4.11 (Darwin)
|
12
113
|
|
13
114
|
mQENBE12G/8BCAC4mnlSMYMBwBYTHe5zURcnYYNCORPWOr0iXGiLWuKxYtrDQyLm
|
14
115
|
X2Nws44Iz7Wp7AuJRAjkitf1cRBgXyDu8wuogXO7JqPmtsUdBCABz9w5NH6IQjgR
|
@@ -16,12 +117,8 @@ describe Backup::Encryptor::GPG do
|
|
16
117
|
=Yvhg
|
17
118
|
-----END PGP PUBLIC KEY BLOCK-----
|
18
119
|
KEY
|
19
|
-
end
|
20
|
-
end
|
21
120
|
|
22
|
-
|
23
|
-
it "should strip initial whitespace from key lines" do
|
24
|
-
key = <<-KEY
|
121
|
+
encryptor.send(:encryption_key).should == <<-KEY
|
25
122
|
-----BEGIN PGP PUBLIC KEY BLOCK-----
|
26
123
|
Version: GnuPG v1.4.11 (Darwin)
|
27
124
|
|
@@ -31,27 +128,7 @@ WNa3g2n0nokA7Zr5FA4GXoEaYivfbvGiyNpd6P4okH+//G2p+3FIryu5xz+89D1b
|
|
31
128
|
=Yvhg
|
32
129
|
-----END PGP PUBLIC KEY BLOCK-----
|
33
130
|
KEY
|
34
|
-
|
35
|
-
encryptor.key.should == key
|
36
131
|
end
|
37
132
|
end
|
38
133
|
|
39
|
-
describe '#options' do
|
40
|
-
it do
|
41
|
-
encryptor.expects(:encryption_key_id).returns('secret')
|
42
|
-
encryptor.send(:options).should == "-e --trust-model always -r 'secret'"
|
43
|
-
end
|
44
|
-
end
|
45
|
-
|
46
|
-
describe '#write_tmp_file!' do
|
47
|
-
it do
|
48
|
-
tmp_file = Tempfile.new("foo")
|
49
|
-
Tempfile.expects(:new).returns(tmp_file)
|
50
|
-
tmp_file.expects(:write).with('secret')
|
51
|
-
tmp_file.expects(:close)
|
52
|
-
|
53
|
-
encryptor.key = 'secret'
|
54
|
-
encryptor.send(:write_tmp_file!)
|
55
|
-
end
|
56
|
-
end
|
57
134
|
end
|
@@ -3,156 +3,127 @@
|
|
3
3
|
require File.expand_path('../../spec_helper.rb', __FILE__)
|
4
4
|
|
5
5
|
describe Backup::Encryptor::OpenSSL do
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
end
|
13
|
-
|
14
|
-
it do
|
15
|
-
encryptor.send(:base64).should == []
|
16
|
-
end
|
17
|
-
|
18
|
-
it do
|
19
|
-
encryptor.send(:salt).should == []
|
6
|
+
let(:encryptor) do
|
7
|
+
Backup::Encryptor::OpenSSL.new do |e|
|
8
|
+
e.password = 'mypassword'
|
9
|
+
e.password_file = '/my/password/file'
|
10
|
+
e.base64 = true
|
11
|
+
e.salt = true
|
20
12
|
end
|
13
|
+
end
|
21
14
|
|
22
|
-
|
23
|
-
|
15
|
+
describe '#initialize' do
|
16
|
+
it 'should read the adapter details correctly' do
|
17
|
+
encryptor.password.should == 'mypassword'
|
18
|
+
encryptor.password_file.should == '/my/password/file'
|
19
|
+
encryptor.base64.should == true
|
20
|
+
encryptor.salt.should == true
|
24
21
|
end
|
25
22
|
|
26
|
-
|
27
|
-
|
23
|
+
context 'when options are not set' do
|
24
|
+
it 'should use default values' do
|
25
|
+
encryptor = Backup::Encryptor::OpenSSL.new
|
26
|
+
encryptor.password.should be_nil
|
27
|
+
encryptor.password_file.should be_nil
|
28
|
+
encryptor.base64.should be_false
|
29
|
+
encryptor.salt.should be_true
|
30
|
+
end
|
28
31
|
end
|
29
|
-
end
|
30
32
|
|
31
|
-
|
33
|
+
context 'when configuration defaults have been set' do
|
34
|
+
after { Backup::Configuration::Encryptor::OpenSSL.clear_defaults! }
|
32
35
|
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
36
|
+
it 'should use configuration defaults' do
|
37
|
+
Backup::Configuration::Encryptor::OpenSSL.defaults do |encryptor|
|
38
|
+
encryptor.password = 'my_password'
|
39
|
+
encryptor.password_file = '/my_password/file'
|
40
|
+
encryptor.base64 = true
|
41
|
+
encryptor.salt = true
|
39
42
|
end
|
40
|
-
end
|
41
|
-
|
42
|
-
it do
|
43
|
-
encryptor.password.should == "my_secret_password"
|
44
|
-
end
|
45
|
-
|
46
|
-
it do
|
47
|
-
encryptor.send(:salt).should == ['-salt']
|
48
|
-
end
|
49
43
|
|
50
|
-
|
51
|
-
encryptor.
|
44
|
+
encryptor = Backup::Encryptor::OpenSSL.new
|
45
|
+
encryptor.password.should == 'my_password'
|
46
|
+
encryptor.password_file.should == '/my_password/file'
|
47
|
+
encryptor.base64.should == true
|
48
|
+
encryptor.salt.should == true
|
52
49
|
end
|
50
|
+
end
|
51
|
+
end # describe '#initialize'
|
53
52
|
|
54
|
-
|
55
|
-
|
56
|
-
|
53
|
+
describe '#encrypt_with' do
|
54
|
+
it 'should yield the encryption command and extension' do
|
55
|
+
encryptor.expects(:log!)
|
56
|
+
encryptor.expects(:utility).with(:openssl).returns('openssl_cmd')
|
57
|
+
encryptor.expects(:options).returns('cmd_options')
|
57
58
|
|
58
|
-
|
59
|
-
|
59
|
+
encryptor.encrypt_with do |command, ext|
|
60
|
+
command.should == 'openssl_cmd cmd_options'
|
61
|
+
ext.should == '.enc'
|
60
62
|
end
|
61
63
|
end
|
64
|
+
end
|
62
65
|
|
63
|
-
|
64
|
-
|
65
|
-
Backup::Encryptor::OpenSSL.new do |e|
|
66
|
-
e.password_file = "/path/to/password/file"
|
67
|
-
e.salt = true
|
68
|
-
e.base64 = true
|
69
|
-
end
|
70
|
-
end
|
66
|
+
describe '#options' do
|
67
|
+
let(:encryptor) { Backup::Encryptor::OpenSSL.new }
|
71
68
|
|
72
|
-
|
73
|
-
|
74
|
-
|
69
|
+
before do
|
70
|
+
# salt is true by default
|
71
|
+
encryptor.salt = false
|
72
|
+
end
|
75
73
|
|
76
|
-
|
77
|
-
|
74
|
+
context 'with no options given' do
|
75
|
+
it 'should always include cipher command' do
|
76
|
+
encryptor.send(:options).should match(/^aes-256-cbc\s.*$/)
|
78
77
|
end
|
79
78
|
|
80
|
-
it do
|
81
|
-
encryptor.send(:
|
79
|
+
it 'should add #password option whenever #password_file not given' do
|
80
|
+
encryptor.send(:options).should ==
|
81
|
+
"aes-256-cbc -k ''"
|
82
82
|
end
|
83
|
+
end
|
83
84
|
|
84
|
-
|
85
|
-
|
86
|
-
end
|
85
|
+
context 'when #password_file is given' do
|
86
|
+
before { encryptor.password_file = 'password_file' }
|
87
87
|
|
88
|
-
it do
|
89
|
-
encryptor.send(:
|
88
|
+
it 'should add #password_file option' do
|
89
|
+
encryptor.send(:options).should ==
|
90
|
+
'aes-256-cbc -pass file:password_file'
|
90
91
|
end
|
91
92
|
|
92
|
-
it do
|
93
|
-
encryptor.
|
93
|
+
it 'should add #password_file option even when #password given' do
|
94
|
+
encryptor.password = 'password'
|
95
|
+
encryptor.send(:options).should ==
|
96
|
+
'aes-256-cbc -pass file:password_file'
|
94
97
|
end
|
95
98
|
end
|
96
99
|
|
97
|
-
|
98
|
-
|
99
|
-
describe '#perform!' do
|
100
|
-
let(:encryptor) { Backup::Encryptor::OpenSSL.new }
|
101
|
-
before do
|
102
|
-
Backup::Model.extension = 'tar'
|
103
|
-
[:utility, :run, :rm].each { |method| encryptor.stubs(method) }
|
104
|
-
end
|
105
|
-
|
106
|
-
it do
|
107
|
-
encryptor = Backup::Encryptor::OpenSSL.new
|
108
|
-
encryptor.expects(:utility).returns(:openssl)
|
109
|
-
encryptor.expects(:run).with("openssl aes-256-cbc -k '' -in '#{ File.join(Backup::TMP_PATH, "#{Backup::TIME}.#{Backup::TRIGGER}.tar") }' -out '#{ File.join(Backup::TMP_PATH, "#{Backup::TIME}.#{Backup::TRIGGER}.tar.enc") }'")
|
110
|
-
encryptor.perform!
|
111
|
-
end
|
100
|
+
context 'when #password is given (without #password_file given)' do
|
101
|
+
before { encryptor.password = 'password' }
|
112
102
|
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
e.salt = true
|
117
|
-
e.base64 = true
|
103
|
+
it 'should include the given password in the #password option' do
|
104
|
+
encryptor.send(:options).should ==
|
105
|
+
"aes-256-cbc -k 'password'"
|
118
106
|
end
|
119
|
-
encryptor.stubs(:utility).returns(:openssl)
|
120
|
-
encryptor.expects(:run).with("openssl aes-256-cbc -base64 -salt -k 'my_secret_password' -in '#{ File.join(Backup::TMP_PATH, "#{Backup::TIME}.#{Backup::TRIGGER}.tar") }' -out '#{ File.join(Backup::TMP_PATH, "#{Backup::TIME}.#{Backup::TRIGGER}.tar.enc") }'")
|
121
|
-
encryptor.perform!
|
122
107
|
end
|
123
108
|
|
124
|
-
|
125
|
-
encryptor =
|
126
|
-
|
127
|
-
|
128
|
-
|
109
|
+
context 'when #base64 is true' do
|
110
|
+
before { encryptor.base64 = true }
|
111
|
+
|
112
|
+
it 'should add the option' do
|
113
|
+
encryptor.send(:options).should ==
|
114
|
+
"aes-256-cbc -base64 -k ''"
|
129
115
|
end
|
130
|
-
encryptor.stubs(:utility).returns(:openssl)
|
131
|
-
encryptor.expects(:run).with("openssl aes-256-cbc -base64 -salt -pass file:/path/to/password/file -in '#{ File.join(Backup::TMP_PATH, "#{Backup::TIME}.#{Backup::TRIGGER}.tar") }' -out '#{ File.join(Backup::TMP_PATH, "#{Backup::TIME}.#{Backup::TRIGGER}.tar.enc") }'")
|
132
|
-
encryptor.perform!
|
133
116
|
end
|
134
117
|
|
135
|
-
|
136
|
-
|
137
|
-
encryptor.perform!
|
138
|
-
Backup::Model.extension.should == 'tar.enc'
|
139
|
-
end
|
118
|
+
context 'when #salt is true' do
|
119
|
+
before { encryptor.salt = true }
|
140
120
|
|
141
|
-
|
142
|
-
|
143
|
-
|
121
|
+
it 'should add the option' do
|
122
|
+
encryptor.send(:options).should ==
|
123
|
+
"aes-256-cbc -salt -k ''"
|
124
|
+
end
|
144
125
|
end
|
145
126
|
|
146
|
-
|
147
|
-
Backup::Logger.expects(:message).with("Backup::Encryptor::OpenSSL started encrypting the archive.")
|
148
|
-
encryptor.perform!
|
149
|
-
end
|
127
|
+
end # describe '#options'
|
150
128
|
|
151
|
-
context "after encrypting the file (which creates a new file)" do
|
152
|
-
it 'should remove the non-encrypted file' do
|
153
|
-
encryptor.expects(:rm).with(Backup::Model.file)
|
154
|
-
encryptor.perform!
|
155
|
-
end
|
156
|
-
end
|
157
|
-
end
|
158
129
|
end
|