purse 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +4 -0
- data/License.txt +20 -0
- data/Manifest.txt +15 -0
- data/PostInstall.txt +2 -0
- data/README.txt +82 -0
- data/Rakefile +4 -0
- data/bin/purse +6 -0
- data/lib/purse.rb +14 -0
- data/lib/purse/cli.rb +238 -0
- data/lib/purse/error.rb +10 -0
- data/lib/purse/help.txt +54 -0
- data/lib/purse/note.rb +62 -0
- data/lib/purse/pocket.rb +80 -0
- data/lib/purse/settings.rb +57 -0
- data/lib/purse/version.rb +9 -0
- data/test/purse/test_cli.rb +51 -0
- data/test/purse/test_note.rb +206 -0
- data/test/purse/test_pocket.rb +168 -0
- data/test/purse/test_settings.rb +141 -0
- data/test/test_helper.rb +49 -0
- metadata +90 -0
@@ -0,0 +1,168 @@
|
|
1
|
+
require 'test_helper.rb'
|
2
|
+
|
3
|
+
class TestPocket < Test::Unit::TestCase
|
4
|
+
|
5
|
+
context "Purse" do
|
6
|
+
context "Pocket" do
|
7
|
+
|
8
|
+
context "an instance" do
|
9
|
+
setup do
|
10
|
+
@pocket = Pocket.new(purse_path)
|
11
|
+
end
|
12
|
+
|
13
|
+
should "require a path" do
|
14
|
+
assert_raise(MissingParameter) do
|
15
|
+
Pocket.new(nil)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
context "initialize" do
|
20
|
+
|
21
|
+
should "assign path to @path" do
|
22
|
+
assert purse_path, @pocket.path
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
26
|
+
context "notes" do
|
27
|
+
|
28
|
+
setup do
|
29
|
+
@notes = @pocket.notes
|
30
|
+
end
|
31
|
+
|
32
|
+
should "find notes by Dir[]" do
|
33
|
+
assert Dir[purse_path + '/*.note'], @pocket.notes_paths
|
34
|
+
end
|
35
|
+
|
36
|
+
should "assign notes to an array in @notes" do
|
37
|
+
assert_set_of Note, @notes
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
context "find" do
|
42
|
+
setup do
|
43
|
+
Dir.expects(:[]).at_most_once.returns([File.join(purse_path, 'jagger.note')])
|
44
|
+
@notes = @pocket.notes
|
45
|
+
end
|
46
|
+
|
47
|
+
context "with a loaded note name" do
|
48
|
+
setup do
|
49
|
+
@note = @pocket.find('jagger')
|
50
|
+
end
|
51
|
+
|
52
|
+
should "return the note" do
|
53
|
+
assert @note.is_a?(Note)
|
54
|
+
assert_equal 'jagger', @note.name
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
context "with an unknown note" do
|
59
|
+
should "raise error" do
|
60
|
+
assert_raise(MissingFile) do
|
61
|
+
@pocket.find('bloober')
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
context "edit" do
|
68
|
+
should "yield the note to the block" do
|
69
|
+
@pocket.edit('jagger') do |note|
|
70
|
+
assert note.is_a?(Note)
|
71
|
+
assert_equal @pocket.find('jagger'), note
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
context "re_encrypt" do
|
77
|
+
should "require a password" do
|
78
|
+
assert_raise(MissingParameter) do
|
79
|
+
@pocket.re_encrypt(nil)
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
context "with a password" do
|
84
|
+
should "call save on each note" do
|
85
|
+
password = 'newpass'
|
86
|
+
Note.any_instance.stubs(:save).times(3).with(password)
|
87
|
+
@pocket.re_encrypt(password)
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
end
|
92
|
+
|
93
|
+
context "init" do
|
94
|
+
context "if the directory already exists" do
|
95
|
+
context "if the git directory already exists" do
|
96
|
+
should "not call Git init" do
|
97
|
+
Git.init(purse_path)
|
98
|
+
Git.expects(:init).once
|
99
|
+
@pocket.init
|
100
|
+
FileUtils.rm_rf(File.join(purse_path, '.git'))
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
104
|
+
context "if the git directory does not exist" do
|
105
|
+
should "initialize the git repo" do
|
106
|
+
Git.expects(:init).with(purse_path).once
|
107
|
+
@pocket.init
|
108
|
+
# assert File.readable?(File.join(purse_path, '.git/config'))
|
109
|
+
FileUtils.rm_rf(File.join(purse_path, '.git'))
|
110
|
+
end
|
111
|
+
end
|
112
|
+
end
|
113
|
+
|
114
|
+
context "if the directory doesn't exist" do
|
115
|
+
setup do
|
116
|
+
@other_purse_path = File.expand_path(File.join('~', 'tmp', 'tmp_purse_path'))
|
117
|
+
@pocket = Pocket.new(@other_purse_path)
|
118
|
+
Git.expects(:init).with(@other_purse_path).once
|
119
|
+
@pocket.init
|
120
|
+
end
|
121
|
+
|
122
|
+
teardown do
|
123
|
+
FileUtils.rm_rf(@other_purse_path)
|
124
|
+
end
|
125
|
+
|
126
|
+
should "create the directory" do
|
127
|
+
assert File.readable?(@other_purse_path)
|
128
|
+
end
|
129
|
+
|
130
|
+
# should "create the git directory" do
|
131
|
+
# assert File.directory?(File.join(@other_purse_path, '.git'))
|
132
|
+
# end
|
133
|
+
end
|
134
|
+
|
135
|
+
end
|
136
|
+
|
137
|
+
context "push" do
|
138
|
+
context "if there is already a git directory" do
|
139
|
+
|
140
|
+
end
|
141
|
+
|
142
|
+
context "if there is no git remote setting" do
|
143
|
+
|
144
|
+
end
|
145
|
+
|
146
|
+
context "if there is a remote setting but there is no repository" do
|
147
|
+
|
148
|
+
end
|
149
|
+
|
150
|
+
should_eventually "push to git repo" do
|
151
|
+
|
152
|
+
end
|
153
|
+
|
154
|
+
end
|
155
|
+
|
156
|
+
context "pull" do
|
157
|
+
|
158
|
+
should_eventually "pull from a git server" do
|
159
|
+
|
160
|
+
end
|
161
|
+
|
162
|
+
end
|
163
|
+
end
|
164
|
+
end
|
165
|
+
end
|
166
|
+
|
167
|
+
|
168
|
+
end
|
@@ -0,0 +1,141 @@
|
|
1
|
+
require 'test_helper.rb'
|
2
|
+
|
3
|
+
class TestSettings < Test::Unit::TestCase
|
4
|
+
|
5
|
+
context "Purse" do
|
6
|
+
context "Settings" do
|
7
|
+
setup do
|
8
|
+
@other_path = File.join(purse_path, 'other_settings.yml')
|
9
|
+
end
|
10
|
+
|
11
|
+
teardown do
|
12
|
+
FileUtils.rm(@other_path, :force => true)
|
13
|
+
end
|
14
|
+
|
15
|
+
|
16
|
+
context "path" do
|
17
|
+
setup do
|
18
|
+
Settings.path = Settings.default_path
|
19
|
+
@path = Settings.path
|
20
|
+
end
|
21
|
+
|
22
|
+
should "return readable file path" do
|
23
|
+
assert File.readable?(@path)
|
24
|
+
end
|
25
|
+
|
26
|
+
should "be a file in ~/" do
|
27
|
+
assert_match(/#{File.expand_path('~/')}/,@path)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
context "path=" do
|
32
|
+
|
33
|
+
context "with a path string" do
|
34
|
+
setup do
|
35
|
+
Settings.path = File.join(purse_path, 'settings.yml')
|
36
|
+
end
|
37
|
+
|
38
|
+
should "set path for class" do
|
39
|
+
assert_equal File.join(purse_path, 'settings.yml'), Settings.path
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
context "load" do
|
45
|
+
context "when the file already exists" do
|
46
|
+
setup do
|
47
|
+
Settings.path = File.join(purse_path, 'settings.yml')
|
48
|
+
YAML.expects(:load_file).with(File.join(purse_path, 'settings.yml')).returns({'repository' => 'github.com', 'path' => '~/aaron/.purse'})
|
49
|
+
Settings.load
|
50
|
+
end
|
51
|
+
|
52
|
+
should "store parsed settings in @settings" do
|
53
|
+
assert Settings.settings.is_a?(Hash)
|
54
|
+
assert_equal 'github.com', Settings.settings['repository']
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
context "when the file does not exist" do
|
59
|
+
setup do
|
60
|
+
Settings.path = @other_path
|
61
|
+
Settings.load
|
62
|
+
end
|
63
|
+
|
64
|
+
should "create the file at path" do
|
65
|
+
assert File.readable?(@other_path)
|
66
|
+
end
|
67
|
+
|
68
|
+
should "initialize @settings" do
|
69
|
+
assert Settings.settings.is_a?(Hash)
|
70
|
+
end
|
71
|
+
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
context "save" do
|
76
|
+
setup do
|
77
|
+
Settings.path = @other_path
|
78
|
+
Settings.settings = {:path => 'farts', :key => '12345'}
|
79
|
+
Settings.save
|
80
|
+
end
|
81
|
+
|
82
|
+
should "convert @settings to_yaml" do
|
83
|
+
assert_match(/key\:.+12345/, File.open(@other_path) {|f| f.read })
|
84
|
+
end
|
85
|
+
|
86
|
+
should "write yaml to path" do
|
87
|
+
assert File.readable?(@other_path)
|
88
|
+
end
|
89
|
+
|
90
|
+
end
|
91
|
+
|
92
|
+
context "get" do
|
93
|
+
context "if @settings are loaded" do
|
94
|
+
setup do
|
95
|
+
Settings.path = @other_path
|
96
|
+
Settings.stubs(:loaded?).returns(true)
|
97
|
+
Settings.settings = {:path => purse_path}
|
98
|
+
end
|
99
|
+
|
100
|
+
should "retrieve setting by key" do
|
101
|
+
assert_equal purse_path, Settings.get('path')
|
102
|
+
assert_equal purse_path, Settings.get(:path)
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
context "if settings are not loaded" do
|
107
|
+
setup do
|
108
|
+
Settings.path = File.join(purse_path, 'settings.yml')
|
109
|
+
YAML.expects(:load_file).returns({'repository' => 'github.com', 'path' => '~/aaron/.purse'})
|
110
|
+
Settings.get('repository')
|
111
|
+
end
|
112
|
+
|
113
|
+
should "load settings from path" do
|
114
|
+
assert Settings.settings
|
115
|
+
end
|
116
|
+
|
117
|
+
should "retrieve setting by key" do
|
118
|
+
assert_equal 'github.com', Settings.get('repository')
|
119
|
+
assert_equal 'github.com', Settings.get(:repository)
|
120
|
+
end
|
121
|
+
end
|
122
|
+
end
|
123
|
+
|
124
|
+
context "set" do
|
125
|
+
setup do
|
126
|
+
Settings.path = @other_path
|
127
|
+
end
|
128
|
+
|
129
|
+
should "put setting with key into @settings" do
|
130
|
+
Settings.set('key', 'value')
|
131
|
+
assert_equal 'value', Settings.settings['key']
|
132
|
+
end
|
133
|
+
|
134
|
+
should "save settings to path" do
|
135
|
+
Settings.expects(:save).at_most_once
|
136
|
+
Settings.set('key', 'value')
|
137
|
+
end
|
138
|
+
end
|
139
|
+
end
|
140
|
+
end
|
141
|
+
end
|
data/test/test_helper.rb
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
require 'test/unit'
|
2
|
+
require 'rubygems'
|
3
|
+
require 'shoulda'
|
4
|
+
require 'mocha'
|
5
|
+
|
6
|
+
require File.dirname(__FILE__) + '/../lib/purse'
|
7
|
+
|
8
|
+
class Test::Unit::TestCase
|
9
|
+
|
10
|
+
include Purse
|
11
|
+
|
12
|
+
def purse_path
|
13
|
+
File.expand_path(File.join(File.dirname(__FILE__), 'test_purse_data'))
|
14
|
+
end
|
15
|
+
|
16
|
+
def assert_all(collection)
|
17
|
+
collection.each do |one|
|
18
|
+
assert yield(one), "#{one} is not true"
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def assert_any(collection, &block)
|
23
|
+
has = collection.any? do |one|
|
24
|
+
yield(one)
|
25
|
+
end
|
26
|
+
assert has
|
27
|
+
end
|
28
|
+
|
29
|
+
def assert_ordered(array_of_ordered_items, message = nil, &block)
|
30
|
+
raise "Parameter must be an Array" unless array_of_ordered_items.is_a?(Array)
|
31
|
+
message ||= "Items were not in the correct order"
|
32
|
+
i = 0
|
33
|
+
# puts array_of_ordered_items.length
|
34
|
+
while i < (array_of_ordered_items.length - 1)
|
35
|
+
# puts "j"
|
36
|
+
a, b = array_of_ordered_items[i], array_of_ordered_items[i+1]
|
37
|
+
comparison = yield(a,b)
|
38
|
+
# raise "#{comparison}"
|
39
|
+
assert(comparison, message + " - #{a}, #{b}")
|
40
|
+
i += 1
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
def assert_set_of(klass, set)
|
45
|
+
assert set.respond_to?(:each), "#{set} is not a set (does not include Enumerable)"
|
46
|
+
assert_all(set) {|a| a.is_a?(klass) }
|
47
|
+
end
|
48
|
+
|
49
|
+
end
|
metadata
ADDED
@@ -0,0 +1,90 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: purse
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Aaron Quint
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2008-10-29 00:00:00 -04:00
|
13
|
+
default_executable:
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: hoe
|
17
|
+
type: :development
|
18
|
+
version_requirement:
|
19
|
+
version_requirements: !ruby/object:Gem::Requirement
|
20
|
+
requirements:
|
21
|
+
- - ">="
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: 1.8.2
|
24
|
+
version:
|
25
|
+
description: A simple but secure password storage solution using git and crypt
|
26
|
+
email:
|
27
|
+
- aaron@quirkey.com
|
28
|
+
executables:
|
29
|
+
- purse
|
30
|
+
extensions: []
|
31
|
+
|
32
|
+
extra_rdoc_files:
|
33
|
+
- History.txt
|
34
|
+
- License.txt
|
35
|
+
- Manifest.txt
|
36
|
+
- PostInstall.txt
|
37
|
+
- README.txt
|
38
|
+
- lib/purse/help.txt
|
39
|
+
files:
|
40
|
+
- History.txt
|
41
|
+
- License.txt
|
42
|
+
- Manifest.txt
|
43
|
+
- PostInstall.txt
|
44
|
+
- README.txt
|
45
|
+
- Rakefile
|
46
|
+
- bin/purse
|
47
|
+
- lib/purse.rb
|
48
|
+
- lib/purse/cli.rb
|
49
|
+
- lib/purse/error.rb
|
50
|
+
- lib/purse/note.rb
|
51
|
+
- lib/purse/pocket.rb
|
52
|
+
- lib/purse/settings.rb
|
53
|
+
- lib/purse/version.rb
|
54
|
+
- lib/purse/help.txt
|
55
|
+
has_rdoc: true
|
56
|
+
homepage: http://quirkey.rubyforge.org
|
57
|
+
post_install_message: |
|
58
|
+
|
59
|
+
For more information on purse, see http://quirkey.com/blog
|
60
|
+
|
61
|
+
rdoc_options:
|
62
|
+
- --main
|
63
|
+
- README.txt
|
64
|
+
require_paths:
|
65
|
+
- lib
|
66
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
67
|
+
requirements:
|
68
|
+
- - ">="
|
69
|
+
- !ruby/object:Gem::Version
|
70
|
+
version: "0"
|
71
|
+
version:
|
72
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
73
|
+
requirements:
|
74
|
+
- - ">="
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
version: "0"
|
77
|
+
version:
|
78
|
+
requirements: []
|
79
|
+
|
80
|
+
rubyforge_project: quirkey
|
81
|
+
rubygems_version: 1.2.0
|
82
|
+
signing_key:
|
83
|
+
specification_version: 2
|
84
|
+
summary: A simple but secure password storage solution using git and crypt
|
85
|
+
test_files:
|
86
|
+
- test/purse/test_cli.rb
|
87
|
+
- test/purse/test_note.rb
|
88
|
+
- test/purse/test_pocket.rb
|
89
|
+
- test/purse/test_settings.rb
|
90
|
+
- test/test_helper.rb
|