Skip to content

Commit cdb2d46

Browse files
authored
Merge pull request #399 from owasp-noir/redesign-options
Refactor code to use YAML::Any for all options
2 parents a6641c1 + 0faacd7 commit cdb2d46

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

56 files changed

+248
-225
lines changed

docs/_advanced/configuration.md

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ layout: page
3131
base: ""
3232

3333
# Whether to use color in the output
34-
color: "yes"
34+
color: true
3535

3636
# The configuration file to use
3737
config_file: ""
@@ -40,7 +40,7 @@ config_file: ""
4040
concurrency: "100"
4141

4242
# Whether to enable debug mode
43-
debug: "no"
43+
debug: false
4444

4545
# Technologies to exclude
4646
exclude_techs: ""
@@ -49,10 +49,10 @@ exclude_techs: ""
4949
format: "plain"
5050

5151
# Whether to include the path in the output
52-
include_path: "no"
52+
include_path: false
5353

5454
# Whether to disable logging
55-
nolog: "no"
55+
nolog: false
5656

5757
# The output file to write to
5858
output: ""
@@ -64,10 +64,12 @@ send_es: ""
6464
send_proxy: ""
6565

6666
# Whether to send a request
67-
send_req: "no"
67+
send_req: false
6868

6969
# Whether to send headers with the request
70-
send_with_headers: ""
70+
send_with_headers:
71+
- "Authorization: ABCD1234"
72+
- "X-API-Key: ABCD1234"
7173

7274
# The value to set for pvalue
7375
set_pvalue: ""
@@ -79,13 +81,15 @@ techs: ""
7981
url: ""
8082

8183
# Whether to use filters
82-
use_filters: ""
84+
use_filters:
85+
- "/admin"
8386

8487
# Whether to use matchers
85-
use_matchers: ""
88+
use_matchers:
89+
- "/user"
8690

8791
# Whether to use all taggers
88-
all_taggers: "no"
92+
all_taggers: false
8993

9094
# The taggers to use
9195
use_taggers: ""

spec/functional_test/func_spec.cr

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ class FunctionalTester
1717
def initialize(@path, expected_count, expected_endpoints)
1818
config_init = ConfigInitializer.new
1919
noir_options = config_init.default_options
20-
noir_options["base"] = "./spec/functional_test/#{@path}"
21-
noir_options["nolog"] = "yes"
20+
noir_options["base"] = YAML::Any.new("./spec/functional_test/#{@path}")
21+
noir_options["nolog"] = YAML::Any.new(true)
2222

2323
if !expected_count.nil?
2424
@expected_count = expected_count
@@ -131,6 +131,6 @@ class FunctionalTester
131131
end
132132

133133
def set_url(url)
134-
@app.options["url"] = url
134+
@app.options["url"] = YAML::Any.new(url)
135135
end
136136
end

spec/functional_test/testers/file_based_spec.cr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,5 @@ tester = FunctionalTester.new("fixtures/file_based/", {
1515
:endpoints => extected_endpoints.size,
1616
}, extected_endpoints)
1717

18-
tester.app.options["url"] = "https://www.hahwul.com"
18+
tester.app.options["url"] = YAML::Any.new("https://www.hahwul.com")
1919
tester.test_all

spec/unit_test/models/analyzer_spec.cr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ require "../../../src/options.cr"
44
describe "Initialize Analyzer" do
55
config_init = ConfigInitializer.new
66
options = config_init.default_options
7-
options["base"] = "noir"
7+
options["base"] = YAML::Any.new("noir")
88
object = Analyzer.new(options)
99

1010
it "getter - url" do
@@ -24,7 +24,7 @@ end
2424
describe "Initialize FileAnalyzer" do
2525
config_init = ConfigInitializer.new
2626
options = config_init.default_options
27-
options["base"] = "noir"
27+
options["base"] = YAML::Any.new("noir")
2828
object = FileAnalyzer.new(options)
2929

3030
it "getter - url" do

spec/unit_test/models/deliver_spec.cr

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,36 +4,36 @@ require "../../../src/options.cr"
44
describe "Initialize" do
55
config_init = ConfigInitializer.new
66
options = config_init.default_options
7-
options["base"] = "noir"
8-
options["send_proxy"] = "http://localhost:8090"
9-
options["nolog"] = "yes"
7+
options["base"] = YAML::Any.new("noir")
8+
options["send_proxy"] = YAML::Any.new("http://localhost:8090")
9+
options["nolog"] = YAML::Any.new(true)
1010

1111
it "Deliver" do
1212
object = Deliver.new options
1313
object.proxy.should eq("http://localhost:8090")
1414
end
1515

1616
it "Deliver with headers" do
17-
options["send_with_headers"] = "X-API-Key: abcdssss"
17+
options["send_with_headers"] = YAML::Any.new([YAML::Any.new("X-API-Key: abcdssss")])
1818
object = Deliver.new options
1919
object.headers["X-API-Key"].should eq("abcdssss")
2020
end
2121

2222
it "Deliver with headers (bearer case)" do
23-
options["send_with_headers"] = "Authorization: Bearer gAAAAABl3qwaQqol243Np"
23+
options["send_with_headers"] = YAML::Any.new([YAML::Any.new("Authorization: Bearer gAAAAABl3qwaQqol243Np")])
2424
object = Deliver.new options
2525
object.headers["Authorization"].should eq("Bearer gAAAAABl3qwaQqol243Np")
2626
end
2727

2828
it "Deliver with matchers" do
29-
options["use_matchers"] = "/admin"
29+
options["use_matchers"] = YAML::Any.new([YAML::Any.new("/admin")])
3030
object = Deliver.new options
31-
object.matchers.should eq(["/admin"])
31+
object.matchers[0].to_s.should eq("/admin")
3232
end
3333

3434
it "Deliver with filters" do
35-
options["use_filters"] = "/admin"
35+
options["use_filters"] = YAML::Any.new([YAML::Any.new("/admin")])
3636
object = Deliver.new options
37-
object.filters.should eq(["/admin"])
37+
object.filters[0].to_s.should eq("/admin")
3838
end
3939
end

spec/unit_test/models/detector_spec.cr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ require "../../../src/config_initializer.cr"
44
describe "Initialize" do
55
config_init = ConfigInitializer.new
66
options = config_init.default_options
7-
options["base"] = "noir"
7+
options["base"] = YAML::Any.new("noir")
88
object = Detector.new(options)
99

1010
it "getter - name" do

spec/unit_test/models/noir_spec.cr

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ require "../../../src/models/endpoint.cr"
55
describe "Initialize" do
66
config_init = ConfigInitializer.new
77
options = config_init.default_options
8-
options["base"] = "noir"
8+
options["base"] = YAML::Any.new("noir")
99
runner = NoirRunner.new(options)
1010

1111
it "getter - options" do
@@ -17,9 +17,9 @@ end
1717
describe "Methods" do
1818
config_init = ConfigInitializer.new
1919
options = config_init.default_options
20-
options["base"] = "noir"
21-
options["url"] = "https://www.hahwul.com"
22-
options["nolog"] = "yes"
20+
options["base"] = YAML::Any.new("noir")
21+
options["url"] = YAML::Any.new("https://www.hahwul.com")
22+
options["nolog"] = YAML::Any.new(true)
2323
runner = NoirRunner.new(options)
2424

2525
runner.endpoints << Endpoint.new("/abcd", "GET")

spec/unit_test/models/output_builder_spec.cr

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ require "../../../src/options.cr"
44
describe "Initialize" do
55
config_init = ConfigInitializer.new
66
options = config_init.default_options
7-
options["base"] = "noir"
8-
options["format"] = "json"
9-
options["output"] = "output.json"
7+
options["base"] = YAML::Any.new("noir")
8+
options["format"] = YAML::Any.new("json")
9+
options["output"] = YAML::Any.new("output.json")
1010

1111
it "OutputBuilder" do
1212
object = OutputBuilder.new options
@@ -72,8 +72,8 @@ end
7272
describe OutputBuilderDiff do
7373
config_init = ConfigInitializer.new
7474
options = config_init.default_options
75-
options["base"] = "noir"
76-
options["format"] = "json"
75+
options["base"] = YAML::Any.new("noir")
76+
options["format"] = YAML::Any.new("json")
7777

7878
it "calculates the diff correctly" do
7979
old_endpoints = [Endpoint.new("GET", "/old")]

spec/unit_test/utils/utils_spec.cr

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,11 +54,11 @@ describe "get_symbol" do
5454
end
5555

5656
describe "str_to_bool" do
57-
it "yes" do
58-
str_to_bool("yes").should eq(true)
57+
it true do
58+
str_to_bool(true).should eq(true)
5959
end
60-
it "no" do
61-
str_to_bool("no").should eq(false)
60+
it false do
61+
str_to_bool(false).should eq(false)
6262
end
6363
it "any string" do
6464
str_to_bool("hahwul").should eq(false)

src/analyzer/analyzer.cr

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -3,36 +3,36 @@ require "./analyzers/file_analyzers/*"
33

44
def initialize_analyzers(logger : NoirLogger)
55
# Initializing analyzers
6-
analyzers = {} of String => Proc(Hash(String, String), Array(Endpoint))
6+
analyzers = {} of String => Proc(Hash(String, YAML::Any), Array(Endpoint))
77

88
# Mapping analyzers to their respective functions
9-
analyzers["c#-aspnet-mvc"] = ->analyzer_cs_aspnet_mvc(Hash(String, String))
10-
analyzers["crystal_kemal"] = ->analyzer_crystal_kemal(Hash(String, String))
11-
analyzers["crystal_lucky"] = ->analyzer_crystal_lucky(Hash(String, String))
12-
analyzers["elixir_phoenix"] = ->analyzer_elixir_phoenix(Hash(String, String))
13-
analyzers["go_beego"] = ->analyzer_go_beego(Hash(String, String))
14-
analyzers["go_echo"] = ->analyzer_go_echo(Hash(String, String))
15-
analyzers["go_fiber"] = ->analyzer_go_fiber(Hash(String, String))
16-
analyzers["go_gin"] = ->analyzer_go_gin(Hash(String, String))
17-
analyzers["har"] = ->analyzer_har(Hash(String, String))
18-
analyzers["java_armeria"] = ->analyzer_armeria(Hash(String, String))
19-
analyzers["java_jsp"] = ->analyzer_jsp(Hash(String, String))
20-
analyzers["java_spring"] = ->analyzer_java_spring(Hash(String, String))
21-
analyzers["js_express"] = ->analyzer_express(Hash(String, String))
22-
analyzers["js_restify"] = ->analyzer_restify(Hash(String, String))
23-
analyzers["kotlin_spring"] = ->analyzer_kotlin_spring(Hash(String, String))
24-
analyzers["oas2"] = ->analyzer_oas2(Hash(String, String))
25-
analyzers["oas3"] = ->analyzer_oas3(Hash(String, String))
26-
analyzers["php_pure"] = ->analyzer_php_pure(Hash(String, String))
27-
analyzers["python_django"] = ->analyzer_python_django(Hash(String, String))
28-
analyzers["python_fastapi"] = ->analyzer_python_fastapi(Hash(String, String))
29-
analyzers["python_flask"] = ->analyzer_python_flask(Hash(String, String))
30-
analyzers["raml"] = ->analyzer_raml(Hash(String, String))
31-
analyzers["ruby_hanami"] = ->analyzer_ruby_hanami(Hash(String, String))
32-
analyzers["ruby_rails"] = ->analyzer_ruby_rails(Hash(String, String))
33-
analyzers["ruby_sinatra"] = ->analyzer_ruby_sinatra(Hash(String, String))
34-
analyzers["rust_axum"] = ->analyzer_rust_axum(Hash(String, String))
35-
analyzers["rust_rocket"] = ->analyzer_rust_rocket(Hash(String, String))
9+
analyzers["c#-aspnet-mvc"] = ->analyzer_cs_aspnet_mvc(Hash(String, YAML::Any))
10+
analyzers["crystal_kemal"] = ->analyzer_crystal_kemal(Hash(String, YAML::Any))
11+
analyzers["crystal_lucky"] = ->analyzer_crystal_lucky(Hash(String, YAML::Any))
12+
analyzers["elixir_phoenix"] = ->analyzer_elixir_phoenix(Hash(String, YAML::Any))
13+
analyzers["go_beego"] = ->analyzer_go_beego(Hash(String, YAML::Any))
14+
analyzers["go_echo"] = ->analyzer_go_echo(Hash(String, YAML::Any))
15+
analyzers["go_fiber"] = ->analyzer_go_fiber(Hash(String, YAML::Any))
16+
analyzers["go_gin"] = ->analyzer_go_gin(Hash(String, YAML::Any))
17+
analyzers["har"] = ->analyzer_har(Hash(String, YAML::Any))
18+
analyzers["java_armeria"] = ->analyzer_armeria(Hash(String, YAML::Any))
19+
analyzers["java_jsp"] = ->analyzer_jsp(Hash(String, YAML::Any))
20+
analyzers["java_spring"] = ->analyzer_java_spring(Hash(String, YAML::Any))
21+
analyzers["js_express"] = ->analyzer_express(Hash(String, YAML::Any))
22+
analyzers["js_restify"] = ->analyzer_restify(Hash(String, YAML::Any))
23+
analyzers["kotlin_spring"] = ->analyzer_kotlin_spring(Hash(String, YAML::Any))
24+
analyzers["oas2"] = ->analyzer_oas2(Hash(String, YAML::Any))
25+
analyzers["oas3"] = ->analyzer_oas3(Hash(String, YAML::Any))
26+
analyzers["php_pure"] = ->analyzer_php_pure(Hash(String, YAML::Any))
27+
analyzers["python_django"] = ->analyzer_python_django(Hash(String, YAML::Any))
28+
analyzers["python_fastapi"] = ->analyzer_python_fastapi(Hash(String, YAML::Any))
29+
analyzers["python_flask"] = ->analyzer_python_flask(Hash(String, YAML::Any))
30+
analyzers["raml"] = ->analyzer_raml(Hash(String, YAML::Any))
31+
analyzers["ruby_hanami"] = ->analyzer_ruby_hanami(Hash(String, YAML::Any))
32+
analyzers["ruby_rails"] = ->analyzer_ruby_rails(Hash(String, YAML::Any))
33+
analyzers["ruby_sinatra"] = ->analyzer_ruby_sinatra(Hash(String, YAML::Any))
34+
analyzers["rust_axum"] = ->analyzer_rust_axum(Hash(String, YAML::Any))
35+
analyzers["rust_rocket"] = ->analyzer_rust_rocket(Hash(String, YAML::Any))
3636

3737
logger.success "#{analyzers.size} Analyzers initialized"
3838
logger.debug "Analyzers:"
@@ -42,7 +42,7 @@ def initialize_analyzers(logger : NoirLogger)
4242
analyzers
4343
end
4444

45-
def analysis_endpoints(options : Hash(String, String), techs, logger : NoirLogger)
45+
def analysis_endpoints(options : Hash(String, YAML::Any), techs, logger : NoirLogger)
4646
result = [] of Endpoint
4747
file_analyzer = FileAnalyzer.new options
4848
logger.info "Initializing analyzers"
@@ -57,7 +57,7 @@ def analysis_endpoints(options : Hash(String, String), techs, logger : NoirLogge
5757

5858
techs.each do |tech|
5959
if analyzer.has_key?(tech)
60-
if NoirTechs.similar_to_tech(options["exclude_techs"]).includes?(tech)
60+
if NoirTechs.similar_to_tech(options["exclude_techs"].to_s).includes?(tech)
6161
logger.sub "➔ Skipping #{tech} analysis"
6262
next
6363
end

src/analyzer/analyzers/analyzer_armeria.cr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ class AnalyzerArmeria < Analyzer
6363
end
6464
end
6565

66-
def analyzer_armeria(options : Hash(String, String))
66+
def analyzer_armeria(options : Hash(String, YAML::Any))
6767
instance = AnalyzerArmeria.new(options)
6868
instance.analyze
6969
end

src/analyzer/analyzers/analyzer_crystal_kemal.cr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ class AnalyzerCrystalKemal < Analyzer
170170
end
171171
end
172172

173-
def analyzer_crystal_kemal(options : Hash(String, String))
173+
def analyzer_crystal_kemal(options : Hash(String, YAML::Any))
174174
instance = AnalyzerCrystalKemal.new(options)
175175
instance.analyze
176176
end

src/analyzer/analyzers/analyzer_crystal_lucky.cr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ class AnalyzerCrystalLucky < Analyzer
135135
end
136136
end
137137

138-
def analyzer_crystal_lucky(options : Hash(String, String))
138+
def analyzer_crystal_lucky(options : Hash(String, YAML::Any))
139139
instance = AnalyzerCrystalLucky.new(options)
140140
instance.analyze
141141
end

src/analyzer/analyzers/analyzer_cs_aspnet_mvc.cr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ class AnalyzerCsAspNetMvc < Analyzer
4545
end
4646
end
4747

48-
def analyzer_cs_aspnet_mvc(options : Hash(String, String))
48+
def analyzer_cs_aspnet_mvc(options : Hash(String, YAML::Any))
4949
instance = AnalyzerCsAspNetMvc.new(options)
5050
instance.analyze
5151
end

src/analyzer/analyzers/analyzer_elixir_phoenix.cr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ class AnalyzerElixirPhoenix < Analyzer
6161
end
6262
end
6363

64-
def analyzer_elixir_phoenix(options : Hash(String, String))
64+
def analyzer_elixir_phoenix(options : Hash(String, YAML::Any))
6565
instance = AnalyzerElixirPhoenix.new(options)
6666
instance.analyze
6767
end

src/analyzer/analyzers/analyzer_example.cr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ class AnalyzerExample < Analyzer
2626
end
2727
end
2828

29-
def analyzer_example(options : Hash(String, String))
29+
def analyzer_example(options : Hash(String, YAML::Any))
3030
instance = AnalyzerExample.new(options)
3131
instance.analyze
3232
end

src/analyzer/analyzers/analyzer_express.cr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ class AnalyzerExpress < Analyzer
105105
end
106106
end
107107

108-
def analyzer_express(options : Hash(String, String))
108+
def analyzer_express(options : Hash(String, YAML::Any))
109109
instance = AnalyzerExpress.new(options)
110110
instance.analyze
111111
end

src/analyzer/analyzers/analyzer_go_beego.cr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ class AnalyzerGoBeego < Analyzer
144144
end
145145
end
146146

147-
def analyzer_go_beego(options : Hash(String, String))
147+
def analyzer_go_beego(options : Hash(String, YAML::Any))
148148
instance = AnalyzerGoBeego.new(options)
149149
instance.analyze
150150
end

src/analyzer/analyzers/analyzer_go_echo.cr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ class AnalyzerGoEcho < Analyzer
186186
end
187187
end
188188

189-
def analyzer_go_echo(options : Hash(String, String))
189+
def analyzer_go_echo(options : Hash(String, YAML::Any))
190190
instance = AnalyzerGoEcho.new(options)
191191
instance.analyze
192192
end

src/analyzer/analyzers/analyzer_go_fiber.cr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ class AnalyzerGoFiber < Analyzer
197197
end
198198
end
199199

200-
def analyzer_go_fiber(options : Hash(String, String))
200+
def analyzer_go_fiber(options : Hash(String, YAML::Any))
201201
instance = AnalyzerGoFiber.new(options)
202202
instance.analyze
203203
end

0 commit comments

Comments
 (0)