backup_checksum 3.0.23
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of backup_checksum might be problematic. Click here for more details.
- data/.gitignore +7 -0
- data/.travis.yml +10 -0
- data/Gemfile +28 -0
- data/Gemfile.lock +130 -0
- data/Guardfile +21 -0
- data/LICENSE.md +24 -0
- data/README.md +476 -0
- data/backup_checksum.gemspec +32 -0
- data/bin/backup +11 -0
- data/lib/backup.rb +217 -0
- data/lib/backup/archive.rb +117 -0
- data/lib/backup/binder.rb +22 -0
- data/lib/backup/checksum/base.rb +44 -0
- data/lib/backup/checksum/shasum.rb +16 -0
- data/lib/backup/cleaner.rb +121 -0
- data/lib/backup/cli/helpers.rb +88 -0
- data/lib/backup/cli/utility.rb +247 -0
- data/lib/backup/compressor/base.rb +29 -0
- data/lib/backup/compressor/bzip2.rb +50 -0
- data/lib/backup/compressor/gzip.rb +47 -0
- data/lib/backup/compressor/lzma.rb +50 -0
- data/lib/backup/compressor/pbzip2.rb +56 -0
- data/lib/backup/config.rb +173 -0
- data/lib/backup/configuration/base.rb +15 -0
- data/lib/backup/configuration/checksum/base.rb +9 -0
- data/lib/backup/configuration/checksum/shasum.rb +9 -0
- data/lib/backup/configuration/compressor/base.rb +9 -0
- data/lib/backup/configuration/compressor/bzip2.rb +23 -0
- data/lib/backup/configuration/compressor/gzip.rb +23 -0
- data/lib/backup/configuration/compressor/lzma.rb +23 -0
- data/lib/backup/configuration/compressor/pbzip2.rb +28 -0
- data/lib/backup/configuration/database/base.rb +19 -0
- data/lib/backup/configuration/database/mongodb.rb +49 -0
- data/lib/backup/configuration/database/mysql.rb +42 -0
- data/lib/backup/configuration/database/postgresql.rb +41 -0
- data/lib/backup/configuration/database/redis.rb +39 -0
- data/lib/backup/configuration/database/riak.rb +29 -0
- data/lib/backup/configuration/encryptor/base.rb +9 -0
- data/lib/backup/configuration/encryptor/gpg.rb +17 -0
- data/lib/backup/configuration/encryptor/open_ssl.rb +32 -0
- data/lib/backup/configuration/helpers.rb +52 -0
- data/lib/backup/configuration/notifier/base.rb +28 -0
- data/lib/backup/configuration/notifier/campfire.rb +25 -0
- data/lib/backup/configuration/notifier/hipchat.rb +41 -0
- data/lib/backup/configuration/notifier/mail.rb +112 -0
- data/lib/backup/configuration/notifier/presently.rb +25 -0
- data/lib/backup/configuration/notifier/prowl.rb +23 -0
- data/lib/backup/configuration/notifier/twitter.rb +21 -0
- data/lib/backup/configuration/storage/base.rb +18 -0
- data/lib/backup/configuration/storage/cloudfiles.rb +25 -0
- data/lib/backup/configuration/storage/dropbox.rb +58 -0
- data/lib/backup/configuration/storage/ftp.rb +29 -0
- data/lib/backup/configuration/storage/local.rb +17 -0
- data/lib/backup/configuration/storage/ninefold.rb +20 -0
- data/lib/backup/configuration/storage/rsync.rb +29 -0
- data/lib/backup/configuration/storage/s3.rb +25 -0
- data/lib/backup/configuration/storage/scp.rb +25 -0
- data/lib/backup/configuration/storage/sftp.rb +25 -0
- data/lib/backup/configuration/syncer/base.rb +10 -0
- data/lib/backup/configuration/syncer/cloud.rb +23 -0
- data/lib/backup/configuration/syncer/cloud_files.rb +30 -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 +23 -0
- data/lib/backup/database/base.rb +59 -0
- data/lib/backup/database/mongodb.rb +232 -0
- data/lib/backup/database/mysql.rb +163 -0
- data/lib/backup/database/postgresql.rb +146 -0
- data/lib/backup/database/redis.rb +139 -0
- data/lib/backup/database/riak.rb +69 -0
- data/lib/backup/dependency.rb +114 -0
- data/lib/backup/encryptor/base.rb +29 -0
- data/lib/backup/encryptor/gpg.rb +80 -0
- data/lib/backup/encryptor/open_ssl.rb +72 -0
- data/lib/backup/errors.rb +124 -0
- data/lib/backup/logger.rb +152 -0
- data/lib/backup/model.rb +386 -0
- data/lib/backup/notifier/base.rb +81 -0
- data/lib/backup/notifier/campfire.rb +168 -0
- data/lib/backup/notifier/hipchat.rb +99 -0
- data/lib/backup/notifier/mail.rb +206 -0
- data/lib/backup/notifier/presently.rb +88 -0
- data/lib/backup/notifier/prowl.rb +65 -0
- data/lib/backup/notifier/twitter.rb +70 -0
- data/lib/backup/package.rb +51 -0
- data/lib/backup/packager.rb +108 -0
- data/lib/backup/pipeline.rb +107 -0
- data/lib/backup/splitter.rb +75 -0
- data/lib/backup/storage/base.rb +119 -0
- data/lib/backup/storage/cloudfiles.rb +87 -0
- data/lib/backup/storage/cycler.rb +117 -0
- data/lib/backup/storage/dropbox.rb +181 -0
- data/lib/backup/storage/ftp.rb +119 -0
- data/lib/backup/storage/local.rb +82 -0
- data/lib/backup/storage/ninefold.rb +116 -0
- data/lib/backup/storage/rsync.rb +149 -0
- data/lib/backup/storage/s3.rb +94 -0
- data/lib/backup/storage/scp.rb +99 -0
- data/lib/backup/storage/sftp.rb +108 -0
- data/lib/backup/syncer/base.rb +42 -0
- data/lib/backup/syncer/cloud.rb +190 -0
- data/lib/backup/syncer/cloud_files.rb +56 -0
- data/lib/backup/syncer/rsync/base.rb +52 -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 +47 -0
- data/lib/backup/template.rb +46 -0
- data/lib/backup/version.rb +43 -0
- data/spec/archive_spec.rb +335 -0
- data/spec/cleaner_spec.rb +304 -0
- data/spec/cli/helpers_spec.rb +176 -0
- data/spec/cli/utility_spec.rb +363 -0
- data/spec/compressor/base_spec.rb +31 -0
- data/spec/compressor/bzip2_spec.rb +83 -0
- data/spec/compressor/gzip_spec.rb +83 -0
- data/spec/compressor/lzma_spec.rb +83 -0
- data/spec/compressor/pbzip2_spec.rb +124 -0
- data/spec/config_spec.rb +321 -0
- data/spec/configuration/base_spec.rb +35 -0
- data/spec/configuration/compressor/bzip2_spec.rb +29 -0
- data/spec/configuration/compressor/gzip_spec.rb +29 -0
- data/spec/configuration/compressor/lzma_spec.rb +29 -0
- data/spec/configuration/compressor/pbzip2_spec.rb +32 -0
- data/spec/configuration/database/base_spec.rb +17 -0
- data/spec/configuration/database/mongodb_spec.rb +56 -0
- data/spec/configuration/database/mysql_spec.rb +53 -0
- data/spec/configuration/database/postgresql_spec.rb +53 -0
- data/spec/configuration/database/redis_spec.rb +50 -0
- data/spec/configuration/database/riak_spec.rb +35 -0
- data/spec/configuration/encryptor/gpg_spec.rb +26 -0
- data/spec/configuration/encryptor/open_ssl_spec.rb +35 -0
- data/spec/configuration/notifier/base_spec.rb +32 -0
- data/spec/configuration/notifier/campfire_spec.rb +32 -0
- data/spec/configuration/notifier/hipchat_spec.rb +44 -0
- data/spec/configuration/notifier/mail_spec.rb +71 -0
- data/spec/configuration/notifier/presently_spec.rb +35 -0
- data/spec/configuration/notifier/prowl_spec.rb +29 -0
- data/spec/configuration/notifier/twitter_spec.rb +35 -0
- data/spec/configuration/storage/cloudfiles_spec.rb +41 -0
- data/spec/configuration/storage/dropbox_spec.rb +38 -0
- data/spec/configuration/storage/ftp_spec.rb +44 -0
- data/spec/configuration/storage/local_spec.rb +29 -0
- data/spec/configuration/storage/ninefold_spec.rb +32 -0
- data/spec/configuration/storage/rsync_spec.rb +41 -0
- data/spec/configuration/storage/s3_spec.rb +38 -0
- data/spec/configuration/storage/scp_spec.rb +41 -0
- data/spec/configuration/storage/sftp_spec.rb +41 -0
- data/spec/configuration/syncer/cloud_files_spec.rb +44 -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/push_spec.rb +43 -0
- data/spec/configuration/syncer/s3_spec.rb +38 -0
- data/spec/database/base_spec.rb +54 -0
- data/spec/database/mongodb_spec.rb +428 -0
- data/spec/database/mysql_spec.rb +335 -0
- data/spec/database/postgresql_spec.rb +278 -0
- data/spec/database/redis_spec.rb +260 -0
- data/spec/database/riak_spec.rb +108 -0
- data/spec/dependency_spec.rb +49 -0
- data/spec/encryptor/base_spec.rb +30 -0
- data/spec/encryptor/gpg_spec.rb +134 -0
- data/spec/encryptor/open_ssl_spec.rb +129 -0
- data/spec/errors_spec.rb +306 -0
- data/spec/logger_spec.rb +363 -0
- data/spec/model_spec.rb +649 -0
- data/spec/notifier/base_spec.rb +89 -0
- data/spec/notifier/campfire_spec.rb +199 -0
- data/spec/notifier/hipchat_spec.rb +188 -0
- data/spec/notifier/mail_spec.rb +280 -0
- data/spec/notifier/presently_spec.rb +181 -0
- data/spec/notifier/prowl_spec.rb +117 -0
- data/spec/notifier/twitter_spec.rb +132 -0
- data/spec/package_spec.rb +61 -0
- data/spec/packager_spec.rb +225 -0
- data/spec/pipeline_spec.rb +257 -0
- data/spec/spec_helper.rb +59 -0
- data/spec/splitter_spec.rb +120 -0
- data/spec/storage/base_spec.rb +160 -0
- data/spec/storage/cloudfiles_spec.rb +230 -0
- data/spec/storage/cycler_spec.rb +239 -0
- data/spec/storage/dropbox_spec.rb +370 -0
- data/spec/storage/ftp_spec.rb +247 -0
- data/spec/storage/local_spec.rb +235 -0
- data/spec/storage/ninefold_spec.rb +319 -0
- data/spec/storage/rsync_spec.rb +345 -0
- data/spec/storage/s3_spec.rb +221 -0
- data/spec/storage/scp_spec.rb +209 -0
- data/spec/storage/sftp_spec.rb +220 -0
- data/spec/syncer/base_spec.rb +22 -0
- data/spec/syncer/cloud_files_spec.rb +192 -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 +192 -0
- data/spec/version_spec.rb +21 -0
- data/templates/cli/utility/archive +25 -0
- data/templates/cli/utility/compressor/bzip2 +7 -0
- data/templates/cli/utility/compressor/gzip +7 -0
- data/templates/cli/utility/compressor/lzma +7 -0
- data/templates/cli/utility/compressor/pbzip2 +7 -0
- data/templates/cli/utility/config +31 -0
- data/templates/cli/utility/database/mongodb +18 -0
- data/templates/cli/utility/database/mysql +21 -0
- data/templates/cli/utility/database/postgresql +17 -0
- data/templates/cli/utility/database/redis +16 -0
- data/templates/cli/utility/database/riak +11 -0
- data/templates/cli/utility/encryptor/gpg +12 -0
- data/templates/cli/utility/encryptor/openssl +9 -0
- data/templates/cli/utility/model.erb +23 -0
- data/templates/cli/utility/notifier/campfire +12 -0
- data/templates/cli/utility/notifier/hipchat +15 -0
- data/templates/cli/utility/notifier/mail +22 -0
- data/templates/cli/utility/notifier/presently +13 -0
- data/templates/cli/utility/notifier/prowl +11 -0
- data/templates/cli/utility/notifier/twitter +13 -0
- data/templates/cli/utility/splitter +7 -0
- data/templates/cli/utility/storage/cloud_files +22 -0
- data/templates/cli/utility/storage/dropbox +20 -0
- data/templates/cli/utility/storage/ftp +12 -0
- data/templates/cli/utility/storage/local +7 -0
- data/templates/cli/utility/storage/ninefold +9 -0
- data/templates/cli/utility/storage/rsync +11 -0
- data/templates/cli/utility/storage/s3 +19 -0
- data/templates/cli/utility/storage/scp +11 -0
- data/templates/cli/utility/storage/sftp +11 -0
- data/templates/cli/utility/syncer/cloud_files +48 -0
- data/templates/cli/utility/syncer/rsync_local +12 -0
- data/templates/cli/utility/syncer/rsync_pull +17 -0
- data/templates/cli/utility/syncer/rsync_push +17 -0
- data/templates/cli/utility/syncer/s3 +45 -0
- data/templates/general/links +11 -0
- data/templates/general/version.erb +2 -0
- data/templates/notifier/mail/failure.erb +9 -0
- data/templates/notifier/mail/success.erb +7 -0
- data/templates/notifier/mail/warning.erb +9 -0
- data/templates/storage/dropbox/authorization_url.erb +6 -0
- data/templates/storage/dropbox/authorized.erb +4 -0
- data/templates/storage/dropbox/cache_file_written.erb +10 -0
- metadata +311 -0
@@ -0,0 +1,108 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require File.expand_path('../../spec_helper.rb', __FILE__)
|
4
|
+
|
5
|
+
describe Backup::Database::Riak do
|
6
|
+
let(:model) { Backup::Model.new('foo', 'foo') }
|
7
|
+
let(:db) do
|
8
|
+
Backup::Database::Riak.new(model) do |db|
|
9
|
+
db.name = 'mydatabase'
|
10
|
+
db.node = 'riak@localhost'
|
11
|
+
db.cookie = 'riak'
|
12
|
+
db.riak_admin_utility = '/path/to/riak-admin'
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
describe '#initialize' do
|
17
|
+
it 'should read the adapter details correctly' do
|
18
|
+
db.name.should == 'mydatabase'
|
19
|
+
db.node.should == 'riak@localhost'
|
20
|
+
db.cookie.should == 'riak'
|
21
|
+
db.riak_admin_utility.should == '/path/to/riak-admin'
|
22
|
+
end
|
23
|
+
|
24
|
+
context 'when options are not set' do
|
25
|
+
before do
|
26
|
+
Backup::Database::Riak.any_instance.expects(:utility).
|
27
|
+
with('riak-admin').returns('/real/riak-admin')
|
28
|
+
end
|
29
|
+
|
30
|
+
it 'should use default values' do
|
31
|
+
db = Backup::Database::Riak.new(model)
|
32
|
+
|
33
|
+
db.name.should be_nil
|
34
|
+
db.node.should be_nil
|
35
|
+
db.cookie.should be_nil
|
36
|
+
db.riak_admin_utility.should == '/real/riak-admin'
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
context 'when configuration defaults have been set' do
|
41
|
+
after { Backup::Configuration::Database::Riak.clear_defaults! }
|
42
|
+
|
43
|
+
it 'should use configuration defaults' do
|
44
|
+
Backup::Configuration::Database::Riak.defaults do |db|
|
45
|
+
db.name = 'db_name'
|
46
|
+
db.node = 'db_node'
|
47
|
+
db.cookie = 'db_cookie'
|
48
|
+
db.riak_admin_utility = '/default/path/to/riak-admin'
|
49
|
+
end
|
50
|
+
|
51
|
+
db = Backup::Database::Riak.new(model)
|
52
|
+
db.name.should == 'db_name'
|
53
|
+
db.node.should == 'db_node'
|
54
|
+
db.cookie.should == 'db_cookie'
|
55
|
+
db.riak_admin_utility.should == '/default/path/to/riak-admin'
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end # describe '#initialize'
|
59
|
+
|
60
|
+
describe '#perform!' do
|
61
|
+
let(:compressor) { mock }
|
62
|
+
let(:s) { sequence '' }
|
63
|
+
before do
|
64
|
+
# superclass actions
|
65
|
+
db.expects(:prepare!).in_sequence(s)
|
66
|
+
db.expects(:log!).in_sequence(s)
|
67
|
+
db.instance_variable_set(:@dump_path, '/dump/path')
|
68
|
+
|
69
|
+
db.stubs(:riakadmin).returns('riakadmin_command')
|
70
|
+
end
|
71
|
+
|
72
|
+
context 'when no compressor is configured' do
|
73
|
+
it 'should only perform the riak-admin backup command' do
|
74
|
+
FileUtils.expects(:chown_R).with('riak', 'riak', '/dump/path')
|
75
|
+
db.expects(:run).in_sequence(s).
|
76
|
+
with('riakadmin_command /dump/path/mydatabase node')
|
77
|
+
|
78
|
+
db.perform!
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
context 'when a compressor is configured' do
|
83
|
+
before do
|
84
|
+
model.stubs(:compressor).returns(compressor)
|
85
|
+
compressor.expects(:compress_with).yields('compressor_command', '.gz')
|
86
|
+
end
|
87
|
+
|
88
|
+
it 'should compress the backup file and remove the source file' do
|
89
|
+
FileUtils.expects(:chown_R).with('riak', 'riak', '/dump/path')
|
90
|
+
db.expects(:run).in_sequence(s).
|
91
|
+
with('riakadmin_command /dump/path/mydatabase node')
|
92
|
+
db.expects(:run).in_sequence(s).with(
|
93
|
+
"compressor_command -c /dump/path/mydatabase > /dump/path/mydatabase.gz"
|
94
|
+
)
|
95
|
+
FileUtils.expects(:rm_f).in_sequence(s).with('/dump/path/mydatabase')
|
96
|
+
|
97
|
+
db.perform!
|
98
|
+
end
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
describe '#riakadmin' do
|
103
|
+
it 'should return the full riakadmin string' do
|
104
|
+
db.send(:riakadmin).should == "/path/to/riak-admin backup riak@localhost riak"
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
end
|
@@ -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
|
@@ -0,0 +1,134 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require File.expand_path('../../spec_helper.rb', __FILE__)
|
4
|
+
|
5
|
+
describe Backup::Encryptor::GPG do
|
6
|
+
let(:encryptor) do
|
7
|
+
Backup::Encryptor::GPG.new do |e|
|
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
|
111
|
+
-----BEGIN PGP PUBLIC KEY BLOCK-----
|
112
|
+
\tVersion: GnuPG v1.4.11 (Darwin)
|
113
|
+
|
114
|
+
mQENBE12G/8BCAC4mnlSMYMBwBYTHe5zURcnYYNCORPWOr0iXGiLWuKxYtrDQyLm
|
115
|
+
X2Nws44Iz7Wp7AuJRAjkitf1cRBgXyDu8wuogXO7JqPmtsUdBCABz9w5NH6IQjgR
|
116
|
+
WNa3g2n0nokA7Zr5FA4GXoEaYivfbvGiyNpd6P4okH+//G2p+3FIryu5xz+89D1b
|
117
|
+
=Yvhg
|
118
|
+
-----END PGP PUBLIC KEY BLOCK-----
|
119
|
+
KEY
|
120
|
+
|
121
|
+
encryptor.send(:encryption_key).should == <<-KEY
|
122
|
+
-----BEGIN PGP PUBLIC KEY BLOCK-----
|
123
|
+
Version: GnuPG v1.4.11 (Darwin)
|
124
|
+
|
125
|
+
mQENBE12G/8BCAC4mnlSMYMBwBYTHe5zURcnYYNCORPWOr0iXGiLWuKxYtrDQyLm
|
126
|
+
X2Nws44Iz7Wp7AuJRAjkitf1cRBgXyDu8wuogXO7JqPmtsUdBCABz9w5NH6IQjgR
|
127
|
+
WNa3g2n0nokA7Zr5FA4GXoEaYivfbvGiyNpd6P4okH+//G2p+3FIryu5xz+89D1b
|
128
|
+
=Yvhg
|
129
|
+
-----END PGP PUBLIC KEY BLOCK-----
|
130
|
+
KEY
|
131
|
+
end
|
132
|
+
end
|
133
|
+
|
134
|
+
end
|
@@ -0,0 +1,129 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require File.expand_path('../../spec_helper.rb', __FILE__)
|
4
|
+
|
5
|
+
describe Backup::Encryptor::OpenSSL do
|
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
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
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
|
21
|
+
end
|
22
|
+
|
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
|
31
|
+
end
|
32
|
+
|
33
|
+
context 'when configuration defaults have been set' do
|
34
|
+
after { Backup::Configuration::Encryptor::OpenSSL.clear_defaults! }
|
35
|
+
|
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
|
42
|
+
end
|
43
|
+
|
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
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end # describe '#initialize'
|
52
|
+
|
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')
|
58
|
+
|
59
|
+
encryptor.encrypt_with do |command, ext|
|
60
|
+
command.should == 'openssl_cmd cmd_options'
|
61
|
+
ext.should == '.enc'
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
describe '#options' do
|
67
|
+
let(:encryptor) { Backup::Encryptor::OpenSSL.new }
|
68
|
+
|
69
|
+
before do
|
70
|
+
# salt is true by default
|
71
|
+
encryptor.salt = false
|
72
|
+
end
|
73
|
+
|
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.*$/)
|
77
|
+
end
|
78
|
+
|
79
|
+
it 'should add #password option whenever #password_file not given' do
|
80
|
+
encryptor.send(:options).should ==
|
81
|
+
"aes-256-cbc -k ''"
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
context 'when #password_file is given' do
|
86
|
+
before { encryptor.password_file = 'password_file' }
|
87
|
+
|
88
|
+
it 'should add #password_file option' do
|
89
|
+
encryptor.send(:options).should ==
|
90
|
+
'aes-256-cbc -pass file:password_file'
|
91
|
+
end
|
92
|
+
|
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'
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
context 'when #password is given (without #password_file given)' do
|
101
|
+
before { encryptor.password = 'password' }
|
102
|
+
|
103
|
+
it 'should include the given password in the #password option' do
|
104
|
+
encryptor.send(:options).should ==
|
105
|
+
"aes-256-cbc -k 'password'"
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
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 ''"
|
115
|
+
end
|
116
|
+
end
|
117
|
+
|
118
|
+
context 'when #salt is true' do
|
119
|
+
before { encryptor.salt = true }
|
120
|
+
|
121
|
+
it 'should add the option' do
|
122
|
+
encryptor.send(:options).should ==
|
123
|
+
"aes-256-cbc -salt -k ''"
|
124
|
+
end
|
125
|
+
end
|
126
|
+
|
127
|
+
end # describe '#options'
|
128
|
+
|
129
|
+
end
|