s7 0.0.1

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.
Files changed (44) hide show
  1. data/ChangeLog +311 -0
  2. data/LICENCE +24 -0
  3. data/README +56 -0
  4. data/Rakefile +128 -0
  5. data/VERSION +1 -0
  6. data/bin/s7cli +27 -0
  7. data/lib/gettext.rb +28 -0
  8. data/lib/s7.rb +12 -0
  9. data/lib/s7/action.rb +7 -0
  10. data/lib/s7/attribute.rb +226 -0
  11. data/lib/s7/cipher.rb +110 -0
  12. data/lib/s7/configuration.rb +41 -0
  13. data/lib/s7/entry.rb +106 -0
  14. data/lib/s7/entry_collection.rb +44 -0
  15. data/lib/s7/entry_template.rb +10 -0
  16. data/lib/s7/exception.rb +116 -0
  17. data/lib/s7/file.rb +77 -0
  18. data/lib/s7/gpass_file.rb +202 -0
  19. data/lib/s7/key.rb +83 -0
  20. data/lib/s7/message_catalog.rb +5 -0
  21. data/lib/s7/s7_file.rb +47 -0
  22. data/lib/s7/s7cli.rb +213 -0
  23. data/lib/s7/s7cli/attribute_command.rb +69 -0
  24. data/lib/s7/s7cli/command.rb +210 -0
  25. data/lib/s7/s7cli/entry_collection_command.rb +63 -0
  26. data/lib/s7/s7cli/entry_command.rb +728 -0
  27. data/lib/s7/s7cli/option.rb +101 -0
  28. data/lib/s7/secret_generator.rb +30 -0
  29. data/lib/s7/undo_stack.rb +7 -0
  30. data/lib/s7/unicode_data.rb +29 -0
  31. data/lib/s7/utils.rb +37 -0
  32. data/lib/s7/world.rb +150 -0
  33. data/setup.rb +1585 -0
  34. data/test/s7/attribute_test.rb +45 -0
  35. data/test/s7/gpass_file_test.rb +169 -0
  36. data/test/s7/gpass_file_test/passwords.gps.empty +1 -0
  37. data/test/s7/gpass_file_test/passwords.gps.one_entry +2 -0
  38. data/test/s7/gpass_file_test/passwords.gps.three_entries +3 -0
  39. data/test/s7/gpass_file_test/passwords.gps.with_folders +0 -0
  40. data/test/s7/secret_generator_test.rb +29 -0
  41. data/test/s7/unicode_data_test.rb +28 -0
  42. data/test/s7/world_test.rb +35 -0
  43. data/test/test_helper.rb +19 -0
  44. metadata +108 -0
@@ -0,0 +1,45 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ require File.expand_path("../test_helper", File.dirname(__FILE__))
4
+ require "s7/attribute"
5
+
6
+ module S7
7
+ class BooleanAttributeTest < Test::Unit::TestCase
8
+ def test_display_value__true
9
+ attr = BooleanAttribute.new("value" => true)
10
+ assert_equal(_("Yes"), attr.display_value)
11
+ end
12
+
13
+ def test_display_value__false
14
+ attr = BooleanAttribute.new("value" => false)
15
+ assert_equal(_("No"), attr.display_value)
16
+ end
17
+
18
+ def test_display_value__secret
19
+ values = [true, false]
20
+ values.each do |value|
21
+ attr = BooleanAttribute.new("value" => value, "secret" => "true")
22
+ assert_equal("*", attr.display_value)
23
+ end
24
+ end
25
+ end
26
+
27
+ class DateTimeAttributeTest < Test::Unit::TestCase
28
+ def test_display_value
29
+ t = Time.mktime(2008, 10, 21, 18, 14, 30).to_datetime
30
+ attr = DateTimeAttribute.new("value" => t)
31
+ assert_equal("2008/10/21 18:14:30", attr.display_value)
32
+ end
33
+
34
+ def test_display_value__only_date
35
+ t = Time.mktime(2008, 10, 21, 0, 0, 0).to_datetime
36
+ attr = DateTimeAttribute.new("value" => t)
37
+ assert_equal("2008/10/21", attr.display_value)
38
+ end
39
+
40
+ def test_display_value__secret
41
+ attr = DateTimeAttribute.new("secret" => "true")
42
+ assert_equal("*", attr.display_value)
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,169 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ require File.expand_path("../test_helper", File.dirname(__FILE__))
4
+ require "s7/gpass_file"
5
+ require "time"
6
+
7
+ module S7
8
+ class GPassFileTest < Test::Unit::TestCase
9
+ # パスフレーズが不正な場合、 InvalidPassphrase 例外が発生する。
10
+ def test_read__invalid_passphrase
11
+ invalid_passphrases = ["", "1234", "qwert", "qwertyu", "QWERTY"]
12
+ file = GPassFile.new
13
+ invalid_passphrases.each do |s|
14
+ assert_raises(InvalidPassphrase) do
15
+ file.read(s, gpass_file_path("empty"))
16
+ end
17
+ end
18
+ end
19
+
20
+ # 機密情報がひとつもないファイルを読み込む。
21
+ def test_read__empty
22
+ file = GPassFile.new
23
+ res = file.read("qwerty", gpass_file_path("empty"))
24
+ assert(res.entries.empty?)
25
+ end
26
+
27
+ # 機密情報がひとつのファイルを読み込む。
28
+ def test_read__one_entry
29
+ file = GPassFile.new
30
+ res = file.read("qwerty", gpass_file_path("one_entry"))
31
+ entry = res.entries.first
32
+ assert_equal(1, entry.id)
33
+ assert_equal("entry1", entry.name)
34
+ assert_equal("This is entry 1.", entry.description)
35
+ assert_equal(Time.parse("2008-10-05 00:17:06").to_datetime, entry.created_at)
36
+ assert_equal(Time.parse("2008-10-05 00:17:06").to_datetime, entry.updated_at)
37
+ assert_equal("foo", entry.username)
38
+ assert_equal("1234", entry.password)
39
+ assert_equal(true, entry.expiration)
40
+ assert_equal(Time.parse("2009-10-05 09:00:00").to_datetime, entry.expire_at)
41
+ assert_equal([], entry.tags)
42
+ assert_equal(1, res.entries.length)
43
+ end
44
+
45
+ # 機密情報が 3 つのファイルを読み込む。
46
+ def test_read__three_entry
47
+ file = GPassFile.new
48
+ res = file.read("qwerty", gpass_file_path("three_entries"))
49
+
50
+ entry = res.entries[0]
51
+ assert_equal(1, entry.id)
52
+ assert_equal("entry1", entry.name)
53
+ assert_equal("This is entry 1.", entry.description)
54
+ assert_equal(Time.parse("2008-10-05 00:17:06").to_datetime, entry.created_at)
55
+ assert_equal(Time.parse("2008-10-05 00:17:06").to_datetime, entry.updated_at)
56
+ assert_equal("foo", entry.username)
57
+ assert_equal("1234", entry.password)
58
+ assert_equal(true, entry.expiration)
59
+ assert_equal(Time.parse("2009-10-05 09:00:00").to_datetime, entry.expire_at)
60
+ assert_equal("example.com", entry.hostname)
61
+ assert_equal([], entry.tags)
62
+
63
+ entry = res.entries[1]
64
+ assert_equal(2, entry.id)
65
+ assert_equal("entry2", entry.name)
66
+ assert_equal("This is entry 2.", entry.description)
67
+ assert_equal(Time.parse("2008-10-05 00:18:41").to_datetime, entry.created_at)
68
+ assert_equal(Time.parse("2008-10-05 00:18:41").to_datetime, entry.updated_at)
69
+ assert_equal("bar", entry.username)
70
+ assert_equal("5678", entry.password)
71
+ assert_equal(false, entry.expiration)
72
+ assert_equal("", entry.hostname)
73
+ assert_equal([], entry.tags)
74
+
75
+ entry = res.entries[2]
76
+ assert_equal(3, entry.id)
77
+ assert_equal("entry3", entry.name)
78
+ assert_equal("This is entry 3.", entry.description)
79
+ assert_equal(Time.parse("2008-10-05 00:19:15").to_datetime, entry.created_at)
80
+ assert_equal(Time.parse("2008-10-05 00:19:15").to_datetime, entry.updated_at)
81
+ assert_equal("baz", entry.username)
82
+ assert_equal("9876", entry.password)
83
+ assert_equal(false, entry.expiration)
84
+ assert_equal("", entry.hostname)
85
+ assert_equal([], entry.tags)
86
+
87
+ assert_equal(3, res.entries.length)
88
+ end
89
+
90
+ # フォルダを含むファイルを読み込む。
91
+ def test_read__with_folders
92
+ file = GPassFile.new
93
+ res = file.read("qwerty", gpass_file_path("with_folders"))
94
+
95
+ entry = res.entries[0]
96
+ assert_equal(1, entry.id)
97
+ assert_equal("entry1-1", entry.name)
98
+ assert_equal("This is entry 1-1.", entry.description)
99
+ assert_equal(Time.parse("2008-10-05 00:17:06").to_datetime, entry.created_at)
100
+ assert_equal(Time.parse("2008-10-05 00:20:58").to_datetime, entry.updated_at)
101
+ assert_equal("foo", entry.username)
102
+ assert_equal("1234", entry.password)
103
+ assert_equal(true, entry.expiration)
104
+ assert_equal(Time.parse("2009-10-05 09:00:00").to_datetime, entry.expire_at)
105
+ assert_equal("example.com", entry.hostname)
106
+ assert_equal(["folder1"], entry.tags)
107
+
108
+ entry = res.entries[1]
109
+ assert_equal(2, entry.id)
110
+ assert_equal("entry1-2", entry.name)
111
+ assert_equal("This is entry 1-2.", entry.description)
112
+ assert_equal(Time.parse("2008-10-05 00:20:33").to_datetime, entry.created_at)
113
+ assert_equal(Time.parse("2008-10-05 00:20:33").to_datetime, entry.updated_at)
114
+ assert_equal("", entry.username)
115
+ assert_equal("", entry.password)
116
+ assert_equal(false, entry.expiration)
117
+ assert_equal("", entry.hostname)
118
+ assert_equal(["folder1"], entry.tags)
119
+
120
+ entry = res.entries[2]
121
+ assert_equal(3, entry.id)
122
+ assert_equal("entry2-1", entry.name)
123
+ assert_equal("This is entry 2-1.", entry.description)
124
+ assert_equal(Time.parse("2008-10-05 00:18:41").to_datetime, entry.created_at)
125
+ assert_equal(Time.parse("2008-10-05 00:21:33").to_datetime, entry.updated_at)
126
+ assert_equal("bar", entry.username)
127
+ assert_equal("5678", entry.password)
128
+ assert_equal(false, entry.expiration)
129
+ assert_equal("", entry.hostname)
130
+ assert_equal(["folder2"], entry.tags)
131
+
132
+ entry = res.entries[3]
133
+ assert_equal(4, entry.id)
134
+ assert_equal("entry 2-2-1", entry.name)
135
+ assert_equal("This is entry 2-2-1.", entry.description)
136
+ assert_equal(Time.parse("2008-10-05 00:22:00").to_datetime, entry.created_at)
137
+ assert_equal(Time.parse("2008-10-05 00:22:00").to_datetime, entry.updated_at)
138
+ assert_equal("", entry.username)
139
+ assert_equal("", entry.password)
140
+ assert_equal(false, entry.expiration)
141
+ assert_equal("", entry.hostname)
142
+ assert_equal(["folder2", "folder2-2"], entry.tags)
143
+
144
+ entry = res.entries[4]
145
+ assert_equal(5, entry.id)
146
+ assert_equal("entry3", entry.name)
147
+ assert_equal("This is entry 3.", entry.description)
148
+ assert_equal(Time.parse("2008-10-05 00:19:15").to_datetime, entry.created_at)
149
+ assert_equal(Time.parse("2008-10-05 00:19:15").to_datetime, entry.updated_at)
150
+ assert_equal("baz", entry.username)
151
+ assert_equal("9876", entry.password)
152
+ assert_equal(false, entry.expiration)
153
+ assert_equal("", entry.hostname)
154
+ assert_equal([], entry.tags)
155
+
156
+ assert_equal(5, res.entries.length)
157
+ end
158
+
159
+ private
160
+
161
+ # 本テストで使用する GPass のファイル名を取得する。
162
+ # name には gpass_file_test/passwords.gps. より後の部分を指定する。
163
+ def gpass_file_path(name)
164
+ return File.join(File.dirname(__FILE__),
165
+ "gpass_file_test",
166
+ "passwords.gps." + name)
167
+ end
168
+ end
169
+ end
@@ -0,0 +1 @@
1
+ ���A2�I P{�Ɉ�H��N���
@@ -0,0 +1,2 @@
1
+ ���A2�I P{�Ɉ�H��N���M�Kdd6B�� ?nQ����o��
2
+ ՍG�&���j� ^+ҍ��z�e��N�2�R����A�`N�s�jB>�3FN:��?��i�/"
@@ -0,0 +1,3 @@
1
+ ���A2�I P{�Ɉ�H��N���M�Kdd6B�� ?nQ����o��
2
+ ՍG�&���j� ^+ҍ��z�e��N�2�R����A�`N�s�jB>�3FN:� ���1�B�u*��<�&��
3
+
@@ -0,0 +1,29 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ require File.expand_path("../test_helper", File.dirname(__FILE__))
4
+ require "s7/secret_generator"
5
+
6
+ module S7
7
+ class SecretGeneratorTest < Test::Unit::TestCase
8
+ def test_s_generate__length
9
+ (1..1000).each do |length|
10
+ value = SecretGenerator.generate(length: length)
11
+ assert_equal(length, value.length)
12
+ end
13
+ end
14
+
15
+ def test_s_generate__characters
16
+ value = SecretGenerator.generate(length: 100,
17
+ characters: [:upper_alphabet])
18
+ assert_equal("", value.delete("A-Z"))
19
+
20
+ value = SecretGenerator.generate(length: 100,
21
+ characters: [:lower_alphabet])
22
+ assert_equal("", value.delete("a-z"))
23
+
24
+ value = SecretGenerator.generate(length: 100,
25
+ characters: [:number])
26
+ assert_equal("", value.delete("0-9"))
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,28 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ require File.expand_path("../test_helper", File.dirname(__FILE__))
4
+ require "s7/unicode_data"
5
+
6
+ module S7
7
+ class UnicodeDataTest < Test::Unit::TestCase
8
+ include UnicodeData
9
+
10
+ def test_s_east_asian_width
11
+ # ASCIi
12
+ ("\u0020".."\u007D").each do |i|
13
+ assert_equal(:N, UnicodeData.east_asian_width(i.chr), "character=<#{i}>")
14
+ end
15
+ assert_equal(:N, UnicodeData.east_asian_width("\u203E"), "character=<\u203E>")
16
+
17
+ # 半角カナ
18
+ ("\uFF61".."\uFF9F").each do |i|
19
+ assert_equal(:H, UnicodeData.east_asian_width(i.chr), "character=<#{i}>")
20
+ end
21
+
22
+ # 上記以外
23
+ ("あ".."ん").each do |i|
24
+ assert_equal(:F, UnicodeData.east_asian_width(i.chr), "character=<#{i}>")
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,35 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ require File.expand_path("../test_helper", File.dirname(__FILE__))
4
+ require "s7/world"
5
+ require "tmpdir"
6
+
7
+ module S7
8
+ class WorldTest < Test::Unit::TestCase
9
+ def test_save__not_changed
10
+ world = World.new
11
+ tmpdir = Dir.mktmpdir
12
+ begin
13
+ world.base_dir = tmpdir
14
+ world.master_key = "qwerty"
15
+ world.save
16
+ assert_equal(false, File.file?(world.secrets_path))
17
+ ensure
18
+ FileUtils.remove_entry_secure(tmpdir)
19
+ end
20
+ end
21
+
22
+ def test_save__force
23
+ world = World.new
24
+ tmpdir = Dir.mktmpdir
25
+ begin
26
+ world.base_dir = tmpdir
27
+ world.master_key = "qwerty"
28
+ world.save(true)
29
+ assert_equal(true, File.file?(world.secrets_path))
30
+ ensure
31
+ FileUtils.remove_entry_secure(tmpdir)
32
+ end
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,19 @@
1
+ $:.unshift(File.expand_path("../lib", File.dirname(__FILE__)))
2
+
3
+ require "s7"
4
+ require "test/unit"
5
+ require "pp"
6
+ require "tempfile"
7
+ require "stringio"
8
+ require "gettext"
9
+
10
+ class Test::Unit::TestCase
11
+ include GetText
12
+
13
+ def tempfile_path
14
+ tempfile = Tempfile.new("tempfile_path")
15
+ path = tempfile.path
16
+ tempfile.close(true)
17
+ return path
18
+ end
19
+ end
metadata ADDED
@@ -0,0 +1,108 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: s7
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - TAKAO Kouji
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-02-02 00:00:00 +09:00
13
+ default_executable: s7cli
14
+ dependencies: []
15
+
16
+ description: s7 (seven) is the secret informations(password, credit number, file, etc..) manager.
17
+ email: kouji@takao7.net
18
+ executables:
19
+ - s7cli
20
+ extensions: []
21
+
22
+ extra_rdoc_files:
23
+ - README
24
+ files:
25
+ - ChangeLog
26
+ - LICENCE
27
+ - README
28
+ - Rakefile
29
+ - VERSION
30
+ - bin/s7cli
31
+ - lib/gettext.rb
32
+ - lib/s7
33
+ - lib/s7/action.rb
34
+ - lib/s7/attribute.rb
35
+ - lib/s7/cipher.rb
36
+ - lib/s7/configuration.rb
37
+ - lib/s7/entry.rb
38
+ - lib/s7/entry_collection.rb
39
+ - lib/s7/entry_template.rb
40
+ - lib/s7/exception.rb
41
+ - lib/s7/file.rb
42
+ - lib/s7/gpass_file.rb
43
+ - lib/s7/key.rb
44
+ - lib/s7/message_catalog.rb
45
+ - lib/s7/s7_file.rb
46
+ - lib/s7/s7cli
47
+ - lib/s7/s7cli/attribute_command.rb
48
+ - lib/s7/s7cli/command.rb
49
+ - lib/s7/s7cli/entry_collection_command.rb
50
+ - lib/s7/s7cli/entry_command.rb
51
+ - lib/s7/s7cli/option.rb
52
+ - lib/s7/s7cli.rb
53
+ - lib/s7/secret_generator.rb
54
+ - lib/s7/undo_stack.rb
55
+ - lib/s7/unicode_data.rb
56
+ - lib/s7/utils.rb
57
+ - lib/s7/world.rb
58
+ - lib/s7.rb
59
+ - test/s7
60
+ - test/s7/attribute_test.rb
61
+ - test/s7/gpass_file_test
62
+ - test/s7/gpass_file_test/passwords.gps.empty
63
+ - test/s7/gpass_file_test/passwords.gps.one_entry
64
+ - test/s7/gpass_file_test/passwords.gps.three_entries
65
+ - test/s7/gpass_file_test/passwords.gps.with_folders
66
+ - test/s7/gpass_file_test.rb
67
+ - test/s7/secret_generator_test.rb
68
+ - test/s7/unicode_data_test.rb
69
+ - test/s7/world_test.rb
70
+ - test/test_helper.rb
71
+ - setup.rb
72
+ has_rdoc: true
73
+ homepage: http://code.google.com/p/s7-seven/
74
+ post_install_message:
75
+ rdoc_options:
76
+ - --line-numbers
77
+ - --inline-source
78
+ - --title
79
+ - s7
80
+ - --main
81
+ - README
82
+ require_paths:
83
+ - lib
84
+ required_ruby_version: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - ">="
87
+ - !ruby/object:Gem::Version
88
+ version: 1.9.1
89
+ version:
90
+ required_rubygems_version: !ruby/object:Gem::Requirement
91
+ requirements:
92
+ - - ">="
93
+ - !ruby/object:Gem::Version
94
+ version: "0"
95
+ version:
96
+ requirements:
97
+ - Ruby, version 1.9.1 (or newer)
98
+ rubyforge_project: s7-seven
99
+ rubygems_version: 1.3.1
100
+ signing_key:
101
+ specification_version: 2
102
+ summary: The secret informations manager.
103
+ test_files:
104
+ - test/s7/attribute_test.rb
105
+ - test/s7/gpass_file_test.rb
106
+ - test/s7/secret_generator_test.rb
107
+ - test/s7/unicode_data_test.rb
108
+ - test/s7/world_test.rb