encbs 0.2.1.beta2 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/bin/encbs +18 -14
- data/encbs.gemspec +7 -5
- data/lib/backup/file_item/local.rb +2 -2
- data/lib/backup/jar.rb +9 -11
- data/lib/backup/timestamp.rb +1 -1
- data/lib/backup.rb +9 -4
- data/lib/crypto.rb +13 -13
- data/test/fixtures/rsa_key.private +27 -0
- data/test/fixtures/rsa_key.public +8 -0
- data/test/test_backup.rb +138 -25
- data/test/test_backup_file_item.rb +1 -1
- data/test/test_backup_timestamp.rb +14 -14
- data/test/test_config.rb +4 -0
- data/test/test_crypto.rb +26 -0
- metadata +26 -24
- data/test/fixtures/test_crypto.rb +0 -23
- data/test/test_jar.rb +0 -0
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.2.1
|
1
|
+
0.2.1
|
data/bin/encbs
CHANGED
@@ -168,21 +168,29 @@ begin
|
|
168
168
|
exit
|
169
169
|
end
|
170
170
|
|
171
|
-
#TODO: Support rescue option as hash
|
172
171
|
if opts.rescue?
|
173
172
|
paths = opts[:rescue].split(" ")
|
174
173
|
jars_list = @backup.jars
|
174
|
+
puts jars_list
|
175
175
|
|
176
|
-
include_path = lambda {|path| jars_list.
|
176
|
+
include_path = lambda {|path| jars_list.has_key?(path)}
|
177
177
|
|
178
178
|
jars_hashes = paths.map do |path|
|
179
|
-
path
|
179
|
+
unless path.length == 32 and path.match /[0-9a-f]{32}/
|
180
|
+
path = File.expand_path path
|
180
181
|
|
181
|
-
|
182
|
-
|
183
|
-
|
182
|
+
unless include_path[path] or include_path["#{path}/"]
|
183
|
+
puts_fail "Jar \"#{path}\" not exists."
|
184
|
+
end
|
184
185
|
|
185
|
-
|
186
|
+
jars_list[path] || jars_list["#{path}/"]
|
187
|
+
else
|
188
|
+
unless jars_list.has_value? path
|
189
|
+
puts_fail "Jar with hash \"#{path}\" not exists."
|
190
|
+
else
|
191
|
+
path
|
192
|
+
end
|
193
|
+
end
|
186
194
|
end
|
187
195
|
|
188
196
|
if opts.to?
|
@@ -192,14 +200,10 @@ begin
|
|
192
200
|
@to = "/"
|
193
201
|
end
|
194
202
|
|
195
|
-
#TODO: Confirm flag
|
196
|
-
#TODO: Empty destination directory
|
197
|
-
|
198
203
|
@index = {}
|
199
204
|
|
200
205
|
jars_hashes.each do |hash|
|
201
206
|
versions = @backup.jar_versions(hash)
|
202
|
-
# puts "Versions: #{versions}" #FIXME
|
203
207
|
|
204
208
|
last_version = Backup::Timestamp.last_from(versions, @end_date, @start_date)
|
205
209
|
|
@@ -231,7 +235,7 @@ begin
|
|
231
235
|
meta = YAML::load open("/var/tmp/encbs.swap").read
|
232
236
|
jar_path, timestamp = meta[:jar_path], meta[:timestamp]
|
233
237
|
dirs = @backup.file_item.dir File.expand_path("../", jar_path)
|
234
|
-
|
238
|
+
|
235
239
|
if dirs.include? File.basename(jar_path)
|
236
240
|
meta.delete :timestamp
|
237
241
|
meta.delete :jar_path
|
@@ -240,11 +244,11 @@ begin
|
|
240
244
|
"#{jar_path}/#{timestamp}.yml",
|
241
245
|
meta.to_yaml
|
242
246
|
)
|
243
|
-
|
247
|
+
|
244
248
|
FileUtils.rm "/var/tmp/encbs.swap"
|
245
249
|
end
|
246
250
|
end
|
247
|
-
|
251
|
+
|
248
252
|
if opts.add?
|
249
253
|
paths = opts[:add].split(" ")
|
250
254
|
else
|
data/encbs.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{encbs}
|
8
|
-
s.version = "0.2.1
|
8
|
+
s.version = "0.2.1"
|
9
9
|
|
10
|
-
s.required_rubygems_version = Gem::Requirement.new("
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Timothy Klim"]
|
12
|
-
s.date = %q{2011-06-
|
12
|
+
s.date = %q{2011-06-04}
|
13
13
|
s.default_executable = %q{encbs}
|
14
14
|
s.description = %q{Simple backup system for pushing into cloud}
|
15
15
|
s.email = %q{klimtimothy@gmail.com}
|
@@ -39,12 +39,14 @@ Gem::Specification.new do |s|
|
|
39
39
|
"lib/helpers.rb",
|
40
40
|
"test/fixtures/etc/.hide",
|
41
41
|
"test/fixtures/etc/root/file",
|
42
|
-
"test/fixtures/
|
42
|
+
"test/fixtures/rsa_key.private",
|
43
|
+
"test/fixtures/rsa_key.public",
|
43
44
|
"test/helper.rb",
|
44
45
|
"test/test_backup.rb",
|
45
46
|
"test/test_backup_file_item.rb",
|
46
47
|
"test/test_backup_timestamp.rb",
|
47
|
-
"test/
|
48
|
+
"test/test_config.rb",
|
49
|
+
"test/test_crypto.rb"
|
48
50
|
]
|
49
51
|
s.homepage = %q{http://github.com/TimothyKlim/encbs}
|
50
52
|
s.licenses = ["MIT"]
|
@@ -4,7 +4,7 @@ module Backup
|
|
4
4
|
module FileItem
|
5
5
|
class Local < Backup::FileItem::Base
|
6
6
|
attr_reader :timeout
|
7
|
-
|
7
|
+
|
8
8
|
def initialize
|
9
9
|
@timeout = 0
|
10
10
|
end
|
@@ -27,7 +27,7 @@ module Backup
|
|
27
27
|
f.read
|
28
28
|
end if File.exists? file
|
29
29
|
end
|
30
|
-
|
30
|
+
|
31
31
|
def timeout= time
|
32
32
|
end
|
33
33
|
|
data/lib/backup/jar.rb
CHANGED
@@ -28,14 +28,14 @@ module Backup
|
|
28
28
|
@local_files.keys.each do |file|
|
29
29
|
current = @local_files[file].dup
|
30
30
|
current.delete(:timestamp)
|
31
|
-
|
31
|
+
|
32
32
|
unless @last_index[file].nil?
|
33
33
|
backup = @last_index[file].dup
|
34
34
|
backup.delete(:timestamp)
|
35
|
-
|
35
|
+
|
36
36
|
if (current == backup) or
|
37
37
|
(!current[:checksum].nil? and current[:checksum] == backup[:checksum])
|
38
|
-
|
38
|
+
|
39
39
|
@meta_index[file] = @local_files[file]
|
40
40
|
@meta_index[file][:timestamp] = @last_index[file][:timestamp]
|
41
41
|
end
|
@@ -72,10 +72,8 @@ module Backup
|
|
72
72
|
@local_files.keys.count
|
73
73
|
)
|
74
74
|
end
|
75
|
-
|
76
|
-
pbar.bar_mark = '*'
|
77
75
|
|
78
|
-
|
76
|
+
pbar.bar_mark = '*'
|
79
77
|
|
80
78
|
begin
|
81
79
|
@local_files.keys.each do |file|
|
@@ -88,15 +86,15 @@ module Backup
|
|
88
86
|
data = compression.compress(data.read, 3) unless compression.nil?
|
89
87
|
|
90
88
|
data = @key.encrypt_to_stream(data) if @key
|
91
|
-
|
89
|
+
|
92
90
|
@file_item.create_file_once(
|
93
91
|
"#{jar_data_path}/#{@file_item.file_hash file}",
|
94
92
|
data
|
95
93
|
)
|
96
|
-
|
94
|
+
|
97
95
|
pbar.inc
|
98
96
|
end
|
99
|
-
|
97
|
+
|
100
98
|
@meta_index[file] = @local_files[file]
|
101
99
|
@meta_index[file][:checksum] = checksum
|
102
100
|
@meta_index[file][:timestamp] = @timestamp
|
@@ -110,7 +108,7 @@ module Backup
|
|
110
108
|
File.open("/var/tmp/encbs.swap", "w") do |f|
|
111
109
|
f.puts @meta_index.to_yaml
|
112
110
|
end
|
113
|
-
|
111
|
+
|
114
112
|
puts
|
115
113
|
puts_fail "Index file has been saved that to allow upload into cloud in next run."
|
116
114
|
else
|
@@ -125,7 +123,7 @@ module Backup
|
|
125
123
|
puts "Removing previous backups..."
|
126
124
|
previous_versions = Jar.jar_versions @file_item, @root_path, jar_hash, true
|
127
125
|
previous_versions.delete @timestamp
|
128
|
-
|
126
|
+
|
129
127
|
previous_versions.each do |version|
|
130
128
|
@file_item.delete_file "#{meta_jar_path}/#{version}.yml"
|
131
129
|
@file_item.delete_dir "#{@root_path}/#{jar_hash}/#{version}"
|
data/lib/backup/timestamp.rb
CHANGED
data/lib/backup.rb
CHANGED
@@ -33,7 +33,11 @@ module Backup
|
|
33
33
|
end
|
34
34
|
|
35
35
|
def rsa_key path, size
|
36
|
-
|
36
|
+
if File.exists? path
|
37
|
+
@key = Crypto::Key.from_file(path, size)
|
38
|
+
else
|
39
|
+
@key = nil
|
40
|
+
end
|
37
41
|
end
|
38
42
|
|
39
43
|
def create! local_path, increment = false, purge_previous = false
|
@@ -51,6 +55,7 @@ module Backup
|
|
51
55
|
|
52
56
|
def restore_jar_to(hash, timestamp, to)
|
53
57
|
files = Jar.fetch_index_for(@file_item, @root_path, hash, timestamp)
|
58
|
+
puts_fail "Jar doesn't exists" if files.nil?
|
54
59
|
|
55
60
|
unless files[:checksum].nil?
|
56
61
|
if @key.nil? or
|
@@ -85,7 +90,7 @@ module Backup
|
|
85
90
|
File.chown current_file[:uid], current_file[:gid], restore_file
|
86
91
|
|
87
92
|
file_ok = @file_item.stat(restore_file)[restore_file]
|
88
|
-
|
93
|
+
|
89
94
|
check_mode(restore_file, file_ok[:mode], current_file[:mode])
|
90
95
|
check_rights(
|
91
96
|
restore_file,
|
@@ -106,7 +111,7 @@ module Backup
|
|
106
111
|
remote_path += "/#{@file_item.file_hash file}"
|
107
112
|
|
108
113
|
data = @file_item.read_file(remote_path)
|
109
|
-
data = @key.decrypt_from_stream data if @key
|
114
|
+
data = @key.decrypt_from_stream data.chomp if @key
|
110
115
|
|
111
116
|
unless compression.nil?
|
112
117
|
data = compression.decompress(data.chomp).read
|
@@ -116,7 +121,7 @@ module Backup
|
|
116
121
|
end
|
117
122
|
|
118
123
|
file_ok = @file_item.stat(restore_file)[restore_file]
|
119
|
-
|
124
|
+
|
120
125
|
check_mode(restore_file, file_ok[:mode], current_file[:mode])
|
121
126
|
check_rights(
|
122
127
|
restore_file,
|
data/lib/crypto.rb
CHANGED
@@ -2,42 +2,42 @@ require 'openssl'
|
|
2
2
|
require 'base64'
|
3
3
|
|
4
4
|
module Crypto
|
5
|
-
|
6
5
|
def self.create_keys(priv, pub, bits)
|
7
6
|
private_key = OpenSSL::PKey::RSA.new(bits)
|
8
7
|
File.open(priv, "w+") { |fp| fp << private_key.to_s }
|
9
|
-
File.open(pub, "w+") { |fp| fp << private_key.public_key.to_s }
|
8
|
+
File.open(pub, "w+") { |fp| fp << private_key.public_key.to_s }
|
10
9
|
private_key
|
11
10
|
end
|
12
|
-
|
11
|
+
|
13
12
|
class Key
|
14
13
|
def initialize(data, size)
|
15
14
|
@public = (data =~ /^-----BEGIN (RSA|DSA) PRIVATE KEY-----$/).nil?
|
16
15
|
@key = OpenSSL::PKey::RSA.new(data)
|
17
16
|
@size = (size == 4096 ? 512 : 256)
|
18
17
|
end
|
19
|
-
|
18
|
+
|
20
19
|
def self.from_file(filename, size = 4096)
|
21
20
|
self.new(File.read(filename), size)
|
22
21
|
end
|
23
22
|
|
24
23
|
def encrypt_to_stream(data)
|
25
24
|
encrypt_data = StringIO.new
|
25
|
+
data = data.read if data.is_a? StringIO
|
26
26
|
i = 0
|
27
|
-
|
27
|
+
|
28
28
|
while buf = data[i..(i+=117)] do
|
29
29
|
encrypt_data << encrypt(buf)
|
30
30
|
end
|
31
|
-
|
31
|
+
|
32
32
|
encrypt_data.seek 0
|
33
33
|
encrypt_data
|
34
34
|
end
|
35
35
|
|
36
36
|
def decrypt_from_stream(data)
|
37
|
-
encrypt_data = StringIO.new
|
37
|
+
encrypt_data = StringIO.new data
|
38
38
|
encrypt_data.seek 0
|
39
39
|
decrypt_data = ""
|
40
|
-
|
40
|
+
|
41
41
|
while buf = encrypt_data.read(@size) do
|
42
42
|
decrypt_data += decrypt(buf)
|
43
43
|
end
|
@@ -50,23 +50,23 @@ module Crypto
|
|
50
50
|
rescue Exception => e
|
51
51
|
puts_fail "RSA encrypt error: #{e.message}"
|
52
52
|
end
|
53
|
-
|
53
|
+
|
54
54
|
def decrypt(text)
|
55
55
|
@key.send("#{key_type}_decrypt", text)
|
56
56
|
rescue Exception => e
|
57
57
|
puts_fail "RSA decrypt error: #{e.message}"
|
58
58
|
end
|
59
|
-
|
59
|
+
|
60
60
|
def private?
|
61
61
|
!@public
|
62
62
|
end
|
63
|
-
|
63
|
+
|
64
64
|
def public?
|
65
65
|
@public
|
66
66
|
end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Yw8+Z3KWl2WM9qTB/VxqbXn3CSzjh0bG/cpw8S35d5pARZFbKHGYut+K3bl
|
4
|
+
7x8dJ4lQukuNJe8Z8MgNjwm16T2M0DCPTGroHpJducuk/vOH5C1udPvAndpOo2Nt
|
5
|
+
28gSqaP2bduQ6aAX5bMKuD2ArW3b5jLMEEuoPPG1w1GNxVfcwO5ggsBy7IJk2t4y
|
6
|
+
h42VGkGJ5BbWRnM7zOy6nXxQ7sDZtWAxxOpA4N2l1S9mVk2EsfAco6G/QR3XTyid
|
7
|
+
2yOj+yAfwyhuF+u5K35CbU+7jI47vZGXJwIDAQAB
|
8
|
+
-----END RSA PUBLIC KEY-----
|
data/test/test_backup.rb
CHANGED
@@ -1,11 +1,9 @@
|
|
1
|
-
require File.expand_path(
|
1
|
+
require File.expand_path('../helper', __FILE__)
|
2
2
|
|
3
3
|
class TestBackup < Test::Unit::TestCase
|
4
4
|
def setup
|
5
5
|
@backups_path = File.expand_path("../fixtures/backups", __FILE__)
|
6
|
-
|
7
|
-
FileUtils.rm_r @backups_path, :force => true
|
8
|
-
FileUtils.mkdir_p @backups_path
|
6
|
+
@restore_path = File.expand_path("../fixtures/restore", __FILE__)
|
9
7
|
|
10
8
|
@hostname = Socket.gethostname
|
11
9
|
|
@@ -15,6 +13,26 @@ class TestBackup < Test::Unit::TestCase
|
|
15
13
|
)
|
16
14
|
end
|
17
15
|
|
16
|
+
def teardown
|
17
|
+
FileUtils.rm_r @backups_path, :force => true
|
18
|
+
FileUtils.rm_r @restore_path, :force => true
|
19
|
+
|
20
|
+
FileUtils.mkdir_p @backups_path
|
21
|
+
FileUtils.mkdir_p @restore_path
|
22
|
+
|
23
|
+
File.open(File.expand_path('../fixtures/etc/root/file', __FILE__), 'w') do |f|
|
24
|
+
f.puts "Root file\n"
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def create_backup! increment = false
|
29
|
+
@local_path = File.expand_path('../fixtures/etc', __FILE__)
|
30
|
+
@local_path_hash = Digest::MD5.hexdigest @local_path
|
31
|
+
|
32
|
+
@timestamp = @backup.create! @local_path, increment, false
|
33
|
+
@back_path = "#{@backups_path}/#{@hostname}"
|
34
|
+
end
|
35
|
+
|
18
36
|
def test_backup_attributes
|
19
37
|
assert_equal(
|
20
38
|
@backup.root_path,
|
@@ -26,36 +44,131 @@ class TestBackup < Test::Unit::TestCase
|
|
26
44
|
end
|
27
45
|
|
28
46
|
def test_create
|
29
|
-
|
30
|
-
|
47
|
+
create_backup!
|
48
|
+
|
49
|
+
assert File.exists?("#{@back_path}")
|
50
|
+
assert File.exists?("#{@back_path}/meta")
|
51
|
+
assert File.exists?("#{@back_path}/meta/#{@local_path_hash}")
|
52
|
+
assert File.exists?("#{@back_path}/meta/#{@local_path_hash}/#{@timestamp}.yml")
|
53
|
+
assert File.exists?("#{@back_path}/meta/jars")
|
54
|
+
assert File.exists?("#{@back_path}/meta/jars/#{@local_path_hash}")
|
55
|
+
assert File.exists?("#{@back_path}/#{@local_path_hash}")
|
31
56
|
|
32
|
-
|
33
|
-
|
57
|
+
assert_equal "#{@local_path}/", open(
|
58
|
+
"#{@back_path}/meta/jars/#{@local_path_hash}"
|
59
|
+
).read.chomp
|
34
60
|
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
assert File.exists?("#{back_path}/meta/#{local_path_hash}/#{timestamp}.yml")
|
39
|
-
assert File.exists?("#{back_path}/meta/jars")
|
40
|
-
assert File.exists?("#{back_path}/meta/jars/#{local_path_hash}")
|
41
|
-
assert File.exists?("#{back_path}/#{local_path_hash}")
|
61
|
+
meta_index = YAML::load open(
|
62
|
+
"#{@back_path}/meta/#{@local_path_hash}/#{@timestamp}.yml"
|
63
|
+
).read
|
42
64
|
|
43
|
-
|
44
|
-
meta_index = YAML::load open("#{back_path}/meta/#{local_path_hash}/#{timestamp}.yml").read
|
45
|
-
assert meta_index.has_key? local_path
|
65
|
+
assert meta_index.has_key? @local_path
|
46
66
|
|
47
67
|
root_file = File.expand_path '../fixtures/etc/root/file', __FILE__
|
48
68
|
assert_equal open(root_file).read, open(
|
49
|
-
"#{back_path}/#{local_path_hash}/#{timestamp}/#{Digest::MD5.hexdigest root_file}"
|
69
|
+
"#{@back_path}/#{@local_path_hash}/#{@timestamp}/#{Digest::MD5.hexdigest root_file}"
|
70
|
+
).read
|
71
|
+
end
|
72
|
+
|
73
|
+
def test_create_with_crypt
|
74
|
+
@backup.rsa_key(
|
75
|
+
File.expand_path('../fixtures/rsa_key.public', __FILE__),
|
76
|
+
2048
|
77
|
+
)
|
78
|
+
private_key = Crypto::Key.from_file(
|
79
|
+
File.expand_path('../fixtures/rsa_key.private', __FILE__),
|
80
|
+
2048
|
81
|
+
)
|
82
|
+
|
83
|
+
create_backup!
|
84
|
+
|
85
|
+
root_file = File.expand_path '../fixtures/etc/root/file', __FILE__
|
86
|
+
root_file_content = open(root_file).read
|
87
|
+
|
88
|
+
root_file_crypt_content = open(
|
89
|
+
"#{@back_path}/#{@local_path_hash}/#{@timestamp}/#{Digest::MD5.hexdigest root_file}"
|
90
|
+
).read
|
91
|
+
|
92
|
+
assert_not_equal root_file_content, root_file_crypt_content
|
93
|
+
assert_equal root_file_content, private_key.decrypt_from_stream(
|
94
|
+
root_file_crypt_content.chomp
|
95
|
+
)
|
96
|
+
end
|
97
|
+
|
98
|
+
def test_show_jars
|
99
|
+
create_backup!
|
100
|
+
|
101
|
+
jars = @backup.jars
|
102
|
+
|
103
|
+
assert jars.has_key? "#{@local_path}/"
|
104
|
+
assert_equal jars["#{@local_path}/"], Digest::MD5.hexdigest(@local_path)
|
105
|
+
end
|
106
|
+
|
107
|
+
def test_jar_versions
|
108
|
+
create_backup!
|
109
|
+
|
110
|
+
jar_timestamp = @backup.jar_versions @local_path
|
111
|
+
|
112
|
+
assert_equal @timestamp, jar_timestamp.first
|
113
|
+
end
|
114
|
+
|
115
|
+
def test_restore
|
116
|
+
create_backup!
|
117
|
+
restore_path = File.expand_path '../fixtures/restore', __FILE__
|
118
|
+
|
119
|
+
@backup.restore_jar_to @local_path_hash, @timestamp, restore_path
|
120
|
+
|
121
|
+
assert "#{@restore_path}/#{@local_path}"
|
122
|
+
assert "#{@restore_path}/#{@local_path}/etc/root/file"
|
123
|
+
|
124
|
+
root_file_content = open(
|
125
|
+
File.expand_path '../fixtures/etc/root/file', __FILE__
|
126
|
+
).read
|
127
|
+
assert_equal root_file_content, open(
|
128
|
+
"#{@restore_path}/#{@local_path}/root/file"
|
50
129
|
).read
|
51
130
|
end
|
52
131
|
|
53
|
-
|
54
|
-
|
132
|
+
def test_restore_with_decrypt
|
133
|
+
@backup.rsa_key(
|
134
|
+
File.expand_path('../fixtures/rsa_key.public', __FILE__),
|
135
|
+
2048
|
136
|
+
)
|
137
|
+
create_backup!
|
55
138
|
|
56
|
-
|
57
|
-
|
139
|
+
restore_path = File.expand_path '../fixtures/restore', __FILE__
|
140
|
+
@backup.rsa_key(
|
141
|
+
File.expand_path('../fixtures/rsa_key.private', __FILE__),
|
142
|
+
2048
|
143
|
+
)
|
144
|
+
@backup.restore_jar_to @local_path_hash, @timestamp, restore_path
|
145
|
+
|
146
|
+
root_file_content = open(
|
147
|
+
File.expand_path '../fixtures/etc/root/file', __FILE__
|
148
|
+
).read
|
149
|
+
root_file_decrypt_content = open(
|
150
|
+
"#{@restore_path}/#{@local_path}/root/file"
|
151
|
+
).read
|
152
|
+
|
153
|
+
assert_equal root_file_content, root_file_decrypt_content
|
154
|
+
end
|
155
|
+
|
156
|
+
def test_increment_backup
|
157
|
+
create_backup!
|
58
158
|
|
59
|
-
|
60
|
-
|
159
|
+
File.open(File.expand_path('../fixtures/etc/root/file', __FILE__), 'w') do |f|
|
160
|
+
f.puts "Changed file\n"
|
161
|
+
end
|
162
|
+
|
163
|
+
sleep 1
|
164
|
+
create_backup! true
|
165
|
+
|
166
|
+
root_file = File.expand_path '../fixtures/etc/root/file', __FILE__
|
167
|
+
root_file_content = open(root_file).read
|
168
|
+
|
169
|
+
assert_equal root_file_content, "Changed file\n"
|
170
|
+
assert_equal root_file_content, open(
|
171
|
+
"#{@back_path}/#{@local_path_hash}/#{@timestamp}/#{Digest::MD5.hexdigest root_file}"
|
172
|
+
).read
|
173
|
+
end
|
61
174
|
end
|
@@ -1,29 +1,29 @@
|
|
1
|
-
require File.expand_path(
|
1
|
+
require File.expand_path('../helper', __FILE__)
|
2
2
|
|
3
3
|
class BackupTimestampTest < Test::Unit::TestCase
|
4
4
|
def test_parse_timestamp
|
5
5
|
assert_equal Backup::Timestamp.parse_timestamp("110102201130"),
|
6
|
-
Time.
|
6
|
+
Time.utc(2011, 01, 02, 20, 11, 30, 0)
|
7
7
|
|
8
8
|
assert_equal Backup::Timestamp.parse_timestamp("11.01.02. 20:11:30"),
|
9
|
-
Time.
|
9
|
+
Time.utc(2011, 01, 02, 20, 11, 30, 0)
|
10
10
|
|
11
11
|
assert_equal Backup::Timestamp.parse_timestamp("1101022011"),
|
12
|
-
Time.
|
12
|
+
Time.utc(2011, 01, 02, 20, 11, 0, 0)
|
13
13
|
assert_equal Backup::Timestamp.parse_timestamp("11010220"),
|
14
|
-
Time.
|
14
|
+
Time.utc(2011, 01, 02, 20, 0, 0, 0)
|
15
15
|
assert_equal Backup::Timestamp.parse_timestamp("110102"),
|
16
|
-
Time.
|
16
|
+
Time.utc(2011, 01, 02, 0, 0, 0, 0)
|
17
17
|
|
18
18
|
assert_equal Backup::Timestamp.parse_timestamp("1101022011", true),
|
19
|
-
Time.
|
19
|
+
Time.utc(2011, 01, 02, 20, 11, 59, 0)
|
20
20
|
assert_equal Backup::Timestamp.parse_timestamp("11010220", true),
|
21
|
-
Time.
|
21
|
+
Time.utc(2011, 01, 02, 20, 59, 59, 0)
|
22
22
|
assert_equal Backup::Timestamp.parse_timestamp("110102", true),
|
23
|
-
Time.
|
23
|
+
Time.utc(2011, 01, 02, 23, 59, 59, 0)
|
24
24
|
|
25
25
|
assert_not_equal Backup::Timestamp.parse_timestamp("110102201130"),
|
26
|
-
Time.
|
26
|
+
Time.utc(2011, 01, 02, 20, 11, 31, 0)
|
27
27
|
|
28
28
|
assert_raise(RuntimeError) { Backup::Timestamp.parse_timestamp("11d10.,130") }
|
29
29
|
end
|
@@ -57,15 +57,15 @@ class BackupTimestampTest < Test::Unit::TestCase
|
|
57
57
|
end
|
58
58
|
|
59
59
|
def test_create_timestamp
|
60
|
-
time = Time.
|
60
|
+
time = Time.utc(2011, 01, 02, 23, 59, 59, 0)
|
61
61
|
|
62
62
|
assert_equal(Backup::Timestamp.create.length, 12)
|
63
63
|
assert_equal(Backup::Timestamp.create(time), "110102235959")
|
64
64
|
end
|
65
|
-
|
65
|
+
|
66
66
|
def test_formatted_timestamp
|
67
|
-
time = Time.
|
68
|
-
|
67
|
+
time = Time.utc(2011, 01, 02, 23, 59, 30, 0)
|
68
|
+
|
69
69
|
assert_equal Backup::Timestamp.to_s(time), "11.01.02 23:59:30"
|
70
70
|
assert_equal Backup::Timestamp.to_s(51), nil
|
71
71
|
assert_equal Backup::Timestamp.to_str("110102235930"), "11.01.02 23:59:30"
|
data/test/test_config.rb
ADDED
data/test/test_crypto.rb
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
require File.expand_path('../helper', __FILE__)
|
2
|
+
|
3
|
+
class TestCrypto < Test::Unit::TestCase
|
4
|
+
def setup
|
5
|
+
@fixtures = File.expand_path('../fixtures/rsa_keys', __FILE__)
|
6
|
+
|
7
|
+
FileUtils.rm_r @fixtures, :force => true
|
8
|
+
FileUtils.mkdir_p @fixtures
|
9
|
+
end
|
10
|
+
|
11
|
+
def create_keys!(bits = 4096)
|
12
|
+
Crypto.create_keys("#{@fixtures}/rsa_key", "#{@fixtures}/rsa_key.pub", bits)
|
13
|
+
end
|
14
|
+
|
15
|
+
def load_keys
|
16
|
+
@priv_key = Crypto::Key.from_file("#{@fixtures}/rsa_key")
|
17
|
+
@pub_key = Crypto::Key.from_file("#{@fixtures}/rsa_key.pub")
|
18
|
+
end
|
19
|
+
|
20
|
+
def test_create_keys
|
21
|
+
create_keys!
|
22
|
+
|
23
|
+
assert_not_nil File.open("#{@fixtures}/rsa_key").read
|
24
|
+
assert_not_nil File.open("#{@fixtures}/rsa_key.pub").read
|
25
|
+
end
|
26
|
+
end
|
metadata
CHANGED
@@ -1,20 +1,20 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: encbs
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.1
|
5
|
-
prerelease:
|
4
|
+
version: 0.2.1
|
5
|
+
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Timothy Klim
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2011-06-
|
12
|
+
date: 2011-06-04 00:00:00.000000000 +04:00
|
13
13
|
default_executable: encbs
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: fog
|
17
|
-
requirement: &
|
17
|
+
requirement: &2155354360 !ruby/object:Gem::Requirement
|
18
18
|
none: false
|
19
19
|
requirements:
|
20
20
|
- - ! '>='
|
@@ -22,10 +22,10 @@ dependencies:
|
|
22
22
|
version: '0'
|
23
23
|
type: :runtime
|
24
24
|
prerelease: false
|
25
|
-
version_requirements: *
|
25
|
+
version_requirements: *2155354360
|
26
26
|
- !ruby/object:Gem::Dependency
|
27
27
|
name: slop
|
28
|
-
requirement: &
|
28
|
+
requirement: &2155353860 !ruby/object:Gem::Requirement
|
29
29
|
none: false
|
30
30
|
requirements:
|
31
31
|
- - ! '>='
|
@@ -33,10 +33,10 @@ dependencies:
|
|
33
33
|
version: '0'
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
|
-
version_requirements: *
|
36
|
+
version_requirements: *2155353860
|
37
37
|
- !ruby/object:Gem::Dependency
|
38
38
|
name: ruby-progressbar
|
39
|
-
requirement: &
|
39
|
+
requirement: &2155353340 !ruby/object:Gem::Requirement
|
40
40
|
none: false
|
41
41
|
requirements:
|
42
42
|
- - ! '>='
|
@@ -44,10 +44,10 @@ dependencies:
|
|
44
44
|
version: '0'
|
45
45
|
type: :runtime
|
46
46
|
prerelease: false
|
47
|
-
version_requirements: *
|
47
|
+
version_requirements: *2155353340
|
48
48
|
- !ruby/object:Gem::Dependency
|
49
49
|
name: lzoruby
|
50
|
-
requirement: &
|
50
|
+
requirement: &2155352820 !ruby/object:Gem::Requirement
|
51
51
|
none: false
|
52
52
|
requirements:
|
53
53
|
- - ! '>='
|
@@ -55,10 +55,10 @@ dependencies:
|
|
55
55
|
version: '0'
|
56
56
|
type: :runtime
|
57
57
|
prerelease: false
|
58
|
-
version_requirements: *
|
58
|
+
version_requirements: *2155352820
|
59
59
|
- !ruby/object:Gem::Dependency
|
60
60
|
name: rake
|
61
|
-
requirement: &
|
61
|
+
requirement: &2155352300 !ruby/object:Gem::Requirement
|
62
62
|
none: false
|
63
63
|
requirements:
|
64
64
|
- - =
|
@@ -66,10 +66,10 @@ dependencies:
|
|
66
66
|
version: 0.8.4
|
67
67
|
type: :development
|
68
68
|
prerelease: false
|
69
|
-
version_requirements: *
|
69
|
+
version_requirements: *2155352300
|
70
70
|
- !ruby/object:Gem::Dependency
|
71
71
|
name: bundler
|
72
|
-
requirement: &
|
72
|
+
requirement: &2155351700 !ruby/object:Gem::Requirement
|
73
73
|
none: false
|
74
74
|
requirements:
|
75
75
|
- - ! '>='
|
@@ -77,10 +77,10 @@ dependencies:
|
|
77
77
|
version: 1.0.0
|
78
78
|
type: :development
|
79
79
|
prerelease: false
|
80
|
-
version_requirements: *
|
80
|
+
version_requirements: *2155351700
|
81
81
|
- !ruby/object:Gem::Dependency
|
82
82
|
name: jeweler
|
83
|
-
requirement: &
|
83
|
+
requirement: &2155351100 !ruby/object:Gem::Requirement
|
84
84
|
none: false
|
85
85
|
requirements:
|
86
86
|
- - ! '>='
|
@@ -88,10 +88,10 @@ dependencies:
|
|
88
88
|
version: 1.6.0
|
89
89
|
type: :development
|
90
90
|
prerelease: false
|
91
|
-
version_requirements: *
|
91
|
+
version_requirements: *2155351100
|
92
92
|
- !ruby/object:Gem::Dependency
|
93
93
|
name: rcov
|
94
|
-
requirement: &
|
94
|
+
requirement: &2155350480 !ruby/object:Gem::Requirement
|
95
95
|
none: false
|
96
96
|
requirements:
|
97
97
|
- - ! '>='
|
@@ -99,7 +99,7 @@ dependencies:
|
|
99
99
|
version: '0'
|
100
100
|
type: :development
|
101
101
|
prerelease: false
|
102
|
-
version_requirements: *
|
102
|
+
version_requirements: *2155350480
|
103
103
|
description: Simple backup system for pushing into cloud
|
104
104
|
email: klimtimothy@gmail.com
|
105
105
|
executables:
|
@@ -129,12 +129,14 @@ files:
|
|
129
129
|
- lib/helpers.rb
|
130
130
|
- test/fixtures/etc/.hide
|
131
131
|
- test/fixtures/etc/root/file
|
132
|
-
- test/fixtures/
|
132
|
+
- test/fixtures/rsa_key.private
|
133
|
+
- test/fixtures/rsa_key.public
|
133
134
|
- test/helper.rb
|
134
135
|
- test/test_backup.rb
|
135
136
|
- test/test_backup_file_item.rb
|
136
137
|
- test/test_backup_timestamp.rb
|
137
|
-
- test/
|
138
|
+
- test/test_config.rb
|
139
|
+
- test/test_crypto.rb
|
138
140
|
has_rdoc: true
|
139
141
|
homepage: http://github.com/TimothyKlim/encbs
|
140
142
|
licenses:
|
@@ -151,13 +153,13 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
151
153
|
version: '0'
|
152
154
|
segments:
|
153
155
|
- 0
|
154
|
-
hash:
|
156
|
+
hash: 59491317708756896
|
155
157
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
156
158
|
none: false
|
157
159
|
requirements:
|
158
|
-
- - ! '
|
160
|
+
- - ! '>='
|
159
161
|
- !ruby/object:Gem::Version
|
160
|
-
version:
|
162
|
+
version: '0'
|
161
163
|
requirements: []
|
162
164
|
rubyforge_project:
|
163
165
|
rubygems_version: 1.6.2
|
@@ -1,23 +0,0 @@
|
|
1
|
-
require File.expand_path('../helper', __FILE__)
|
2
|
-
|
3
|
-
class TestCrypto < Test::Unit::TestCase
|
4
|
-
def fixtures
|
5
|
-
File.expand_path('../fixtures/rsa_keys', __FILE__)
|
6
|
-
end
|
7
|
-
|
8
|
-
def create_keys!(bits = 4096)
|
9
|
-
Crypto.create_keys("#{fixtures}/rsa_key", "#{fixtures}/rsa_key.pub", bits)
|
10
|
-
end
|
11
|
-
|
12
|
-
def load_keys
|
13
|
-
@priv_key = Crypto::Key.from_file("#{fixtures}/rsa_key")
|
14
|
-
@pub_key = Crypto::Key.from_file("#{fixtures}/rsa_key.pub")
|
15
|
-
end
|
16
|
-
|
17
|
-
def test_create_keys
|
18
|
-
create_keys!
|
19
|
-
|
20
|
-
assert_not_nil File.open("#{fixtures}/rsa_key").read
|
21
|
-
assert_not_nil File.open("#{fixtures}/rsa_key.pub").read
|
22
|
-
end
|
23
|
-
end
|
data/test/test_jar.rb
DELETED
File without changes
|