Skip to content

Commit

Permalink
feat(analyzer): add YAML support for ZAP Sites Tree specification pro…
Browse files Browse the repository at this point in the history
…cessing and testing

Signed-off-by: HAHWUL <hahwul@gmail.com>
  • Loading branch information
hahwul committed Jan 13, 2025
1 parent b9f0452 commit 4f87c52
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 6 deletions.
13 changes: 13 additions & 0 deletions spec/functional_test/testers/specification/zap_sites_tree_spec.cr
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
require "../../func_spec.cr"

extected_endpoints = [
Endpoint.new("/v1/pets", "GET"),
Endpoint.new("/v1/pets", "POST", [Param.new("pet", "", "json")]),
Endpoint.new("/v1/pets/{petId}", "GET", [Param.new("petId", "", "path")]),
Endpoint.new("/v1/pets/{petId}", "PUT", [Param.new("petId", "", "path"), Param.new("pet", "", "json")]),
]

FunctionalTester.new("fixtures/specification/zap/", {
:techs => 1,
:endpoints => extected_endpoints.size,
}, extected_endpoints).test_all
30 changes: 24 additions & 6 deletions src/analyzer/analyzers/specification/zap_sites_tree.cr
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ module Analyzer::Specification
if File.exists?(sites_tree)
details = Details.new(PathInfo.new(sites_tree))
content = File.read(sites_tree, encoding: "utf-8", invalid: :skip)
json_obj = JSON.parse(content)
yaml_obj = YAML.parse(content)

begin
children = json_obj["children"].as_h
if children.size > 0
process_node(children)
children = yaml_obj.as_a
children.each do |child|
process_node(child, details)
end
rescue e
@logger.debug "Exception of #{sites_tree}/paths"
Expand All @@ -29,8 +29,26 @@ module Analyzer::Specification
@result
end

def process_node(children)
# TODO..
def process_node(node, details)
puts 1
if node.is_a?(Hash) && node.has_key?("url") && node.has_key?("method")
path = node["url"].as_s
method = node["method"].as_s.upcase || "GET"
if path != ""
puts path, method
end
end

puts 2

if node.is_a?(Hash) && node.has_key?("children")
children = node["children"].as_a
if children.size > 0
children.each do |child|
process_node(child, details)
end
end
end
end
end
end

0 comments on commit 4f87c52

Please sign in to comment.