keepassx 0.1.0 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (46) hide show
  1. checksums.yaml +7 -0
  2. data/.codeclimate.yml +30 -0
  3. data/.gitignore +9 -0
  4. data/.rubocop.yml +64 -0
  5. data/.travis.yml +12 -3
  6. data/Gemfile +4 -2
  7. data/Guardfile +16 -0
  8. data/LICENSE +19 -0
  9. data/README.md +33 -0
  10. data/Rakefile +3 -2
  11. data/keepassx.gemspec +20 -10
  12. data/lib/keepassx.rb +42 -3
  13. data/lib/keepassx/aes_crypt.rb +16 -6
  14. data/lib/keepassx/database.rb +218 -27
  15. data/lib/keepassx/database/dumper.rb +87 -0
  16. data/lib/keepassx/database/finder.rb +102 -0
  17. data/lib/keepassx/database/loader.rb +217 -0
  18. data/lib/keepassx/entry.rb +70 -38
  19. data/lib/keepassx/field/base.rb +191 -0
  20. data/lib/keepassx/field/entry.rb +32 -0
  21. data/lib/keepassx/field/group.rb +27 -0
  22. data/lib/keepassx/fieldable.rb +161 -0
  23. data/lib/keepassx/group.rb +93 -20
  24. data/lib/keepassx/hashable_payload.rb +6 -0
  25. data/lib/keepassx/header.rb +102 -27
  26. data/lib/keepassx/version.rb +5 -0
  27. data/spec/factories.rb +23 -0
  28. data/spec/fixtures/database_empty.kdb +0 -0
  29. data/spec/fixtures/database_test.kdb +0 -0
  30. data/spec/fixtures/database_test_dumped.yml +76 -0
  31. data/spec/fixtures/database_with_key.kdb +0 -0
  32. data/spec/fixtures/database_with_key.key +1 -0
  33. data/spec/fixtures/database_with_key2.key +1 -0
  34. data/spec/fixtures/test_data_array.yml +113 -0
  35. data/spec/fixtures/test_data_array_dumped.yml +124 -0
  36. data/spec/keepassx/database_spec.rb +491 -29
  37. data/spec/keepassx/entry_spec.rb +95 -0
  38. data/spec/keepassx/group_spec.rb +92 -0
  39. data/spec/keepassx_spec.rb +17 -0
  40. data/spec/spec_helper.rb +59 -3
  41. metadata +143 -69
  42. data/.rvmrc +0 -1
  43. data/Gemfile.lock +0 -28
  44. data/lib/keepassx/entry_field.rb +0 -49
  45. data/lib/keepassx/group_field.rb +0 -44
  46. data/spec/test_database.kdb +0 -0
@@ -0,0 +1,95 @@
1
+ require 'spec_helper'
2
+
3
+ describe Keepassx::Entry do
4
+
5
+ let :entry_schema do
6
+ Respect::HashSchema.define do |s|
7
+ s.uuid :id
8
+ s.integer :group_id
9
+ s.integer :icon
10
+ s.string :name
11
+ s.string :url, format: :uri
12
+ s.string :username
13
+ s.string :password
14
+ s.string :notes
15
+ s.datetime :creation_time
16
+ s.datetime :last_mod_time
17
+ s.datetime :last_acc_time
18
+ s.datetime :expiration_time
19
+ # s.string :binary_desc # 'binary_desc' comes empty in test data
20
+ # s.string :binary_data # 'binary_data' comes empty in test data
21
+ end
22
+ end
23
+
24
+ let(:test_entry) { build(:entry) }
25
+
26
+
27
+ describe '.fields' do
28
+ it 'returns the list of fields' do
29
+ expect(described_class.fields).to eq %w(ignored id group_id icon name url username password notes creation_time last_mod_time last_acc_time expiration_time binary_desc binary_data terminator)
30
+ end
31
+ end
32
+
33
+
34
+ describe '.new' do
35
+ it 'raise error when first argument is not a hash or a binary payload' do
36
+ expect { Keepassx::Entry.new('foo') }.to raise_error(ArgumentError)
37
+ end
38
+
39
+ it 'raise error when name is not a string or is missing' do
40
+ [0, :foo, [], {}, nil, ''].each do |name|
41
+ expect { Keepassx::Entry.new(name: name, group_id: 0, icon: 20) }.to raise_error(ArgumentError)
42
+ end
43
+ end
44
+
45
+ it 'raise error when group_id is not an integer or is missing' do
46
+ ['foo', :foo, [], {}, nil, ''].each do |group_id|
47
+ expect { Keepassx::Entry.new(name: 'test_entry', group_id: group_id, icon: 20) }.to raise_error(ArgumentError)
48
+ end
49
+ end
50
+
51
+ it 'does not raise errors with valid data' do
52
+ expect { test_entry }.to_not raise_error
53
+ end
54
+ end
55
+
56
+
57
+ describe '#fields' do
58
+ it 'returns the list of fields' do
59
+ expect(test_entry.fields.length).to eq 15
60
+ end
61
+ end
62
+
63
+
64
+ describe '#length' do
65
+ it 'returns the length of fields' do
66
+ expect(test_entry.length).to eq 189
67
+ end
68
+ end
69
+
70
+
71
+ describe '#encode' do
72
+ it 'returns the encoded version of fields' do
73
+ expect { test_entry.encode }.to_not raise_error
74
+ end
75
+ end
76
+
77
+
78
+ describe '#to_hash' do
79
+ it 'returns Hash entry representation' do
80
+ expect(entry_schema.validate?(test_entry.to_hash)).to be true
81
+ end
82
+
83
+ it 'returns Hash entry representation' do
84
+ expect(entry_schema.validate?(build(:entry, id: '1').to_hash)).to be false
85
+ end
86
+ end
87
+
88
+
89
+ describe 'fields are editable' do
90
+ it 'should allow update of attributes' do
91
+ test_entry.name = 'foo'
92
+ expect(test_entry.name).to eq 'foo'
93
+ end
94
+ end
95
+ end
@@ -0,0 +1,92 @@
1
+ require 'spec_helper'
2
+
3
+ describe Keepassx::Group do
4
+
5
+ let :group_schema do
6
+ Respect::HashSchema.define do |s|
7
+ s.integer :id
8
+ s.string :name
9
+ s.integer :icon
10
+ s.datetime :creation_time
11
+ s.datetime :last_mod_time
12
+ s.datetime :last_acc_time
13
+ s.datetime :expiration_time
14
+ s.integer :level
15
+ s.integer :flags
16
+ end
17
+ end
18
+
19
+ let(:test_group) { build(:group) }
20
+
21
+
22
+ describe '.fields' do
23
+ it 'returns the list of fields' do
24
+ expect(described_class.fields).to eq %w(ignored id name creation_time last_mod_time last_acc_time expiration_time icon level flags terminator)
25
+ end
26
+ end
27
+
28
+
29
+ describe '.new' do
30
+ it 'raise error when first argument is not a hash or a binary payload' do
31
+ expect { Keepassx::Group.new('foo') }.to raise_error(ArgumentError)
32
+ end
33
+
34
+ it 'raise error when id is not an integer or is missing' do
35
+ ['foo', :foo, [], {}, nil, ''].each do |id|
36
+ expect { Keepassx::Group.new(id: id, name: 'test_group', icon: 20) }.to raise_error(ArgumentError)
37
+ end
38
+ end
39
+
40
+ it 'raise error when name is not a string or is missing' do
41
+ [0, :foo, [], {}, nil, ''].each do |name|
42
+ expect { Keepassx::Group.new(id: 0, name: name, icon: 20) }.to raise_error(ArgumentError)
43
+ end
44
+ end
45
+
46
+ it 'does not raise errors with valid data' do
47
+ expect { test_group }.to_not raise_error
48
+ end
49
+ end
50
+
51
+
52
+ describe '#fields' do
53
+ it 'returns the list of fields' do
54
+ expect(test_group.fields.length).to eq 10
55
+ end
56
+ end
57
+
58
+
59
+ describe '#length' do
60
+ it 'returns the length of fields' do
61
+ expect(test_group.length).to eq 105
62
+ end
63
+ end
64
+
65
+
66
+ describe '#encode' do
67
+ it 'returns the encoded version of fields' do
68
+ expect { test_group.encode }.to_not raise_error
69
+ end
70
+ end
71
+
72
+
73
+ describe '#to_hash' do
74
+ it 'returns Hash group representation' do
75
+ expect(group_schema.validate?(test_group.to_hash)).to be true
76
+ end
77
+ end
78
+
79
+
80
+ describe '#entries' do
81
+ it 'returns the list of entries' do
82
+ expect(test_group.entries.length).to eq 0
83
+ end
84
+ end
85
+
86
+ describe 'fields are editable' do
87
+ it 'should allow update of attributes' do
88
+ test_group.name = 'foo'
89
+ expect(test_group.name).to eq 'foo'
90
+ end
91
+ end
92
+ end
@@ -0,0 +1,17 @@
1
+ require 'spec_helper'
2
+
3
+ describe Keepassx do
4
+
5
+ describe '.new' do
6
+ it 'should allow creation of database from scratch' do
7
+ expect { |b| described_class.new('/tmp/test_db.kdb', &b) }.to yield_control
8
+ end
9
+ end
10
+
11
+ describe '.open' do
12
+ it 'should allow creation of database from scratch' do
13
+ expect { |b| described_class.open('/tmp/test_db.kdb', &b) }.to yield_control
14
+ end
15
+ end
16
+
17
+ end
@@ -1,5 +1,61 @@
1
- $:.unshift File.expand_path('../../lib', __FILE__)
2
- require 'keepassx'
1
+ require 'simplecov'
3
2
  require 'rspec'
3
+ require 'respect'
4
+ require 'factory_bot'
5
+
6
+ # Start Simplecov
7
+ SimpleCov.start do
8
+ add_filter '/spec/'
9
+ end
10
+
11
+ # Configure RSpec
12
+ RSpec.configure do |config|
13
+ config.include FactoryBot::Syntax::Methods
14
+
15
+ config.color = true
16
+ config.fail_fast = false
17
+
18
+ config.order = :random
19
+ Kernel.srand config.seed
20
+
21
+ config.expect_with :rspec do |c|
22
+ c.syntax = :expect
23
+ end
24
+ end
25
+
26
+ # Load lib
27
+ require 'keepassx'
28
+ require_relative 'factories'
29
+
30
+ FIXTURE_PATH = File.expand_path File.join(File.dirname(__FILE__), 'fixtures')
31
+ TEST_DATABASE_PATH = File.join(FIXTURE_PATH, 'database_test.kdb')
32
+ EMPTY_DATABASE_PATH = File.join(FIXTURE_PATH, 'database_empty.kdb')
33
+ KEYFILE_DATABASE_PATH = File.join(FIXTURE_PATH, 'database_with_key.kdb')
34
+
35
+
36
+ module RespectPatch
37
+ def self.included(base)
38
+ base.send(:prepend, InstanceMethods)
39
+ end
40
+
41
+ module InstanceMethods
42
+
43
+ def validate_uuid(uuid)
44
+ return true if uuid =~ /\A[0-9a-f]{32}\z/i
45
+ raise Respect::ValidationError, "invalid UUID"
46
+ end
47
+
48
+ end
49
+ end
50
+
51
+ module UUIDValidator
52
+ def uuid(name, options = {})
53
+ string(name, { format: :uuid }.merge(options))
54
+ end
55
+ end
56
+
57
+ unless Respect::FormatValidator.included_modules.include?(RespectPatch)
58
+ Respect::FormatValidator.send(:include, RespectPatch)
59
+ end
4
60
 
5
- TEST_DATABASE_PATH = File.expand_path('../test_database.kdb', __FILE__)
61
+ Respect.extend_dsl_with(UUIDValidator)
metadata CHANGED
@@ -1,108 +1,182 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: keepassx
3
- version: !ruby/object:Gem::Version
4
- prerelease: false
5
- segments:
6
- - 0
7
- - 1
8
- - 0
9
- version: 0.1.0
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
10
5
  platform: ruby
11
- authors:
6
+ authors:
12
7
  - Tony Pitluga
13
8
  - Paul Hinze
14
9
  autorequire:
15
10
  bindir: bin
16
11
  cert_chain: []
17
-
18
- date: 2012-10-14 00:00:00 -05:00
19
- default_executable:
20
- dependencies:
21
- - !ruby/object:Gem::Dependency
22
- name: fast-aes
12
+ date: 2019-10-25 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: factory_bot
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - ">="
19
+ - !ruby/object:Gem::Version
20
+ version: '0'
21
+ type: :development
22
+ prerelease: false
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - ">="
26
+ - !ruby/object:Gem::Version
27
+ version: '0'
28
+ - !ruby/object:Gem::Dependency
29
+ name: guard
30
+ requirement: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - ">="
33
+ - !ruby/object:Gem::Version
34
+ version: '0'
35
+ type: :development
36
+ prerelease: false
37
+ version_requirements: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - ">="
40
+ - !ruby/object:Gem::Version
41
+ version: '0'
42
+ - !ruby/object:Gem::Dependency
43
+ name: guard-rspec
44
+ requirement: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - ">="
47
+ - !ruby/object:Gem::Version
48
+ version: '0'
49
+ type: :development
23
50
  prerelease: false
24
- requirement: &id001 !ruby/object:Gem::Requirement
25
- requirements:
26
- - - ~>
27
- - !ruby/object:Gem::Version
28
- segments:
29
- - 0
30
- - 1
31
- version: "0.1"
32
- type: :runtime
33
- version_requirements: *id001
34
- - !ruby/object:Gem::Dependency
51
+ version_requirements: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - ">="
54
+ - !ruby/object:Gem::Version
55
+ version: '0'
56
+ - !ruby/object:Gem::Dependency
57
+ name: rake
58
+ requirement: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - "~>"
61
+ - !ruby/object:Gem::Version
62
+ version: '10.4'
63
+ type: :development
64
+ prerelease: false
65
+ version_requirements: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - "~>"
68
+ - !ruby/object:Gem::Version
69
+ version: '10.4'
70
+ - !ruby/object:Gem::Dependency
71
+ name: respect
72
+ requirement: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - ">="
75
+ - !ruby/object:Gem::Version
76
+ version: '0'
77
+ type: :development
78
+ prerelease: false
79
+ version_requirements: !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - ">="
82
+ - !ruby/object:Gem::Version
83
+ version: '0'
84
+ - !ruby/object:Gem::Dependency
35
85
  name: rspec
86
+ requirement: !ruby/object:Gem::Requirement
87
+ requirements:
88
+ - - ">="
89
+ - !ruby/object:Gem::Version
90
+ version: '0'
91
+ type: :development
36
92
  prerelease: false
37
- requirement: &id002 !ruby/object:Gem::Requirement
38
- requirements:
39
- - - "="
40
- - !ruby/object:Gem::Version
41
- segments:
42
- - 2
43
- - 11
44
- - 0
45
- version: 2.11.0
93
+ version_requirements: !ruby/object:Gem::Requirement
94
+ requirements:
95
+ - - ">="
96
+ - !ruby/object:Gem::Version
97
+ version: '0'
98
+ - !ruby/object:Gem::Dependency
99
+ name: simplecov
100
+ requirement: !ruby/object:Gem::Requirement
101
+ requirements:
102
+ - - ">="
103
+ - !ruby/object:Gem::Version
104
+ version: '0'
46
105
  type: :development
47
- version_requirements: *id002
106
+ prerelease: false
107
+ version_requirements: !ruby/object:Gem::Requirement
108
+ requirements:
109
+ - - ">="
110
+ - !ruby/object:Gem::Version
111
+ version: '0'
48
112
  description: See http://github.com/pitluga/keepassx
49
- email:
113
+ email:
50
114
  - tony.pitluga@gmail.com
51
115
  - paul.t.hinze@gmail.com
52
116
  executables: []
53
-
54
117
  extensions: []
55
-
56
118
  extra_rdoc_files: []
57
-
58
- files:
59
- - .rvmrc
60
- - .travis.yml
119
+ files:
120
+ - ".codeclimate.yml"
121
+ - ".gitignore"
122
+ - ".rubocop.yml"
123
+ - ".travis.yml"
61
124
  - Gemfile
62
- - Gemfile.lock
125
+ - Guardfile
126
+ - LICENSE
63
127
  - README.md
64
128
  - Rakefile
65
129
  - keepassx.gemspec
66
130
  - lib/keepassx.rb
67
131
  - lib/keepassx/aes_crypt.rb
68
132
  - lib/keepassx/database.rb
133
+ - lib/keepassx/database/dumper.rb
134
+ - lib/keepassx/database/finder.rb
135
+ - lib/keepassx/database/loader.rb
69
136
  - lib/keepassx/entry.rb
70
- - lib/keepassx/entry_field.rb
137
+ - lib/keepassx/field/base.rb
138
+ - lib/keepassx/field/entry.rb
139
+ - lib/keepassx/field/group.rb
140
+ - lib/keepassx/fieldable.rb
71
141
  - lib/keepassx/group.rb
72
- - lib/keepassx/group_field.rb
142
+ - lib/keepassx/hashable_payload.rb
73
143
  - lib/keepassx/header.rb
144
+ - lib/keepassx/version.rb
145
+ - spec/factories.rb
146
+ - spec/fixtures/database_empty.kdb
147
+ - spec/fixtures/database_test.kdb
148
+ - spec/fixtures/database_test_dumped.yml
149
+ - spec/fixtures/database_with_key.kdb
150
+ - spec/fixtures/database_with_key.key
151
+ - spec/fixtures/database_with_key2.key
152
+ - spec/fixtures/test_data_array.yml
153
+ - spec/fixtures/test_data_array_dumped.yml
74
154
  - spec/keepassx/database_spec.rb
155
+ - spec/keepassx/entry_spec.rb
156
+ - spec/keepassx/group_spec.rb
157
+ - spec/keepassx_spec.rb
75
158
  - spec/spec_helper.rb
76
- - spec/test_database.kdb
77
- has_rdoc: true
78
159
  homepage: http://github.com/pitluga/keepassx
79
- licenses: []
80
-
160
+ licenses:
161
+ - MIT
162
+ metadata: {}
81
163
  post_install_message:
82
164
  rdoc_options: []
83
-
84
- require_paths:
165
+ require_paths:
85
166
  - lib
86
- required_ruby_version: !ruby/object:Gem::Requirement
87
- requirements:
167
+ required_ruby_version: !ruby/object:Gem::Requirement
168
+ requirements:
88
169
  - - ">="
89
- - !ruby/object:Gem::Version
90
- segments:
91
- - 0
92
- version: "0"
93
- required_rubygems_version: !ruby/object:Gem::Requirement
94
- requirements:
170
+ - !ruby/object:Gem::Version
171
+ version: '0'
172
+ required_rubygems_version: !ruby/object:Gem::Requirement
173
+ requirements:
95
174
  - - ">="
96
- - !ruby/object:Gem::Version
97
- segments:
98
- - 0
99
- version: "0"
175
+ - !ruby/object:Gem::Version
176
+ version: '0'
100
177
  requirements: []
101
-
102
- rubyforge_project:
103
- rubygems_version: 1.3.6
178
+ rubygems_version: 3.0.3
104
179
  signing_key:
105
- specification_version: 3
180
+ specification_version: 4
106
181
  summary: Ruby API access for KeePassX databases
107
182
  test_files: []
108
-