siba 0.4.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +7 -0
- data/Gemfile +4 -0
- data/Guardfile +18 -0
- data/LICENSE +22 -0
- data/README.md +47 -0
- data/Rakefile +27 -0
- data/bin/siba +5 -0
- data/lib/siba.rb +27 -0
- data/lib/siba/backup.rb +31 -0
- data/lib/siba/console.rb +196 -0
- data/lib/siba/errors.rb +8 -0
- data/lib/siba/generator.rb +115 -0
- data/lib/siba/globals.rb +19 -0
- data/lib/siba/helpers/encoding_helper.rb +38 -0
- data/lib/siba/helpers/file_helper.rb +89 -0
- data/lib/siba/helpers/gem_helper.rb +22 -0
- data/lib/siba/helpers/password_strength.rb +94 -0
- data/lib/siba/helpers/security_helper.rb +30 -0
- data/lib/siba/helpers/string_helper.rb +32 -0
- data/lib/siba/helpers/test/extend_test.rb +114 -0
- data/lib/siba/helpers/test/file_mock.rb +38 -0
- data/lib/siba/helpers/test/helper.rb +55 -0
- data/lib/siba/helpers/test/kernel_mock.rb +44 -0
- data/lib/siba/helpers/test/removable_constants.rb +18 -0
- data/lib/siba/helpers/test/require.rb +12 -0
- data/lib/siba/logger_plug.rb +36 -0
- data/lib/siba/options_backup.rb +37 -0
- data/lib/siba/options_loader.rb +38 -0
- data/lib/siba/plugins/archive/tar/archive.rb +117 -0
- data/lib/siba/plugins/archive/tar/init.rb +38 -0
- data/lib/siba/plugins/archive/tar/options.yml +1 -0
- data/lib/siba/plugins/destination/dir/dest_dir.rb +77 -0
- data/lib/siba/plugins/destination/dir/init.rb +31 -0
- data/lib/siba/plugins/destination/dir/options.yml +2 -0
- data/lib/siba/plugins/encryption/gpg/encryption.rb +140 -0
- data/lib/siba/plugins/encryption/gpg/init.rb +45 -0
- data/lib/siba/plugins/encryption/gpg/options.yml +2 -0
- data/lib/siba/plugins/installed_plugins.rb +77 -0
- data/lib/siba/plugins/plugin_loader.rb +100 -0
- data/lib/siba/plugins/plugins.rb +57 -0
- data/lib/siba/plugins/plugins.yml +9 -0
- data/lib/siba/plugins/source/files/files.rb +166 -0
- data/lib/siba/plugins/source/files/init.rb +33 -0
- data/lib/siba/plugins/source/files/options.yml +11 -0
- data/lib/siba/restore.rb +113 -0
- data/lib/siba/scaffold.rb +166 -0
- data/lib/siba/siba_check.rb +75 -0
- data/lib/siba/siba_file.rb +89 -0
- data/lib/siba/siba_kernel.rb +37 -0
- data/lib/siba/siba_logger.rb +172 -0
- data/lib/siba/tasks/siba_task.rb +42 -0
- data/lib/siba/tasks/siba_tasks.rb +120 -0
- data/lib/siba/test_files.rb +76 -0
- data/lib/siba/test_files/a_file +1 -0
- data/lib/siba/test_files/files_and_dirs/.hidden +1 -0
- data/lib/siba/test_files/files_and_dirs/.hidden_dir/file10 +1 -0
- data/lib/siba/test_files/files_and_dirs/File With Spaces +1 -0
- data/lib/siba/test_files/files_and_dirs/dir1/file10 +1 -0
- data/lib/siba/test_files/files_and_dirs/dir1/sub-dir/file111.txt +1 -0
- data/lib/siba/test_files/files_and_dirs/file1 +1 -0
- data/lib/siba/test_files/files_and_dirs/file2.txt +1 -0
- data/lib/siba/tmp_dir.rb +94 -0
- data/lib/siba/version.rb +5 -0
- data/scaffolds/archive.rb +26 -0
- data/scaffolds/destination.rb +20 -0
- data/scaffolds/encryption.rb +26 -0
- data/scaffolds/project/.gitignore +5 -0
- data/scaffolds/project/Gemfile +4 -0
- data/scaffolds/project/Guardfile +9 -0
- data/scaffolds/project/LICENSE +22 -0
- data/scaffolds/project/README.md +33 -0
- data/scaffolds/project/Rakefile +28 -0
- data/scaffolds/project/lib/siba-c6y-demo.rb +11 -0
- data/scaffolds/project/lib/siba-c6y-demo/options.yml +2 -0
- data/scaffolds/project/lib/siba-c6y-demo/version.rb +9 -0
- data/scaffolds/project/siba-c6y-demo.gemspec +26 -0
- data/scaffolds/project/test/helper/require_integration.rb +5 -0
- data/scaffolds/project/test/helper/require_unit.rb +4 -0
- data/scaffolds/project/test/integration/i9n_init.rb +35 -0
- data/scaffolds/project/test/unit/test_init.rb +43 -0
- data/scaffolds/project/test/unit/yml/valid.yml +8 -0
- data/scaffolds/shared/examples.rb +47 -0
- data/scaffolds/shared/init_example.rb +13 -0
- data/scaffolds/source.rb +25 -0
- data/siba.gemspec +30 -0
- data/test/helper/require_integration.rb +4 -0
- data/test/helper/require_unit.rb +4 -0
- data/test/integration/helpers/i9n_file_helper.rb +50 -0
- data/test/integration/i9n_backup.rb +53 -0
- data/test/integration/i9n_console.rb +16 -0
- data/test/integration/i9n_generator.rb +29 -0
- data/test/integration/i9n_options_backup.rb +22 -0
- data/test/integration/i9n_scaffold.rb +27 -0
- data/test/integration/i9n_siba_file.rb +30 -0
- data/test/integration/i9n_test_unicode_files.rb +40 -0
- data/test/integration/i9n_tmp_dir.rb +44 -0
- data/test/integration/plugins/archive/tar/i9n_archive.rb +18 -0
- data/test/integration/plugins/destination/dir/i9n_dest_dir.rb +52 -0
- data/test/integration/plugins/encryption/gpg/i9n_encryption.rb +87 -0
- data/test/integration/plugins/i9n_installed_plugins.rb +13 -0
- data/test/integration/plugins/source/files/i9n_files.rb +146 -0
- data/test/integration/tasks/i9n_siba_tasks.rb +30 -0
- data/test/integration/yml/valid.yml +16 -0
- data/test/unit/helpers/test_encoding_helper.rb +17 -0
- data/test/unit/helpers/test_gem_helper.rb +17 -0
- data/test/unit/helpers/test_security_helper.rb +21 -0
- data/test/unit/helpers/test_string_helper.rb +35 -0
- data/test/unit/plugins/archive/tar/test_archive.rb +41 -0
- data/test/unit/plugins/archive/tar/test_init.rb +36 -0
- data/test/unit/plugins/archive/tar/yml/archive/check_installed.yml +2 -0
- data/test/unit/plugins/archive/tar/yml/init/default_compression.yml +1 -0
- data/test/unit/plugins/archive/tar/yml/init/invalid_compression.yml +2 -0
- data/test/unit/plugins/archive/tar/yml/init/valid.yml +2 -0
- data/test/unit/plugins/destination/dir/test_dest_dir.rb +41 -0
- data/test/unit/plugins/destination/dir/test_init.rb +36 -0
- data/test/unit/plugins/destination/dir/yml/init/valid.yml +2 -0
- data/test/unit/plugins/encryption/gpg/test_encryption.rb +70 -0
- data/test/unit/plugins/encryption/gpg/test_init.rb +47 -0
- data/test/unit/plugins/source/files/test_files.rb +44 -0
- data/test/unit/plugins/source/files/test_init.rb +48 -0
- data/test/unit/plugins/source/files/test_path_match.rb +140 -0
- data/test/unit/plugins/source/files/yml/ignore_list.yml +8 -0
- data/test/unit/plugins/source/files/yml/ignore_not_array.yml +5 -0
- data/test/unit/plugins/source/files/yml/include_not_array.yml +3 -0
- data/test/unit/plugins/source/files/yml/include_subdirs_false.yml +6 -0
- data/test/unit/plugins/source/files/yml/include_subdirs_missing.yml +5 -0
- data/test/unit/plugins/source/files/yml/no_ignore.yml +4 -0
- data/test/unit/plugins/source/files/yml/no_include.yml +1 -0
- data/test/unit/plugins/source/files/yml/valid.yml +9 -0
- data/test/unit/plugins/test_installed_plugins.rb +32 -0
- data/test/unit/plugins/test_plugin_loader.rb +27 -0
- data/test/unit/plugins/test_plugins.rb +44 -0
- data/test/unit/tasks/test_siba_task.rb +30 -0
- data/test/unit/tasks/test_siba_tasks.rb +84 -0
- data/test/unit/tasks/yml/task/invalid.yml +4 -0
- data/test/unit/tasks/yml/task/valid.yml +7 -0
- data/test/unit/test_backup.rb +18 -0
- data/test/unit/test_console.rb +166 -0
- data/test/unit/test_generator.rb +21 -0
- data/test/unit/test_globals.rb +34 -0
- data/test/unit/test_log_message.rb +26 -0
- data/test/unit/test_logger_plug.rb +49 -0
- data/test/unit/test_options_backup.rb +21 -0
- data/test/unit/test_options_loader.rb +72 -0
- data/test/unit/test_password_strength.rb +76 -0
- data/test/unit/test_restore.rb +18 -0
- data/test/unit/test_scaffold.rb +26 -0
- data/test/unit/test_siba_check.rb +118 -0
- data/test/unit/test_siba_logger.rb +174 -0
- data/test/unit/test_tmp_dir.rb +21 -0
- data/test/unit/yml/options_loader/array.yml +2 -0
- data/test/unit/yml/options_loader/empty.yml +0 -0
- data/test/unit/yml/options_loader/invalid.yml +4 -0
- data/test/unit/yml/options_loader/string.yml +1 -0
- data/test/unit/yml/options_loader/utf8_with_bom.yml +2 -0
- data/test/unit/yml/options_loader/valid.yml +12 -0
- data/test/unit/yml/siba_options_backup.yml +20 -0
- data/test/unit/yml/valid.yml +18 -0
- metadata +240 -0
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
# encoding: UTF-8
|
|
2
|
+
|
|
3
|
+
require 'helper/require_unit'
|
|
4
|
+
|
|
5
|
+
describe Siba::Console do
|
|
6
|
+
before do
|
|
7
|
+
@console = Siba::Console.new true
|
|
8
|
+
@yml_path = File.expand_path('../yml', __FILE__)
|
|
9
|
+
@path_to_yml = File.join @yml_path, "valid.yml"
|
|
10
|
+
@unused = Siba::Console::UNUSED_COMMAND
|
|
11
|
+
Siba::LoggerPlug.close
|
|
12
|
+
Siba::SibaLogger.quiet = true
|
|
13
|
+
Siba::SibaLogger.no_log = true
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
it "should parse console command" do
|
|
17
|
+
@console.parse ["-h"]
|
|
18
|
+
@console.parse ["-help"]
|
|
19
|
+
@console.parse ["--version"]
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
it "should accept quiet mode with q" do
|
|
23
|
+
Siba::SibaLogger.quiet = false
|
|
24
|
+
@console.parse [@unused, "-q"]
|
|
25
|
+
Siba::SibaLogger.quiet.must_equal true
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
it "should accept quiet mode with quiet" do
|
|
29
|
+
Siba::SibaLogger.quiet = false
|
|
30
|
+
@console.parse [@unused, "--quiet"]
|
|
31
|
+
Siba::SibaLogger.quiet.must_equal true
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
it "should accept verbose mode with v" do
|
|
35
|
+
Siba::SibaLogger.verbose = false
|
|
36
|
+
@console.parse [@unused, "-v"]
|
|
37
|
+
Siba::SibaLogger.verbose.must_equal true
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
it "should accept quiet mode with quiet" do
|
|
41
|
+
Siba::SibaLogger.verbose = false
|
|
42
|
+
@console.parse [@unused, "--verbose"]
|
|
43
|
+
Siba::SibaLogger.verbose.must_equal true
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
it "should accept log switch" do
|
|
47
|
+
Siba::SibaLogger.no_log = false
|
|
48
|
+
@console.parse [@unused, "--log=/test"]
|
|
49
|
+
@console.options["log"].must_equal "/test"
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
it "should accept no-log switch" do
|
|
53
|
+
Siba::SibaLogger.no_log = false
|
|
54
|
+
@console.parse [@unused, "--no-log"]
|
|
55
|
+
Siba::SibaLogger.no_log.must_equal true
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
it "should fail when using both log and no-log" do
|
|
59
|
+
Siba::SibaLogger.no_log = false
|
|
60
|
+
->{@console.parse [@unused, "--no-log", "--log=test"]}.must_raise Siba::ConsoleArgumentError
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
it "should fail when arguments are invalid" do
|
|
64
|
+
->{@console.parse ["-unknown"]}.must_raise OptionParser::InvalidOption
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
it "should fail when invalid command" do
|
|
68
|
+
->{@console.parse ["invalid"]}.must_raise Siba::ConsoleArgumentError
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
it "should fail when missing a command" do
|
|
72
|
+
->{@console.parse ["-v"]}.must_raise Siba::ConsoleArgumentError
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
it "should show no errors with not arguments" do
|
|
76
|
+
@console.parse []
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
describe "when run backup command" do
|
|
80
|
+
it "should run b command" do
|
|
81
|
+
@console.parse ["b", @path_to_yml]
|
|
82
|
+
wont_log_from "warn"
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
it "should run backup command" do
|
|
86
|
+
@console.parse ["backup", @path_to_yml]
|
|
87
|
+
wont_log_from "warn"
|
|
88
|
+
end
|
|
89
|
+
|
|
90
|
+
it "should fail when backup options file is missing" do
|
|
91
|
+
->{@console.parse ["backup"]}.must_raise Siba::ConsoleArgumentError
|
|
92
|
+
end
|
|
93
|
+
|
|
94
|
+
it "should fail when needless arguments are specified" do
|
|
95
|
+
->{@console.parse ["backup", "one", "two"]}.must_raise Siba::ConsoleArgumentError
|
|
96
|
+
end
|
|
97
|
+
end
|
|
98
|
+
|
|
99
|
+
describe "when run scaffold commend" do
|
|
100
|
+
it "should run b command" do
|
|
101
|
+
@console.parse ["s", "source", "myname"]
|
|
102
|
+
end
|
|
103
|
+
|
|
104
|
+
it "should run backup command" do
|
|
105
|
+
@console.parse ["scaffold", "destination", "myname"]
|
|
106
|
+
end
|
|
107
|
+
|
|
108
|
+
it "scaffold should fail when category is missing" do
|
|
109
|
+
->{@console.parse ["s"]}.must_raise Siba::ConsoleArgumentError
|
|
110
|
+
end
|
|
111
|
+
|
|
112
|
+
it "scaffold should fail when category is incorrect" do
|
|
113
|
+
->{@console.parse ["s", "incorrect"]}.must_raise Siba::ConsoleArgumentError
|
|
114
|
+
end
|
|
115
|
+
|
|
116
|
+
it "scaffold should fail when name is missing" do
|
|
117
|
+
->{@console.parse ["s", "destination"]}.must_raise Siba::ConsoleArgumentError
|
|
118
|
+
end
|
|
119
|
+
|
|
120
|
+
it "should fail when needless arguments are specified" do
|
|
121
|
+
->{@console.parse ["s", "source", "name", "needless"]}.must_raise Siba::ConsoleArgumentError
|
|
122
|
+
end
|
|
123
|
+
end
|
|
124
|
+
|
|
125
|
+
describe "when run list commend" do
|
|
126
|
+
it "should run l command" do
|
|
127
|
+
@console.parse ["l"]
|
|
128
|
+
end
|
|
129
|
+
|
|
130
|
+
it "should run list command" do
|
|
131
|
+
@console.parse ["list"]
|
|
132
|
+
end
|
|
133
|
+
end
|
|
134
|
+
|
|
135
|
+
describe "when run generate commend" do
|
|
136
|
+
it "should run g command" do
|
|
137
|
+
@console.parse ["g", "myfile"]
|
|
138
|
+
end
|
|
139
|
+
|
|
140
|
+
it "should run generate command" do
|
|
141
|
+
@console.parse ["generate", "myfile"]
|
|
142
|
+
end
|
|
143
|
+
|
|
144
|
+
it "should fail if file name is missing" do
|
|
145
|
+
->{@console.parse ["g"]}.must_raise Siba::ConsoleArgumentError
|
|
146
|
+
end
|
|
147
|
+
end
|
|
148
|
+
|
|
149
|
+
describe "when run restore command" do
|
|
150
|
+
it "should run r command" do
|
|
151
|
+
@console.parse ["r", @path_to_yml]
|
|
152
|
+
end
|
|
153
|
+
|
|
154
|
+
it "should run restore command" do
|
|
155
|
+
@console.parse ["restore", @path_to_yml]
|
|
156
|
+
end
|
|
157
|
+
|
|
158
|
+
it "should fail when backup options file is missing" do
|
|
159
|
+
->{@console.parse ["restore"]}.must_raise Siba::ConsoleArgumentError
|
|
160
|
+
end
|
|
161
|
+
|
|
162
|
+
it "should fail when needless arguments are specified" do
|
|
163
|
+
->{@console.parse ["restore", "one", "two"]}.must_raise Siba::ConsoleArgumentError
|
|
164
|
+
end
|
|
165
|
+
end
|
|
166
|
+
end
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
# encoding: UTF-8
|
|
2
|
+
|
|
3
|
+
require 'helper/require_unit'
|
|
4
|
+
|
|
5
|
+
describe Siba::Generator do
|
|
6
|
+
before do
|
|
7
|
+
@obj = Siba::Generator.new("file")
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
it "should call generate" do
|
|
11
|
+
@obj.generate
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
it "should call get_plugin_yaml_path" do
|
|
15
|
+
Siba::Generator.get_plugin_yaml_path "source", "files"
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
it "should call load_plugin_yaml_content" do
|
|
19
|
+
Siba::Generator.load_plugin_yaml_content "source", "files"
|
|
20
|
+
end
|
|
21
|
+
end
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
# encoding: UTF-8
|
|
2
|
+
|
|
3
|
+
require 'helper/require_unit'
|
|
4
|
+
|
|
5
|
+
describe Siba do
|
|
6
|
+
it "should access settings" do
|
|
7
|
+
Siba.settings
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
it "should get tmp_dir" do
|
|
11
|
+
Siba.tmp_dir.must_equal SibaTest::TmpDirMocked
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
it "should cleanup tmp dir" do
|
|
15
|
+
Siba.tmp_dir
|
|
16
|
+
Siba.cleanup_tmp_dir
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
it "should call cleanup" do
|
|
20
|
+
Siba::LoggerPlug.opened?.must_equal true
|
|
21
|
+
Siba.tmp_dir_clean?.must_equal false
|
|
22
|
+
Siba.cleanup
|
|
23
|
+
Siba::LoggerPlug.opened?.must_equal false
|
|
24
|
+
Siba.tmp_dir_clean?.must_equal true
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
it "should get current_dir" do
|
|
28
|
+
Siba.current_dir.wont_be_nil
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
it "should get settings" do
|
|
32
|
+
Siba.settings.wont_be_nil
|
|
33
|
+
end
|
|
34
|
+
end
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
# encoding: UTF-8
|
|
2
|
+
|
|
3
|
+
require 'helper/require_unit'
|
|
4
|
+
|
|
5
|
+
describe Siba::LogMessage do
|
|
6
|
+
before do
|
|
7
|
+
@message = Siba::LogMessage.new
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
it "should contain level" do
|
|
11
|
+
@message.level = 2
|
|
12
|
+
@message.level.must_equal 2
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
it "should contain time" do
|
|
16
|
+
time = Time.now
|
|
17
|
+
@message.time = time
|
|
18
|
+
@message.time.must_equal time
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
it "should contain msg" do
|
|
22
|
+
msg = "hey"
|
|
23
|
+
@message.msg = msg
|
|
24
|
+
@message.msg.must_equal msg
|
|
25
|
+
end
|
|
26
|
+
end
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
# encoding: UTF-8
|
|
2
|
+
|
|
3
|
+
require 'helper/require_unit'
|
|
4
|
+
|
|
5
|
+
describe Siba::LoggerPlug do
|
|
6
|
+
describe "when accessing LoggerPlug class" do
|
|
7
|
+
it "must create logger" do
|
|
8
|
+
Siba::LoggerPlug.close
|
|
9
|
+
Siba::SibaLogger.quiet = true
|
|
10
|
+
Siba::LoggerPlug.create "Log",nil
|
|
11
|
+
Siba::SibaLogger.count.must_equal 1
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
it "must create logger without start message" do
|
|
15
|
+
Siba::LoggerPlug.close
|
|
16
|
+
Siba::SibaLogger.quiet = true
|
|
17
|
+
Siba::LoggerPlug.create "Log", nil, false
|
|
18
|
+
Siba::SibaLogger.count.must_equal 0
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
it "must have logger" do
|
|
22
|
+
Siba::LoggerPlug.logger.wont_be_nil
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
it "must have logger of type SibaLogger" do
|
|
26
|
+
Siba::LoggerPlug.logger.must_be_instance_of Siba::SibaLogger
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
it "must include logger instance method" do
|
|
30
|
+
Siba::LoggerPlug.instance_methods.must_include :logger
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
it "must call opened?" do
|
|
34
|
+
Siba::LoggerPlug.opened?.must_equal true, "should be opened"
|
|
35
|
+
Siba::LoggerPlug.close
|
|
36
|
+
Siba::LoggerPlug.opened?.must_equal false, "should be closed"
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
it "must call close" do
|
|
40
|
+
Siba::SibaLogger.quiet = true
|
|
41
|
+
Siba::SibaLogger.verbose = true
|
|
42
|
+
Siba::SibaLogger.no_log = true
|
|
43
|
+
Siba::LoggerPlug.close
|
|
44
|
+
Siba::SibaLogger.quiet.must_equal false
|
|
45
|
+
Siba::SibaLogger.verbose.must_equal false
|
|
46
|
+
Siba::SibaLogger.no_log.must_equal false
|
|
47
|
+
end
|
|
48
|
+
end
|
|
49
|
+
end
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
# encoding: UTF-8
|
|
2
|
+
|
|
3
|
+
require 'helper/require_unit'
|
|
4
|
+
|
|
5
|
+
describe Siba::OptionsBackup do
|
|
6
|
+
before do
|
|
7
|
+
@cls = Siba::OptionsBackup
|
|
8
|
+
@yml_path = File.expand_path('../yml', __FILE__)
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
it "should call save_options_backup" do
|
|
12
|
+
@cls.save_options_backup File.join(@yml_path, "valid.yml"), "/dir"
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
it "should call load_source_from_backup" do
|
|
16
|
+
options = load_options Siba::OptionsBackup::OPTIONS_BACKUP_FILE_NAME
|
|
17
|
+
new_task = @cls.load_source_from_backup @yml_path
|
|
18
|
+
new_task.must_be_instance_of Siba::SibaTask
|
|
19
|
+
Siba.current_dir.must_equal options["current_dir"]
|
|
20
|
+
end
|
|
21
|
+
end
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
# encoding: UTF-8
|
|
2
|
+
|
|
3
|
+
require 'helper/require_unit'
|
|
4
|
+
|
|
5
|
+
class OptionsLoaderTest < MiniTest::Unit::TestCase
|
|
6
|
+
def setup
|
|
7
|
+
@yml_path = File.expand_path('../yml/options_loader', __FILE__)
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
def test_load_yml
|
|
11
|
+
load_options "valid"
|
|
12
|
+
assert_instance_of Hash, @options
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def test_load_hash_from_yml
|
|
16
|
+
hash = Siba::OptionsLoader.load_hash_from_yml File.join(@yml_path, "valid.yml")
|
|
17
|
+
assert_instance_of Hash, hash
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def test_load_erb
|
|
21
|
+
data = Siba::OptionsLoader.load_erb File.join(@yml_path, "valid.yml")
|
|
22
|
+
assert_instance_of String, data
|
|
23
|
+
refute_empty data
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def test_load_yml_check_erb
|
|
27
|
+
load_options "valid"
|
|
28
|
+
assert_equal 4, @options["erb"]
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
def test_should_fail_if_options_file_does_not_have_yml_extension
|
|
32
|
+
path = File.join @yml_path, "file_without_yml_extension"
|
|
33
|
+
assert_raises(Siba::Error) do
|
|
34
|
+
Siba::OptionsLoader.load_yml(path)
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
def test_load_file_missing
|
|
39
|
+
assert_raises(Siba::Error) do
|
|
40
|
+
load_options "missing"
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
def test_load_invalid_yml
|
|
45
|
+
assert_raises(Siba::Error) do
|
|
46
|
+
load_options "invalid"
|
|
47
|
+
end
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
def test_should_not_load_empty_yml
|
|
51
|
+
assert_raises(Siba::Error) do
|
|
52
|
+
load_options "empty"
|
|
53
|
+
end
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
def test_should_not_load_yml_with_string
|
|
57
|
+
assert_raises(Siba::Error) do
|
|
58
|
+
load_options "string"
|
|
59
|
+
end
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
def test_should_not_load_yml_with_array
|
|
63
|
+
assert_raises(Siba::Error) do
|
|
64
|
+
load_options "array"
|
|
65
|
+
end
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
def test_load_yml_with_bom
|
|
69
|
+
options = load_options("utf8_with_bom")
|
|
70
|
+
assert_equal options["key"], "value"
|
|
71
|
+
end
|
|
72
|
+
end
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
# encoding: UTF-8
|
|
2
|
+
|
|
3
|
+
require 'helper/require_unit'
|
|
4
|
+
require 'siba/helpers/password_strength'
|
|
5
|
+
|
|
6
|
+
describe Siba::PasswordStrength do
|
|
7
|
+
before do
|
|
8
|
+
@ps = Siba::PasswordStrength
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
it "should run seconds_to_crack" do
|
|
12
|
+
Siba::PasswordStrength.seconds_to_crack("Pass123$").round(2).must_equal 67.05
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
it "runs seconds_to_crack with a very long password" do
|
|
16
|
+
Siba::PasswordStrength.seconds_to_crack("very lonG p@asswoRd very lonG p@asswoRd very lonG p@asswoRd
|
|
17
|
+
very lonG p@asswoRd very lonG p@asswoRd very lonG p@asswoRd very lonG p@asswoRd very lonG p@asswoRd
|
|
18
|
+
very lonG p@asswoRd very lonG p@asswoRd very lonG p@asswoRd very lonG p@asswoRd very lonG p@asswoRd
|
|
19
|
+
very lonG p@asswoRd very lonG p@asswoRd very lonG p@asswoRd very lonG p@asswoRd very lonG p@asswoRd
|
|
20
|
+
very lonG p@asswoRd very lonG p@asswoRd very lonG p@asswoRd very lonG p@asswoRd very lonG p@asswoRd
|
|
21
|
+
very lonG p@asswoRd very lonG p@asswoRd very lonG p@asswoRd very lonG p@asswoRd very lonG p@asswoRd
|
|
22
|
+
very lonG p@asswoRd very lonG p@asswoRd very lonG p@asswoRd very lonG p@asswoRd very lonG p@asswoRd
|
|
23
|
+
very lonG p@asswoRd very lonG p@asswoRd very lonG p@asswoRd very lonG p@asswoRd very lonG p@asswoRd
|
|
24
|
+
very lonG p@asswoRd very lonG p@asswoRd very lonG p@asswoRd very lonG p@asswoRd very lonG p@asswoRd
|
|
25
|
+
very lonG p@asswoRd very lonG p@asswoRd very lonG p@asswoRd very lonG p@asswoRd very lonG p@asswoRd
|
|
26
|
+
very lonG p@asswoRd very lonG p@asswoRd very lonG p@asswoRd very lonG p@asswoRd very lonG p@asswoRd").must_equal Float::INFINITY
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
it "should run in_weak?" do
|
|
30
|
+
Siba::PasswordStrength.is_weak?(10).must_equal true
|
|
31
|
+
Siba::PasswordStrength.is_weak?(60*60*24).must_equal true
|
|
32
|
+
Siba::PasswordStrength.is_weak?(60*60*24*365).must_equal false
|
|
33
|
+
Siba::PasswordStrength.is_weak?(1000*60*60*24*365).must_equal false
|
|
34
|
+
Siba::PasswordStrength.is_weak?(Float::INFINITY).must_equal false
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
it "should run seconds_to_timespan" do
|
|
38
|
+
two_cents = 200 * 365 * 86400
|
|
39
|
+
thousand = 1000
|
|
40
|
+
million = 1000 * 1000
|
|
41
|
+
billion = 1000 * 1000 * 1000
|
|
42
|
+
|
|
43
|
+
valid_strings = [
|
|
44
|
+
[0.2, "less than a second"],
|
|
45
|
+
[0.5, "less than a second"],
|
|
46
|
+
[1, "1 second"],
|
|
47
|
+
[2, "2 seconds"],
|
|
48
|
+
[59, "59 seconds"],
|
|
49
|
+
[60, "1 minute"],
|
|
50
|
+
[80, "1 minute"],
|
|
51
|
+
[110, "1 minute"],
|
|
52
|
+
[3599, "59 minutes"],
|
|
53
|
+
[3600, "1 hour"],
|
|
54
|
+
[43202, "12 hours"],
|
|
55
|
+
[86403, "1 day"],
|
|
56
|
+
[1209606, "14 days"],
|
|
57
|
+
[2592000, "1 month"],
|
|
58
|
+
[8592000, "3 months"],
|
|
59
|
+
[365 * 86400, "1 year"],
|
|
60
|
+
[14 * 365 * 86400, "14 years"],
|
|
61
|
+
[100 * 365 * 86400, "1 century"],
|
|
62
|
+
[two_cents, "2 centuries"],
|
|
63
|
+
[100 * 100 * 365 * 86400, "1 hundred centuries"],
|
|
64
|
+
[100 * two_cents, "2 hundred centuries"],
|
|
65
|
+
[thousand * two_cents, "2 thousand centuries"],
|
|
66
|
+
[10 * thousand * two_cents, "20 thousand centuries"],
|
|
67
|
+
[million * two_cents, "2 million centuries"],
|
|
68
|
+
[billion * two_cents, "forever"],
|
|
69
|
+
[Float::INFINITY, "forever"]
|
|
70
|
+
]
|
|
71
|
+
|
|
72
|
+
valid_strings.each do |a|
|
|
73
|
+
Siba::PasswordStrength.seconds_to_timespan(a[0]).must_equal a[1]
|
|
74
|
+
end
|
|
75
|
+
end
|
|
76
|
+
end
|