Skip to content

Commit

Permalink
Merge pull request #515 from owasp-noir/issue-511-add-cache-scope
Browse files Browse the repository at this point in the history
Add cache scope to Docker actions and fix #508
  • Loading branch information
ksg97031 authored Jan 24, 2025
2 parents 37b7531 + 302e403 commit 83b700f
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 8 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ jobs:
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
platforms: ${{ matrix.arch }}
cache-from: type=gha
cache-to: type=gha,mode=max
cache-from: type=gha,scope=${{ matrix.arch }}
cache-to: type=gha,mode=max,scope=${{ matrix.arch }}
lint:
runs-on: ubuntu-latest
container:
Expand Down
42 changes: 42 additions & 0 deletions spec/functional_test/fixtures/java/spring/src/ItemController2.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package com.test;
import org.springframework.web.bind.annotation.*;
import a.b.c.bind.annotation.*;
import org.springframework.c.d.e.*;

@RestController
@RequestMapping("items2")
public class ItemController {

@GetMapping("{id}")
public Item getItem(@PathVariable Long id) throws ItemNotFoundException {
}

@PostMapping("/create")
public Item createItem(@RequestBody Item item) {
}

@PutMapping("edit/")
public Item editItem(@RequestBody Item item) {
}
}

class Item {
int id;
String name;

public void setId(int _id) {
id = _id;
}

public int getId() {
return id;
}

public void setName(String _name) {
name = _name;
}

public String getName() {
return name;
}
}
8 changes: 6 additions & 2 deletions spec/functional_test/testers/java/spring_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ extected_endpoints = [
# ItemController.java
Endpoint.new("/items/{id}", "GET", [Param.new("id", "", "path")]),
Endpoint.new("/items/json/{id}", "GET", [Param.new("id", "", "path")]),
Endpoint.new("/items", "POST", [Param.new("id", "", "form"), Param.new("name", "", "form")]),
Endpoint.new("/items/", "POST", [Param.new("id", "", "form"), Param.new("name", "", "form")]),
Endpoint.new("/items/update/{id}", "PUT", [Param.new("id", "", "path"), Param.new("id", "", "json"), Param.new("name", "", "json")]),
Endpoint.new("/items/delete/{id}", "DELETE", [Param.new("id", "", "path")]),
Endpoint.new("/items/requestmap/put", "PUT"),
Expand All @@ -34,8 +34,12 @@ extected_endpoints = [
Param.new("b", "", "query"),
Param.new("name", "", "query"),
]),
# ItemController2.java
Endpoint.new("/items2/{id}", "GET", [Param.new("id", "", "path")]),
Endpoint.new("/items2/create", "POST", [Param.new("id", "", "form"), Param.new("name", "", "form")]),
Endpoint.new("/items2/edit/", "PUT", [Param.new("id", "", "json"), Param.new("name", "", "json")]),
# EmptyController.java
Endpoint.new("/empty", "GET"),
Endpoint.new("/empty/", "GET"),
]

FunctionalTester.new("fixtures/java/spring/", {
Expand Down
4 changes: 4 additions & 0 deletions src/analyzer/analyzer.cr
Original file line number Diff line number Diff line change
Expand Up @@ -83,3 +83,7 @@ def analysis_endpoints(options : Hash(String, YAML::Any), techs, logger : NoirLo
logger.info "Found #{result.size} endpoints"
result
end

def join_paths(*paths : String) : String
File.join(paths)
end
8 changes: 4 additions & 4 deletions src/analyzer/analyzers/java/spring.cr
Original file line number Diff line number Diff line change
Expand Up @@ -211,15 +211,15 @@ module Analyzer::Java
["GET", "POST", "PUT", "DELETE", "PATCH"].each do |_request_method|
parameters = get_endpoint_parameters(parser, _request_method, method, parameter_format, class_map)
url_paths.each do |url_path|
@result << Endpoint.new("#{webflux_base_path}#{url}#{url_path}", _request_method, parameters, details)
@result << Endpoint.new(join_paths(webflux_base_path, url, url_path), _request_method, parameters, details)
end
end
else
# Create endpoints for annotated HTTP methods
url_paths.each do |url_path|
request_methods.each do |request_method|
parameters = get_endpoint_parameters(parser, request_method, method, parameter_format, class_map)
@result << Endpoint.new("#{webflux_base_path}#{url}#{url_path}", request_method, parameters, details)
@result << Endpoint.new(join_paths(webflux_base_path, url, url_path), request_method, parameters, details)
end
end
end
Expand All @@ -243,7 +243,7 @@ module Analyzer::Java

details = Details.new(PathInfo.new(path, line))
url_paths.each do |url_path|
@result << Endpoint.new("#{webflux_base_path}#{url}#{url_path}", request_method, parameters, details)
@result << Endpoint.new(join_paths(webflux_base_path, url, url_path), request_method, parameters, details)
end
break
end
Expand All @@ -261,7 +261,7 @@ module Analyzer::Java
method = match[2]
endpoint = match[3].gsub(/\n/, "")
details = Details.new(PathInfo.new(path))
@result << Endpoint.new("#{url}#{endpoint}", method, details)
@result << Endpoint.new(join_paths(url, endpoint), method, details)
end
end
end
Expand Down

0 comments on commit 83b700f

Please sign in to comment.