forest_liana 9.22.16 → 9.22.17
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/app/services/forest_liana/resources_getter.rb +1 -1
- data/app/services/forest_liana/scope_manager.rb +4 -2
- data/app/services/forest_liana/utils/context_variables_injector.rb +1 -15
- data/app/services/forest_liana/utils/live_query_injector.rb +36 -17
- data/lib/forest_liana/version.rb +1 -1
- data/spec/services/forest_liana/resources_getter_spec.rb +41 -0
- data/spec/services/forest_liana/scope_manager_spec.rb +40 -0
- data/spec/services/forest_liana/utils/context_variables_injector_spec.rb +20 -0
- data/spec/services/forest_liana/utils/live_query_injector_spec.rb +78 -5
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 10b9f231f7625702c1c63e6c2c2133360ccf2e9eaa6a68069a206669d902e93b
|
|
4
|
+
data.tar.gz: 73c495fa6e0e02428eff8147b57387a640a244c91a4f745e7b0db7ac0d12d146
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: c3b01f5f3f3c4572fbad83d6b39436bb2eb12bd266fa61ac7048e0172d5922493b1cb1e0afeb0f6af0f07fe24ef45ac79804c298af2ee826a8221f542b850eb8
|
|
7
|
+
data.tar.gz: 9f699625865575db5ebf7f7104b9004ecf8d091feb2401e490091b3eed83ef049eac4ebda850eeee565c04a80d52a5c7e4273b7c119643718be13d8c28c4e825
|
|
@@ -235,7 +235,7 @@ module ForestLiana
|
|
|
235
235
|
|
|
236
236
|
begin
|
|
237
237
|
segment_query = @params[:segmentQuery].gsub(/\;\s*$/, '')
|
|
238
|
-
segment_query = ScopeManager.inject_context_variables_on_query(segment_query, @user)
|
|
238
|
+
segment_query = ScopeManager.inject_context_variables_on_query(segment_query, @user, @resource.connection)
|
|
239
239
|
|
|
240
240
|
@records = @records.where(
|
|
241
241
|
"#{@resource.table_name}.#{@resource.primary_key} IN (SELECT id FROM (#{segment_query}) as ids)"
|
|
@@ -55,11 +55,13 @@ module ForestLiana
|
|
|
55
55
|
Utils::ContextVariablesInjector.inject_context_in_filter(filter, context_variables)
|
|
56
56
|
end
|
|
57
57
|
|
|
58
|
-
def self.inject_context_variables_on_query(query, user)
|
|
58
|
+
def self.inject_context_variables_on_query(query, user, connection = ActiveRecord::Base.connection)
|
|
59
|
+
return query unless query.match?(Utils::ContextVariablesInjector::PLACEHOLDER)
|
|
60
|
+
|
|
59
61
|
retrieve = fetch_scopes(user['rendering_id'])
|
|
60
62
|
context_variables = Utils::ContextVariables.new(retrieve['team'], user)
|
|
61
63
|
|
|
62
|
-
Utils::
|
|
64
|
+
Utils::LiveQueryInjector.inject(query, context_variables, nil, connection, error_prefix: '')
|
|
63
65
|
end
|
|
64
66
|
|
|
65
67
|
def self.invalidate_scope_cache(rendering_id)
|
|
@@ -24,21 +24,7 @@ module ForestLiana
|
|
|
24
24
|
def self.inject_context_in_value_custom(value)
|
|
25
25
|
return value unless value.is_a?(String)
|
|
26
26
|
|
|
27
|
-
|
|
28
|
-
encountered_variables = []
|
|
29
|
-
|
|
30
|
-
while (match = PLACEHOLDER.match(value_with_context_variables_injected))
|
|
31
|
-
context_variable_key = match[1]
|
|
32
|
-
|
|
33
|
-
value_with_context_variables_injected = value_with_context_variables_injected.gsub(
|
|
34
|
-
/{{#{context_variable_key}}}/,
|
|
35
|
-
yield(context_variable_key)
|
|
36
|
-
)
|
|
37
|
-
|
|
38
|
-
encountered_variables.push(context_variable_key)
|
|
39
|
-
end
|
|
40
|
-
|
|
41
|
-
value_with_context_variables_injected
|
|
27
|
+
value.gsub(PLACEHOLDER) { yield(Regexp.last_match(1)) }
|
|
42
28
|
end
|
|
43
29
|
|
|
44
30
|
def self.inject_context_in_filter(filter, context_variables)
|
|
@@ -4,7 +4,7 @@ module ForestLiana
|
|
|
4
4
|
module Utils
|
|
5
5
|
class LiveQueryInjector
|
|
6
6
|
PLACEHOLDER = Regexp.union(ContextVariablesInjector::PLACEHOLDER, '?')
|
|
7
|
-
VERBATIM_VALUE = /\A(?:\d+(?:\.\d+)?(
|
|
7
|
+
VERBATIM_VALUE = /\A(?:\d+(?:\.\d+)?(?:\s*,\s*\d+(?:\.\d+)?)*|true|false)\z/i
|
|
8
8
|
CHARACTERS_CLOSING_QUOTED_TEXT = /["`'\\$\]\r\n\0]/
|
|
9
9
|
LINE_COMMENT = /--[^\n]*/
|
|
10
10
|
MYSQL_LINE_COMMENT = /--(?=[[:space:][:cntrl:]]|\z)[^\n]*/
|
|
@@ -14,20 +14,31 @@ module ForestLiana
|
|
|
14
14
|
WORD = /[[:alpha:]_][[:alnum:]_$]*/
|
|
15
15
|
STRING_CONTINUATION = /[ \t\f\r]*\n[[:space:]]*(?=')/
|
|
16
16
|
DOLLAR_QUOTED = /\$([[:alpha:]_][[:alnum:]_]*|)\$.*?(?:\$\1\$|\z)/m
|
|
17
|
+
# Every character next_token can open a token on, besides letters and underscores.
|
|
18
|
+
TOKEN_OPENERS = %q('"`$[{?-/#)
|
|
19
|
+
NEUTRAL_TEXT = /[^[:alpha:]_#{Regexp.escape(TOKEN_OPENERS)}]+/
|
|
20
|
+
QUOTED_PATTERNS = ["'", '"', '`'].product([false, true]).to_h do |quote, backslash_escapes|
|
|
21
|
+
escaped = Regexp.escape(quote)
|
|
22
|
+
content = backslash_escapes ? "[^#{escaped}\\\\]|\\\\.|#{escaped}#{escaped}" : "[^#{escaped}]|#{escaped}#{escaped}"
|
|
23
|
+
[[quote, backslash_escapes], /#{escaped}(?:#{content})*#{escaped}?/m]
|
|
24
|
+
end.freeze
|
|
17
25
|
|
|
18
|
-
def self.inject(query, context_variables, record_id, connection = ActiveRecord::Base.connection)
|
|
19
|
-
new(context_variables, record_id, connection).inject(query)
|
|
26
|
+
def self.inject(query, context_variables, record_id, connection = ActiveRecord::Base.connection, error_prefix: 'Live Query Chart: ')
|
|
27
|
+
new(context_variables, record_id, connection, error_prefix).inject(query)
|
|
20
28
|
end
|
|
21
29
|
|
|
22
|
-
def initialize(context_variables, record_id, connection)
|
|
30
|
+
def initialize(context_variables, record_id, connection, error_prefix = 'Live Query Chart: ')
|
|
23
31
|
@context_variables = context_variables
|
|
32
|
+
@error_prefix = error_prefix
|
|
24
33
|
@record_id = record_id
|
|
25
34
|
@connection = connection
|
|
26
35
|
@mysql = connection.adapter_name.match?(/mysql|trilogy/i)
|
|
27
36
|
@postgresql = connection.adapter_name.match?(/postg/i)
|
|
28
37
|
@bracket_quotes = connection.adapter_name.match?(/sqlite|sqlserver/i)
|
|
29
38
|
@nested_comments = @postgresql || connection.adapter_name.match?(/sqlserver/i)
|
|
30
|
-
|
|
39
|
+
sql_mode = @mysql ? mysql_sql_mode : ''
|
|
40
|
+
@backslash_escapes = @mysql && !sql_mode.include?('NO_BACKSLASH_ESCAPES')
|
|
41
|
+
@double_quoted_strings = @mysql && !sql_mode.include?('ANSI_QUOTES')
|
|
31
42
|
end
|
|
32
43
|
|
|
33
44
|
def inject(query)
|
|
@@ -40,14 +51,22 @@ module ForestLiana
|
|
|
40
51
|
private
|
|
41
52
|
|
|
42
53
|
def next_token(scanner)
|
|
43
|
-
if (
|
|
54
|
+
if (neutral = scanner.scan(NEUTRAL_TEXT))
|
|
55
|
+
neutral
|
|
56
|
+
elsif (comment = scan_comment(scanner))
|
|
44
57
|
comment
|
|
45
58
|
elsif (word = scanner.scan(WORD))
|
|
46
59
|
return word unless @postgresql && word.casecmp?('e') && scanner.peek(1) == "'"
|
|
47
60
|
|
|
48
|
-
word + inject_in_string(scan_escape_string(scanner), backslash_escapes: true
|
|
61
|
+
word + inject_in_string(scan_escape_string(scanner), backslash_escapes: true) do |text|
|
|
62
|
+
text.gsub(/[\\']/) { |character| character * 2 }
|
|
63
|
+
end
|
|
49
64
|
elsif (string = scanner.scan(quoted_pattern("'", backslash_escapes: @backslash_escapes)))
|
|
50
|
-
inject_in_string(string, backslash_escapes: @backslash_escapes
|
|
65
|
+
inject_in_string(string, backslash_escapes: @backslash_escapes) { |text| @connection.quote_string(text) }
|
|
66
|
+
elsif @double_quoted_strings && (string = scanner.scan(quoted_pattern('"', backslash_escapes: @backslash_escapes)))
|
|
67
|
+
inject_in_string(string, backslash_escapes: @backslash_escapes) do |text|
|
|
68
|
+
@backslash_escapes ? @connection.quote_string(text) : text.gsub('"', '""')
|
|
69
|
+
end
|
|
51
70
|
elsif (quoted = scan_quoted_text(scanner))
|
|
52
71
|
inject_in_quoted_text(quoted)
|
|
53
72
|
elsif (placeholder = scanner.scan(PLACEHOLDER))
|
|
@@ -57,8 +76,10 @@ module ForestLiana
|
|
|
57
76
|
end
|
|
58
77
|
end
|
|
59
78
|
|
|
60
|
-
def
|
|
61
|
-
|
|
79
|
+
def mysql_sql_mode
|
|
80
|
+
RequestCache.fetch([:mysql_sql_mode, @connection]) do
|
|
81
|
+
@connection.select_value('SELECT @@SESSION.sql_mode').to_s
|
|
82
|
+
end
|
|
62
83
|
end
|
|
63
84
|
|
|
64
85
|
def scan_comment(scanner)
|
|
@@ -83,9 +104,7 @@ module ForestLiana
|
|
|
83
104
|
end
|
|
84
105
|
|
|
85
106
|
def quoted_pattern(quote, backslash_escapes: false)
|
|
86
|
-
|
|
87
|
-
content = backslash_escapes ? "[^#{escaped}\\\\]|\\\\.|#{escaped}#{escaped}" : "[^#{escaped}]|#{escaped}#{escaped}"
|
|
88
|
-
/#{escaped}(?:#{content})*#{escaped}?/m
|
|
107
|
+
QUOTED_PATTERNS[[quote, backslash_escapes]]
|
|
89
108
|
end
|
|
90
109
|
|
|
91
110
|
def inject_in_code(placeholder)
|
|
@@ -94,14 +113,14 @@ module ForestLiana
|
|
|
94
113
|
end
|
|
95
114
|
end
|
|
96
115
|
|
|
97
|
-
def inject_in_string(string, backslash_escapes:,
|
|
116
|
+
def inject_in_string(string, backslash_escapes:, &escape)
|
|
98
117
|
replace_placeholders(string) do |text, placeholder, preceding_text|
|
|
99
118
|
if backslash_escapes && preceding_text[/\\*\z/].length.odd?
|
|
100
119
|
raise ForestLiana::Errors::LiveQueryError.new(
|
|
101
|
-
"
|
|
120
|
+
"#{@error_prefix}#{placeholder} cannot follow a backslash inside a string."
|
|
102
121
|
)
|
|
103
122
|
end
|
|
104
|
-
|
|
123
|
+
escape.call(text)
|
|
105
124
|
end
|
|
106
125
|
end
|
|
107
126
|
|
|
@@ -109,7 +128,7 @@ module ForestLiana
|
|
|
109
128
|
replace_placeholders(quoted) do |text, placeholder|
|
|
110
129
|
if text.match?(CHARACTERS_CLOSING_QUOTED_TEXT)
|
|
111
130
|
raise ForestLiana::Errors::LiveQueryError.new(
|
|
112
|
-
"
|
|
131
|
+
"#{@error_prefix}The value of #{placeholder} cannot contain quotes, brackets, backslashes, " \
|
|
113
132
|
'dollar signs or line breaks when it is written inside a quoted identifier or a dollar-quoted string.'
|
|
114
133
|
)
|
|
115
134
|
end
|
data/lib/forest_liana/version.rb
CHANGED
|
@@ -166,6 +166,47 @@ module ForestLiana
|
|
|
166
166
|
|
|
167
167
|
expect(getter.records.map(&:name)).to eq(['Michel'])
|
|
168
168
|
end
|
|
169
|
+
|
|
170
|
+
describe 'when the variable value carries SQL' do
|
|
171
|
+
let(:user) { { 'id' => '1', 'name' => "Michel' OR '1'='1", 'rendering_id' => rendering_id } }
|
|
172
|
+
|
|
173
|
+
it 'matches the value as a literal in the records' do
|
|
174
|
+
getter.perform
|
|
175
|
+
|
|
176
|
+
expect(getter.records).to be_empty
|
|
177
|
+
end
|
|
178
|
+
|
|
179
|
+
it 'matches the value as a literal in the count' do
|
|
180
|
+
getter.count
|
|
181
|
+
|
|
182
|
+
expect(getter.count).to eq 0
|
|
183
|
+
end
|
|
184
|
+
end
|
|
185
|
+
|
|
186
|
+
describe 'when every record of the segment is selected' do
|
|
187
|
+
def ids_from_request(user)
|
|
188
|
+
params = ActionController::Parameters.new(
|
|
189
|
+
data: {
|
|
190
|
+
attributes: {
|
|
191
|
+
collection_name: 'User',
|
|
192
|
+
all_records: true,
|
|
193
|
+
all_records_subset_query: {
|
|
194
|
+
segmentQuery: "SELECT id FROM users WHERE name = '{{currentUser.name}}'",
|
|
195
|
+
},
|
|
196
|
+
},
|
|
197
|
+
},
|
|
198
|
+
)
|
|
199
|
+
described_class.get_ids_from_request(params, user)
|
|
200
|
+
end
|
|
201
|
+
|
|
202
|
+
it 'injects the variable into the query that selects the ids' do
|
|
203
|
+
expect(ids_from_request(user)).to eq(User.where(name: 'Michel').pluck(:id))
|
|
204
|
+
end
|
|
205
|
+
|
|
206
|
+
it 'matches a value carrying SQL as a literal' do
|
|
207
|
+
expect(ids_from_request(user.merge('name' => "Michel' OR '1'='1"))).to be_empty
|
|
208
|
+
end
|
|
209
|
+
end
|
|
169
210
|
end
|
|
170
211
|
|
|
171
212
|
describe 'when there are more records than the page size' do
|
|
@@ -366,6 +366,46 @@ module ForestLiana
|
|
|
366
366
|
|
|
367
367
|
expect(query).to eq "SELECT id FROM users WHERE email = '{{currentUser.email}}'"
|
|
368
368
|
end
|
|
369
|
+
|
|
370
|
+
it 'should escape a value written inside a string' do
|
|
371
|
+
user['first_name'] = "x' OR '1'='1"
|
|
372
|
+
|
|
373
|
+
expect(described_class.inject_context_variables_on_query(
|
|
374
|
+
"SELECT id FROM users WHERE first_name = '{{currentUser.first_name}}'", user
|
|
375
|
+
)).to eq "SELECT id FROM users WHERE first_name = 'x'' OR ''1''=''1'"
|
|
376
|
+
end
|
|
377
|
+
|
|
378
|
+
it 'should quote a value written outside a string' do
|
|
379
|
+
user['first_name'] = '0 OR 1=1'
|
|
380
|
+
|
|
381
|
+
expect(described_class.inject_context_variables_on_query(
|
|
382
|
+
'SELECT id FROM users WHERE first_name = {{currentUser.first_name}}', user
|
|
383
|
+
)).to eq "SELECT id FROM users WHERE first_name = '0 OR 1=1'"
|
|
384
|
+
end
|
|
385
|
+
|
|
386
|
+
it 'should inject a numeric value as is' do
|
|
387
|
+
expect(described_class.inject_context_variables_on_query(
|
|
388
|
+
'SELECT id FROM users WHERE id = {{currentUser.id}}', user
|
|
389
|
+
)).to eq 'SELECT id FROM users WHERE id = 1'
|
|
390
|
+
end
|
|
391
|
+
|
|
392
|
+
it 'should not fetch the scopes when the query has no context variable' do
|
|
393
|
+
query_without_variable = 'SELECT id FROM users WHERE id > 1'
|
|
394
|
+
|
|
395
|
+
expect(described_class.inject_context_variables_on_query(query_without_variable, user))
|
|
396
|
+
.to eq query_without_variable
|
|
397
|
+
expect(ForestLiana::ForestApiRequester).not_to have_received(:get)
|
|
398
|
+
end
|
|
399
|
+
|
|
400
|
+
it 'should not prefix the error it raises with the chart label' do
|
|
401
|
+
user['first_name'] = 'a"b'
|
|
402
|
+
|
|
403
|
+
expect {
|
|
404
|
+
described_class.inject_context_variables_on_query(
|
|
405
|
+
'SELECT id FROM users WHERE "{{currentUser.first_name}}" = 1', user
|
|
406
|
+
)
|
|
407
|
+
}.to raise_error(ForestLiana::Errors::LiveQueryError, /\AThe value of {{currentUser.first_name}}/)
|
|
408
|
+
end
|
|
369
409
|
end
|
|
370
410
|
end
|
|
371
411
|
end
|
|
@@ -51,6 +51,26 @@ module ForestLiana
|
|
|
51
51
|
|
|
52
52
|
expect(result).to eq('It should be POWER of rank RANK. But POWER can be duplicated.')
|
|
53
53
|
end
|
|
54
|
+
|
|
55
|
+
it 'does not inject variables again into an injected value' do
|
|
56
|
+
result = described_class.inject_context_in_value_custom('Hi {{currentUser.firstName}}') do
|
|
57
|
+
'{{currentUser.firstName}}'
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
expect(result).to eq('Hi {{currentUser.firstName}}')
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
it 'inserts a value holding backslash sequences as is' do
|
|
64
|
+
result = described_class.inject_context_in_value_custom('Hi {{currentUser.firstName}}!') { "\\0 \\' \\1" }
|
|
65
|
+
|
|
66
|
+
expect(result).to eq("Hi \\0 \\' \\1!")
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
it 'replaces a variable whose key holds regular expression characters' do
|
|
70
|
+
result = described_class.inject_context_in_value_custom('Hi {{currentUser.tags.a+b}}') { |key| key }
|
|
71
|
+
|
|
72
|
+
expect(result).to eq('Hi currentUser.tags.a+b')
|
|
73
|
+
end
|
|
54
74
|
end
|
|
55
75
|
|
|
56
76
|
context('when inject_context_in_value is called') do
|
|
@@ -30,13 +30,46 @@ module ForestLiana
|
|
|
30
30
|
connection
|
|
31
31
|
end
|
|
32
32
|
|
|
33
|
+
# NEUTRAL_TEXT is only a shortcut: a token opener missing from TOKEN_OPENERS shows up as a different outcome without it.
|
|
33
34
|
def inject(query, connection, record_id: nil)
|
|
34
|
-
|
|
35
|
+
outcome = injection_outcome(query, connection, record_id)
|
|
36
|
+
neutral_text = LiveQueryInjector::NEUTRAL_TEXT
|
|
37
|
+
stub_const('ForestLiana::Utils::LiveQueryInjector::NEUTRAL_TEXT', /(?!)/)
|
|
38
|
+
outcome_without_shortcut = injection_outcome(query, connection, record_id)
|
|
39
|
+
stub_const('ForestLiana::Utils::LiveQueryInjector::NEUTRAL_TEXT', neutral_text)
|
|
40
|
+
|
|
41
|
+
expect(outcome_without_shortcut.map { |value| value.is_a?(Exception) ? value.message : value })
|
|
42
|
+
.to eq(outcome.map { |value| value.is_a?(Exception) ? value.message : value })
|
|
43
|
+
injected, error = outcome
|
|
44
|
+
raise error if error
|
|
45
|
+
|
|
46
|
+
injected
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
def injection_outcome(query, connection, record_id)
|
|
50
|
+
[LiveQueryInjector.inject(query, context_variables, record_id, connection), nil]
|
|
51
|
+
rescue ForestLiana::Errors::LiveQueryError => error
|
|
52
|
+
[nil, error]
|
|
35
53
|
end
|
|
36
54
|
|
|
37
55
|
describe 'on MySQL' do
|
|
38
56
|
let(:request_context_variables) { { 'x.value' => '0 OR 1=1' } }
|
|
39
57
|
|
|
58
|
+
it 'reads the session sql_mode once per request and connection' do
|
|
59
|
+
connection = mysql_connection
|
|
60
|
+
other_connection = mysql_connection
|
|
61
|
+
|
|
62
|
+
query = 'SELECT 1 FROM t WHERE id = {{x.value}}'
|
|
63
|
+
RequestCache.with do
|
|
64
|
+
2.times { LiveQueryInjector.inject(query, context_variables, nil, connection) }
|
|
65
|
+
LiveQueryInjector.inject(query, context_variables, nil, other_connection)
|
|
66
|
+
end
|
|
67
|
+
LiveQueryInjector.inject(query, context_variables, nil, connection)
|
|
68
|
+
|
|
69
|
+
expect(connection).to have_received(:select_value).with('SELECT @@SESSION.sql_mode').twice
|
|
70
|
+
expect(other_connection).to have_received(:select_value).with('SELECT @@SESSION.sql_mode').once
|
|
71
|
+
end
|
|
72
|
+
|
|
40
73
|
it 'reads a backslash-escaped quote as part of the string literal' do
|
|
41
74
|
expect(inject("SELECT 1 FROM t WHERE a = 'it\\'s' AND id = {{x.value}}", mysql_connection))
|
|
42
75
|
.to eq("SELECT 1 FROM t WHERE a = 'it\\'s' AND id = '0 OR 1=1'")
|
|
@@ -56,10 +89,25 @@ module ForestLiana
|
|
|
56
89
|
.to eq('SELECT 1 FROM t WHERE a = "Aragorn"')
|
|
57
90
|
end
|
|
58
91
|
|
|
59
|
-
it '
|
|
92
|
+
it 'escapes a value injected inside a double-quoted string with the connection' do
|
|
93
|
+
request_context_variables['x.value'] = %q(O'Brien" OR "1)
|
|
94
|
+
|
|
95
|
+
expect(inject('SELECT 1 FROM t WHERE a = "{{x.value}}"', mysql_connection))
|
|
96
|
+
.to eq(%q(SELECT 1 FROM t WHERE a = "O\'Brien\" OR \"1"))
|
|
97
|
+
end
|
|
98
|
+
|
|
99
|
+
it 'refuses a value placed right after a backslash inside a double-quoted string' do
|
|
100
|
+
request_context_variables['x.value'] = '" OR true -- '
|
|
101
|
+
|
|
102
|
+
expect { inject('SELECT 1 FROM t WHERE a = "\\{{x.value}}"', mysql_connection) }
|
|
103
|
+
.to raise_error(ForestLiana::Errors::LiveQueryError)
|
|
104
|
+
end
|
|
105
|
+
|
|
106
|
+
it 'refuses a value holding a quote inside a double-quoted identifier when the session uses ANSI quotes' do
|
|
60
107
|
request_context_variables['x.value'] = 'a" OR "1'
|
|
108
|
+
connection = mysql_connection(sql_mode: 'REAL_AS_FLOAT,PIPES_AS_CONCAT,ANSI_QUOTES,IGNORE_SPACE,ANSI')
|
|
61
109
|
|
|
62
|
-
expect { inject('SELECT 1 FROM t WHERE
|
|
110
|
+
expect { inject('SELECT 1 FROM t WHERE "{{x.value}}" = 1', connection) }
|
|
63
111
|
.to raise_error(ForestLiana::Errors::LiveQueryError)
|
|
64
112
|
end
|
|
65
113
|
|
|
@@ -120,6 +168,13 @@ module ForestLiana
|
|
|
120
168
|
expect(inject("SELECT 1 FROM t WHERE a = '\\{{x.value}}'", connection))
|
|
121
169
|
.to eq("SELECT 1 FROM t WHERE a = '\\a''b'")
|
|
122
170
|
end
|
|
171
|
+
|
|
172
|
+
it 'doubles the double quotes of a value injected inside a double-quoted string' do
|
|
173
|
+
request_context_variables['x.value'] = %q(O'Brien" OR "1)
|
|
174
|
+
|
|
175
|
+
expect(inject('SELECT 1 FROM t WHERE a = "\\{{x.value}}"', connection))
|
|
176
|
+
.to eq(%q(SELECT 1 FROM t WHERE a = "\\O'Brien"" OR ""1"))
|
|
177
|
+
end
|
|
123
178
|
end
|
|
124
179
|
|
|
125
180
|
it 'leaves a hash comment untouched' do
|
|
@@ -228,6 +283,23 @@ module ForestLiana
|
|
|
228
283
|
.to raise_error(ForestLiana::Errors::LiveQueryError)
|
|
229
284
|
end
|
|
230
285
|
|
|
286
|
+
it 'prefixes the error with the chart label by default' do
|
|
287
|
+
request_context_variables['x.value'] = 'users]'
|
|
288
|
+
|
|
289
|
+
expect { inject('SELECT COUNT(*) AS value FROM [{{x.value}}]', sqlite_connection) }
|
|
290
|
+
.to raise_error(ForestLiana::Errors::LiveQueryError, /\ALive Query Chart: The value of {{x.value}}/)
|
|
291
|
+
end
|
|
292
|
+
|
|
293
|
+
it 'prefixes the error with the prefix it is given' do
|
|
294
|
+
request_context_variables['x.value'] = 'users]'
|
|
295
|
+
|
|
296
|
+
expect {
|
|
297
|
+
LiveQueryInjector.inject(
|
|
298
|
+
'SELECT COUNT(*) AS value FROM [{{x.value}}]', context_variables, nil, sqlite_connection, error_prefix: ''
|
|
299
|
+
)
|
|
300
|
+
}.to raise_error(ForestLiana::Errors::LiveQueryError, /\AThe value of {{x.value}}/)
|
|
301
|
+
end
|
|
302
|
+
|
|
231
303
|
it 'reads a nested block comment marker as plain comment text' do
|
|
232
304
|
request_context_variables['x.value'] = '0 OR 1=1'
|
|
233
305
|
|
|
@@ -255,6 +327,7 @@ module ForestLiana
|
|
|
255
327
|
'n.value' => '42',
|
|
256
328
|
'd.value' => '4.5',
|
|
257
329
|
'l.value' => '1,2,3',
|
|
330
|
+
'spaced.value' => '1, 2 ,3',
|
|
258
331
|
'b.value' => 'FALSE',
|
|
259
332
|
'neg.value' => '-1',
|
|
260
333
|
's.value' => 'DESC'
|
|
@@ -262,10 +335,10 @@ module ForestLiana
|
|
|
262
335
|
end
|
|
263
336
|
|
|
264
337
|
it 'injects unsigned numbers, lists of numbers and booleans as they are, everything else as a string' do
|
|
265
|
-
query = 'SELECT {{n.value}}, {{d.value}}, ({{l.value}}), {{b.value}}, {{neg.value}}, {{s.value}}'
|
|
338
|
+
query = 'SELECT {{n.value}}, {{d.value}}, ({{l.value}}), ({{spaced.value}}), {{b.value}}, {{neg.value}}, {{s.value}}'
|
|
266
339
|
|
|
267
340
|
expect(inject(query, postgresql_connection))
|
|
268
|
-
.to eq("SELECT 42, 4.5, (1,2,3), FALSE, '-1', 'DESC'")
|
|
341
|
+
.to eq("SELECT 42, 4.5, (1,2,3), (1, 2 ,3), FALSE, '-1', 'DESC'")
|
|
269
342
|
end
|
|
270
343
|
end
|
|
271
344
|
end
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: forest_liana
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 9.22.
|
|
4
|
+
version: 9.22.17
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Sandro Munda
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2026-
|
|
11
|
+
date: 2026-11-03 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: rails
|