diff --git a/spec/functional_test/fixtures/crystal_kemal/custom_public/2.html b/spec/functional_test/fixtures/crystal_kemal/custom_public/2.html new file mode 100644 index 00000000..e69de29b diff --git a/spec/functional_test/fixtures/crystal_kemal/public/1.html b/spec/functional_test/fixtures/crystal_kemal/public/1.html new file mode 100644 index 00000000..e69de29b diff --git a/spec/functional_test/fixtures/crystal_kemal/src/testapp.cr b/spec/functional_test/fixtures/crystal_kemal/src/testapp.cr index 787f08ac..05829a28 100644 --- a/spec/functional_test/fixtures/crystal_kemal/src/testapp.cr +++ b/spec/functional_test/fixtures/crystal_kemal/src/testapp.cr @@ -14,4 +14,6 @@ ws "/socket" do |socket| socket.send "Hello from Kemal!" end +public_folder "custom_public" + Kemal.run diff --git a/spec/functional_test/testers/crystal_kemal_spec.cr b/spec/functional_test/testers/crystal_kemal_spec.cr index 5359e6fe..08ebe642 100644 --- a/spec/functional_test/testers/crystal_kemal_spec.cr +++ b/spec/functional_test/testers/crystal_kemal_spec.cr @@ -7,9 +7,11 @@ extected_endpoints = [ Param.new("query", "", "form"), Param.new("my_auth", "", "cookie"), ]), + Endpoint.new("/1.html", "GET"), + Endpoint.new("/2.html", "GET"), ] FunctionalTester.new("fixtures/crystal_kemal/", { :techs => 1, - :endpoints => 3, + :endpoints => 5, }, extected_endpoints).test_all diff --git a/src/analyzer/analyzers/analyzer_crystal_kemal.cr b/src/analyzer/analyzers/analyzer_crystal_kemal.cr index 7914606f..f93a390a 100644 --- a/src/analyzer/analyzers/analyzer_crystal_kemal.cr +++ b/src/analyzer/analyzers/analyzer_crystal_kemal.cr @@ -2,6 +2,10 @@ require "../../models/analyzer" class AnalyzerCrystalKemal < Analyzer def analyze + # Variables + is_public = true + public_folders = [] of String + # Source Analysis begin Dir.glob("#{@base_path}/**/*") do |path| @@ -24,6 +28,25 @@ class AnalyzerCrystalKemal < Analyzer last_endpoint.push_param(param) end end + + if line.includes? "serve_static false" || "serve_static(false)" + is_public = false + end + + if line.includes? "public_folder" + begin + splited = line.split("public_folder") + public_folder = "" + + if splited.size > 1 + public_folder = splited[1].gsub("(", "").gsub(")", "").gsub(" ", "").gsub("\"", "").gsub("'", "") + if public_folder != "" + public_folders << public_folder + end + end + rescue + end + end end end end @@ -32,6 +55,29 @@ class AnalyzerCrystalKemal < Analyzer logger.debug e end + # Public Dir Analysis + if is_public + begin + Dir.glob("#{@base_path}/public/**/*") do |file| + next if File.directory?(file) + real_path = "#{@base_path}/public/".gsub(/\/+/, '/') + relative_path = file.sub(real_path, "") + @result << Endpoint.new("/#{relative_path}", "GET") + end + + public_folders.each do |folder| + Dir.glob("#{@base_path}/#{folder}/**/*") do |file| + next if File.directory?(file) + relative_path = get_relative_path(@base_path, file) + relative_path = get_relative_path(folder, relative_path) + @result << Endpoint.new("/#{relative_path}", "GET") + end + end + rescue e + logger.debug e + end + end + result end