keepass_kpscript 1.1.1 → 2.0.0
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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +6 -0
- data/lib/keepass_kpscript/database.rb +37 -50
- data/lib/keepass_kpscript/kpscript.rb +15 -29
- data/lib/keepass_kpscript/select.rb +18 -38
- data/lib/keepass_kpscript/version.rb +2 -3
- data/lib/keepass_kpscript.rb +4 -10
- metadata +5 -70
- data/spec/keepass_kpscript_test/helpers.rb +0 -56
- data/spec/keepass_kpscript_test/tests/keepass_kpscript/database_spec.rb +0 -246
- data/spec/keepass_kpscript_test/tests/keepass_kpscript/kpscript_spec.rb +0 -160
- data/spec/keepass_kpscript_test/tests/keepass_kpscript/select_spec.rb +0 -61
- data/spec/keepass_kpscript_test/tests/rubocop_spec.rb +0 -31
- data/spec/spec_helper.rb +0 -102
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: b754d8235936df28aed1ee695879da4aa898b1c01dfdff32dc1ecd4bf0eb0bde
|
|
4
|
+
data.tar.gz: f22206e94c0fc82470d8413812f2606ea25a698c78e4716563ea1d26ec6d4bd7
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 7de5fad3ecef8e503ad4b02a0aa7270fcb3ad224cfa1af3ac0340fc2ec2147e9ba5e322f283b98fc9112d5783d3b73226683cb2a40fe3362b42f64a04b94da95
|
|
7
|
+
data.tar.gz: 73c27cf3cb410d5c54f9f7776f0ebba22be8ef6f6eab918d365bb53b86a21fc96399e32dc2f6b6567b43bff049f2a3673e9c5c8b504e3d769ef962ff7cb30fe2
|
data/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,9 @@
|
|
|
1
|
+
# [v2.0.0](https://github.com/Muriel-Salvan/keepass_kpscript/compare/v1.1.1...v2.0.0) (2026-12-02 17:47:20)
|
|
2
|
+
|
|
3
|
+
### Breaking changes
|
|
4
|
+
|
|
5
|
+
* [breaking: update to Ruby 4, update dependencies, modernize the pipeline and reorganize test suite](https://github.com/Muriel-Salvan/keepass_kpscript/commit/1d4d40e7840ae0765bc36b2e8325e7362492fae2)
|
|
6
|
+
|
|
1
7
|
# [v1.1.1](https://github.com/Muriel-Salvan/keepass_kpscript/compare/v1.1.0...v1.1.1) (2022-12-31 12:36:42)
|
|
2
8
|
|
|
3
9
|
### Patches
|
|
@@ -5,19 +5,16 @@ require 'time'
|
|
|
5
5
|
require 'keepass_kpscript/select'
|
|
6
6
|
|
|
7
7
|
module KeepassKpscript
|
|
8
|
-
|
|
9
8
|
# KPScript API handling a KeePass database
|
|
10
9
|
class Database
|
|
11
|
-
|
|
12
10
|
# Constructor
|
|
13
11
|
# At least 1 of password, password_enc or key_file is mandatory.
|
|
14
12
|
#
|
|
15
|
-
#
|
|
16
|
-
#
|
|
17
|
-
#
|
|
18
|
-
#
|
|
19
|
-
#
|
|
20
|
-
# * *key_file* (String, SecretString or nil): Key file path opening the database, or nil if none [default: nil].
|
|
13
|
+
# @param kpscript [Kpscript] The KPScript instance handling this database
|
|
14
|
+
# @param database_file [String] Database file path
|
|
15
|
+
# @param password [String, SecretString, nil] Password opening the database, or nil if none
|
|
16
|
+
# @param password_enc [String, SecretString, nil] Encrypted password opening the database, or nil if none
|
|
17
|
+
# @param key_file [String, SecretString, nil] Key file path opening the database, or nil if none
|
|
21
18
|
def initialize(kpscript, database_file, password: nil, password_enc: nil, key_file: nil)
|
|
22
19
|
@kpscript = kpscript
|
|
23
20
|
@database_file = database_file
|
|
@@ -29,17 +26,17 @@ module KeepassKpscript
|
|
|
29
26
|
|
|
30
27
|
# Securely select field values from entries.
|
|
31
28
|
# Using this will make sure the entries' values are then erased from memory for security when exiting client code.
|
|
32
|
-
# Try to not clone or extrapolate those values in other String variables
|
|
29
|
+
# Try to not clone or extrapolate those values in other String variables.
|
|
30
|
+
# If you have to, call SecretString.erase on those variables to also erase their content.
|
|
31
|
+
#
|
|
32
|
+
# Takes the same parameters as {#entries_string}.
|
|
33
33
|
#
|
|
34
|
-
#
|
|
35
|
-
#
|
|
36
|
-
|
|
37
|
-
# * Parameters::
|
|
38
|
-
# * *values* (Array<String>)
|
|
39
|
-
def with_entries_string(*args, **kwargs)
|
|
34
|
+
# @yield Code called with the entries retrieved
|
|
35
|
+
# @yieldparam values [Array<String>] The retrieved field values
|
|
36
|
+
def with_entries_string(*, **)
|
|
40
37
|
values = []
|
|
41
38
|
begin
|
|
42
|
-
values = entries_string(
|
|
39
|
+
values = entries_string(*, **).map { |str| SecretString.new(str) }
|
|
43
40
|
yield values
|
|
44
41
|
ensure
|
|
45
42
|
values.each(&:erase)
|
|
@@ -48,14 +45,12 @@ module KeepassKpscript
|
|
|
48
45
|
|
|
49
46
|
# Get field string values from entries.
|
|
50
47
|
#
|
|
51
|
-
#
|
|
52
|
-
#
|
|
53
|
-
#
|
|
54
|
-
#
|
|
55
|
-
#
|
|
56
|
-
#
|
|
57
|
-
# Result::
|
|
58
|
-
# * Array<String>: List of retrieved field values
|
|
48
|
+
# @param select [Select] The entries selector
|
|
49
|
+
# @param field [String] Field to be selected
|
|
50
|
+
# @param fail_if_not_exists [Boolean] Do we fail if the field does not exist?
|
|
51
|
+
# @param fail_if_no_entry [Boolean] Do we fail if no entry was found?
|
|
52
|
+
# @param spr [Boolean] Do we Spr-compile the value of the retrieved field?
|
|
53
|
+
# @return [Array<String>] List of retrieved field values
|
|
59
54
|
def entries_string(
|
|
60
55
|
select,
|
|
61
56
|
field,
|
|
@@ -76,14 +71,13 @@ module KeepassKpscript
|
|
|
76
71
|
|
|
77
72
|
# Edit field values from entries.
|
|
78
73
|
#
|
|
79
|
-
#
|
|
80
|
-
#
|
|
81
|
-
#
|
|
82
|
-
#
|
|
83
|
-
#
|
|
84
|
-
#
|
|
85
|
-
#
|
|
86
|
-
# * *create_backup* (Boolean): Should we create backup of entries before modifying them? [default: false]
|
|
74
|
+
# @param select [Select] The entries selector
|
|
75
|
+
# @param fields [Hash{String, Symbol => String, SecretString}] Set of `field name => field value` to be set
|
|
76
|
+
# @param icon_idx [Integer, nil] Set the icon index, or nil if none
|
|
77
|
+
# @param custom_icon_idx [Integer, nil] Set the custom icon index, or nil if none
|
|
78
|
+
# @param expires [Boolean, nil] Edit the expires flag, or nil to leave it untouched
|
|
79
|
+
# @param expiry_time [Time, nil] Expiry time or nil to leave it untouched
|
|
80
|
+
# @param create_backup [Boolean] Should we create backup of entries before modifying them?
|
|
87
81
|
def edit_entries(
|
|
88
82
|
select,
|
|
89
83
|
fields: {},
|
|
@@ -109,19 +103,17 @@ module KeepassKpscript
|
|
|
109
103
|
|
|
110
104
|
# Retrieve a password for a given entry title
|
|
111
105
|
#
|
|
112
|
-
#
|
|
113
|
-
#
|
|
114
|
-
# Result::
|
|
115
|
-
# * String: Corresponding password
|
|
106
|
+
# @param title [String] Entry title
|
|
107
|
+
# @return [String] Corresponding password
|
|
116
108
|
def password_for(title)
|
|
117
109
|
entries_string(@kpscript.select.fields(Title: title), 'Password').first
|
|
118
110
|
end
|
|
119
111
|
|
|
120
112
|
# Detach binaries.
|
|
121
113
|
#
|
|
122
|
-
#
|
|
123
|
-
#
|
|
124
|
-
#
|
|
114
|
+
# @param copy_to_dir [String, nil] Specify a directory in which binaries are extracted, or nil to extract next to the database file.
|
|
115
|
+
# If copy_to_dir is specified, then the directory will be created and a copy of the original database will be used
|
|
116
|
+
# to detach bins, leaving the original database untouched.
|
|
125
117
|
def detach_bins(copy_to_dir: nil)
|
|
126
118
|
if copy_to_dir.nil?
|
|
127
119
|
execute_kpscript('-c:DetachBins')
|
|
@@ -142,11 +134,10 @@ module KeepassKpscript
|
|
|
142
134
|
|
|
143
135
|
# Export the database
|
|
144
136
|
#
|
|
145
|
-
#
|
|
146
|
-
#
|
|
147
|
-
#
|
|
148
|
-
#
|
|
149
|
-
# * *xsl_file* (String or nil): In case of transforming using XSL, this specifies the XSL file path to be used, or nil for none. [default: nil]
|
|
137
|
+
# @param format [String] Format to export to (see the KeePass Export dialog for possible values)
|
|
138
|
+
# @param file [String] File path to export to
|
|
139
|
+
# @param group_path [Array<String>, nil] Group path to export, or nil for all
|
|
140
|
+
# @param xsl_file [String, nil] In case of transforming using XSL, this specifies the XSL file path to be used, or nil for none
|
|
150
141
|
def export(format, file, group_path: nil, xsl_file: nil)
|
|
151
142
|
args = [
|
|
152
143
|
'-c:Export',
|
|
@@ -166,10 +157,8 @@ module KeepassKpscript
|
|
|
166
157
|
# Execute KPScript on our database with a given list of arguments.
|
|
167
158
|
# Handle internally all arguments needed to open the database with the correct secrets.
|
|
168
159
|
#
|
|
169
|
-
#
|
|
170
|
-
#
|
|
171
|
-
# Result::
|
|
172
|
-
# * String: stdout
|
|
160
|
+
# @param args [Array<String>] List of arguments
|
|
161
|
+
# @return [String] The command stdout
|
|
173
162
|
def execute_kpscript(*args)
|
|
174
163
|
resulting_stdout = nil
|
|
175
164
|
begin
|
|
@@ -188,7 +177,5 @@ module KeepassKpscript
|
|
|
188
177
|
end
|
|
189
178
|
resulting_stdout
|
|
190
179
|
end
|
|
191
|
-
|
|
192
180
|
end
|
|
193
|
-
|
|
194
181
|
end
|
|
@@ -4,16 +4,13 @@ require 'keepass_kpscript/select'
|
|
|
4
4
|
require 'keepass_kpscript/database'
|
|
5
5
|
|
|
6
6
|
module KeepassKpscript
|
|
7
|
-
|
|
8
7
|
# Drives an instance of KPScript
|
|
9
8
|
class Kpscript
|
|
10
|
-
|
|
11
9
|
# Constructor
|
|
12
10
|
#
|
|
13
|
-
#
|
|
14
|
-
#
|
|
15
|
-
#
|
|
16
|
-
# Warning: Those logs can contain passwords and secrets from your database. Only use it in a local environment.
|
|
11
|
+
# @param cmd [String] The KPScript command line
|
|
12
|
+
# @param debug [Boolean] Do we activate debugging logs?
|
|
13
|
+
# Warning: Those logs can contain passwords and secrets from your database. Only use it in a local environment.
|
|
17
14
|
def initialize(cmd, debug: false)
|
|
18
15
|
@cmd = cmd
|
|
19
16
|
@debug = debug
|
|
@@ -22,31 +19,26 @@ module KeepassKpscript
|
|
|
22
19
|
# Open a database using this KPScript instance.
|
|
23
20
|
# At least 1 of password, password_enc or key_file is mandatory.
|
|
24
21
|
#
|
|
25
|
-
#
|
|
26
|
-
#
|
|
27
|
-
#
|
|
28
|
-
#
|
|
29
|
-
#
|
|
30
|
-
# Result::
|
|
31
|
-
# * Database: The database
|
|
22
|
+
# @param database_file [String] Path to the database file
|
|
23
|
+
# @param password [String, SecretString, nil] Password opening the database, or nil if none
|
|
24
|
+
# @param password_enc [String, SecretString, nil] Encrypted password opening the database, or nil if none
|
|
25
|
+
# @param key_file [String, SecretString, nil] Key file path opening the database, or nil if none
|
|
26
|
+
# @return [Database] The database
|
|
32
27
|
def open(database_file, password: nil, password_enc: nil, key_file: nil)
|
|
33
28
|
Database.new(self, database_file, password:, password_enc:, key_file:)
|
|
34
29
|
end
|
|
35
30
|
|
|
36
31
|
# Shortcut to get easily access to selectors
|
|
37
32
|
#
|
|
38
|
-
#
|
|
39
|
-
# * Select: A new entries selector
|
|
33
|
+
# @return [Select] A new entries selector
|
|
40
34
|
def select
|
|
41
35
|
Select.new
|
|
42
36
|
end
|
|
43
37
|
|
|
44
38
|
# Encrypt a password so that it can be used to open databases without using the real password
|
|
45
39
|
#
|
|
46
|
-
#
|
|
47
|
-
#
|
|
48
|
-
# Result::
|
|
49
|
-
# * String: The encrypted password
|
|
40
|
+
# @param password [String, SecretString] Password to be encrypted
|
|
41
|
+
# @return [String] The encrypted password
|
|
50
42
|
def encrypt_password(password)
|
|
51
43
|
password_enc = nil
|
|
52
44
|
# We use a temporary database to encypt the password
|
|
@@ -65,10 +57,8 @@ module KeepassKpscript
|
|
|
65
57
|
|
|
66
58
|
# Run KPScript with a given list of arguments
|
|
67
59
|
#
|
|
68
|
-
#
|
|
69
|
-
#
|
|
70
|
-
# Result::
|
|
71
|
-
# * String: The stdout of the command (without the last status line)
|
|
60
|
+
# @param args [Array<String, SecretString>] List of arguments that are given to the KPScript command-line
|
|
61
|
+
# @return [String] The stdout of the command (without the last status line)
|
|
72
62
|
def run(*args)
|
|
73
63
|
args.flatten!
|
|
74
64
|
resulting_stdout = nil
|
|
@@ -99,14 +89,10 @@ module KeepassKpscript
|
|
|
99
89
|
# Issue some debugging logs, if debug is activated.
|
|
100
90
|
# Secret strings will be displayed unprotected by those logs.
|
|
101
91
|
#
|
|
102
|
-
#
|
|
103
|
-
#
|
|
104
|
-
# * Result::
|
|
105
|
-
# * String: Message to display
|
|
92
|
+
# @yield Code giving the message to be displayed
|
|
93
|
+
# @yieldreturn [String, SecretString] Message to display
|
|
106
94
|
def log_debug
|
|
107
95
|
puts "[ DEBUG ] - #{yield.to_unprotected}" if @debug
|
|
108
96
|
end
|
|
109
|
-
|
|
110
97
|
end
|
|
111
|
-
|
|
112
98
|
end
|
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
module KeepassKpscript
|
|
2
|
-
|
|
3
2
|
# Define rules to select entries from a Keepass database.
|
|
4
3
|
# Those rules are taken from https://keepass.info/help/v2_dev/scr_sc_index.html#editentry
|
|
5
4
|
class Select
|
|
6
|
-
|
|
7
5
|
# Constructor
|
|
8
6
|
def initialize
|
|
9
7
|
@selectors = []
|
|
@@ -11,10 +9,8 @@ module KeepassKpscript
|
|
|
11
9
|
|
|
12
10
|
# Select a set of given field values
|
|
13
11
|
#
|
|
14
|
-
#
|
|
15
|
-
#
|
|
16
|
-
# Result::
|
|
17
|
-
# * self: The selector itself, useful for chaining
|
|
12
|
+
# @param selection [Hash{String, Symbol => String}] Set of `field name => field value` to be selected
|
|
13
|
+
# @return [self] The selector itself, useful for chaining
|
|
18
14
|
def fields(selection)
|
|
19
15
|
selection.each do |field_name, field_value|
|
|
20
16
|
@selectors << "-ref-#{field_name}:\"#{field_value}\""
|
|
@@ -24,10 +20,8 @@ module KeepassKpscript
|
|
|
24
20
|
|
|
25
21
|
# Select a UUID
|
|
26
22
|
#
|
|
27
|
-
#
|
|
28
|
-
#
|
|
29
|
-
# Result::
|
|
30
|
-
# * self: The selector itself, useful for chaining
|
|
23
|
+
# @param id [String] The UUID
|
|
24
|
+
# @return [self] The selector itself, useful for chaining
|
|
31
25
|
def uuid(id)
|
|
32
26
|
@selectors << "-refx-UUID:#{id}"
|
|
33
27
|
self
|
|
@@ -35,10 +29,8 @@ module KeepassKpscript
|
|
|
35
29
|
|
|
36
30
|
# Select a list of tags
|
|
37
31
|
#
|
|
38
|
-
#
|
|
39
|
-
#
|
|
40
|
-
# Result::
|
|
41
|
-
# * self: The selector itself, useful for chaining
|
|
32
|
+
# @param lst_tags [Array<String>] List of tags to select
|
|
33
|
+
# @return [self] The selector itself, useful for chaining
|
|
42
34
|
def tags(*lst_tags)
|
|
43
35
|
@selectors << "-refx-Tags:\"#{lst_tags.flatten.join(',')}\""
|
|
44
36
|
self
|
|
@@ -46,32 +38,26 @@ module KeepassKpscript
|
|
|
46
38
|
|
|
47
39
|
# Select entries that expire
|
|
48
40
|
#
|
|
49
|
-
#
|
|
50
|
-
#
|
|
51
|
-
|
|
52
|
-
# * self: The selector itself, useful for chaining
|
|
53
|
-
def expires(switch = true)
|
|
41
|
+
# @param switch [Boolean] Do we select entries that expire?
|
|
42
|
+
# @return [self] The selector itself, useful for chaining
|
|
43
|
+
def expires(switch: true)
|
|
54
44
|
@selectors << "-refx-Expires:#{switch ? 'true' : 'false'}"
|
|
55
45
|
self
|
|
56
46
|
end
|
|
57
47
|
|
|
58
48
|
# Select entries that have expired
|
|
59
49
|
#
|
|
60
|
-
#
|
|
61
|
-
#
|
|
62
|
-
|
|
63
|
-
# * self: The selector itself, useful for chaining
|
|
64
|
-
def expired(switch = true)
|
|
50
|
+
# @param switch [Boolean] Do we select entries that have expired?
|
|
51
|
+
# @return [self] The selector itself, useful for chaining
|
|
52
|
+
def expired(switch: true)
|
|
65
53
|
@selectors << "-refx-Expired:#{switch ? 'true' : 'false'}"
|
|
66
54
|
self
|
|
67
55
|
end
|
|
68
56
|
|
|
69
57
|
# Select entries that have a given parent group
|
|
70
58
|
#
|
|
71
|
-
#
|
|
72
|
-
#
|
|
73
|
-
# Result::
|
|
74
|
-
# * self: The selector itself, useful for chaining
|
|
59
|
+
# @param group_name [String] Name of the parent group
|
|
60
|
+
# @return [self] The selector itself, useful for chaining
|
|
75
61
|
def group(group_name)
|
|
76
62
|
@selectors << "-refx-Group:\"#{group_name}\""
|
|
77
63
|
self
|
|
@@ -79,10 +65,8 @@ module KeepassKpscript
|
|
|
79
65
|
|
|
80
66
|
# Select entries that have a given group path
|
|
81
67
|
#
|
|
82
|
-
#
|
|
83
|
-
#
|
|
84
|
-
# Result::
|
|
85
|
-
# * self: The selector itself, useful for chaining
|
|
68
|
+
# @param group_path_entries [Array<String>] Group path
|
|
69
|
+
# @return [self] The selector itself, useful for chaining
|
|
86
70
|
def group_path(*group_path_entries)
|
|
87
71
|
@selectors << "-refx-GroupPath:\"#{group_path_entries.flatten.join('/')}\""
|
|
88
72
|
self
|
|
@@ -90,8 +74,7 @@ module KeepassKpscript
|
|
|
90
74
|
|
|
91
75
|
# Select all entries
|
|
92
76
|
#
|
|
93
|
-
#
|
|
94
|
-
# * self: The selector itself, useful for chaining
|
|
77
|
+
# @return [self] The selector itself, useful for chaining
|
|
95
78
|
def all
|
|
96
79
|
@selectors << '-refx-All'
|
|
97
80
|
self
|
|
@@ -99,12 +82,9 @@ module KeepassKpscript
|
|
|
99
82
|
|
|
100
83
|
# Return the command-line string selecting the entries
|
|
101
84
|
#
|
|
102
|
-
#
|
|
103
|
-
# * String: The command-line string
|
|
85
|
+
# @return [String] The command-line string
|
|
104
86
|
def to_s
|
|
105
87
|
@selectors.join(' ')
|
|
106
88
|
end
|
|
107
|
-
|
|
108
89
|
end
|
|
109
|
-
|
|
110
90
|
end
|
data/lib/keepass_kpscript.rb
CHANGED
|
@@ -2,21 +2,15 @@ require 'keepass_kpscript/kpscript'
|
|
|
2
2
|
|
|
3
3
|
# Ruby API wrapping the KPScript CLI
|
|
4
4
|
module KeepassKpscript
|
|
5
|
-
|
|
6
5
|
class << self
|
|
7
|
-
|
|
8
6
|
# Get a KPScript instance from a given KPScript command line
|
|
9
7
|
#
|
|
10
|
-
#
|
|
11
|
-
#
|
|
12
|
-
#
|
|
13
|
-
#
|
|
14
|
-
# Result::
|
|
15
|
-
# * Kpscript: A KPScript instance
|
|
8
|
+
# @param cmd [String] KPScript command line
|
|
9
|
+
# @param debug [Boolean] Do we activate debugging logs?
|
|
10
|
+
# Warning: Those logs can contain passwords and secrets from your database. Only use it in a local environment.
|
|
11
|
+
# @return [Kpscript] A KPScript instance
|
|
16
12
|
def use(cmd, debug: false)
|
|
17
13
|
Kpscript.new(cmd, debug:)
|
|
18
14
|
end
|
|
19
|
-
|
|
20
15
|
end
|
|
21
|
-
|
|
22
16
|
end
|
metadata
CHANGED
|
@@ -1,14 +1,13 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: keepass_kpscript
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version:
|
|
4
|
+
version: 2.0.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Muriel Salvan
|
|
8
|
-
autorequire:
|
|
9
8
|
bindir: bin
|
|
10
9
|
cert_chain: []
|
|
11
|
-
date:
|
|
10
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
|
12
11
|
dependencies:
|
|
13
12
|
- !ruby/object:Gem::Dependency
|
|
14
13
|
name: secret_string
|
|
@@ -24,62 +23,6 @@ dependencies:
|
|
|
24
23
|
- - "~>"
|
|
25
24
|
- !ruby/object:Gem::Version
|
|
26
25
|
version: '1.1'
|
|
27
|
-
- !ruby/object:Gem::Dependency
|
|
28
|
-
name: rspec
|
|
29
|
-
requirement: !ruby/object:Gem::Requirement
|
|
30
|
-
requirements:
|
|
31
|
-
- - "~>"
|
|
32
|
-
- !ruby/object:Gem::Version
|
|
33
|
-
version: '3.12'
|
|
34
|
-
type: :development
|
|
35
|
-
prerelease: false
|
|
36
|
-
version_requirements: !ruby/object:Gem::Requirement
|
|
37
|
-
requirements:
|
|
38
|
-
- - "~>"
|
|
39
|
-
- !ruby/object:Gem::Version
|
|
40
|
-
version: '3.12'
|
|
41
|
-
- !ruby/object:Gem::Dependency
|
|
42
|
-
name: sem_ver_components
|
|
43
|
-
requirement: !ruby/object:Gem::Requirement
|
|
44
|
-
requirements:
|
|
45
|
-
- - "~>"
|
|
46
|
-
- !ruby/object:Gem::Version
|
|
47
|
-
version: '0.3'
|
|
48
|
-
type: :development
|
|
49
|
-
prerelease: false
|
|
50
|
-
version_requirements: !ruby/object:Gem::Requirement
|
|
51
|
-
requirements:
|
|
52
|
-
- - "~>"
|
|
53
|
-
- !ruby/object:Gem::Version
|
|
54
|
-
version: '0.3'
|
|
55
|
-
- !ruby/object:Gem::Dependency
|
|
56
|
-
name: rubocop
|
|
57
|
-
requirement: !ruby/object:Gem::Requirement
|
|
58
|
-
requirements:
|
|
59
|
-
- - "~>"
|
|
60
|
-
- !ruby/object:Gem::Version
|
|
61
|
-
version: '1.41'
|
|
62
|
-
type: :development
|
|
63
|
-
prerelease: false
|
|
64
|
-
version_requirements: !ruby/object:Gem::Requirement
|
|
65
|
-
requirements:
|
|
66
|
-
- - "~>"
|
|
67
|
-
- !ruby/object:Gem::Version
|
|
68
|
-
version: '1.41'
|
|
69
|
-
- !ruby/object:Gem::Dependency
|
|
70
|
-
name: rubocop-rspec
|
|
71
|
-
requirement: !ruby/object:Gem::Requirement
|
|
72
|
-
requirements:
|
|
73
|
-
- - "~>"
|
|
74
|
-
- !ruby/object:Gem::Version
|
|
75
|
-
version: '2.16'
|
|
76
|
-
type: :development
|
|
77
|
-
prerelease: false
|
|
78
|
-
version_requirements: !ruby/object:Gem::Requirement
|
|
79
|
-
requirements:
|
|
80
|
-
- - "~>"
|
|
81
|
-
- !ruby/object:Gem::Version
|
|
82
|
-
version: '2.16'
|
|
83
26
|
description: Ruby API to handle Keepass databases using KPScript
|
|
84
27
|
email:
|
|
85
28
|
- muriel@x-aeon.com
|
|
@@ -97,18 +40,11 @@ files:
|
|
|
97
40
|
- lib/keepass_kpscript/pass_encryptor.kdbx
|
|
98
41
|
- lib/keepass_kpscript/select.rb
|
|
99
42
|
- lib/keepass_kpscript/version.rb
|
|
100
|
-
|
|
101
|
-
- spec/keepass_kpscript_test/tests/keepass_kpscript/database_spec.rb
|
|
102
|
-
- spec/keepass_kpscript_test/tests/keepass_kpscript/kpscript_spec.rb
|
|
103
|
-
- spec/keepass_kpscript_test/tests/keepass_kpscript/select_spec.rb
|
|
104
|
-
- spec/keepass_kpscript_test/tests/rubocop_spec.rb
|
|
105
|
-
- spec/spec_helper.rb
|
|
106
|
-
homepage:
|
|
43
|
+
homepage: https://github.com/Muriel-Salvan/keepass_kpscript
|
|
107
44
|
licenses:
|
|
108
45
|
- BSD-3-Clause
|
|
109
46
|
metadata:
|
|
110
47
|
rubygems_mfa_required: 'true'
|
|
111
|
-
post_install_message:
|
|
112
48
|
rdoc_options: []
|
|
113
49
|
require_paths:
|
|
114
50
|
- lib
|
|
@@ -116,15 +52,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
|
116
52
|
requirements:
|
|
117
53
|
- - "~>"
|
|
118
54
|
- !ruby/object:Gem::Version
|
|
119
|
-
version: '
|
|
55
|
+
version: '4.0'
|
|
120
56
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
121
57
|
requirements:
|
|
122
58
|
- - ">="
|
|
123
59
|
- !ruby/object:Gem::Version
|
|
124
60
|
version: '0'
|
|
125
61
|
requirements: []
|
|
126
|
-
rubygems_version:
|
|
127
|
-
signing_key:
|
|
62
|
+
rubygems_version: 4.0.20
|
|
128
63
|
specification_version: 4
|
|
129
64
|
summary: Keepass KPScript
|
|
130
65
|
test_files: []
|
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
require 'stringio'
|
|
2
|
-
require 'keepass_kpscript'
|
|
3
|
-
|
|
4
|
-
module KeepassKpscriptTest
|
|
5
|
-
|
|
6
|
-
module Helpers
|
|
7
|
-
|
|
8
|
-
# Expect some calls to be done on KPScript
|
|
9
|
-
#
|
|
10
|
-
# Parameters::
|
|
11
|
-
# * *expected_calls* (Array<[String, String or Hash]>): The list of calls and their corresponding mocked response:
|
|
12
|
-
# * String: Mocked stdout
|
|
13
|
-
# * Hash<Symbol,Object>: More complete structure defining the mocked response:
|
|
14
|
-
# * *exit_status* (Integer): The command exit status [default: 0]
|
|
15
|
-
# * *stdout* (String): The command stdout
|
|
16
|
-
def expect_calls_to_kpscript(expected_calls)
|
|
17
|
-
if expected_calls.empty?
|
|
18
|
-
expect(Open3).not_to receive(:popen3)
|
|
19
|
-
else
|
|
20
|
-
expected_calls.each do |(expected_call, mocked_call)|
|
|
21
|
-
mocked_call = { stdout: mocked_call } if mocked_call.is_a?(String)
|
|
22
|
-
mocked_call[:exit_status] = 0 unless mocked_call.key?(:exit_status)
|
|
23
|
-
expect(Open3).to receive(:popen3).with(expected_call) do |_cmd, &block|
|
|
24
|
-
wait_thr_double = instance_double(Process::Waiter)
|
|
25
|
-
allow(wait_thr_double).to receive(:value) do
|
|
26
|
-
wait_thr_value_double = instance_double(Process::Status)
|
|
27
|
-
allow(wait_thr_value_double).to receive(:exitstatus) do
|
|
28
|
-
mocked_call[:exit_status]
|
|
29
|
-
end
|
|
30
|
-
wait_thr_value_double
|
|
31
|
-
end
|
|
32
|
-
block.call(
|
|
33
|
-
StringIO.new,
|
|
34
|
-
StringIO.new(mocked_call[:stdout]),
|
|
35
|
-
StringIO.new,
|
|
36
|
-
wait_thr_double
|
|
37
|
-
)
|
|
38
|
-
end
|
|
39
|
-
end
|
|
40
|
-
end
|
|
41
|
-
end
|
|
42
|
-
|
|
43
|
-
end
|
|
44
|
-
|
|
45
|
-
end
|
|
46
|
-
|
|
47
|
-
RSpec.configure do |config|
|
|
48
|
-
config.include KeepassKpscriptTest::Helpers
|
|
49
|
-
|
|
50
|
-
config.before do
|
|
51
|
-
# Make sure log debugs are not output on screen during tests
|
|
52
|
-
# rubocop:disable RSpec/AnyInstance
|
|
53
|
-
allow_any_instance_of(KeepassKpscript::Kpscript).to receive(:log_debug).and_yield
|
|
54
|
-
# rubocop:enable RSpec/AnyInstance
|
|
55
|
-
end
|
|
56
|
-
end
|
|
@@ -1,246 +0,0 @@
|
|
|
1
|
-
describe KeepassKpscript::Database do
|
|
2
|
-
|
|
3
|
-
shared_examples 'a database' do
|
|
4
|
-
|
|
5
|
-
subject(:database) { kpscript.open('/path/to/my_db.kdbx', password: 'MyPassword') }
|
|
6
|
-
|
|
7
|
-
let(:kpscript) { KeepassKpscript.use('/path/to/KPScript.exe', debug:) }
|
|
8
|
-
|
|
9
|
-
it 'gets a simple password for an entry title' do
|
|
10
|
-
expect_calls_to_kpscript [
|
|
11
|
-
[
|
|
12
|
-
'/path/to/KPScript.exe "/path/to/my_db.kdbx" -pw:"MyPassword" -c:GetEntryString -ref-Title:"MyEntryTitle" -Field:"Password"',
|
|
13
|
-
<<~EO_STDOUT
|
|
14
|
-
MyEntryPassword
|
|
15
|
-
OK: Operation completed successfully.
|
|
16
|
-
EO_STDOUT
|
|
17
|
-
]
|
|
18
|
-
]
|
|
19
|
-
expect(database.password_for('MyEntryTitle')).to eq 'MyEntryPassword'
|
|
20
|
-
end
|
|
21
|
-
|
|
22
|
-
it 'fails if no authentication mechanism is provided' do
|
|
23
|
-
expect_calls_to_kpscript []
|
|
24
|
-
expect { kpscript.open('/path/to/my_db.kdbx') }.to raise_error 'Please specify at least one of password, password_enc or key_file arguments'
|
|
25
|
-
end
|
|
26
|
-
|
|
27
|
-
it 'fails with an error silencing secrets when KPScript returns a non-zero exit status' do
|
|
28
|
-
expect_calls_to_kpscript [
|
|
29
|
-
[
|
|
30
|
-
'/path/to/KPScript.exe "/path/to/my_db.kdbx" -pw:"MyPassword" -c:GetEntryString -ref-Title:"MyEntryTitle" -Field:"Password"',
|
|
31
|
-
{
|
|
32
|
-
stdout: '',
|
|
33
|
-
exit_status: 1
|
|
34
|
-
}
|
|
35
|
-
]
|
|
36
|
-
]
|
|
37
|
-
expect { database.password_for('MyEntryTitle') }.to raise_error 'Error while executing /path/to/KPScript.exe "/path/to/my_db.kdbx" -pw:"XXXXX" -c:GetEntryString -ref-Title:"MyEntryTitle" -Field:"Password" (exit status: 1)'
|
|
38
|
-
end
|
|
39
|
-
|
|
40
|
-
it 'fails with an error silencing secrets when KPScript returns an error message' do
|
|
41
|
-
expect_calls_to_kpscript [
|
|
42
|
-
[
|
|
43
|
-
'/path/to/KPScript.exe "/path/to/my_db.kdbx" -pw:"MyPassword" -c:GetEntryString -ref-Title:"MyEntryTitle" -Field:"Password"',
|
|
44
|
-
'E: Error reading database.'
|
|
45
|
-
]
|
|
46
|
-
]
|
|
47
|
-
expect { database.password_for('MyEntryTitle') }.to raise_error 'Error returned by /path/to/KPScript.exe "/path/to/my_db.kdbx" -pw:"XXXXX" -c:GetEntryString -ref-Title:"MyEntryTitle" -Field:"Password": E: Error reading database.'
|
|
48
|
-
end
|
|
49
|
-
|
|
50
|
-
it 'reads entries string' do
|
|
51
|
-
expect_calls_to_kpscript [
|
|
52
|
-
[
|
|
53
|
-
'/path/to/KPScript.exe "/path/to/my_db.kdbx" -pw:"MyPassword" -c:GetEntryString -refx-All -Field:"Field"',
|
|
54
|
-
<<~EO_STDOUT
|
|
55
|
-
Value1
|
|
56
|
-
Value2
|
|
57
|
-
Value3
|
|
58
|
-
OK: Operation completed successfully.
|
|
59
|
-
EO_STDOUT
|
|
60
|
-
]
|
|
61
|
-
]
|
|
62
|
-
expect(database.entries_string(kpscript.select.all, 'Field')).to eq %w[Value1 Value2 Value3]
|
|
63
|
-
end
|
|
64
|
-
|
|
65
|
-
it 'reads entries string in a secured way with secret strings' do
|
|
66
|
-
expect_calls_to_kpscript [
|
|
67
|
-
[
|
|
68
|
-
'/path/to/KPScript.exe "/path/to/my_db.kdbx" -pw:"MyPassword" -c:GetEntryString -refx-All -Field:"Field"',
|
|
69
|
-
<<~EO_STDOUT
|
|
70
|
-
Value1
|
|
71
|
-
Value2
|
|
72
|
-
Value3
|
|
73
|
-
OK: Operation completed successfully.
|
|
74
|
-
EO_STDOUT
|
|
75
|
-
]
|
|
76
|
-
]
|
|
77
|
-
leaked_values = nil
|
|
78
|
-
expect do
|
|
79
|
-
database.with_entries_string(kpscript.select.all, 'Field') do |values|
|
|
80
|
-
expect(values.map(&:to_s)).to eq %w[XXXXX XXXXX XXXXX]
|
|
81
|
-
expect(values.map(&:to_unprotected)).to eq %w[Value1 Value2 Value3]
|
|
82
|
-
leaked_values = values
|
|
83
|
-
end
|
|
84
|
-
end.not_to raise_error
|
|
85
|
-
expect(leaked_values.map(&:to_s)).to eq %w[XXXXX XXXXX XXXXX]
|
|
86
|
-
expect(leaked_values.map(&:to_unprotected)).to eq ["\x00\x00\x00\x00\x00\x00", "\x00\x00\x00\x00\x00\x00", "\x00\x00\x00\x00\x00\x00"]
|
|
87
|
-
end
|
|
88
|
-
|
|
89
|
-
{
|
|
90
|
-
fail_if_not_exists: '-FailIfNotExists',
|
|
91
|
-
fail_if_no_entry: '-FailIfNoEntry',
|
|
92
|
-
spr: '-Spr'
|
|
93
|
-
}.each do |keyword, kpscript_flag|
|
|
94
|
-
|
|
95
|
-
it "reads entries string with #{keyword} flag" do
|
|
96
|
-
expect_calls_to_kpscript [
|
|
97
|
-
[
|
|
98
|
-
"/path/to/KPScript.exe \"/path/to/my_db.kdbx\" -pw:\"MyPassword\" -c:GetEntryString -refx-All -Field:\"Field\" #{kpscript_flag}",
|
|
99
|
-
<<~EO_STDOUT
|
|
100
|
-
Value1
|
|
101
|
-
Value2
|
|
102
|
-
Value3
|
|
103
|
-
OK: Operation completed successfully.
|
|
104
|
-
EO_STDOUT
|
|
105
|
-
]
|
|
106
|
-
]
|
|
107
|
-
expect(database.entries_string(kpscript.select.all, 'Field', **{ keyword => true })).to eq %w[Value1 Value2 Value3]
|
|
108
|
-
end
|
|
109
|
-
|
|
110
|
-
it "reads entries string in a secured way with secret strings with #{keyword} flag" do
|
|
111
|
-
expect_calls_to_kpscript [
|
|
112
|
-
[
|
|
113
|
-
"/path/to/KPScript.exe \"/path/to/my_db.kdbx\" -pw:\"MyPassword\" -c:GetEntryString -refx-All -Field:\"Field\" #{kpscript_flag}",
|
|
114
|
-
<<~EO_STDOUT
|
|
115
|
-
Value1
|
|
116
|
-
Value2
|
|
117
|
-
Value3
|
|
118
|
-
OK: Operation completed successfully.
|
|
119
|
-
EO_STDOUT
|
|
120
|
-
]
|
|
121
|
-
]
|
|
122
|
-
leaked_values = nil
|
|
123
|
-
expect do
|
|
124
|
-
database.with_entries_string(kpscript.select.all, 'Field', **{ keyword => true }) do |values|
|
|
125
|
-
expect(values.map(&:to_s)).to eq %w[XXXXX XXXXX XXXXX]
|
|
126
|
-
expect(values.map(&:to_unprotected)).to eq %w[Value1 Value2 Value3]
|
|
127
|
-
leaked_values = values
|
|
128
|
-
end
|
|
129
|
-
end.not_to raise_error
|
|
130
|
-
expect(leaked_values.map(&:to_s)).to eq %w[XXXXX XXXXX XXXXX]
|
|
131
|
-
expect(leaked_values.map(&:to_unprotected)).to eq ["\x00\x00\x00\x00\x00\x00", "\x00\x00\x00\x00\x00\x00", "\x00\x00\x00\x00\x00\x00"]
|
|
132
|
-
end
|
|
133
|
-
|
|
134
|
-
end
|
|
135
|
-
|
|
136
|
-
# All edit entries test cases
|
|
137
|
-
{
|
|
138
|
-
{ fields: { Field: 'Value' } } => '-set-Field:"Value"',
|
|
139
|
-
{ fields: { Field: SecretString.new('Value') } } => '-set-Field:"Value"',
|
|
140
|
-
{ fields: { Field1: 'Value1', Field2: 'Value2' } } => '-set-Field1:"Value1" -set-Field2:"Value2"',
|
|
141
|
-
{ icon_idx: 7 } => '-setx-Icon:7',
|
|
142
|
-
{ custom_icon_idx: 11 } => '-setx-CustomIcon:11',
|
|
143
|
-
{ expires: true } => '-setx-Expires:true',
|
|
144
|
-
{ expiry_time: Time.parse('2021-06-30 15:12:11') } => '-setx-ExpiryTime:"2021-06-30T15:12:11"',
|
|
145
|
-
{ fields: { Field: 'Value' }, create_backup: true } => '-set-Field:"Value" -CreateBackup',
|
|
146
|
-
{
|
|
147
|
-
fields: { Field1: 'Value1', Field2: 'Value2' },
|
|
148
|
-
expiry_time: Time.parse('2021-06-30 15:12:11'),
|
|
149
|
-
icon_idx: 7,
|
|
150
|
-
create_backup: true
|
|
151
|
-
} => '-set-Field1:"Value1" -set-Field2:"Value2" -setx-Icon:7 -setx-ExpiryTime:"2021-06-30T15:12:11" -CreateBackup'
|
|
152
|
-
}.each do |kwargs, expected_args|
|
|
153
|
-
|
|
154
|
-
it "edit entries using #{kwargs}" do
|
|
155
|
-
expect_calls_to_kpscript [
|
|
156
|
-
[
|
|
157
|
-
"/path/to/KPScript.exe \"/path/to/my_db.kdbx\" -pw:\"MyPassword\" -c:EditEntry -refx-All #{expected_args}",
|
|
158
|
-
'OK: Operation completed successfully.'
|
|
159
|
-
]
|
|
160
|
-
]
|
|
161
|
-
expect { database.edit_entries(kpscript.select.all, **kwargs) }.not_to raise_error
|
|
162
|
-
end
|
|
163
|
-
|
|
164
|
-
end
|
|
165
|
-
|
|
166
|
-
it 'detaches binaries' do
|
|
167
|
-
expect_calls_to_kpscript [
|
|
168
|
-
[
|
|
169
|
-
'/path/to/KPScript.exe "/path/to/my_db.kdbx" -pw:"MyPassword" -c:DetachBins',
|
|
170
|
-
'OK: Operation completed successfully.'
|
|
171
|
-
]
|
|
172
|
-
]
|
|
173
|
-
expect { database.detach_bins }.not_to raise_error
|
|
174
|
-
end
|
|
175
|
-
|
|
176
|
-
it 'detaches binaries in another directory' do
|
|
177
|
-
tmpdir = "#{Dir.tmpdir}/keepass_kpscript_test"
|
|
178
|
-
FileUtils.mkdir_p tmpdir
|
|
179
|
-
begin
|
|
180
|
-
database_file = "#{tmpdir}/my_db.kdbx"
|
|
181
|
-
File.write(database_file, 'Dummy database')
|
|
182
|
-
bins_dir = "#{tmpdir}/bins_dir"
|
|
183
|
-
expect_calls_to_kpscript [
|
|
184
|
-
[
|
|
185
|
-
"/path/to/KPScript.exe \"#{bins_dir}/my_db.kdbx.tmp.kdbx\" -pw:\"MyPassword\" -c:DetachBins",
|
|
186
|
-
'OK: Operation completed successfully.'
|
|
187
|
-
]
|
|
188
|
-
]
|
|
189
|
-
expect { kpscript.open(database_file, password: 'MyPassword').detach_bins(copy_to_dir: bins_dir) }.not_to raise_error
|
|
190
|
-
expect(File.exist?(bins_dir)).to be true
|
|
191
|
-
# Check that no database copy is remaining
|
|
192
|
-
expect(Dir.glob("#{bins_dir}/*")).to eq []
|
|
193
|
-
ensure
|
|
194
|
-
FileUtils.rm_rf tmpdir
|
|
195
|
-
end
|
|
196
|
-
end
|
|
197
|
-
|
|
198
|
-
it 'exports the database' do
|
|
199
|
-
expect_calls_to_kpscript [
|
|
200
|
-
[
|
|
201
|
-
'/path/to/KPScript.exe "/path/to/my_db.kdbx" -pw:"MyPassword" -c:Export -Format:"Export Format" -OutFile:"/path/to/export_file"',
|
|
202
|
-
'OK: Operation completed successfully.'
|
|
203
|
-
]
|
|
204
|
-
]
|
|
205
|
-
expect { database.export('Export Format', '/path/to/export_file') }.not_to raise_error
|
|
206
|
-
end
|
|
207
|
-
|
|
208
|
-
it 'exports the database with a group path selected' do
|
|
209
|
-
expect_calls_to_kpscript [
|
|
210
|
-
[
|
|
211
|
-
'/path/to/KPScript.exe "/path/to/my_db.kdbx" -pw:"MyPassword" -c:Export -Format:"Export Format" -OutFile:"/path/to/export_file" -GroupPath:"Group1/Group2/Group3"',
|
|
212
|
-
'OK: Operation completed successfully.'
|
|
213
|
-
]
|
|
214
|
-
]
|
|
215
|
-
expect { database.export('Export Format', '/path/to/export_file', group_path: %w[Group1 Group2 Group3]) }.not_to raise_error
|
|
216
|
-
end
|
|
217
|
-
|
|
218
|
-
it 'exports the database with an XSL file specified' do
|
|
219
|
-
expect_calls_to_kpscript [
|
|
220
|
-
[
|
|
221
|
-
'/path/to/KPScript.exe "/path/to/my_db.kdbx" -pw:"MyPassword" -c:Export -Format:"Export Format" -OutFile:"/path/to/export_file" -XslFile:"/path/to/xsl_file.xsl"',
|
|
222
|
-
'OK: Operation completed successfully.'
|
|
223
|
-
]
|
|
224
|
-
]
|
|
225
|
-
expect { database.export('Export Format', '/path/to/export_file', xsl_file: '/path/to/xsl_file.xsl') }.not_to raise_error
|
|
226
|
-
end
|
|
227
|
-
|
|
228
|
-
end
|
|
229
|
-
|
|
230
|
-
context 'without debug' do
|
|
231
|
-
|
|
232
|
-
it_behaves_like 'a database' do
|
|
233
|
-
let(:debug) { false }
|
|
234
|
-
end
|
|
235
|
-
|
|
236
|
-
end
|
|
237
|
-
|
|
238
|
-
context 'with debug' do
|
|
239
|
-
|
|
240
|
-
it_behaves_like 'a database' do
|
|
241
|
-
let(:debug) { true }
|
|
242
|
-
end
|
|
243
|
-
|
|
244
|
-
end
|
|
245
|
-
|
|
246
|
-
end
|
|
@@ -1,160 +0,0 @@
|
|
|
1
|
-
describe KeepassKpscript::Kpscript do
|
|
2
|
-
|
|
3
|
-
shared_examples 'a kpscript instance' do
|
|
4
|
-
|
|
5
|
-
subject(:kpscript) { KeepassKpscript.use('/path/to/KPScript.exe', debug:) }
|
|
6
|
-
|
|
7
|
-
it 'gives an instance wrapping a KPScript installation' do
|
|
8
|
-
expect_calls_to_kpscript [['/path/to/KPScript.exe -example-arg', 'OK: Operation completed successfully.']]
|
|
9
|
-
kpscript.run('-example-arg')
|
|
10
|
-
end
|
|
11
|
-
|
|
12
|
-
it 'encrypts passwords' do
|
|
13
|
-
expect_calls_to_kpscript [
|
|
14
|
-
[
|
|
15
|
-
"/path/to/KPScript.exe \"#{Dir.tmpdir}/keepass_kpscript.tmp.kdbx\" -pw:\"pass_encryptor\" -c:EditEntry -ref-Title:\"pass_encryptor\" -set-Password:\"MyPassword\"",
|
|
16
|
-
'OK: Operation completed successfully.'
|
|
17
|
-
],
|
|
18
|
-
[
|
|
19
|
-
"/path/to/KPScript.exe \"#{Dir.tmpdir}/keepass_kpscript.tmp.kdbx\" -pw:\"pass_encryptor\" -c:GetEntryString -ref-Title:\"pass_encryptor\" -Field:\"URL\" -Spr",
|
|
20
|
-
<<~EO_STDOUT
|
|
21
|
-
ENCRYPTED_PASSWORD
|
|
22
|
-
OK: Operation completed successfully.
|
|
23
|
-
EO_STDOUT
|
|
24
|
-
]
|
|
25
|
-
]
|
|
26
|
-
expect(kpscript.encrypt_password('MyPassword')).to eq 'ENCRYPTED_PASSWORD'
|
|
27
|
-
end
|
|
28
|
-
|
|
29
|
-
it 'encrypts passwords using SecretString' do
|
|
30
|
-
expect_calls_to_kpscript [
|
|
31
|
-
[
|
|
32
|
-
"/path/to/KPScript.exe \"#{Dir.tmpdir}/keepass_kpscript.tmp.kdbx\" -pw:\"pass_encryptor\" -c:EditEntry -ref-Title:\"pass_encryptor\" -set-Password:\"MyPassword\"",
|
|
33
|
-
'OK: Operation completed successfully.'
|
|
34
|
-
],
|
|
35
|
-
[
|
|
36
|
-
"/path/to/KPScript.exe \"#{Dir.tmpdir}/keepass_kpscript.tmp.kdbx\" -pw:\"pass_encryptor\" -c:GetEntryString -ref-Title:\"pass_encryptor\" -Field:\"URL\" -Spr",
|
|
37
|
-
<<~EO_STDOUT
|
|
38
|
-
ENCRYPTED_PASSWORD
|
|
39
|
-
OK: Operation completed successfully.
|
|
40
|
-
EO_STDOUT
|
|
41
|
-
]
|
|
42
|
-
]
|
|
43
|
-
expect(kpscript.encrypt_password(SecretString.new('MyPassword'))).to eq 'ENCRYPTED_PASSWORD'
|
|
44
|
-
end
|
|
45
|
-
|
|
46
|
-
it 'opens a database with a password' do
|
|
47
|
-
expect_calls_to_kpscript [
|
|
48
|
-
[
|
|
49
|
-
'/path/to/KPScript.exe "/path/to/my_db.kdbx" -pw:"MyPassword" -c:GetEntryString -ref-Title:"MyEntryTitle" -Field:"Password"',
|
|
50
|
-
<<~EO_STDOUT
|
|
51
|
-
MyEntryPassword
|
|
52
|
-
OK: Operation completed successfully.
|
|
53
|
-
EO_STDOUT
|
|
54
|
-
]
|
|
55
|
-
]
|
|
56
|
-
expect(kpscript.open('/path/to/my_db.kdbx', password: 'MyPassword').password_for('MyEntryTitle')).to eq 'MyEntryPassword'
|
|
57
|
-
end
|
|
58
|
-
|
|
59
|
-
it 'opens a database with a password using SecretString' do
|
|
60
|
-
expect_calls_to_kpscript [
|
|
61
|
-
[
|
|
62
|
-
'/path/to/KPScript.exe "/path/to/my_db.kdbx" -pw:"MyPassword" -c:GetEntryString -ref-Title:"MyEntryTitle" -Field:"Password"',
|
|
63
|
-
<<~EO_STDOUT
|
|
64
|
-
MyEntryPassword
|
|
65
|
-
OK: Operation completed successfully.
|
|
66
|
-
EO_STDOUT
|
|
67
|
-
]
|
|
68
|
-
]
|
|
69
|
-
expect(kpscript.open('/path/to/my_db.kdbx', password: SecretString.new('MyPassword')).password_for('MyEntryTitle')).to eq 'MyEntryPassword'
|
|
70
|
-
end
|
|
71
|
-
|
|
72
|
-
it 'opens a database with an encrypted password' do
|
|
73
|
-
expect_calls_to_kpscript [
|
|
74
|
-
[
|
|
75
|
-
'/path/to/KPScript.exe "/path/to/my_db.kdbx" -pw-enc:"MyEncryptedPassword" -c:GetEntryString -ref-Title:"MyEntryTitle" -Field:"Password"',
|
|
76
|
-
<<~EO_STDOUT
|
|
77
|
-
MyEntryPassword
|
|
78
|
-
OK: Operation completed successfully.
|
|
79
|
-
EO_STDOUT
|
|
80
|
-
]
|
|
81
|
-
]
|
|
82
|
-
expect(kpscript.open('/path/to/my_db.kdbx', password_enc: 'MyEncryptedPassword').password_for('MyEntryTitle')).to eq 'MyEntryPassword'
|
|
83
|
-
end
|
|
84
|
-
|
|
85
|
-
it 'opens a database with a key file' do
|
|
86
|
-
expect_calls_to_kpscript [
|
|
87
|
-
[
|
|
88
|
-
'/path/to/KPScript.exe "/path/to/my_db.kdbx" -keyfile:"/path/to/key_file" -c:GetEntryString -ref-Title:"MyEntryTitle" -Field:"Password"',
|
|
89
|
-
<<~EO_STDOUT
|
|
90
|
-
MyEntryPassword
|
|
91
|
-
OK: Operation completed successfully.
|
|
92
|
-
EO_STDOUT
|
|
93
|
-
]
|
|
94
|
-
]
|
|
95
|
-
expect(kpscript.open('/path/to/my_db.kdbx', key_file: '/path/to/key_file').password_for('MyEntryTitle')).to eq 'MyEntryPassword'
|
|
96
|
-
end
|
|
97
|
-
|
|
98
|
-
it 'opens a database with a key file and password' do
|
|
99
|
-
expect_calls_to_kpscript [
|
|
100
|
-
[
|
|
101
|
-
'/path/to/KPScript.exe "/path/to/my_db.kdbx" -pw:"MyPassword" -keyfile:"/path/to/key_file" -c:GetEntryString -ref-Title:"MyEntryTitle" -Field:"Password"',
|
|
102
|
-
<<~EO_STDOUT
|
|
103
|
-
MyEntryPassword
|
|
104
|
-
OK: Operation completed successfully.
|
|
105
|
-
EO_STDOUT
|
|
106
|
-
]
|
|
107
|
-
]
|
|
108
|
-
expect(kpscript.open('/path/to/my_db.kdbx', password: 'MyPassword', key_file: '/path/to/key_file').password_for('MyEntryTitle')).to eq 'MyEntryPassword'
|
|
109
|
-
end
|
|
110
|
-
|
|
111
|
-
it 'opens a database with a key file and encrypted password' do
|
|
112
|
-
expect_calls_to_kpscript [
|
|
113
|
-
[
|
|
114
|
-
'/path/to/KPScript.exe "/path/to/my_db.kdbx" -pw-enc:"MyEncryptedPassword" -keyfile:"/path/to/key_file" -c:GetEntryString -ref-Title:"MyEntryTitle" -Field:"Password"',
|
|
115
|
-
<<~EO_STDOUT
|
|
116
|
-
MyEntryPassword
|
|
117
|
-
OK: Operation completed successfully.
|
|
118
|
-
EO_STDOUT
|
|
119
|
-
]
|
|
120
|
-
]
|
|
121
|
-
expect(kpscript.open('/path/to/my_db.kdbx', password_enc: 'MyEncryptedPassword', key_file: '/path/to/key_file').password_for('MyEntryTitle')).to eq 'MyEntryPassword'
|
|
122
|
-
end
|
|
123
|
-
|
|
124
|
-
it 'opens a database with a key file and encrypted password using SecretStrings' do
|
|
125
|
-
expect_calls_to_kpscript [
|
|
126
|
-
[
|
|
127
|
-
'/path/to/KPScript.exe "/path/to/my_db.kdbx" -pw-enc:"MyEncryptedPassword" -keyfile:"/path/to/key_file" -c:GetEntryString -ref-Title:"MyEntryTitle" -Field:"Password"',
|
|
128
|
-
<<~EO_STDOUT
|
|
129
|
-
MyEntryPassword
|
|
130
|
-
OK: Operation completed successfully.
|
|
131
|
-
EO_STDOUT
|
|
132
|
-
]
|
|
133
|
-
]
|
|
134
|
-
expect(kpscript.open('/path/to/my_db.kdbx', password_enc: SecretString.new('MyEncryptedPassword'), key_file: SecretString.new('/path/to/key_file')).password_for('MyEntryTitle')).to eq 'MyEntryPassword'
|
|
135
|
-
end
|
|
136
|
-
|
|
137
|
-
it 'gives a selector' do
|
|
138
|
-
expect_calls_to_kpscript []
|
|
139
|
-
expect(kpscript.select.fields(Title: 'MyEntryTitle').to_s).to eq '-ref-Title:"MyEntryTitle"'
|
|
140
|
-
end
|
|
141
|
-
|
|
142
|
-
end
|
|
143
|
-
|
|
144
|
-
context 'without debug' do
|
|
145
|
-
|
|
146
|
-
it_behaves_like 'a kpscript instance' do
|
|
147
|
-
let(:debug) { false }
|
|
148
|
-
end
|
|
149
|
-
|
|
150
|
-
end
|
|
151
|
-
|
|
152
|
-
context 'with debug' do
|
|
153
|
-
|
|
154
|
-
it_behaves_like 'a kpscript instance' do
|
|
155
|
-
let(:debug) { true }
|
|
156
|
-
end
|
|
157
|
-
|
|
158
|
-
end
|
|
159
|
-
|
|
160
|
-
end
|
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
describe KeepassKpscript::Select do
|
|
2
|
-
|
|
3
|
-
shared_examples 'a selector' do
|
|
4
|
-
|
|
5
|
-
subject(:selector) { KeepassKpscript.use('/path/to/KPScript.exe', debug:).select }
|
|
6
|
-
|
|
7
|
-
{
|
|
8
|
-
proc { |s| s.fields(Field: 'Value') } => '-ref-Field:"Value"',
|
|
9
|
-
proc { |s| s.fields(Field1: 'Value1', Field2: 'Value2') } => '-ref-Field1:"Value1" -ref-Field2:"Value2"',
|
|
10
|
-
proc { |s| s.fields(Field1: 'Value1').fields(Field2: 'Value2') } => '-ref-Field1:"Value1" -ref-Field2:"Value2"',
|
|
11
|
-
proc { |s| s.uuid('MyUUID') } => '-refx-UUID:MyUUID',
|
|
12
|
-
proc { |s| s.tags %w[tag1 tag2] } => '-refx-Tags:"tag1,tag2"',
|
|
13
|
-
proc { |s| s.tags(*%w[tag1 tag2]) } => '-refx-Tags:"tag1,tag2"',
|
|
14
|
-
proc { |s| s.expires } => '-refx-Expires:true',
|
|
15
|
-
proc { |s| s.expires(false) } => '-refx-Expires:false',
|
|
16
|
-
proc { |s| s.expired } => '-refx-Expired:true',
|
|
17
|
-
proc { |s| s.expired(false) } => '-refx-Expired:false',
|
|
18
|
-
proc { |s| s.group('MyGroup') } => '-refx-Group:"MyGroup"',
|
|
19
|
-
proc { |s| s.group_path %w[Group1 Group2 Group3] } => '-refx-GroupPath:"Group1/Group2/Group3"',
|
|
20
|
-
proc { |s| s.group_path(*%w[Group1 Group2 Group3]) } => '-refx-GroupPath:"Group1/Group2/Group3"',
|
|
21
|
-
proc { |s| s.all } => '-refx-All',
|
|
22
|
-
proc do |s|
|
|
23
|
-
# Check here that all methods are chainable
|
|
24
|
-
s.
|
|
25
|
-
group('MyGroup').
|
|
26
|
-
expires.
|
|
27
|
-
expired(false).
|
|
28
|
-
tags('MyTag').
|
|
29
|
-
fields(Field: 'Value').
|
|
30
|
-
uuid('MyUUID').
|
|
31
|
-
group_path(%w[Group1 Group2]).
|
|
32
|
-
all.
|
|
33
|
-
fields(Field1: 'Value1', Field2: 'Value2')
|
|
34
|
-
end => '-refx-Group:"MyGroup" -refx-Expires:true -refx-Expired:false -refx-Tags:"MyTag" -ref-Field:"Value" -refx-UUID:MyUUID -refx-GroupPath:"Group1/Group2" -refx-All -ref-Field1:"Value1" -ref-Field2:"Value2"'
|
|
35
|
-
}.each.with_index do |(select_block, expected_args), example_idx|
|
|
36
|
-
|
|
37
|
-
it "selects #{expected_args} (example ##{example_idx})" do
|
|
38
|
-
expect(select_block.call(selector).to_s).to eq expected_args
|
|
39
|
-
end
|
|
40
|
-
|
|
41
|
-
end
|
|
42
|
-
|
|
43
|
-
end
|
|
44
|
-
|
|
45
|
-
context 'without debug' do
|
|
46
|
-
|
|
47
|
-
it_behaves_like 'a selector' do
|
|
48
|
-
let(:debug) { false }
|
|
49
|
-
end
|
|
50
|
-
|
|
51
|
-
end
|
|
52
|
-
|
|
53
|
-
context 'with debug' do
|
|
54
|
-
|
|
55
|
-
it_behaves_like 'a selector' do
|
|
56
|
-
let(:debug) { true }
|
|
57
|
-
end
|
|
58
|
-
|
|
59
|
-
end
|
|
60
|
-
|
|
61
|
-
end
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
require 'json'
|
|
2
|
-
|
|
3
|
-
describe 'Coding guidelines' do
|
|
4
|
-
|
|
5
|
-
it 'makes sure code style follow Rubocop guides' do
|
|
6
|
-
rubocop_report = JSON.parse(`bundle exec rubocop --format json`)
|
|
7
|
-
expect(rubocop_report['summary']['offense_count']).to(
|
|
8
|
-
eq(0),
|
|
9
|
-
proc do
|
|
10
|
-
# Format a great error message to help
|
|
11
|
-
wrong_files = rubocop_report['files'].reject { |file_info| file_info['offenses'].empty? }
|
|
12
|
-
<<~EO_ERROR
|
|
13
|
-
#{wrong_files.size} files have Rubocop issues:
|
|
14
|
-
#{
|
|
15
|
-
wrong_files.map do |file_info|
|
|
16
|
-
offenses = file_info['offenses'].map { |offense_info| "L#{offense_info['location']['start_line']}: #{offense_info['cop_name']} - #{offense_info['message']}" }
|
|
17
|
-
"* #{file_info['path']}:#{
|
|
18
|
-
if offenses.size == 1
|
|
19
|
-
" #{offenses.first}"
|
|
20
|
-
else
|
|
21
|
-
" #{offenses.size} offenses:\n#{offenses.map { |offense| " - #{offense}" }.join("\n")}"
|
|
22
|
-
end
|
|
23
|
-
}"
|
|
24
|
-
end.join("\n")
|
|
25
|
-
}
|
|
26
|
-
EO_ERROR
|
|
27
|
-
end
|
|
28
|
-
)
|
|
29
|
-
end
|
|
30
|
-
|
|
31
|
-
end
|
data/spec/spec_helper.rb
DELETED
|
@@ -1,102 +0,0 @@
|
|
|
1
|
-
require 'keepass_kpscript_test/helpers'
|
|
2
|
-
|
|
3
|
-
# This file was generated by the `rspec --init` command. Conventionally, all
|
|
4
|
-
# specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
|
|
5
|
-
# The generated `.rspec` file contains `--require spec_helper` which will cause
|
|
6
|
-
# this file to always be loaded, without a need to explicitly require it in any
|
|
7
|
-
# files.
|
|
8
|
-
#
|
|
9
|
-
# Given that it is always loaded, you are encouraged to keep this file as
|
|
10
|
-
# light-weight as possible. Requiring heavyweight dependencies from this file
|
|
11
|
-
# will add to the boot time of your test suite on EVERY test run, even for an
|
|
12
|
-
# individual file that may not need all of that loaded. Instead, consider making
|
|
13
|
-
# a separate helper file that requires the additional dependencies and performs
|
|
14
|
-
# the additional setup, and require it from the spec files that actually need
|
|
15
|
-
# it.
|
|
16
|
-
#
|
|
17
|
-
# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
|
|
18
|
-
RSpec.configure do |config|
|
|
19
|
-
# rspec-expectations config goes here. You can use an alternate
|
|
20
|
-
# assertion/expectation library such as wrong or the stdlib/minitest
|
|
21
|
-
# assertions if you prefer.
|
|
22
|
-
config.expect_with :rspec do |expectations|
|
|
23
|
-
# This option will default to `true` in RSpec 4. It makes the `description`
|
|
24
|
-
# and `failure_message` of custom matchers include text for helper methods
|
|
25
|
-
# defined using `chain`, e.g.:
|
|
26
|
-
# be_bigger_than(2).and_smaller_than(4).description
|
|
27
|
-
# # => "be bigger than 2 and smaller than 4"
|
|
28
|
-
# ...rather than:
|
|
29
|
-
# # => "be bigger than 2"
|
|
30
|
-
expectations.include_chain_clauses_in_custom_matcher_descriptions = true
|
|
31
|
-
end
|
|
32
|
-
|
|
33
|
-
# rspec-mocks config goes here. You can use an alternate test double
|
|
34
|
-
# library (such as bogus or mocha) by changing the `mock_with` option here.
|
|
35
|
-
config.mock_with :rspec do |mocks|
|
|
36
|
-
# Prevents you from mocking or stubbing a method that does not exist on
|
|
37
|
-
# a real object. This is generally recommended, and will default to
|
|
38
|
-
# `true` in RSpec 4.
|
|
39
|
-
mocks.verify_partial_doubles = true
|
|
40
|
-
end
|
|
41
|
-
|
|
42
|
-
# This option will default to `:apply_to_host_groups` in RSpec 4 (and will
|
|
43
|
-
# have no way to turn it off -- the option exists only for backwards
|
|
44
|
-
# compatibility in RSpec 3). It causes shared context metadata to be
|
|
45
|
-
# inherited by the metadata hash of host groups and examples, rather than
|
|
46
|
-
# triggering implicit auto-inclusion in groups with matching metadata.
|
|
47
|
-
config.shared_context_metadata_behavior = :apply_to_host_groups
|
|
48
|
-
|
|
49
|
-
# The settings below are suggested to provide a good initial experience
|
|
50
|
-
# with RSpec, but feel free to customize to your heart's content.
|
|
51
|
-
|
|
52
|
-
# This allows you to limit a spec run to individual examples or groups
|
|
53
|
-
# you care about by tagging them with `:focus` metadata. When nothing
|
|
54
|
-
# is tagged with `:focus`, all examples get run. RSpec also provides
|
|
55
|
-
# aliases for `it`, `describe`, and `context` that include `:focus`
|
|
56
|
-
# metadata: `fit`, `fdescribe` and `fcontext`, respectively.
|
|
57
|
-
# config.filter_run_when_matching :focus
|
|
58
|
-
|
|
59
|
-
# Allows RSpec to persist some state between runs in order to support
|
|
60
|
-
# the `--only-failures` and `--next-failure` CLI options. We recommend
|
|
61
|
-
# you configure your source control system to ignore this file.
|
|
62
|
-
# config.example_status_persistence_file_path = "spec/examples.txt"
|
|
63
|
-
|
|
64
|
-
# Limits the available syntax to the non-monkey patched syntax that is
|
|
65
|
-
# recommended. For more details, see:
|
|
66
|
-
# - http://rspec.info/blog/2012/06/rspecs-new-expectation-syntax/
|
|
67
|
-
# - http://www.teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
|
|
68
|
-
# - http://rspec.info/blog/2014/05/notable-changes-in-rspec-3/#zero-monkey-patching-mode
|
|
69
|
-
# config.disable_monkey_patching!
|
|
70
|
-
|
|
71
|
-
# This setting enables warnings. It's recommended, but in some cases may
|
|
72
|
-
# be too noisy due to issues in dependencies.
|
|
73
|
-
# config.warnings = true
|
|
74
|
-
|
|
75
|
-
# Many RSpec users commonly either run the entire suite or an individual
|
|
76
|
-
# file, and it's useful to allow more verbose output when running an
|
|
77
|
-
# individual spec file.
|
|
78
|
-
# if config.files_to_run.one?
|
|
79
|
-
# # Use the documentation formatter for detailed output,
|
|
80
|
-
# # unless a formatter has already been configured
|
|
81
|
-
# # (e.g. via a command-line flag).
|
|
82
|
-
# config.default_formatter = "doc"
|
|
83
|
-
# end
|
|
84
|
-
|
|
85
|
-
# Print the 10 slowest examples and example groups at the
|
|
86
|
-
# end of the spec run, to help surface which specs are running
|
|
87
|
-
# particularly slow.
|
|
88
|
-
# config.profile_examples = 10
|
|
89
|
-
|
|
90
|
-
# Run specs in random order to surface order dependencies. If you find an
|
|
91
|
-
# order dependency and want to debug it, you can fix the order by providing
|
|
92
|
-
# the seed, which is printed after each run.
|
|
93
|
-
# --seed 1234
|
|
94
|
-
# config.order = :random
|
|
95
|
-
|
|
96
|
-
# Seed global randomization in this process using the `--seed` CLI option.
|
|
97
|
-
# Setting this allows you to use `--seed` to deterministically reproduce
|
|
98
|
-
# test failures related to randomization by passing the same `--seed` value
|
|
99
|
-
# as the one that triggered the failure.
|
|
100
|
-
# Kernel.srand config.seed
|
|
101
|
-
|
|
102
|
-
end
|