donjon 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,24 @@
1
+ require 'spec_helper'
2
+ require 'donjon/repository'
3
+
4
+ describe Donjon::Repository do
5
+ let(:uid) { "%08x" % rand(1<<32) }
6
+ let(:options) {[
7
+ "/tmp/donjon-#{uid}"
8
+ ]}
9
+
10
+ subject { described_class.new(*options) }
11
+
12
+ describe '#initialize' do
13
+ it 'passes with valid options' do
14
+ expect { subject }.not_to raise_error
15
+ end
16
+ end
17
+
18
+ describe '#to_s' do
19
+ it 'returns the path' do
20
+ expect(subject.to_s).to eq(options.first)
21
+ end
22
+ end
23
+ end
24
+
@@ -0,0 +1,98 @@
1
+ require 'spec_helper'
2
+ require 'donjon/user'
3
+ require 'donjon/repository'
4
+ require 'spec/support/repos'
5
+ require 'spec/support/keys'
6
+
7
+ describe Donjon::User do
8
+ let_repo(:repo)
9
+
10
+ let(:options) {{
11
+ name: 'john-doe',
12
+ key: random_key,
13
+ repo: repo
14
+ }}
15
+
16
+ subject { described_class.new(**options) }
17
+
18
+ describe '#initialize' do
19
+ it 'passes with valid arguments' do
20
+ expect { subject }.not_to raise_error
21
+ end
22
+ end
23
+
24
+ describe '#save' do
25
+ it 'passes' do
26
+ expect { subject.save }.not_to raise_error
27
+ end
28
+
29
+ it 'creates public key file' do
30
+ subject.save
31
+ expect( repo.join('users/john-doe.pub') ).to be_exist
32
+ end
33
+
34
+ it 'does not save the private key' do
35
+ subject.save
36
+ data = repo.join('users/john-doe.pub').read
37
+ expect(data).to match(/PUBLIC KEY/)
38
+ expect(data).not_to match(/PRIVATE KEY/)
39
+ end
40
+
41
+ xit 'fails if existing, different key'
42
+ end
43
+
44
+ describe '.find' do
45
+ context 'with no users' do
46
+ it 'returns nil' do
47
+ expect(
48
+ described_class.find(name: 'bob', repo: repo)
49
+ ).to be_nil
50
+ end
51
+ end
52
+
53
+ context 'with users' do
54
+ let(:bob_key) { random_key }
55
+
56
+ before do
57
+ Donjon::User.new(name: 'alice', key: random_key, repo: repo).save
58
+ Donjon::User.new(name: 'bob', key: bob_key, repo: repo).save
59
+ end
60
+
61
+ it 'returns nil for unknown users' do
62
+ expect(
63
+ described_class.find(name: 'charlie', repo: repo)
64
+ ).to be_nil
65
+ end
66
+
67
+ it 'returns known users' do
68
+ bob = described_class.find(name: 'bob', repo: repo)
69
+ expect(bob.name).to eq('bob')
70
+ expect(bob.key.to_pem).to eq(bob_key.public_key.to_pem)
71
+ end
72
+ end
73
+ end
74
+
75
+ describe '.each' do
76
+ context 'with no users' do
77
+ it 'returns nil' do
78
+ expect { |b|
79
+ described_class.each(repo, &b)
80
+ }.not_to yield_control
81
+ end
82
+ end
83
+
84
+ context 'with users' do
85
+ before do
86
+ Donjon::User.new(name: 'alice', key: random_key, repo: repo).save
87
+ Donjon::User.new(name: 'bob', key: random_key, repo: repo).save
88
+ end
89
+
90
+ it 'returns known users' do
91
+ expect { |b|
92
+ described_class.each(repo, &b)
93
+ }.to yield_successive_args(Donjon::User, Donjon::User)
94
+ end
95
+ end
96
+ end
97
+
98
+ end
@@ -0,0 +1,78 @@
1
+ # This file was generated by the `rspec --init` command. Conventionally, all
2
+ # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
3
+ # The generated `.rspec` file contains `--require spec_helper` which will cause this
4
+ # file to always be loaded, without a need to explicitly require it in any files.
5
+ #
6
+ # Given that it is always loaded, you are encouraged to keep this file as
7
+ # light-weight as possible. Requiring heavyweight dependencies from this file
8
+ # will add to the boot time of your test suite on EVERY test run, even for an
9
+ # individual file that may not need all of that loaded. Instead, make a
10
+ # separate helper file that requires this one and then use it only in the specs
11
+ # that actually need it.
12
+ #
13
+ # The `.rspec` file also contains a few flags that are not defaults but that
14
+ # users commonly want.
15
+ #
16
+ # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
17
+ RSpec.configure do |config|
18
+ # The settings below are suggested to provide a good initial experience
19
+ # with RSpec, but feel free to customize to your heart's content.
20
+ =begin
21
+ # These two settings work together to allow you to limit a spec run
22
+ # to individual examples or groups you care about by tagging them with
23
+ # `:focus` metadata. When nothing is tagged with `:focus`, all examples
24
+ # get run.
25
+ config.filter_run :focus
26
+ config.run_all_when_everything_filtered = true
27
+
28
+ # Many RSpec users commonly either run the entire suite or an individual
29
+ # file, and it's useful to allow more verbose output when running an
30
+ # individual spec file.
31
+ if config.files_to_run.one?
32
+ # Use the documentation formatter for detailed output,
33
+ # unless a formatter has already been configured
34
+ # (e.g. via a command-line flag).
35
+ config.default_formatter = 'doc'
36
+ end
37
+
38
+ # Print the 10 slowest examples and example groups at the
39
+ # end of the spec run, to help surface which specs are running
40
+ # particularly slow.
41
+ config.profile_examples = 10
42
+
43
+ # Run specs in random order to surface order dependencies. If you find an
44
+ # order dependency and want to debug it, you can fix the order by providing
45
+ # the seed, which is printed after each run.
46
+ # --seed 1234
47
+ config.order = :random
48
+
49
+ # Seed global randomization in this process using the `--seed` CLI option.
50
+ # Setting this allows you to use `--seed` to deterministically reproduce
51
+ # test failures related to randomization by passing the same `--seed` value
52
+ # as the one that triggered the failure.
53
+ Kernel.srand config.seed
54
+
55
+ # rspec-expectations config goes here. You can use an alternate
56
+ # assertion/expectation library such as wrong or the stdlib/minitest
57
+ # assertions if you prefer.
58
+ config.expect_with :rspec do |expectations|
59
+ # Enable only the newer, non-monkey-patching expect syntax.
60
+ # For more details, see:
61
+ # - http://myronmars.to/n/dev-blog/2012/06/rspecs-new-expectation-syntax
62
+ expectations.syntax = :expect
63
+ end
64
+
65
+ # rspec-mocks config goes here. You can use an alternate test double
66
+ # library (such as bogus or mocha) by changing the `mock_with` option here.
67
+ config.mock_with :rspec do |mocks|
68
+ # Enable only the newer, non-monkey-patching expect syntax.
69
+ # For more details, see:
70
+ # - http://teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
71
+ mocks.syntax = :expect
72
+
73
+ # Prevents you from mocking or stubbing a method that does not exist on
74
+ # a real object. This is generally recommended.
75
+ mocks.verify_partial_doubles = true
76
+ end
77
+ =end
78
+ end
@@ -0,0 +1,7 @@
1
+ require 'openssl'
2
+
3
+ def random_key
4
+ OpenSSL::PKey::RSA.new(2048)
5
+ end
6
+
7
+
@@ -0,0 +1,22 @@
1
+ require 'spec_helper'
2
+ require 'openssl'
3
+ require 'donjon/repository'
4
+
5
+
6
+
7
+ def let_repo(name)
8
+ let(name) do
9
+ id = "%08x" % rand(1<<32)
10
+ Donjon::Repository.new("tmp/repo-#{id}")
11
+ end
12
+
13
+ after do
14
+ send(name).tap do |repo|
15
+ repo.rmtree if repo.exist?
16
+ end
17
+ end
18
+ end
19
+
20
+
21
+
22
+
metadata ADDED
@@ -0,0 +1,183 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: donjon
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Julien Letessier
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-07-17 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: thor
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: gibberish
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: pry
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: guard-rspec
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ description:
112
+ email:
113
+ - julien.letessier@gmail.com
114
+ executables:
115
+ - dj
116
+ extensions: []
117
+ extra_rdoc_files: []
118
+ files:
119
+ - ".gitignore"
120
+ - ".rspec"
121
+ - ".ruby-version"
122
+ - Gemfile
123
+ - Guardfile
124
+ - LICENSE.txt
125
+ - README.md
126
+ - Rakefile
127
+ - bin/dj
128
+ - donjon.gemspec
129
+ - lib/core_ext/assert.rb
130
+ - lib/core_ext/io_get_password.rb
131
+ - lib/donjon.rb
132
+ - lib/donjon/cli.rb
133
+ - lib/donjon/commands/base.rb
134
+ - lib/donjon/commands/config.rb
135
+ - lib/donjon/commands/user.rb
136
+ - lib/donjon/commands/vault.rb
137
+ - lib/donjon/configurator.rb
138
+ - lib/donjon/database.rb
139
+ - lib/donjon/encrypted_file.rb
140
+ - lib/donjon/repository.rb
141
+ - lib/donjon/settings.rb
142
+ - lib/donjon/shell.rb
143
+ - lib/donjon/user.rb
144
+ - lib/donjon/version.rb
145
+ - spec/donjon/database_spec.rb
146
+ - spec/donjon/encrypted_file_spec.rb
147
+ - spec/donjon/repository_spec.rb
148
+ - spec/donjon/user_spec.rb
149
+ - spec/spec_helper.rb
150
+ - spec/support/keys.rb
151
+ - spec/support/repos.rb
152
+ homepage: ''
153
+ licenses:
154
+ - MIT
155
+ metadata: {}
156
+ post_install_message:
157
+ rdoc_options: []
158
+ require_paths:
159
+ - lib
160
+ required_ruby_version: !ruby/object:Gem::Requirement
161
+ requirements:
162
+ - - ">="
163
+ - !ruby/object:Gem::Version
164
+ version: '0'
165
+ required_rubygems_version: !ruby/object:Gem::Requirement
166
+ requirements:
167
+ - - ">="
168
+ - !ruby/object:Gem::Version
169
+ version: '0'
170
+ requirements: []
171
+ rubyforge_project:
172
+ rubygems_version: 2.2.2
173
+ signing_key:
174
+ specification_version: 4
175
+ summary: Secure, multi-user data store.
176
+ test_files:
177
+ - spec/donjon/database_spec.rb
178
+ - spec/donjon/encrypted_file_spec.rb
179
+ - spec/donjon/repository_spec.rb
180
+ - spec/donjon/user_spec.rb
181
+ - spec/spec_helper.rb
182
+ - spec/support/keys.rb
183
+ - spec/support/repos.rb