sanford 0.10.0 → 0.10.1
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/sanford/service_handler.rb +8 -1
- data/lib/sanford/template_source.rb +8 -0
- data/lib/sanford/version.rb +1 -1
- data/test/support/service_handlers.rb +1 -1
- data/test/support/test_disallowed_template.rb +0 -0
- data/test/unit/service_handler_tests.rb +13 -1
- data/test/unit/template_source_tests.rb +19 -1
- metadata +5 -3
@@ -1,7 +1,12 @@
|
|
1
|
+
require 'sanford/sanford_runner'
|
2
|
+
require 'sanford/template_source'
|
3
|
+
|
1
4
|
module Sanford
|
2
5
|
|
3
6
|
module ServiceHandler
|
4
7
|
|
8
|
+
DISALLOWED_TEMPLATE_EXTS = Sanford::TemplateSource::DISALLOWED_ENGINE_EXTS
|
9
|
+
|
5
10
|
def self.constantize(class_name)
|
6
11
|
names = class_name.to_s.split('::').reject{|name| name.empty? }
|
7
12
|
klass = names.inject(Object) do |constant, name|
|
@@ -85,7 +90,9 @@ module Sanford
|
|
85
90
|
end
|
86
91
|
|
87
92
|
def get_template(path, source)
|
88
|
-
Dir.glob("#{Pathname.new(source.path).join(path.to_s)}.*")
|
93
|
+
files = Dir.glob("#{Pathname.new(source.path).join(path.to_s)}.*")
|
94
|
+
files = files.reject{ |p| DISALLOWED_TEMPLATE_EXTS.include?(File.extname(p)) }
|
95
|
+
files.first.to_s
|
89
96
|
end
|
90
97
|
|
91
98
|
end
|
@@ -4,6 +4,10 @@ module Sanford
|
|
4
4
|
|
5
5
|
class TemplateSource
|
6
6
|
|
7
|
+
DISALLOWED_ENGINE_EXTS = [ '.rb' ]
|
8
|
+
|
9
|
+
DisallowedEngineExtError = Class.new(ArgumentError)
|
10
|
+
|
7
11
|
attr_reader :path, :engines
|
8
12
|
|
9
13
|
def initialize(path)
|
@@ -13,6 +17,10 @@ module Sanford
|
|
13
17
|
end
|
14
18
|
|
15
19
|
def engine(input_ext, engine_class, registered_opts = nil)
|
20
|
+
if DISALLOWED_ENGINE_EXTS.include?(".#{input_ext}")
|
21
|
+
raise DisallowedEngineExtError, "`#{input_ext}` is disallowed as an"\
|
22
|
+
" engine extension."
|
23
|
+
end
|
16
24
|
engine_opts = @default_opts.merge(registered_opts || {})
|
17
25
|
@engines[input_ext.to_s] = engine_class.new(engine_opts)
|
18
26
|
end
|
data/lib/sanford/version.rb
CHANGED
File without changes
|
@@ -2,6 +2,7 @@ require 'assert'
|
|
2
2
|
require 'sanford/service_handler'
|
3
3
|
|
4
4
|
require 'bson'
|
5
|
+
require 'sanford/template_source'
|
5
6
|
require 'sanford/test_helpers'
|
6
7
|
require 'test/support/service_handlers'
|
7
8
|
|
@@ -27,6 +28,11 @@ module Sanford::ServiceHandler
|
|
27
28
|
should have_imeths :prepend_before_init, :prepend_after_init
|
28
29
|
should have_imeths :prepend_before_run, :prepend_after_run
|
29
30
|
|
31
|
+
should "disallow certain template extensions" do
|
32
|
+
exp = Sanford::TemplateSource::DISALLOWED_ENGINE_EXTS
|
33
|
+
assert_equal exp, subject::DISALLOWED_TEMPLATE_EXTS
|
34
|
+
end
|
35
|
+
|
30
36
|
should "allow running a handler class with the class method #run" do
|
31
37
|
response = HaltServiceHandler.run({
|
32
38
|
'code' => 648,
|
@@ -328,10 +334,16 @@ module Sanford::ServiceHandler
|
|
328
334
|
desc "render helper method"
|
329
335
|
|
330
336
|
should "render template files" do
|
331
|
-
response = test_runner(RenderHandler).run
|
337
|
+
response = test_runner(RenderHandler, 'template_name' => 'test_template').run
|
332
338
|
assert_equal ['test_template', 'RenderHandler', {}], response.data
|
333
339
|
end
|
334
340
|
|
341
|
+
should "not render any template files with a disallowed template ext" do
|
342
|
+
assert_raises ArgumentError do
|
343
|
+
test_runner(RenderHandler, 'template_name' => 'test_disallowed_template').run
|
344
|
+
end
|
345
|
+
end
|
346
|
+
|
335
347
|
end
|
336
348
|
|
337
349
|
class RunHandlerTests < UnitTests
|
@@ -7,6 +7,16 @@ class Sanford::TemplateSource
|
|
7
7
|
|
8
8
|
class UnitTests < Assert::Context
|
9
9
|
desc "Sanford::TemplateSource"
|
10
|
+
subject{ Sanford::TemplateSource }
|
11
|
+
|
12
|
+
should "disallow certain engine extensions" do
|
13
|
+
exp = [ '.rb' ]
|
14
|
+
assert_equal exp, subject::DISALLOWED_ENGINE_EXTS
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
18
|
+
|
19
|
+
class InitTests < Assert::Context
|
10
20
|
setup do
|
11
21
|
@source_path = File.join(ROOT, 'test/support')
|
12
22
|
@source = Sanford::TemplateSource.new(@source_path)
|
@@ -22,7 +32,7 @@ class Sanford::TemplateSource
|
|
22
32
|
|
23
33
|
end
|
24
34
|
|
25
|
-
class EngineRegistrationTests <
|
35
|
+
class EngineRegistrationTests < InitTests
|
26
36
|
desc "when registering an engine"
|
27
37
|
setup do
|
28
38
|
@empty_engine = Class.new(Sanford::TemplateEngine) do
|
@@ -53,6 +63,14 @@ class Sanford::TemplateSource
|
|
53
63
|
assert_equal exp_opts, subject.engines['empty'].opts
|
54
64
|
end
|
55
65
|
|
66
|
+
should "complain if registering a disallowed temp" do
|
67
|
+
assert_kind_of Sanford::NullTemplateEngine, subject.engines['rb']
|
68
|
+
assert_raises DisallowedEngineExtError do
|
69
|
+
subject.engine 'rb', @empty_engine
|
70
|
+
end
|
71
|
+
assert_kind_of Sanford::NullTemplateEngine, subject.engines['rb']
|
72
|
+
end
|
73
|
+
|
56
74
|
end
|
57
75
|
|
58
76
|
class NullTemplateSourceTests < Assert::Context
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sanford
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 53
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 10
|
9
|
-
-
|
10
|
-
version: 0.10.
|
9
|
+
- 1
|
10
|
+
version: 0.10.1
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Collin Redding
|
@@ -144,6 +144,7 @@ files:
|
|
144
144
|
- test/support/services.rb
|
145
145
|
- test/support/simple_client.rb
|
146
146
|
- test/support/template.json
|
147
|
+
- test/support/test_disallowed_template.rb
|
147
148
|
- test/support/test_template.test
|
148
149
|
- test/system/request_handling_tests.rb
|
149
150
|
- test/unit/config_tests.rb
|
@@ -203,6 +204,7 @@ test_files:
|
|
203
204
|
- test/support/services.rb
|
204
205
|
- test/support/simple_client.rb
|
205
206
|
- test/support/template.json
|
207
|
+
- test/support/test_disallowed_template.rb
|
206
208
|
- test/support/test_template.test
|
207
209
|
- test/system/request_handling_tests.rb
|
208
210
|
- test/unit/config_tests.rb
|