marty 1.0.48 → 1.0.50
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/Gemfile.lock +1 -1
- data/app/controllers/marty/diagnostic_controller.rb +37 -7
- data/app/controllers/marty/rpc_controller.rb +61 -89
- data/app/views/marty/diagnostic/op.html.erb +7 -5
- data/lib/marty/version.rb +1 -1
- data/spec/controllers/diagnostic_controller_spec.rb +28 -21
- data/spec/controllers/rpc_controller_spec.rb +310 -344
- data/spec/controllers/rpc_import_spec.rb +7 -7
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 73b7b86b7b401ad7cd06091b271c56ba22b5cc1d
|
4
|
+
data.tar.gz: c047c73fe41f5c5336813a6be4867e9613d98679
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7aea286471dee9a5ae2212b04a5da813aaf647c760a91ce60c05c94c0921ff5390f63a9e32e0aeb0344acf845ef3afb4e89852984974a76c1d4b2b853bc84af7
|
7
|
+
data.tar.gz: fe45b8a98c849b94e2a5d70fad092be0f96c2d3f16589673a7fb68ea124f2759b1fe742b759a58795e492e9fdeade1997dd7bd856add88feb27346f184120d0e
|
data/Gemfile.lock
CHANGED
@@ -58,6 +58,11 @@ module Marty
|
|
58
58
|
end.sum
|
59
59
|
end
|
60
60
|
|
61
|
+
def self.find_failures data
|
62
|
+
data.each_with_object({}){
|
63
|
+
|(k,v), h| h[k] = v.include?('Failure') ? 'F' : 'P'}
|
64
|
+
end
|
65
|
+
|
61
66
|
def self.errors data
|
62
67
|
data.keys.count{|n| is_failure?(data[n])}
|
63
68
|
end
|
@@ -89,9 +94,12 @@ module Marty
|
|
89
94
|
<% data.each do |node, result| %>
|
90
95
|
<table>
|
91
96
|
<% issues = ('error' if inconsistent) %>
|
92
|
-
<th class="<%=issues%>"
|
93
|
-
|
94
|
-
|
97
|
+
<th colspan="2" class="<%=issues%>">
|
98
|
+
<small>
|
99
|
+
<%=inconsistent ? node :
|
100
|
+
(type == 'local' ? 'local' : 'consistent') %>
|
101
|
+
</small>
|
102
|
+
</th>
|
95
103
|
<% result.each do |name, value| %>
|
96
104
|
<tr class="<%=is_failure?(value) ? 'failed' :
|
97
105
|
'passed' %>">
|
@@ -145,15 +153,15 @@ module Marty
|
|
145
153
|
class Version < Base
|
146
154
|
def self.generate
|
147
155
|
begin
|
148
|
-
message = `cd #{Rails.root.to_s}; git describe;`.strip
|
156
|
+
message = `cd #{Rails.root.to_s}; git describe --tags --always;`.strip
|
149
157
|
rescue
|
150
158
|
message = error("Failed accessing git")
|
151
159
|
end
|
152
160
|
{
|
153
|
-
'Git' => message,
|
154
161
|
'Marty' => Marty::VERSION,
|
155
162
|
'Delorean' => Delorean::VERSION,
|
156
|
-
'Mcfly' => Mcfly::VERSION
|
163
|
+
'Mcfly' => Mcfly::VERSION,
|
164
|
+
'Git' => message,
|
157
165
|
}
|
158
166
|
end
|
159
167
|
end
|
@@ -216,9 +224,31 @@ module Marty
|
|
216
224
|
" - AWS: [#{a_nodes.join(', ')}]")
|
217
225
|
{"PG/AWS" => message}
|
218
226
|
end
|
227
|
+
end
|
228
|
+
|
229
|
+
class Env < Base
|
230
|
+
def self.filter_env filter=''
|
231
|
+
env = ENV.clone
|
232
|
+
|
233
|
+
# obfuscate SECRET_KEY_BASE for comparison
|
234
|
+
env['SECRET_KEY_BASE'] = env['SECRET_KEY_BASE'][0,4] if
|
235
|
+
env['SECRET_KEY_BASE']
|
236
|
+
|
237
|
+
# remove SCRIPT_URI, SCRIPT_URL as calling node differs
|
238
|
+
['SCRIPT_URI', 'SCRIPT_URL'].each{|k| env.delete(k)}
|
239
|
+
|
240
|
+
to_block = ['PASSWORD', 'DEBUG']
|
241
|
+
env.sort.each_with_object({}){|(k,v),h|
|
242
|
+
h[k] = v if to_block.all?{|b| !k.include?(b)} && k.include?(filter)}
|
243
|
+
end
|
244
|
+
|
245
|
+
def self.generate
|
246
|
+
filter_env
|
247
|
+
end
|
219
248
|
|
220
249
|
def self.aggregate
|
221
|
-
|
250
|
+
envs = get_nodal_diags(name.demodulize)
|
251
|
+
diff(envs) ? envs : package({})
|
222
252
|
end
|
223
253
|
end
|
224
254
|
|
@@ -19,18 +19,15 @@ class Marty::RpcController < ActionController::Base
|
|
19
19
|
end
|
20
20
|
|
21
21
|
private
|
22
|
-
|
23
22
|
# FIXME: move to (probably) agrim's schema code in lib
|
24
|
-
def
|
23
|
+
def get_schema(tag, sname, node, attr)
|
25
24
|
begin
|
26
|
-
|
27
|
-
|
28
|
-
attrs.zip(result)
|
25
|
+
Marty::ScriptSet.new(tag).get_engine(sname+'Schemas').
|
26
|
+
evaluate(node, attr, {})
|
29
27
|
rescue => e
|
30
28
|
use_message = e.message == 'No such script' ?
|
31
|
-
|
32
|
-
raise "Schema error for #{sname}/#{node} "
|
33
|
-
"attrs=#{attrs.join(',')}: #{use_message}"
|
29
|
+
'Schema not defined' : 'Problem with schema: ' + e.message
|
30
|
+
raise "Schema error for #{sname}/#{node} attrs=#{attr}: #{use_message}"
|
34
31
|
end
|
35
32
|
end
|
36
33
|
|
@@ -39,6 +36,7 @@ class Marty::RpcController < ActionController::Base
|
|
39
36
|
return msg unless m
|
40
37
|
"disallowed parameter '#{m[1]}' of type #{m[2]} was received"
|
41
38
|
end
|
39
|
+
|
42
40
|
def _get_errors(errs)
|
43
41
|
if errs.is_a?(Array)
|
44
42
|
errs.map { |err| _get_errors(err) }
|
@@ -54,29 +52,26 @@ class Marty::RpcController < ActionController::Base
|
|
54
52
|
end
|
55
53
|
end
|
56
54
|
end
|
55
|
+
|
57
56
|
def get_errors(errs)
|
58
57
|
_get_errors(errs).flatten
|
59
58
|
end
|
60
59
|
|
61
|
-
def do_eval(sname, tag, node,
|
62
|
-
|
60
|
+
def do_eval(sname, tag, node, attr, params, api_key, background)
|
61
|
+
# FIXME: small patch to allow for single attr array
|
62
|
+
attr = ActiveSupport::JSON.decode(attr) rescue attr
|
63
63
|
|
64
|
-
|
65
|
-
|
64
|
+
return {error: "Malformed attrs"} unless
|
65
|
+
attr.is_a?(String) || (attr.is_a?(Array) && attr.count == 1)
|
66
66
|
|
67
|
-
if
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
attrs = ActiveSupport::JSON.decode(attrs)
|
72
|
-
rescue JSON::ParserError => e
|
73
|
-
return {error: "Malformed attrs"}
|
74
|
-
end
|
67
|
+
# if attr is a single attr array, remember to return as an array
|
68
|
+
if attr.is_a? Array
|
69
|
+
attr = attr[0]
|
70
|
+
ret_arr = true
|
75
71
|
end
|
76
72
|
|
77
|
-
|
78
|
-
|
79
|
-
|
73
|
+
start_time = Time.zone.now
|
74
|
+
return {error: "Malformed attrs"} unless attr =~ /\A[a-z][a-zA-Z0-9_]*\z/
|
80
75
|
return {error: "Bad params"} unless params.is_a?(String)
|
81
76
|
|
82
77
|
begin
|
@@ -87,44 +82,34 @@ class Marty::RpcController < ActionController::Base
|
|
87
82
|
end
|
88
83
|
|
89
84
|
return {error: "Malformed params"} unless params.is_a?(Hash)
|
90
|
-
|
91
|
-
need_input_validate,
|
92
|
-
|
93
|
-
Marty::ApiConfig.
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
opt = { :validate_schema => true,
|
102
|
-
:errors_as_objects => true,
|
103
|
-
:version => Marty::JsonSchema::RAW_URI }
|
104
|
-
to_append = {"\$schema" => Marty::JsonSchema::RAW_URI}
|
105
|
-
|
106
|
-
validation_error = {}
|
107
|
-
err_count = 0
|
108
|
-
if need_input_validate.present?
|
85
|
+
need_log,
|
86
|
+
need_input_validate,
|
87
|
+
need_output_validate,
|
88
|
+
need_strict_validate = Marty::ApiConfig.lookup(sname, node, attr)
|
89
|
+
opt = {validate_schema: true,
|
90
|
+
errors_as_objects: true,
|
91
|
+
version: Marty::JsonSchema::RAW_URI }
|
92
|
+
to_append = {"\$schema" => Marty::JsonSchema::RAW_URI}
|
93
|
+
validation_error = nil
|
94
|
+
|
95
|
+
if need_input_validate
|
109
96
|
begin
|
110
|
-
|
97
|
+
schema = get_schema(tag, sname, node, attr)
|
111
98
|
rescue => e
|
112
99
|
return {error: e.message}
|
113
100
|
end
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
end
|
122
|
-
|
123
|
-
validation_error[attr] = get_errors(er) if er.size > 0
|
124
|
-
err_count += er.size
|
101
|
+
begin
|
102
|
+
er = JSON::Validator.
|
103
|
+
fully_validate(schema.merge(to_append), params, opt)
|
104
|
+
rescue NameError
|
105
|
+
return {error: "Unrecognized PgEnum for attribute #{attr}"}
|
106
|
+
rescue => ex
|
107
|
+
return {error: "#{attr}: #{ex.message}"}
|
125
108
|
end
|
109
|
+
validation_error = get_errors(er) if er.size > 0
|
126
110
|
end
|
127
|
-
return {error: "Error(s) validating: #{validation_error}"} if
|
111
|
+
return {error: "Error(s) validating: #{validation_error}"} if
|
112
|
+
validation_error
|
128
113
|
|
129
114
|
auth = Marty::ApiAuth.authorized?(sname, api_key)
|
130
115
|
return {error: "Permission denied" } unless auth
|
@@ -142,49 +127,36 @@ class Marty::RpcController < ActionController::Base
|
|
142
127
|
|
143
128
|
begin
|
144
129
|
if background
|
145
|
-
result = engine.background_eval(node, params,
|
130
|
+
result = engine.background_eval(node, params, attr)
|
146
131
|
return retval = {"job_id" => result.__promise__.id}
|
147
132
|
end
|
148
|
-
res = engine.evaluate(node, attrs, params)
|
149
133
|
|
150
|
-
|
151
|
-
|
152
|
-
if need_output_validate.
|
134
|
+
res = engine.evaluate(node, attr, params)
|
135
|
+
|
136
|
+
if need_output_validate && !(res.is_a?(Hash) && res['error'])
|
153
137
|
begin
|
154
|
-
|
138
|
+
schema = get_schema(tag, sname, node, attr + '_')
|
155
139
|
rescue => e
|
156
140
|
return {error: e.message}
|
157
141
|
end
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
rescue NameError
|
166
|
-
return {error: "Unrecognized PgEnum for attribute #{attr}"}
|
167
|
-
rescue => ex
|
168
|
-
return {error: "#{attr}: #{ex.message}"}
|
169
|
-
end
|
170
|
-
validation_error[attr] = er.map{ |e| e[:message] } if er.size > 0
|
171
|
-
err_count += er.size
|
142
|
+
|
143
|
+
begin
|
144
|
+
er = JSON::Validator.fully_validate(schema.merge(to_append), res, opt)
|
145
|
+
rescue NameError
|
146
|
+
return {error: "Unrecognized PgEnum for attribute #{attr}"}
|
147
|
+
rescue => ex
|
148
|
+
return {error: "#{attr}: #{ex.message}"}
|
172
149
|
end
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
data: result})
|
181
|
-
strict_validate.include?(attr) ?
|
182
|
-
{error: "Error(s) validating: #{the_error}",
|
183
|
-
data: result} : result
|
184
|
-
end
|
150
|
+
|
151
|
+
if er.size > 0
|
152
|
+
errors = er.map{|e| e[:message]}
|
153
|
+
Marty::Logger.error("API #{sname}:#{node}.#{attr}",
|
154
|
+
{error: errors, data: res})
|
155
|
+
res = need_strict_validate ? {error: "Error(s) validating: #{errors}",
|
156
|
+
data: res} : res
|
185
157
|
end
|
186
158
|
end
|
187
|
-
return retval =
|
159
|
+
return retval = ret_arr ? [res] : res
|
188
160
|
rescue => exc
|
189
161
|
err_msg = Delorean::Engine.grok_runtime_exception(exc).symbolize_keys
|
190
162
|
logger.info "Evaluation error: #{err_msg}"
|
@@ -195,7 +167,7 @@ class Marty::RpcController < ActionController::Base
|
|
195
167
|
"#{sname} - #{node}",
|
196
168
|
{script: sname,
|
197
169
|
node: node,
|
198
|
-
attrs:
|
170
|
+
attrs: (ret_arr ? [attr] : attr),
|
199
171
|
input: orig_params,
|
200
172
|
output: error ? nil : retval,
|
201
173
|
start_time: start_time,
|
@@ -20,12 +20,13 @@
|
|
20
20
|
th { padding: 9px;
|
21
21
|
border: none;
|
22
22
|
background-color: #d6d6d6 }
|
23
|
-
td {
|
24
|
-
|
25
|
-
|
23
|
+
td { text-align: left;
|
24
|
+
padding: 9px;
|
25
|
+
}
|
26
26
|
th.error { background-color: #ff5555;
|
27
27
|
color: #ffffff;
|
28
28
|
}
|
29
|
+
tr { text-align: center;}
|
29
30
|
tr.passed { background-color: #d0e9c6 }
|
30
31
|
tr.failed { background-color: #ff5555;
|
31
32
|
color: #ffffff
|
@@ -50,8 +51,9 @@
|
|
50
51
|
</style>
|
51
52
|
</head>
|
52
53
|
<body>
|
53
|
-
|
54
|
-
|
54
|
+
<div style="text-align:center">
|
55
|
+
<h1><%=Rails.application.class.parent_name%> Diagnostic</h1>
|
56
|
+
<h3><i><%= DateTime.now %></i></h3>
|
55
57
|
<%== @result %>
|
56
58
|
</div>
|
57
59
|
</body>
|
data/lib/marty/version.rb
CHANGED
@@ -4,11 +4,21 @@ module Marty
|
|
4
4
|
before(:each) { @routes = Marty::Engine.routes }
|
5
5
|
let(:json_response) { JSON.parse(response.body) }
|
6
6
|
|
7
|
+
def git
|
8
|
+
begin
|
9
|
+
message = `cd #{Rails.root.to_s}; git describe --tags --always;`.strip
|
10
|
+
rescue
|
11
|
+
message = error("Failed accessing git")
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
7
15
|
def version
|
8
|
-
{
|
9
|
-
|
10
|
-
|
11
|
-
|
16
|
+
{
|
17
|
+
"Marty" => Marty::VERSION,
|
18
|
+
"Delorean" => Delorean::VERSION,
|
19
|
+
"Mcfly" => Mcfly::VERSION,
|
20
|
+
"Git" => git,
|
21
|
+
}
|
12
22
|
end
|
13
23
|
|
14
24
|
def environment
|
@@ -30,12 +40,7 @@ module Marty
|
|
30
40
|
<h3>Version</h3>
|
31
41
|
<div class="wrapper">
|
32
42
|
<table>
|
33
|
-
<th class=""><small>consistent</small></th>
|
34
|
-
<th class=""></th>
|
35
|
-
<tr class="passed">
|
36
|
-
<td>Git</td>
|
37
|
-
<td class="overflow"></td>
|
38
|
-
</tr>
|
43
|
+
<th colspan="2" class=""><small>consistent</small></th>
|
39
44
|
<tr class="passed">
|
40
45
|
<td>Marty</td>
|
41
46
|
<td class="overflow">#{Marty::VERSION}</td>
|
@@ -48,6 +53,10 @@ module Marty
|
|
48
53
|
<td>Mcfly</td>
|
49
54
|
<td class="overflow">#{Mcfly::VERSION}</td>
|
50
55
|
</tr>
|
56
|
+
<tr class="passed">
|
57
|
+
<td>Git</td>
|
58
|
+
<td class="overflow">#{git}</td>
|
59
|
+
</tr>
|
51
60
|
</table>
|
52
61
|
</div>
|
53
62
|
ERB
|
@@ -59,12 +68,7 @@ module Marty
|
|
59
68
|
<h3 class="error">Issues Detected </h3>
|
60
69
|
<div class="wrapper">
|
61
70
|
<table>
|
62
|
-
<th class="error">node1</th>
|
63
|
-
<th class="error"></th>
|
64
|
-
<tr class="passed">
|
65
|
-
<td>Git</td>
|
66
|
-
<td class="overflow"></td>
|
67
|
-
</tr>
|
71
|
+
<th colspan="2" class="error"><small>node1</small></th>
|
68
72
|
<tr class="passed">
|
69
73
|
<td>Marty</td>
|
70
74
|
<td class="overflow">#{Marty::VERSION}</td>
|
@@ -77,14 +81,13 @@ module Marty
|
|
77
81
|
<td>Mcfly</td>
|
78
82
|
<td class="overflow">#{Mcfly::VERSION}</td>
|
79
83
|
</tr>
|
80
|
-
</table>
|
81
|
-
<table>
|
82
|
-
<th class="error">node2</th>
|
83
|
-
<th class="error"></th>
|
84
84
|
<tr class="passed">
|
85
85
|
<td>Git</td>
|
86
|
-
<td class="overflow"
|
86
|
+
<td class="overflow">#{git}</td>
|
87
87
|
</tr>
|
88
|
+
</table>
|
89
|
+
<table>
|
90
|
+
<th colspan="2" class="error"><small>node2</small></th>
|
88
91
|
<tr class="passed">
|
89
92
|
<td>Marty</td>
|
90
93
|
<td class="overflow">#{val}</td>
|
@@ -97,6 +100,10 @@ module Marty
|
|
97
100
|
<td>Mcfly</td>
|
98
101
|
<td class="overflow">#{Mcfly::VERSION}</td>
|
99
102
|
</tr>
|
103
|
+
<tr class="passed">
|
104
|
+
<td>Git</td>
|
105
|
+
<td class="overflow">#{git}</td>
|
106
|
+
</tr>
|
100
107
|
</table>
|
101
108
|
</div>
|
102
109
|
ERB
|
@@ -370,7 +370,7 @@ describe Marty::RpcController do
|
|
370
370
|
@p2 = Marty::Posting.do_create("BASE", Date.today + 4.minute, 'a comment')
|
371
371
|
@data = [["some data",7,[1,2,3],{foo: "bar", baz: "quz"},5,"string"],
|
372
372
|
["some more data",[1,2,3],5,{foo: "bar", baz: "quz"},5,"string"]]
|
373
|
-
@data_json =
|
373
|
+
@data_json = @data.to_json
|
374
374
|
}
|
375
375
|
|
376
376
|
after(:each) do
|
@@ -388,11 +388,11 @@ describe Marty::RpcController do
|
|
388
388
|
format: :json,
|
389
389
|
script: "M1",
|
390
390
|
node: "B",
|
391
|
-
attrs:
|
391
|
+
attrs: "e",
|
392
392
|
tag: t1.name,
|
393
393
|
params: { a: 333, d: 5}.to_json,
|
394
394
|
}
|
395
|
-
expect(response.body).to eq(
|
395
|
+
expect(response.body).to eq(4.to_json)
|
396
396
|
end
|
397
397
|
|
398
398
|
it "should be able to post background job" do
|
@@ -401,7 +401,7 @@ describe Marty::RpcController do
|
|
401
401
|
format: :json,
|
402
402
|
script: "M1",
|
403
403
|
node: "B",
|
404
|
-
attrs:
|
404
|
+
attrs: "e",
|
405
405
|
tag: t1.name,
|
406
406
|
params: { a: 333, d: 5}.to_json,
|
407
407
|
background: true,
|
@@ -412,12 +412,12 @@ describe Marty::RpcController do
|
|
412
412
|
|
413
413
|
promise = Marty::Promise.find_by_id(job_id)
|
414
414
|
|
415
|
-
expect(promise.result).to eq({"e"=>4
|
415
|
+
expect(promise.result).to eq({"e"=>4})
|
416
416
|
|
417
417
|
Delayed::Worker.delay_jobs = true
|
418
418
|
end
|
419
419
|
|
420
|
-
it "should be able to post background job with non-array
|
420
|
+
it "should be able to post background job with non-array attr" do
|
421
421
|
Delayed::Worker.delay_jobs = false
|
422
422
|
post 'evaluate', {
|
423
423
|
format: :json,
|
@@ -444,12 +444,13 @@ describe Marty::RpcController do
|
|
444
444
|
format: :json,
|
445
445
|
script: "M1",
|
446
446
|
node: "D",
|
447
|
-
attrs:
|
447
|
+
attrs: "out",
|
448
448
|
tag: t1.name,
|
449
449
|
params: {in: @data}.to_json
|
450
450
|
}
|
451
451
|
expect(response.body).to eq(@data_json)
|
452
452
|
end
|
453
|
+
|
453
454
|
# content-type: application/json structures the request a little differently
|
454
455
|
# so we also test that
|
455
456
|
it "should be able to post (JSON) with complex data" do
|
@@ -459,155 +460,154 @@ describe Marty::RpcController do
|
|
459
460
|
format: :json,
|
460
461
|
script: "M1",
|
461
462
|
node: "D",
|
462
|
-
attrs:
|
463
|
+
attrs:"out",
|
463
464
|
tag: t1.name,
|
464
465
|
params: {in: @data}.to_json
|
465
466
|
}
|
466
467
|
expect(response.body).to eq(@data_json)
|
467
468
|
end
|
469
|
+
|
468
470
|
it "should be able to run scripts" do
|
469
471
|
get 'evaluate', {
|
470
|
-
|
471
|
-
|
472
|
-
|
473
|
-
|
474
|
-
|
475
|
-
|
472
|
+
format: :json,
|
473
|
+
script: "M1",
|
474
|
+
node: "A",
|
475
|
+
attrs: "a",
|
476
|
+
tag: t1.name,
|
477
|
+
}
|
476
478
|
# puts 'Z'*40, request.inspect
|
477
|
-
expect(response.body).to eq(
|
479
|
+
expect(response.body).to eq(123.0.to_json)
|
478
480
|
|
479
481
|
get 'evaluate', {
|
480
|
-
|
481
|
-
|
482
|
-
|
483
|
-
|
484
|
-
|
485
|
-
|
486
|
-
|
487
|
-
expect(response.body).to eq(
|
482
|
+
format: :json,
|
483
|
+
script: "M1",
|
484
|
+
node: "A",
|
485
|
+
attrs: "a",
|
486
|
+
params: {"a" => 4.5}.to_json,
|
487
|
+
tag: t1.name,
|
488
|
+
}
|
489
|
+
expect(response.body).to eq(4.5.to_json)
|
488
490
|
|
489
491
|
get 'evaluate', {
|
490
|
-
|
491
|
-
|
492
|
-
|
493
|
-
|
494
|
-
|
495
|
-
|
496
|
-
|
497
|
-
expect(response.body).to eq(
|
492
|
+
format: :json,
|
493
|
+
script: "M1",
|
494
|
+
node: "B",
|
495
|
+
attrs: "a",
|
496
|
+
params: {"a" => 4.5}.to_json,
|
497
|
+
tag: t1.name,
|
498
|
+
}
|
499
|
+
expect(response.body).to eq(4.5.to_json)
|
498
500
|
|
499
501
|
get 'evaluate', {
|
500
|
-
|
501
|
-
|
502
|
-
|
503
|
-
|
504
|
-
|
505
|
-
|
506
|
-
|
507
|
-
|
508
|
-
expect(res).to eq([3.3, 9.9])
|
502
|
+
format: :json,
|
503
|
+
script: "M1",
|
504
|
+
tag: "DEV",
|
505
|
+
node: "AA",
|
506
|
+
attrs: "a",
|
507
|
+
params: {"a" => 3.3}.to_json,
|
508
|
+
}
|
509
|
+
expect(response.body).to eq(3.3.to_json)
|
509
510
|
end
|
510
511
|
|
511
512
|
it "should be able to use posting name for tags" do
|
512
513
|
get 'evaluate', {
|
513
|
-
|
514
|
-
|
515
|
-
|
516
|
-
|
517
|
-
|
518
|
-
|
514
|
+
format: :json,
|
515
|
+
script: "M1",
|
516
|
+
node: "A",
|
517
|
+
attrs: "a",
|
518
|
+
tag: p0.name,
|
519
|
+
}
|
519
520
|
expect(response.body["error"]).to_not be_nil
|
520
521
|
|
521
522
|
get 'evaluate', {
|
522
|
-
|
523
|
-
|
524
|
-
|
525
|
-
|
526
|
-
|
527
|
-
|
528
|
-
|
529
|
-
expect(response.body).to eq(
|
523
|
+
format: :json,
|
524
|
+
script: "M1",
|
525
|
+
node: "A",
|
526
|
+
attrs: "a",
|
527
|
+
params: {"a" => 4.5}.to_json,
|
528
|
+
tag: p1.name,
|
529
|
+
}
|
530
|
+
expect(response.body).to eq(4.5.to_json)
|
530
531
|
|
531
532
|
get 'evaluate', {
|
532
|
-
|
533
|
-
|
534
|
-
|
535
|
-
|
536
|
-
|
537
|
-
|
538
|
-
|
539
|
-
expect(response.body).to eq(
|
533
|
+
format: :json,
|
534
|
+
script: "M1",
|
535
|
+
node: "B",
|
536
|
+
attrs: "a",
|
537
|
+
params: {"a" => 4.5}.to_json,
|
538
|
+
tag: p2.name,
|
539
|
+
}
|
540
|
+
expect(response.body).to eq(4.5.to_json)
|
540
541
|
|
541
542
|
get 'evaluate', {
|
542
|
-
|
543
|
-
|
544
|
-
|
545
|
-
|
546
|
-
|
547
|
-
|
548
|
-
|
549
|
-
|
550
|
-
expect(res).to eq([3.3, 9.9])
|
543
|
+
format: :json,
|
544
|
+
script: "M1",
|
545
|
+
tag: "NOW",
|
546
|
+
node: "AA",
|
547
|
+
attrs: "a",
|
548
|
+
params: {"a" => 3.3}.to_json,
|
549
|
+
}
|
550
|
+
expect(response.body).to eq(3.3.to_json)
|
551
551
|
end
|
552
552
|
|
553
553
|
it "should be able to run scripts 2" do
|
554
554
|
get 'evaluate', {
|
555
|
-
|
556
|
-
|
557
|
-
|
558
|
-
|
559
|
-
|
555
|
+
format: :json,
|
556
|
+
script: "M3",
|
557
|
+
node: "C",
|
558
|
+
attrs: "pc",
|
559
|
+
}
|
560
560
|
# puts 'Z'*40, request.inspect
|
561
|
-
expect(response.body).to eq(
|
561
|
+
expect(response.body).to eq(7.to_json)
|
562
562
|
|
563
563
|
get 'evaluate', {
|
564
|
-
|
565
|
-
|
566
|
-
|
567
|
-
|
568
|
-
|
564
|
+
format: :json,
|
565
|
+
script: "M3",
|
566
|
+
node: "B",
|
567
|
+
attrs: "pc",
|
568
|
+
}
|
569
569
|
# puts 'Z'*40, request.inspect
|
570
|
-
expect(response.body).to eq(
|
570
|
+
expect(response.body).to eq(9.to_json)
|
571
571
|
|
572
572
|
get 'evaluate', {
|
573
|
-
|
574
|
-
|
575
|
-
|
576
|
-
|
577
|
-
|
573
|
+
format: :json,
|
574
|
+
script: "M3",
|
575
|
+
node: "A",
|
576
|
+
attrs: "pc",
|
577
|
+
}
|
578
578
|
# puts 'Z'*40, request.inspect
|
579
579
|
expect(response.body).to match(/"error":"undefined parameter p"/)
|
580
580
|
end
|
581
581
|
|
582
582
|
it "should be able to handle imports" do
|
583
583
|
get 'evaluate', {
|
584
|
-
|
585
|
-
|
586
|
-
|
587
|
-
|
588
|
-
|
584
|
+
format: :json,
|
585
|
+
script: "M4",
|
586
|
+
node: "A",
|
587
|
+
attrs: "a",
|
588
|
+
}
|
589
589
|
# puts 'Z'*40, request.inspect
|
590
|
-
expect(response.body).to eq(
|
590
|
+
expect(response.body).to eq(2.to_json)
|
591
591
|
end
|
592
592
|
|
593
593
|
it "should support CSV" do
|
594
594
|
get 'evaluate', {
|
595
|
-
|
596
|
-
|
597
|
-
|
598
|
-
|
599
|
-
|
595
|
+
format: :csv,
|
596
|
+
script: "M4",
|
597
|
+
node: "A",
|
598
|
+
attrs: "a",
|
599
|
+
}
|
600
600
|
# puts 'Z'*40, request.inspect
|
601
|
-
expect(response.body).to eq("2\r\
|
601
|
+
expect(response.body).to eq("2\r\n")
|
602
602
|
end
|
603
603
|
|
604
604
|
it "should support CSV (2)" do
|
605
605
|
get 'evaluate', {
|
606
|
-
|
607
|
-
|
608
|
-
|
609
|
-
|
610
|
-
|
606
|
+
format: :csv,
|
607
|
+
script: "M4",
|
608
|
+
node: "A",
|
609
|
+
attrs: "result",
|
610
|
+
}
|
611
611
|
# puts 'Z'*40, request.inspect
|
612
612
|
expect(response.body).to eq("a,b\r\n10,456\r\n789,10\r\n")
|
613
613
|
end
|
@@ -618,15 +618,15 @@ describe Marty::RpcController do
|
|
618
618
|
attr: nil,
|
619
619
|
logged: false,
|
620
620
|
input_validated: true)
|
621
|
-
|
621
|
+
attr = "b"
|
622
622
|
params = {"a" => 5}.to_json
|
623
623
|
get 'evaluate', {
|
624
|
-
|
625
|
-
|
626
|
-
|
627
|
-
|
628
|
-
|
629
|
-
|
624
|
+
format: :csv,
|
625
|
+
script: "M1",
|
626
|
+
node: "A",
|
627
|
+
attrs: attr,
|
628
|
+
params: params
|
629
|
+
}
|
630
630
|
expect = "Schema error for M1/A attrs=b: Schema not defined\r\n"
|
631
631
|
expect(response.body).to eq("error,#{expect}")
|
632
632
|
end
|
@@ -637,20 +637,20 @@ describe Marty::RpcController do
|
|
637
637
|
attr: nil,
|
638
638
|
logged: false,
|
639
639
|
input_validated: true)
|
640
|
-
|
640
|
+
attr = "b"
|
641
641
|
params = {"a" => 5}.to_json
|
642
642
|
get 'evaluate', {
|
643
|
-
|
644
|
-
|
645
|
-
|
646
|
-
|
647
|
-
|
648
|
-
|
643
|
+
format: :json,
|
644
|
+
script: "M1",
|
645
|
+
node: "A",
|
646
|
+
attrs: attr,
|
647
|
+
params: params
|
648
|
+
}
|
649
649
|
expect = "Schema error for M1/A attrs=b: Schema not defined"
|
650
|
-
|
651
|
-
expect(
|
652
|
-
expect(
|
653
|
-
expect(
|
650
|
+
res = JSON.parse(response.body)
|
651
|
+
expect(res.keys.size).to eq(1)
|
652
|
+
expect(res.keys[0]).to eq("error")
|
653
|
+
expect(res.values[0]).to eq(expect)
|
654
654
|
end
|
655
655
|
|
656
656
|
it "returns an error message on missing attributes in schema script" do
|
@@ -659,15 +659,15 @@ describe Marty::RpcController do
|
|
659
659
|
attr: nil,
|
660
660
|
logged: false,
|
661
661
|
input_validated: true)
|
662
|
-
|
662
|
+
attr = "h"
|
663
663
|
params = {"f" => 5}.to_json
|
664
664
|
get 'evaluate', {
|
665
|
-
|
666
|
-
|
667
|
-
|
668
|
-
|
669
|
-
|
670
|
-
|
665
|
+
format: :csv,
|
666
|
+
script: "M4",
|
667
|
+
node: "A",
|
668
|
+
attrs: attr,
|
669
|
+
params: params
|
670
|
+
}
|
671
671
|
expect = "Schema error for M4/A attrs=h: Problem with schema"
|
672
672
|
expect(response.body).to include("error,#{expect}")
|
673
673
|
end
|
@@ -678,15 +678,15 @@ describe Marty::RpcController do
|
|
678
678
|
attr: nil,
|
679
679
|
logged: false,
|
680
680
|
input_validated: true)
|
681
|
-
|
681
|
+
attr = "pc"
|
682
682
|
params = {"p" => 5}.to_json
|
683
683
|
get 'evaluate', {
|
684
|
-
|
685
|
-
|
686
|
-
|
687
|
-
|
688
|
-
|
689
|
-
|
684
|
+
format: :csv,
|
685
|
+
script: "M3",
|
686
|
+
node: "A",
|
687
|
+
attrs: attr,
|
688
|
+
params: params
|
689
|
+
}
|
690
690
|
expect = "Schema error for M3/A attrs=pc: Problem with schema: "\
|
691
691
|
"syntax error M3Schemas:2\r\n"
|
692
692
|
expect(response.body).to eq("error,#{expect}")
|
@@ -698,43 +698,16 @@ describe Marty::RpcController do
|
|
698
698
|
attr: nil,
|
699
699
|
logged: false,
|
700
700
|
input_validated: true)
|
701
|
-
|
701
|
+
attr = "d"
|
702
702
|
params = {"p" => "132"}.to_json
|
703
703
|
get 'evaluate', {
|
704
|
-
|
705
|
-
|
706
|
-
|
707
|
-
|
708
|
-
|
709
|
-
}
|
710
|
-
expect = '""d""=>[""The property \'#/p\' of type string did not '\
|
711
|
-
'match the following type: integer'
|
712
|
-
expect(response.body).to include(expect)
|
713
|
-
end
|
714
|
-
|
715
|
-
it "returns a validation error when validating multiple attributes" do
|
716
|
-
Marty::ApiConfig.create!(script: "M4",
|
717
|
-
node: "A",
|
718
|
-
attr: nil,
|
719
|
-
logged: false,
|
720
|
-
input_validated: true,
|
721
|
-
output_validated: true)
|
722
|
-
attrs = ["d", "g"].to_json
|
723
|
-
params = {"p" => "132", "e" => "55", "f"=>"16"}.to_json
|
724
|
-
get 'evaluate', {
|
725
|
-
format: :csv,
|
726
|
-
script: "M4",
|
727
|
-
node: "A",
|
728
|
-
attrs: attrs,
|
729
|
-
params: params
|
704
|
+
format: :csv,
|
705
|
+
script: "M4",
|
706
|
+
node: "A",
|
707
|
+
attrs: attr,
|
708
|
+
params: params
|
730
709
|
}
|
731
|
-
expect = '
|
732
|
-
'match the following type: integer'
|
733
|
-
expect(response.body).to include(expect)
|
734
|
-
expect = '""g""=>[""The property \'#/e\' of type string did not '\
|
735
|
-
'match the following type: integer'
|
736
|
-
expect(response.body).to include(expect)
|
737
|
-
expect = 'The property \'#/f\' of type string did not '\
|
710
|
+
expect = '[""The property \'#/p\' of type string did not '\
|
738
711
|
'match the following type: integer'
|
739
712
|
expect(response.body).to include(expect)
|
740
713
|
end
|
@@ -748,58 +721,60 @@ describe Marty::RpcController do
|
|
748
721
|
input_validated: true,
|
749
722
|
output_validated: true,
|
750
723
|
strict_validate: true)
|
751
|
-
|
724
|
+
attr = "ii"
|
752
725
|
params = {"p" => 132, "e" => 55, "f"=>16, "i"=>"string"}.to_json
|
753
726
|
get 'evaluate', {
|
754
727
|
format: :json,
|
755
728
|
script: "M4",
|
756
729
|
node: "A",
|
757
|
-
attrs:
|
730
|
+
attrs: attr,
|
758
731
|
params: params
|
759
732
|
}
|
760
|
-
|
733
|
+
res = JSON.parse(response.body)
|
761
734
|
errpart = "of type string did not match the following type: integer"
|
762
|
-
expect(
|
763
|
-
expect(res_hash[1]).to eq(291)
|
764
|
-
expect(res_hash[2]["error"]).to include(errpart)
|
765
|
-
expect(res_hash[3]).to eq([{"a"=>132,"b"=>456},
|
766
|
-
{"a"=>789,"b"=>132}])
|
735
|
+
expect(res['error']).to include(errpart)
|
767
736
|
logs = Marty::Log.all
|
768
737
|
expect(logs.count).to eq(1)
|
769
738
|
expect(logs[0].details["error"][0]).to include(errpart)
|
770
739
|
end
|
771
|
-
|
772
|
-
|
773
|
-
Marty::ApiConfig.create!(script: "
|
740
|
+
|
741
|
+
it "validates output (bad type, with strict errors)" do
|
742
|
+
Marty::ApiConfig.create!(script: "M5",
|
774
743
|
node: "A",
|
775
|
-
attr:
|
744
|
+
attr: nil,
|
776
745
|
logged: false,
|
777
746
|
input_validated: true,
|
778
|
-
output_validated: true
|
779
|
-
|
780
|
-
|
747
|
+
output_validated: true,
|
748
|
+
strict_validate: true)
|
749
|
+
|
750
|
+
attr = "result"
|
751
|
+
params = {"f" => "Banana"}.to_json
|
781
752
|
get 'evaluate', {
|
782
753
|
format: :json,
|
783
|
-
script: "
|
754
|
+
script: "M5",
|
784
755
|
node: "A",
|
785
|
-
attrs:
|
756
|
+
attrs: attr,
|
786
757
|
params: params
|
787
758
|
}
|
788
|
-
|
789
|
-
expect(
|
790
|
-
|
759
|
+
res = JSON.parse(response.body)
|
760
|
+
expect(res).to include("error")
|
761
|
+
expect1 = "The property '#/0/b' of type integer did not match the "\
|
762
|
+
"following type: string"
|
763
|
+
expect2 = "The property '#/0/a' of type string did not match the "\
|
764
|
+
"following type: integer"
|
765
|
+
expect(res["error"]).to include(expect1)
|
766
|
+
expect(res["error"]).to include(expect2)
|
767
|
+
|
791
768
|
logs = Marty::Log.all
|
792
|
-
expect(logs.count).to eq(
|
769
|
+
expect(logs.count).to eq(1)
|
770
|
+
expect(logs[0].message).to eq("API M5:A.result")
|
771
|
+
expect(logs[0].details["error"].join).to include(expect1)
|
772
|
+
expect(logs[0].details["error"].join).to include(expect2)
|
773
|
+
expect(logs[0].details["data"]).to eq([{"a"=>"str", "b"=>456},
|
774
|
+
{"a"=>789, "b"=>"str"}])
|
793
775
|
end
|
794
776
|
|
795
|
-
it "validates output (bad type, with
|
796
|
-
Marty::ApiConfig.create!(script: "M5",
|
797
|
-
node: "A",
|
798
|
-
attr: nil,
|
799
|
-
logged: false,
|
800
|
-
input_validated: true,
|
801
|
-
output_validated: true,
|
802
|
-
strict_validate: true)
|
777
|
+
it "validates output (bad type, with non strict errors)" do
|
803
778
|
Marty::ApiConfig.create!(script: "M5",
|
804
779
|
node: "A",
|
805
780
|
attr: "result2",
|
@@ -807,34 +782,26 @@ describe Marty::RpcController do
|
|
807
782
|
input_validated: true,
|
808
783
|
output_validated: true,
|
809
784
|
strict_validate: false)
|
810
|
-
|
785
|
+
attr = "result2"
|
811
786
|
params = {"f" => "Banana"}.to_json
|
812
787
|
get 'evaluate', {
|
813
788
|
format: :json,
|
814
789
|
script: "M5",
|
815
790
|
node: "A",
|
816
|
-
attrs:
|
791
|
+
attrs: attr,
|
817
792
|
params: params
|
818
793
|
}
|
819
|
-
res_hash = JSON.parse(response.body)
|
820
|
-
expect(res_hash[0]).to include("error")
|
821
794
|
expect1 = "The property '#/0/b' of type integer did not match the "\
|
822
|
-
|
795
|
+
"following type: string"
|
823
796
|
expect2 = "The property '#/0/a' of type string did not match the "\
|
824
797
|
"following type: integer"
|
825
|
-
expect(res_hash[0]["error"]).to include(expect1)
|
826
|
-
expect(res_hash[0]["error"]).to include(expect2)
|
827
|
-
|
828
798
|
logs = Marty::Log.all
|
829
|
-
expect(logs.count).to eq(
|
830
|
-
expect(logs[0].message).to eq("API M5:A.
|
831
|
-
expect(logs[
|
832
|
-
logs.
|
833
|
-
|
834
|
-
|
835
|
-
expect(ml.details["data"]).to eq([{"a"=>"str", "b"=>456},
|
836
|
-
{"a"=>789, "b"=>"str"}])
|
837
|
-
end
|
799
|
+
expect(logs.count).to eq(1)
|
800
|
+
expect(logs[0].message).to eq("API M5:A.result2")
|
801
|
+
expect(logs[0].details["error"].join).to include(expect1)
|
802
|
+
expect(logs[0].details["error"].join).to include(expect2)
|
803
|
+
expect(logs[0].details["data"]).to eq([{"a"=>"str", "b"=>456},
|
804
|
+
{"a"=>789, "b"=>"str"}])
|
838
805
|
end
|
839
806
|
|
840
807
|
it "validates output (missing item)" do
|
@@ -845,21 +812,22 @@ describe Marty::RpcController do
|
|
845
812
|
input_validated: true,
|
846
813
|
output_validated: true,
|
847
814
|
strict_validate: true)
|
848
|
-
|
815
|
+
attr = "result"
|
849
816
|
params = {"b" => 122}.to_json
|
850
817
|
get 'evaluate', {
|
851
818
|
format: :json,
|
852
819
|
script: "M9",
|
853
820
|
node: "A",
|
854
|
-
attrs:
|
821
|
+
attrs: attr,
|
855
822
|
params: params
|
856
823
|
}
|
857
|
-
|
858
|
-
|
824
|
+
|
825
|
+
res = JSON.parse(response.body)
|
826
|
+
expect(res).to include("error")
|
859
827
|
expect1 = "The property '#/0' did not contain a required property of 'c'"
|
860
828
|
expect2 = "The property '#/1' did not contain a required property of 'c'"
|
861
|
-
expect(
|
862
|
-
expect(
|
829
|
+
expect(res["error"]).to include(expect1)
|
830
|
+
expect(res["error"]).to include(expect2)
|
863
831
|
|
864
832
|
logs = Marty::Log.all
|
865
833
|
expect(logs.count).to eq(1)
|
@@ -877,15 +845,15 @@ describe Marty::RpcController do
|
|
877
845
|
attr: nil,
|
878
846
|
logged: false,
|
879
847
|
input_validated: true)
|
880
|
-
|
848
|
+
attr = "lc"
|
881
849
|
params = {"p" => 5}.to_json
|
882
850
|
get 'evaluate', {
|
883
|
-
|
884
|
-
|
885
|
-
|
886
|
-
|
887
|
-
|
888
|
-
|
851
|
+
format: :csv,
|
852
|
+
script: "M4",
|
853
|
+
node: "A",
|
854
|
+
attrs: attr,
|
855
|
+
params: params
|
856
|
+
}
|
889
857
|
expect(response.body).to eq("9\r\n9\r\n")
|
890
858
|
end
|
891
859
|
|
@@ -895,21 +863,21 @@ describe Marty::RpcController do
|
|
895
863
|
attr: nil,
|
896
864
|
logged: false,
|
897
865
|
input_validated: true)
|
898
|
-
|
866
|
+
attr = "res"
|
899
867
|
params = {"b" => 5.22}.to_json
|
900
868
|
get 'evaluate', {
|
901
|
-
|
902
|
-
|
903
|
-
|
904
|
-
|
905
|
-
|
906
|
-
|
869
|
+
format: :json,
|
870
|
+
script: "M6",
|
871
|
+
node: "A",
|
872
|
+
attrs: attr,
|
873
|
+
params: params
|
874
|
+
}
|
907
875
|
expect = 'res: The property \'#/properties/b/type\' of type string '\
|
908
876
|
'did not match one or more of the required schemas'
|
909
|
-
|
910
|
-
expect(
|
911
|
-
expect(
|
912
|
-
expect(
|
877
|
+
res = JSON.parse(response.body)
|
878
|
+
expect(res.keys.size).to eq(1)
|
879
|
+
expect(res.keys[0]).to eq("error")
|
880
|
+
expect(res.values[0]).to eq(expect)
|
913
881
|
end
|
914
882
|
|
915
883
|
|
@@ -926,15 +894,15 @@ describe Marty::RpcController do
|
|
926
894
|
attr: nil,
|
927
895
|
logged: false,
|
928
896
|
input_validated: true)
|
929
|
-
|
897
|
+
attr = "res"
|
930
898
|
params = {"f" => "Banana"}.to_json
|
931
899
|
get 'evaluate', {
|
932
|
-
|
933
|
-
|
934
|
-
|
935
|
-
|
936
|
-
|
937
|
-
|
900
|
+
format: :csv,
|
901
|
+
script: "M5",
|
902
|
+
node: "A",
|
903
|
+
attrs: attr,
|
904
|
+
params: params
|
905
|
+
}
|
938
906
|
expect(response.body).to eq("1\r\n")
|
939
907
|
end
|
940
908
|
|
@@ -944,15 +912,15 @@ describe Marty::RpcController do
|
|
944
912
|
attr: nil,
|
945
913
|
logged: false,
|
946
914
|
input_validated: true)
|
947
|
-
|
915
|
+
attr = "res"
|
948
916
|
params = {"f" => "Beans"}.to_json
|
949
917
|
get 'evaluate', {
|
950
|
-
|
951
|
-
|
952
|
-
|
953
|
-
|
954
|
-
|
955
|
-
|
918
|
+
format: :csv,
|
919
|
+
script: "M5",
|
920
|
+
node: "A",
|
921
|
+
attrs: attr,
|
922
|
+
params: params
|
923
|
+
}
|
956
924
|
expect = "property '#/f' value 'Beans' not contained in FruitsEnum"
|
957
925
|
expect(response.body).to include(expect)
|
958
926
|
end
|
@@ -963,20 +931,20 @@ describe Marty::RpcController do
|
|
963
931
|
attr: nil,
|
964
932
|
logged: false,
|
965
933
|
input_validated: true)
|
966
|
-
|
934
|
+
attr = "res"
|
967
935
|
params = {"b" => "MemberOfANonExistantEnum"}.to_json
|
968
936
|
get 'evaluate', {
|
969
|
-
|
970
|
-
|
971
|
-
|
972
|
-
|
973
|
-
|
974
|
-
|
937
|
+
format: :json,
|
938
|
+
script: "M7",
|
939
|
+
node: "A",
|
940
|
+
attrs: attr,
|
941
|
+
params: params
|
942
|
+
}
|
975
943
|
expect = "property '#/b': 'NonExistantEnum' is not a pg_enum"
|
976
|
-
|
977
|
-
expect(
|
978
|
-
expect(
|
979
|
-
expect(
|
944
|
+
res = JSON.parse(response.body)
|
945
|
+
expect(res.keys.size).to eq(1)
|
946
|
+
expect(res.keys[0]).to eq("error")
|
947
|
+
expect(res.values[0]).to include(expect)
|
980
948
|
end
|
981
949
|
|
982
950
|
it "validates pgenum with capitalization issues" do
|
@@ -987,15 +955,15 @@ describe Marty::RpcController do
|
|
987
955
|
input_validated: true)
|
988
956
|
skip "pending until a solution is found that handles "\
|
989
957
|
"autoload issues involving constantize"
|
990
|
-
|
958
|
+
attr = "res"
|
991
959
|
params = {"b" => "Annual"}.to_json
|
992
960
|
get 'evaluate', {
|
993
|
-
|
994
|
-
|
995
|
-
|
996
|
-
|
997
|
-
|
998
|
-
|
961
|
+
format: :json,
|
962
|
+
script: "M8",
|
963
|
+
node: "A",
|
964
|
+
attrs: attr,
|
965
|
+
params: params
|
966
|
+
}
|
999
967
|
end
|
1000
968
|
|
1001
969
|
it "should log good req" do
|
@@ -1003,23 +971,23 @@ describe Marty::RpcController do
|
|
1003
971
|
node: "A",
|
1004
972
|
attr: nil,
|
1005
973
|
logged: true)
|
1006
|
-
|
974
|
+
attr = "lc"
|
1007
975
|
params = {"p" => 5}
|
1008
976
|
get 'evaluate', {
|
1009
|
-
|
1010
|
-
|
1011
|
-
|
1012
|
-
|
1013
|
-
|
1014
|
-
|
977
|
+
format: :csv,
|
978
|
+
script: "M3",
|
979
|
+
node: "A",
|
980
|
+
attrs: attr,
|
981
|
+
params: params.to_json
|
982
|
+
}
|
1015
983
|
expect(response.body).to eq("9\r\n9\r\n")
|
1016
984
|
log = Marty::Log.order(id: :desc).first
|
1017
985
|
|
1018
986
|
expect(log.details['script']).to eq("M3")
|
1019
987
|
expect(log.details['node']).to eq("A")
|
1020
|
-
expect(log.details['attrs']).to eq(
|
988
|
+
expect(log.details['attrs']).to eq(attr)
|
1021
989
|
expect(log.details['input']).to eq(params)
|
1022
|
-
expect(log.details['output']).to eq([
|
990
|
+
expect(log.details['output']).to eq([9, 9])
|
1023
991
|
expect(log.details['remote_ip']).to eq("0.0.0.0")
|
1024
992
|
expect(log.details['error']).to eq(nil)
|
1025
993
|
|
@@ -1030,16 +998,16 @@ describe Marty::RpcController do
|
|
1030
998
|
node: "A",
|
1031
999
|
attr: nil,
|
1032
1000
|
logged: true)
|
1033
|
-
|
1001
|
+
attr = "lc"
|
1034
1002
|
params = {"p" => 5}
|
1035
1003
|
get 'evaluate', {
|
1036
|
-
|
1037
|
-
|
1038
|
-
|
1039
|
-
|
1040
|
-
|
1041
|
-
|
1042
|
-
|
1004
|
+
format: :csv,
|
1005
|
+
script: "M3",
|
1006
|
+
node: "A",
|
1007
|
+
attrs: attr,
|
1008
|
+
params: params.to_json,
|
1009
|
+
background: true
|
1010
|
+
}
|
1043
1011
|
expect(response.body).to match(/job_id,/)
|
1044
1012
|
log = Marty::Log.order(id: :desc).first
|
1045
1013
|
|
@@ -1047,12 +1015,12 @@ describe Marty::RpcController do
|
|
1047
1015
|
|
1048
1016
|
it "should not log if it should not log" do
|
1049
1017
|
get 'evaluate', {
|
1050
|
-
|
1051
|
-
|
1052
|
-
|
1053
|
-
|
1054
|
-
|
1055
|
-
|
1018
|
+
format: :json,
|
1019
|
+
script: "M1",
|
1020
|
+
node: "A",
|
1021
|
+
attrs: "a",
|
1022
|
+
tag: t1.name,
|
1023
|
+
}
|
1056
1024
|
expect(Marty::Log.count).to eq(0)
|
1057
1025
|
end
|
1058
1026
|
|
@@ -1063,12 +1031,12 @@ describe Marty::RpcController do
|
|
1063
1031
|
logged: true)
|
1064
1032
|
params = {"p" => 5}
|
1065
1033
|
get 'evaluate', {
|
1066
|
-
|
1067
|
-
|
1068
|
-
|
1069
|
-
|
1070
|
-
|
1071
|
-
|
1034
|
+
format: :csv,
|
1035
|
+
script: "M3",
|
1036
|
+
node: "A",
|
1037
|
+
attrs: "lc",
|
1038
|
+
params: params.to_json
|
1039
|
+
}
|
1072
1040
|
expect(response.body).to eq("9\r\n9\r\n")
|
1073
1041
|
log = Marty::Log.order(id: :desc).first
|
1074
1042
|
|
@@ -1089,12 +1057,12 @@ describe Marty::RpcController do
|
|
1089
1057
|
api.save!
|
1090
1058
|
|
1091
1059
|
get 'evaluate', {
|
1092
|
-
|
1093
|
-
|
1094
|
-
|
1095
|
-
|
1096
|
-
|
1097
|
-
expect(response.body).to eq(
|
1060
|
+
format: :json,
|
1061
|
+
script: "M3",
|
1062
|
+
node: "C",
|
1063
|
+
attrs: "pc",
|
1064
|
+
}
|
1065
|
+
expect(response.body).to eq(7.to_json)
|
1098
1066
|
end
|
1099
1067
|
|
1100
1068
|
it "should support api authorization - api_key required but missing" do
|
@@ -1104,11 +1072,11 @@ describe Marty::RpcController do
|
|
1104
1072
|
api.save!
|
1105
1073
|
|
1106
1074
|
get 'evaluate', {
|
1107
|
-
|
1108
|
-
|
1109
|
-
|
1110
|
-
|
1111
|
-
|
1075
|
+
format: :json,
|
1076
|
+
script: "M3",
|
1077
|
+
node: "C",
|
1078
|
+
attrs: "pc",
|
1079
|
+
}
|
1112
1080
|
expect(response.body).to match(/"error":"Permission denied"/)
|
1113
1081
|
end
|
1114
1082
|
|
@@ -1121,21 +1089,21 @@ describe Marty::RpcController do
|
|
1121
1089
|
apic = Marty::ApiConfig.create!(script: 'M3',
|
1122
1090
|
logged: true)
|
1123
1091
|
|
1124
|
-
|
1092
|
+
attr = "pc"
|
1125
1093
|
get 'evaluate', {
|
1126
|
-
|
1127
|
-
|
1128
|
-
|
1129
|
-
|
1130
|
-
|
1131
|
-
|
1132
|
-
expect(response.body).to eq(
|
1094
|
+
format: :json,
|
1095
|
+
script: "M3",
|
1096
|
+
node: "C",
|
1097
|
+
attrs: attr,
|
1098
|
+
api_key: api.api_key,
|
1099
|
+
}
|
1100
|
+
expect(response.body).to eq(7.to_json)
|
1133
1101
|
log = Marty::Log.order(id: :desc).first
|
1134
1102
|
|
1135
1103
|
expect(log.details['script']).to eq("M3")
|
1136
1104
|
expect(log.details['node']).to eq("C")
|
1137
|
-
expect(log.details['attrs']).to eq(
|
1138
|
-
expect(log.details['output']).to eq(
|
1105
|
+
expect(log.details['attrs']).to eq(attr)
|
1106
|
+
expect(log.details['output']).to eq(7)
|
1139
1107
|
expect(log.details['remote_ip']).to eq("0.0.0.0")
|
1140
1108
|
expect(log.details['auth_name']).to eq("TestApp")
|
1141
1109
|
end
|
@@ -1147,12 +1115,12 @@ describe Marty::RpcController do
|
|
1147
1115
|
api.save!
|
1148
1116
|
|
1149
1117
|
get 'evaluate', {
|
1150
|
-
|
1151
|
-
|
1152
|
-
|
1153
|
-
|
1154
|
-
|
1155
|
-
|
1118
|
+
format: :json,
|
1119
|
+
script: "M3",
|
1120
|
+
node: "C",
|
1121
|
+
attrs: "pc",
|
1122
|
+
api_key: api.api_key + 'x',
|
1123
|
+
}
|
1156
1124
|
expect(response.body).to match(/"error":"Permission denied"/)
|
1157
1125
|
end
|
1158
1126
|
|
@@ -1167,21 +1135,21 @@ describe Marty::RpcController do
|
|
1167
1135
|
strict_validate: false)
|
1168
1136
|
end
|
1169
1137
|
def do_call(req1, req2, req3, optionals={})
|
1170
|
-
|
1138
|
+
attr = "v1"
|
1171
1139
|
params = optionals.merge({"req1" => req1,
|
1172
1140
|
"req2"=> req2,
|
1173
1141
|
"req3"=> req3}).to_json
|
1174
1142
|
|
1175
1143
|
# to see what the schema helpers generated:
|
1176
1144
|
# engine = Marty::ScriptSet.new(nil).get_engine("M10Schemas")
|
1177
|
-
# x=engine.evaluate("A",
|
1145
|
+
# x=engine.evaluate("A", "v1", {})
|
1178
1146
|
# binding.pry
|
1179
1147
|
|
1180
1148
|
get 'evaluate', {
|
1181
1149
|
format: :json,
|
1182
1150
|
script: "M10",
|
1183
1151
|
node: "A",
|
1184
|
-
attrs:
|
1152
|
+
attrs: attr,
|
1185
1153
|
params: params
|
1186
1154
|
}
|
1187
1155
|
|
@@ -1223,17 +1191,15 @@ describe Marty::RpcController do
|
|
1223
1191
|
].each do
|
1224
1192
|
|a, exp|
|
1225
1193
|
do_call(*a)
|
1226
|
-
|
1227
|
-
|
1228
|
-
|
1229
|
-
expect(got).to include(exp)
|
1194
|
+
res = JSON.parse(response.body)
|
1195
|
+
expect(res.is_a?(Hash) ? res['error'] : res).to include(exp)
|
1230
1196
|
end
|
1231
1197
|
end
|
1232
1198
|
end
|
1233
1199
|
end
|
1234
1200
|
|
1235
1201
|
context "error handling" do
|
1236
|
-
it 'returns bad attrs if
|
1202
|
+
it 'returns bad attrs if attr is not a string' do
|
1237
1203
|
get :evaluate, format: :json, attrs: 0
|
1238
1204
|
expect(response.body).to match(/"error":"Malformed attrs"/)
|
1239
1205
|
end
|
@@ -1243,7 +1209,7 @@ describe Marty::RpcController do
|
|
1243
1209
|
expect(response.body).to match(/"error":"Malformed attrs"/)
|
1244
1210
|
end
|
1245
1211
|
|
1246
|
-
it 'returns malformed attrs if
|
1212
|
+
it 'returns malformed attrs if attr is not an array of strings' do
|
1247
1213
|
get :evaluate, format: :json, attrs: "{}"
|
1248
1214
|
expect(response.body).to match(/"error":"Malformed attrs"/)
|
1249
1215
|
|
@@ -1252,29 +1218,29 @@ describe Marty::RpcController do
|
|
1252
1218
|
end
|
1253
1219
|
|
1254
1220
|
it 'returns bad params if params is not a string' do
|
1255
|
-
get
|
1221
|
+
get :evaluate, format: :json, attrs: "e", params: 0
|
1256
1222
|
expect(response.body).to match(/"error":"Bad params"/)
|
1257
1223
|
end
|
1258
1224
|
|
1259
1225
|
it 'returns malformed params for improperly formatted json' do
|
1260
|
-
get :evaluate, format: :json, params: "{"
|
1226
|
+
get :evaluate, format: :json, attrs: "e", params: "{"
|
1261
1227
|
expect(response.body).to match(/"error":"Malformed params"/)
|
1262
1228
|
end
|
1263
1229
|
|
1264
1230
|
it 'returns malformed params if params is not a hash' do
|
1265
|
-
get :evaluate, format: :json, params: "[0]"
|
1231
|
+
get :evaluate, format: :json, attrs: "e", params: "[0]"
|
1266
1232
|
expect(response.body).to match(/"error":"Malformed params"/)
|
1267
1233
|
end
|
1268
1234
|
|
1269
1235
|
it 'returns engine/tag lookup error if script not found' do
|
1270
|
-
get :evaluate, format: :json, script: 'M1', tag: 'invalid'
|
1236
|
+
get :evaluate, format: :json, script: 'M1', attrs: "e", tag: 'invalid'
|
1271
1237
|
expect(response.body).to match(/"error":"Can't get engine:/)
|
1272
|
-
get :evaluate, format: :json, script: 'Invalid', tag: t1.name
|
1238
|
+
get :evaluate, format: :json, script: 'Invalid', attrs: "e", tag: t1.name
|
1273
1239
|
expect(response.body).to match(/"error":"Can't get engine:/)
|
1274
1240
|
end
|
1275
1241
|
|
1276
1242
|
it 'returns the script runtime error (no node specified)' do
|
1277
|
-
get :evaluate, format: :json, script: 'M1', tag: t1.name
|
1243
|
+
get :evaluate, format: :json, script: 'M1', attrs: "e", tag: t1.name
|
1278
1244
|
expect(response.body).to match(/"error":"bad node/)
|
1279
1245
|
end
|
1280
1246
|
end
|