passwordstate 0.0.4 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (39) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/ruby.yml +33 -0
  3. data/.gitignore +2 -1
  4. data/.gitlab-ci.yml +10 -7
  5. data/.rubocop.yml +6 -9
  6. data/CHANGELOG.md +7 -0
  7. data/README.md +64 -16
  8. data/Rakefile +2 -2
  9. data/lib/passwordstate/client.rb +62 -16
  10. data/lib/passwordstate/errors.rb +6 -1
  11. data/lib/passwordstate/resource.rb +137 -53
  12. data/lib/passwordstate/resource_list.rb +56 -42
  13. data/lib/passwordstate/resources/active_directory.rb +23 -0
  14. data/lib/passwordstate/resources/address_book.rb +28 -0
  15. data/lib/passwordstate/resources/document.rb +32 -3
  16. data/lib/passwordstate/resources/folder.rb +6 -3
  17. data/lib/passwordstate/resources/host.rb +2 -0
  18. data/lib/passwordstate/resources/password.rb +50 -15
  19. data/lib/passwordstate/resources/password_list.rb +41 -8
  20. data/lib/passwordstate/resources/permission.rb +2 -0
  21. data/lib/passwordstate/resources/privileged_account.rb +32 -0
  22. data/lib/passwordstate/resources/remote_site.rb +26 -0
  23. data/lib/passwordstate/resources/report.rb +2 -0
  24. data/lib/passwordstate/util.rb +22 -2
  25. data/lib/passwordstate/version.rb +3 -1
  26. data/lib/passwordstate.rb +4 -1
  27. data/passwordstate.gemspec +9 -3
  28. data/test/client_test.rb +39 -0
  29. data/test/fixtures/get_password.json +31 -0
  30. data/test/fixtures/get_password_list.json +42 -0
  31. data/test/fixtures/get_password_otp.json +5 -0
  32. data/test/fixtures/password_list_search_passwords.json +60 -0
  33. data/test/fixtures/update_password.json +31 -0
  34. data/test/fixtures/update_password_managed.json +8 -0
  35. data/test/passwordstate_test.rb +10 -2
  36. data/test/resources/password_list_test.rb +81 -0
  37. data/test/resources/password_test.rb +105 -0
  38. data/test/test_helper.rb +8 -0
  39. metadata +56 -15
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'test_helper'
2
4
 
3
5
  class PasswordstateTest < Minitest::Test
@@ -5,7 +7,13 @@ class PasswordstateTest < Minitest::Test
5
7
  refute_nil ::Passwordstate::VERSION
6
8
  end
7
9
 
8
- def test_it_does_something_useful
9
- assert false
10
+ def test_logging_setup
11
+ assert_equal 2, Passwordstate.logger.level # :warn
12
+
13
+ Passwordstate.debug!
14
+
15
+ assert_equal 0, Passwordstate.logger.level # :debug
16
+
17
+ Passwordstate.logger.level = :warn
10
18
  end
11
19
  end
@@ -0,0 +1,81 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'test_helper'
4
+
5
+ class PasswordListTest < Minitest::Test
6
+ def setup
7
+ Net::HTTP.any_instance.expects(:start).never
8
+
9
+ @client = Passwordstate::Client.new 'http://passwordstate.example.com'
10
+ @client.expects(:request)
11
+ .with(:get, 'passwordlists/100', query: {}, reason: nil)
12
+ .returns(JSON.parse(File.read('test/fixtures/get_password_list.json')))
13
+
14
+ @list = @client.password_lists.get 100
15
+ end
16
+
17
+ # CRUD tests
18
+ def test_create
19
+ @client.expects(:request)
20
+ .with(:post, 'passwordlists', query: {}, reason: nil, body:
21
+ {
22
+ 'PasswordList' => 'Managed Passwords',
23
+ 'Description' => "Someone's managed passwords",
24
+ 'NestUnderFolderID' => 23
25
+ })
26
+ .returns(JSON.parse(File.read('test/fixtures/get_password_list.json')))
27
+
28
+ @client.password_lists.create password_list: 'Managed Passwords',
29
+ description: "Someone's managed passwords",
30
+ nest_under_folder_id: 23
31
+ end
32
+
33
+ def test_read
34
+ @client.expects(:request)
35
+ .with(:get, 'passwordlists/100', query: {}, reason: nil)
36
+ .returns(JSON.parse(File.read('test/fixtures/get_password_list.json')))
37
+
38
+ @list.get
39
+ end
40
+
41
+ def test_update
42
+ assert_raises(Passwordstate::NotAcceptableError) { @list.put }
43
+ end
44
+
45
+ def test_delete
46
+ assert_raises(Passwordstate::NotAcceptableError) { @list.delete }
47
+ end
48
+
49
+ # Functionality test
50
+ def test_parsed
51
+ refute_nil @list.nil?
52
+
53
+ assert_equal 100, @list.password_list_id
54
+
55
+ assert_equal false, @list.hide_passwords.view
56
+ assert_equal true, @list.hide_passwords.modify
57
+ assert_equal false, @list.hide_passwords.admin
58
+
59
+ assert_equal '/Shared/Somewhere/Managed Passwords', @list.full_path(unix: true)
60
+ end
61
+
62
+ def test_search
63
+ @client.expects(:request)
64
+ .with(:get, 'searchpasswordlists', query: { 'SiteID' => 0 }, reason: nil)
65
+ .returns([JSON.parse(File.read('test/fixtures/get_password_list.json'))])
66
+
67
+ assert_equal @list.attributes, @client.password_lists.search(site_id: 0).first.attributes
68
+ end
69
+
70
+ def test_password_search
71
+ @client.expects(:request)
72
+ .with(:get, 'searchpasswords/100', query: { 'Description' => 'borg' }, reason: nil)
73
+ .returns(JSON.parse(File.read('test/fixtures/password_list_search_passwords.json')))
74
+
75
+ passwords = @list.passwords.search description: 'borg'
76
+
77
+ assert_equal 2, passwords.count
78
+ assert_equal 'borgdrone-4673615', passwords.first.user_name
79
+ assert_equal 'borgdrone-9342756', passwords.last.user_name
80
+ end
81
+ end
@@ -0,0 +1,105 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'test_helper'
4
+
5
+ class PasswordTest < Minitest::Test
6
+ def setup
7
+ Net::HTTP.any_instance.expects(:start).never
8
+
9
+ @client = Passwordstate::Client.new 'http://passwordstate.example.com'
10
+ @client.expects(:request)
11
+ .with(:get, 'passwords/18075', query: {}, reason: nil)
12
+ .returns(JSON.parse(File.read('test/fixtures/get_password.json')))
13
+
14
+ @password = @client.passwords.get 18_075
15
+ end
16
+
17
+ # CRUD tests
18
+ def test_create
19
+ @client.expects(:request)
20
+ .with(:post, 'passwords', query: {}, reason: nil, body:
21
+ {
22
+ 'PasswordListID' => 100,
23
+ 'Title' => 'borgdrone-4673615 @ Unimatrix Zero',
24
+ 'UserName' => 'borgdrone-4673615',
25
+ 'GeneratePassword' => true
26
+ })
27
+ .returns(JSON.parse(File.read('test/fixtures/get_password.json')))
28
+
29
+ @client.passwords.create password_list_id: 100,
30
+ title: 'borgdrone-4673615 @ Unimatrix Zero',
31
+ user_name: 'borgdrone-4673615',
32
+ generate_password: true
33
+ end
34
+
35
+ def test_read
36
+ @client.expects(:request)
37
+ .with(:get, 'passwords/18075', query: {}, reason: nil)
38
+ .returns(JSON.parse(File.read('test/fixtures/get_password.json')))
39
+
40
+ @password.get
41
+ end
42
+
43
+ def test_update
44
+ @password.domain = '1c0389a1-6e63-4276-8500-1e595f0288e9.cube.collective'
45
+
46
+ @client.expects(:request)
47
+ .with(:put, 'passwords', query: {}, reason: nil, body:
48
+ {
49
+ 'PasswordID' => 18_075,
50
+ 'Domain' => @password.domain
51
+ })
52
+ .returns(JSON.parse(File.read('test/fixtures/update_password.json')))
53
+
54
+ @password.put
55
+
56
+ assert_nil @password.status
57
+
58
+ @client.expects(:request)
59
+ .with(:put, 'passwords', query: {}, reason: nil, body:
60
+ {
61
+ 'PasswordID' => 18_075,
62
+ 'Password' => '<redacted>'
63
+ })
64
+ .returns(JSON.parse(File.read('test/fixtures/update_password_managed.json')))
65
+
66
+ @password.password = '<redacted>'
67
+ @password.put
68
+
69
+ refute_nil @password.status
70
+ assert_equal '<redacted>', @password.new_password
71
+ refute_equal '<redacted>', @password.current_password
72
+ end
73
+
74
+ def test_delete
75
+ @client.expects(:request)
76
+ .with(:delete, 'passwords/18075', query: { 'MoveToRecycleBin' => false }, reason: nil)
77
+ .returns(true)
78
+
79
+ @password.delete
80
+
81
+ @client.expects(:request)
82
+ .with(:get, 'passwords/18075', query: {}, reason: nil)
83
+ .raises(Passwordstate::HTTPError.new_by_code(404, nil, nil))
84
+
85
+ assert_raises(Passwordstate::NotFoundError) { @password.get }
86
+ end
87
+
88
+ # Functionality test
89
+ def test_otp
90
+ @client.expects(:request)
91
+ .with(:get, 'onetimepassword/18075')
92
+ .returns(JSON.parse(File.read('test/fixtures/get_password_otp.json')))
93
+
94
+ assert_nil @password.otp
95
+ assert_equal '123456', @password.otp!
96
+ end
97
+
98
+ def test_check_in
99
+ @client.expects(:request)
100
+ .with(:get, 'passwords/18075', query: { 'CheckIn' => nil })
101
+ .returns(true)
102
+
103
+ @password.check_in
104
+ end
105
+ end
data/test/test_helper.rb CHANGED
@@ -1,4 +1,12 @@
1
+ # frozen_string_literal: true
2
+
1
3
  $LOAD_PATH.unshift File.expand_path('../lib', __dir__)
2
4
  require 'passwordstate'
3
5
 
6
+ require 'minitest/reporters'
7
+ Minitest::Reporters.use! [
8
+ Minitest::Reporters::ProgressReporter.new,
9
+ Minitest::Reporters::JUnitReporter.new
10
+ ]
4
11
  require 'minitest/autorun'
12
+ require 'mocha/minitest'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: passwordstate
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alexander Olofsson
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-10-23 00:00:00.000000000 Z
11
+ date: 2024-03-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: logging
@@ -16,28 +16,28 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '2.2'
19
+ version: '2'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '2.2'
26
+ version: '2'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rubyntlm
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '0.6'
33
+ version: '0'
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: '0.6'
40
+ version: '0'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: bundler
43
43
  requirement: !ruby/object:Gem::Requirement
@@ -66,6 +66,34 @@ dependencies:
66
66
  - - ">="
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: minitest-reporters
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: mocha
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'
69
97
  - !ruby/object:Gem::Dependency
70
98
  name: rake
71
99
  requirement: !ruby/object:Gem::Requirement
@@ -101,6 +129,7 @@ executables: []
101
129
  extensions: []
102
130
  extra_rdoc_files: []
103
131
  files:
132
+ - ".github/workflows/ruby.yml"
104
133
  - ".gitignore"
105
134
  - ".gitlab-ci.yml"
106
135
  - ".rubocop.yml"
@@ -114,23 +143,37 @@ files:
114
143
  - lib/passwordstate/errors.rb
115
144
  - lib/passwordstate/resource.rb
116
145
  - lib/passwordstate/resource_list.rb
146
+ - lib/passwordstate/resources/active_directory.rb
147
+ - lib/passwordstate/resources/address_book.rb
117
148
  - lib/passwordstate/resources/document.rb
118
149
  - lib/passwordstate/resources/folder.rb
119
150
  - lib/passwordstate/resources/host.rb
120
151
  - lib/passwordstate/resources/password.rb
121
152
  - lib/passwordstate/resources/password_list.rb
122
153
  - lib/passwordstate/resources/permission.rb
154
+ - lib/passwordstate/resources/privileged_account.rb
155
+ - lib/passwordstate/resources/remote_site.rb
123
156
  - lib/passwordstate/resources/report.rb
124
157
  - lib/passwordstate/util.rb
125
158
  - lib/passwordstate/version.rb
126
159
  - passwordstate.gemspec
160
+ - test/client_test.rb
161
+ - test/fixtures/get_password.json
162
+ - test/fixtures/get_password_list.json
163
+ - test/fixtures/get_password_otp.json
164
+ - test/fixtures/password_list_search_passwords.json
165
+ - test/fixtures/update_password.json
166
+ - test/fixtures/update_password_managed.json
127
167
  - test/passwordstate_test.rb
168
+ - test/resources/password_list_test.rb
169
+ - test/resources/password_test.rb
128
170
  - test/test_helper.rb
129
171
  homepage: https://github.com/ananace/ruby-passwordstate
130
172
  licenses:
131
173
  - MIT
132
- metadata: {}
133
- post_install_message:
174
+ metadata:
175
+ rubygems_mfa_required: 'true'
176
+ post_install_message:
134
177
  rdoc_options: []
135
178
  require_paths:
136
179
  - lib
@@ -138,17 +181,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
138
181
  requirements:
139
182
  - - ">="
140
183
  - !ruby/object:Gem::Version
141
- version: '0'
184
+ version: '2.7'
142
185
  required_rubygems_version: !ruby/object:Gem::Requirement
143
186
  requirements:
144
187
  - - ">="
145
188
  - !ruby/object:Gem::Version
146
189
  version: '0'
147
190
  requirements: []
148
- rubygems_version: 3.0.6
149
- signing_key:
191
+ rubygems_version: 3.5.3
192
+ signing_key:
150
193
  specification_version: 4
151
194
  summary: A ruby API client for interacting with a passwordstate server
152
- test_files:
153
- - test/passwordstate_test.rb
154
- - test/test_helper.rb
195
+ test_files: []