Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
李少辉-开发者
Brakeman
提交
4c44bd76
B
Brakeman
项目概览
李少辉-开发者
/
Brakeman
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
B
Brakeman
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
4c44bd76
编写于
8月 16, 2015
作者:
J
Justin
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #700 from presidentbeef/remove_global_scans_in_tests
Remove remaining global scans in tests
上级
d4cf4c2b
ce7099a6
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
39 addition
and
35 deletion
+39
-35
test/tests/differ.rb
test/tests/differ.rb
+2
-3
test/tests/json_output.rb
test/tests/json_output.rb
+7
-8
test/tests/markdown_output.rb
test/tests/markdown_output.rb
+9
-7
test/tests/report_generation.rb
test/tests/report_generation.rb
+12
-10
test/tests/tabs_output.rb
test/tests/tabs_output.rb
+9
-7
未找到文件。
test/tests/differ.rb
浏览文件 @
4c44bd76
require
'brakeman/differ'
DiffRun
=
Brakeman
.
run
:app_path
=>
"
#{
TEST_PATH
}
/apps/rails2"
class
DifferTests
<
Test
::
Unit
::
TestCase
include
BrakemanTester
::
DiffHelper
def
setup
@warnings
=
DiffRun
.
warnings
@@diffrun
||=
Brakeman
.
run
:app_path
=>
"
#{
TEST_PATH
}
/apps/rails2"
@warnings
||=
@@diffrun
.
warnings
end
def
diff
new
,
old
...
...
test/tests/json_output.rb
浏览文件 @
4c44bd76
JSON_REPORT
=
MultiJson
.
load
(
Brakeman
.
run
(
"
#{
TEST_PATH
}
/apps/rails3.2"
).
report
.
to_json
)
class
JSONOutputTests
<
Test
::
Unit
::
TestCase
def
setup
@
json
=
JSON_REPORT
@
@json
||=
MultiJson
.
load
(
Brakeman
.
run
(
"
#{
TEST_PATH
}
/apps/rails3.2"
).
report
.
to_json
)
end
def
test_for_render_path
@json
[
"warnings"
].
each
do
|
warning
|
@
@
json
[
"warnings"
].
each
do
|
warning
|
is_right_thing
=
warning
.
keys
.
include?
(
"render_path"
)
&&
(
warning
[
"render_path"
].
nil?
or
warning
[
"render_path"
].
is_a?
Array
)
assert
is_right_thing
,
"
#{
warning
[
"render_path"
].
class
}
is not right"
end
end
def
test_for_expected_keys
assert
(
@json
.
keys
-
[
"warnings"
,
"ignored_warnings"
,
"scan_info"
,
"errors"
]).
empty?
assert
(
@
@
json
.
keys
-
[
"warnings"
,
"ignored_warnings"
,
"scan_info"
,
"errors"
]).
empty?
end
def
test_for_scan_info_keys
...
...
@@ -21,23 +20,23 @@ class JSONOutputTests < Test::Unit::TestCase
"checks_performed"
,
"number_of_controllers"
,
"number_of_models"
,
"number_of_templates"
,
"ruby_version"
,
"brakeman_version"
]
assert
(
@json
[
"scan_info"
].
keys
-
info_keys
).
empty?
assert
(
@
@
json
[
"scan_info"
].
keys
-
info_keys
).
empty?
end
def
test_for_expected_warning_keys
expected
=
[
"warning_type"
,
"message"
,
"file"
,
"link"
,
"code"
,
"location"
,
"render_path"
,
"user_input"
,
"confidence"
,
"line"
,
"warning_code"
,
"fingerprint"
]
@json
[
"warnings"
].
each
do
|
warning
|
@
@
json
[
"warnings"
].
each
do
|
warning
|
assert
(
warning
.
keys
-
expected
).
empty?
,
"
#{
(
warning
.
keys
-
expected
).
inspect
}
did not match expected keys"
end
end
def
test_for_errors
assert
@json
[
"errors"
].
is_a?
Array
assert
@
@
json
[
"errors"
].
is_a?
Array
end
def
test_paths
assert
@json
[
"warnings"
].
all?
{
|
w
|
not
w
[
"file"
].
start_with?
"/"
}
assert
@
@
json
[
"warnings"
].
all?
{
|
w
|
not
w
[
"file"
].
start_with?
"/"
}
end
end
test/tests/markdown_output.rb
浏览文件 @
4c44bd76
class
TestMarkdownOutput
<
Test
::
Unit
::
TestCase
Report
=
Brakeman
.
run
(
:app_path
=>
"
#{
TEST_PATH
}
/apps/rails2"
,
:quiet
=>
true
,
:run_all_checks
=>
true
).
report
.
to_markdown
def
setup
@@report
||=
Brakeman
.
run
(
:app_path
=>
"
#{
TEST_PATH
}
/apps/rails2"
,
:quiet
=>
true
,
:run_all_checks
=>
true
).
report
.
to_markdown
end
def
test_reported_warnings
if
Brakeman
::
Scanner
::
RUBY_1_9
assert_equal
172
,
R
eport
.
lines
.
to_a
.
count
assert_equal
172
,
@@r
eport
.
lines
.
to_a
.
count
else
assert_equal
173
,
R
eport
.
lines
.
to_a
.
count
assert_equal
173
,
@@r
eport
.
lines
.
to_a
.
count
end
end
end
test/tests/report_generation.rb
浏览文件 @
4c44bd76
class
TestReportGeneration
<
Test
::
Unit
::
TestCase
Report
=
Brakeman
.
run
(
:app_path
=>
"
#{
TEST_PATH
}
/apps/rails3.2"
,
:quiet
=>
true
,
:report_routes
=>
true
).
report
def
setup
@@report
||=
Brakeman
.
run
(
:app_path
=>
"
#{
TEST_PATH
}
/apps/rails3.2"
,
:quiet
=>
true
,
:report_routes
=>
true
).
report
end
def
test_html_sanity
report
=
R
eport
.
to_html
report
=
@@r
eport
.
to_html
assert
report
.
is_a?
String
assert
report
.
match
(
/\A<!DOCTYPE HTML SYSTEM>.*<\/html>\z/m
)
...
...
@@ -12,7 +14,7 @@ class TestReportGeneration < Test::Unit::TestCase
end
def
test_json_sanity
report
=
R
eport
.
to_json
report
=
@@r
eport
.
to_json
expected_keys
=
[
"scan_info"
,
"warnings"
,
"errors"
]
assert
report
.
is_a?
String
...
...
@@ -23,7 +25,7 @@ class TestReportGeneration < Test::Unit::TestCase
end
def
test_csv_sanity
report
=
R
eport
.
to_csv
report
=
@@r
eport
.
to_csv
parsed
=
CSV
.
parse
report
summary_header
=
[
"Application Path"
,
"Report Generation Time"
,
"Checks Performed"
,
"Rails Version"
]
...
...
@@ -39,35 +41,35 @@ class TestReportGeneration < Test::Unit::TestCase
end
def
test_tabs_sanity
report
=
R
eport
.
to_tabs
report
=
@@r
eport
.
to_tabs
assert
report
.
is_a?
String
end
def
test_text_sanity
report
=
R
eport
.
to_s
report
=
@@r
eport
.
to_s
assert
report
.
is_a?
String
end
def
test_markdown_sanity
report
=
R
eport
.
to_markdown
report
=
@@r
eport
.
to_markdown
assert
report
.
is_a?
String
end
def
test_bad_format_type
assert_raises
RuntimeError
do
R
eport
.
format
(
:to_something_else
)
@@r
eport
.
format
(
:to_something_else
)
end
end
def
test_controller_output
text_report
=
R
eport
.
to_s
text_report
=
@@r
eport
.
to_s
assert
text_report
.
include?
"+CONTROLLERS+"
html_report
=
R
eport
.
to_html
html_report
=
@@r
eport
.
to_html
assert
html_report
.
include?
"<h2>Controllers</h2>"
end
...
...
test/tests/tabs_output.rb
浏览文件 @
4c44bd76
class
TestTabsOutput
<
Test
::
Unit
::
TestCase
Report
=
Brakeman
.
run
(
:app_path
=>
"
#{
TEST_PATH
}
/apps/rails2"
,
:quiet
=>
true
,
:run_all_checks
=>
true
).
report
.
to_tabs
def
setup
@@report
||=
Brakeman
.
run
(
:app_path
=>
"
#{
TEST_PATH
}
/apps/rails2"
,
:quiet
=>
true
,
:run_all_checks
=>
true
).
report
.
to_tabs
end
def
test_reported_warnings
if
Brakeman
::
Scanner
::
RUBY_1_9
assert_equal
110
,
R
eport
.
lines
.
to_a
.
count
assert_equal
110
,
@@r
eport
.
lines
.
to_a
.
count
else
assert_equal
111
,
R
eport
.
lines
.
to_a
.
count
assert_equal
111
,
@@r
eport
.
lines
.
to_a
.
count
end
end
end
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录