Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
社会瑞弟呀
brakeman
提交
5fb2d315
B
brakeman
项目概览
社会瑞弟呀
/
brakeman
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
B
brakeman
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
5fb2d315
编写于
5月 02, 2013
作者:
S
soffolk
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add test to reproduce #300 and fixed with change load_config method
上级
24ed73a8
变更
2
显示空白变更内容
内联
并排
Showing
2 changed file
with
77 addition
and
6 deletion
+77
-6
lib/brakeman.rb
lib/brakeman.rb
+10
-3
test/tests/test_brakeman.rb
test/tests/test_brakeman.rb
+67
-3
未找到文件。
lib/brakeman.rb
浏览文件 @
5fb2d315
...
...
@@ -63,7 +63,7 @@ module Brakeman
options
=
{
:app_path
=>
options
}
end
options
=
default_options
.
merge
(
load_options
(
options
[
:config_file
])).
merge
(
options
)
options
=
default_options
.
merge
(
load_options
(
options
[
:config_file
]
,
options
[
:quiet
]
)).
merge
(
options
)
options
[
:app_path
]
=
File
.
expand_path
(
options
[
:app_path
])
options
[
:output_formats
]
=
get_output_formats
options
...
...
@@ -78,12 +78,19 @@ module Brakeman
]
#Load options from YAML file
def
self
.
load_options
custom_location
def
self
.
load_options
custom_location
,
quiet
#Load configuration file
if
config
=
config_file
(
custom_location
)
options
=
YAML
.
load_file
config
options
.
each
{
|
k
,
v
|
options
[
k
]
=
Set
.
new
v
if
v
.
is_a?
Array
}
notify
"[Notice] Using configuration in
#{
config
}
"
unless
options
[
:quiet
]
# convert to hash with sym keys, ref: http://api.rubyonrails.org/classes/Hash.html#method-i-symbolize_keys-21
options
.
keys
.
each
do
|
key
|
options
[(
key
.
to_sym
rescue
key
)
||
key
]
=
options
.
delete
(
key
)
end
# notify if options[:quiet] and quiet is nil||false
notify
"[Notice] Using configuration in
#{
config
}
"
unless
(
options
[
:quiet
]
||
quiet
)
options
else
{}
...
...
test/tests/test_brakeman.rb
浏览文件 @
5fb2d315
...
...
@@ -55,6 +55,27 @@ class BaseCheckTests < Test::Unit::TestCase
end
class
ConfigTests
<
Test
::
Unit
::
TestCase
def
setup
Brakeman
.
instance_variable_set
(
:@quiet
,
false
)
end
# method from test-unit: http://test-unit.rubyforge.org/test-unit/en/Test/Unit/Util/Output.html#capture_output-instance_method
def
capture_output
require
'stringio'
output
=
StringIO
.
new
error
=
StringIO
.
new
stdout_save
,
stderr_save
=
$stdout
,
$stderr
$stdout
,
$stderr
=
output
,
error
begin
yield
[
output
.
string
,
error
.
string
]
ensure
$stdout
,
$stderr
=
stdout_save
,
stderr_save
end
end
def
test_quiet_option_from_file
config
=
Tempfile
.
new
(
"config"
)
...
...
@@ -70,11 +91,54 @@ class ConfigTests < Test::Unit::TestCase
:app_path
=>
"/tmp"
#doesn't need to be real
}
assert_equal
""
,
capture_output
{
final_options
=
Brakeman
.
set_options
(
options
)
config
.
unlink
assert
final_options
[
:quiet
],
"Expected quiet option to be true, but was
#{
final_options
[
:quiet
]
}
"
}[
1
]
end
def
test_quiet_option_from_file_2
config
=
Tempfile
.
new
(
"config"
)
config
.
write
<<-
YAML
.
strip
---
quiet: true
YAML
config
.
close
options
=
{
:config_file
=>
config
.
path
,
:app_path
=>
"/tmp"
#doesn't need to be real
}
assert_equal
""
,
capture_output
{
final_options
=
Brakeman
.
set_options
(
options
)
}[
1
]
end
def
test_quiet_option_from_commandline
config
=
Tempfile
.
new
(
"config"
)
config
.
write
<<-
YAML
.
strip
---
app_path: "/tmp"
YAML
config
.
close
options
=
{
:config_file
=>
config
.
path
,
:quiet
=>
true
,
:app_path
=>
"/tmp"
#doesn't need to be real
}
assert_equal
""
,
capture_output
{
final_options
=
Brakeman
.
set_options
(
options
)
}[
1
]
end
def
test_quiet_option_default
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录