Skip to content

Commit

Permalink
(#58) Improve PHP Analyzer (+add header)
Browse files Browse the repository at this point in the history
  • Loading branch information
hahwul committed Aug 30, 2023
1 parent 6924d38 commit 5cb8863
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 3 deletions.
3 changes: 3 additions & 0 deletions spec/functional_test/fixtures/php_pure/get.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<?
$param1 = $_GET['param1'];
?>
4 changes: 4 additions & 0 deletions spec/functional_test/fixtures/php_pure/header.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?
$param1 = $_GET['param1'];
$api_key = $_SERVER['HTTP_X_API_KEY'];
?>
3 changes: 3 additions & 0 deletions spec/functional_test/fixtures/php_pure/post.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<?
$param1 = $_POST['param1'];
?>
3 changes: 3 additions & 0 deletions spec/functional_test/fixtures/php_pure/request.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<?
$param1 = $_REQUEST['param1'];
?>
15 changes: 15 additions & 0 deletions spec/functional_test/testers/php_pure_spec.cr
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
require "../func_spec.cr"

extected_endpoints = [
Endpoint.new("/get.php", "GET"),
Endpoint.new("/header.php", "GET", [Param.new("X-API-KEY", "", "header")]),
Endpoint.new("/post.php", "GET"),
Endpoint.new("/post.php", "POST", [Param.new("param1", "", "body")]),
Endpoint.new("/request.php", "GET", [Param.new("param1", "", "query")]),
Endpoint.new("/request.php", "POST", [Param.new("param1", "", "body")]),
]

FunctionalTester.new("fixtures/php_pure/", {
:techs => 1,
:endpoints => 6,
}, extected_endpoints).test_all
25 changes: 22 additions & 3 deletions src/analyzer/analyzers/analyzer_php_pure.cr
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,23 @@ class AnalyzerPhpPure < Analyzer
method = match[1]
param_name = match[2]

methods = methods | [method]
params_query << Param.new(param_name, "string", "query")
params_body << Param.new(param_name, "string", "form")

if method == "GET"
params_query << Param.new(param_name, "", "query")
elsif method == "POST"
params_body << Param.new(param_name, "", "body")
methods << "POST"
elsif method == "REQUEST"
params_query << Param.new(param_name, "", "query")
params_body << Param.new(param_name, "", "body")
methods << "POST"
elsif method == "SERVER"
if param_name.includes? "HTTP_"
param_name = param_name.sub("HTTP_", "").gsub("_", "-")
params_query << Param.new(param_name, "", "header")
params_body << Param.new(param_name, "", "header")
end
end
end
rescue
next
Expand All @@ -44,8 +58,13 @@ class AnalyzerPhpPure < Analyzer

result
end

def allow_methods
["GET", "POST", "PUT", "DELETE", "PATCH"]
end
end


def analyzer_php_pure(options : Hash(Symbol, String))
instance = AnalyzerPhpPure.new(options)
instance.analyze
Expand Down

0 comments on commit 5cb8863

Please sign in to comment.