Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
xxadev
jenkins
提交
3584e093
J
jenkins
项目概览
xxadev
/
jenkins
与 Fork 源项目一致
从无法访问的项目Fork
通知
3
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
J
jenkins
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
3584e093
编写于
9月 26, 2013
作者:
J
Jesse Glick
浏览文件
操作
浏览文件
下载
差异文件
Merge branch 'master' of github.com:jenkinsci/jenkins
上级
d82ba3b7
ca067fd2
变更
3
显示空白变更内容
内联
并排
Showing
3 changed file
with
77 addition
and
18 deletion
+77
-18
core/src/main/java/hudson/model/DirectoryBrowserSupport.java
core/src/main/java/hudson/model/DirectoryBrowserSupport.java
+1
-1
core/src/main/resources/lib/hudson/artifactList.jelly
core/src/main/resources/lib/hudson/artifactList.jelly
+2
-0
test/src/test/java/hudson/model/DirectoryBrowserSupportTest.java
...c/test/java/hudson/model/DirectoryBrowserSupportTest.java
+74
-17
未找到文件。
core/src/main/java/hudson/model/DirectoryBrowserSupport.java
浏览文件 @
3584e093
...
...
@@ -345,7 +345,7 @@ public final class DirectoryBrowserSupport implements HttpResponse {
VirtualFile
f
=
dir
.
child
(
n
);
e
.
setTime
(
f
.
lastModified
());
zos
.
putNextEntry
(
e
);
Util
.
copyStream
(
f
.
open
(),
outputStream
);
Util
.
copyStream
(
f
.
open
(),
zos
);
zos
.
closeEntry
();
}
zos
.
close
();
...
...
core/src/main/resources/lib/hudson/artifactList.jelly
浏览文件 @
3584e093
...
...
@@ -63,6 +63,8 @@ THE SOFTWARE.
<a href="${baseURL}artifact/${f.href}/*fingerprint*/">
<img src="${imagesURL}/16x16/fingerprint.png" alt="[fingerprint]" height="16" width="16"/>
</a>
<st:nbsp/>
<a href="${baseURL}artifact/${f.href}/*view*/">${%view}</a>
</td>
</tr>
</j:forEach>
...
...
test/src/test/java/hudson/model/DirectoryBrowserSupportTest.java
浏览文件 @
3584e093
...
...
@@ -23,28 +23,50 @@
*/
package
hudson.model
;
import
static
org
.
junit
.
Assert
.
assertEquals
;
import
static
org
.
junit
.
Assert
.
assertFalse
;
import
static
org
.
junit
.
Assert
.
assertTrue
;
import
hudson.FilePath
;
import
hudson.Functions
;
import
hudson.tasks.Shell
;
import
hudson.tasks.BatchFile
;
import
hudson.Launcher
;
import
hudson.Util
;
import
hudson.tasks.ArtifactArchiver
;
import
hudson.tasks.BatchFile
;
import
hudson.tasks.Shell
;
import
java.io.File
;
import
java.io.FileOutputStream
;
import
java.io.IOException
;
import
java.io.InputStream
;
import
java.util.zip.ZipFile
;
import
org.junit.Rule
;
import
org.junit.Test
;
import
org.jvnet.hudson.test.Bug
;
import
org.jvnet.hudson.test.Email
;
import
org.jvnet.hudson.test.HudsonTestCase
;
import
org.jvnet.hudson.test.JenkinsRule
;
import
org.jvnet.hudson.test.SingleFileSCM
;
import
org.jvnet.hudson.test.TestBuilder
;
import
java.io.IOException
;
import
com.gargoylesoftware.htmlunit.Page
;
import
com.gargoylesoftware.htmlunit.UnexpectedPage
;
import
com.gargoylesoftware.htmlunit.html.HtmlPage
;
/**
* @author Kohsuke Kawaguchi
*/
public
class
DirectoryBrowserSupportTest
extends
HudsonTestCase
{
public
class
DirectoryBrowserSupportTest
{
@Rule
public
JenkinsRule
j
=
new
JenkinsRule
();
/**
* Double dots that appear in file name is OK.
*/
@Email
(
"http://www.nabble.com/Status-Code-400-viewing-or-downloading-artifact-whose-filename-contains-two-consecutive-periods-tt21407604.html"
)
public
void
testDoubleDots
()
throws
Exception
{
@Test
public
void
doubleDots
()
throws
Exception
{
// create a problematic file name in the workspace
FreeStyleProject
p
=
createFreeStyleProject
();
FreeStyleProject
p
=
j
.
createFreeStyleProject
();
if
(
Functions
.
isWindows
())
p
.
getBuildersList
().
add
(
new
BatchFile
(
"echo > abc..def"
));
else
...
...
@@ -52,7 +74,7 @@ public class DirectoryBrowserSupportTest extends HudsonTestCase {
p
.
scheduleBuild2
(
0
).
get
();
// can we see it?
new
WebClient
().
goTo
(
"job/"
+
p
.
getName
()+
"/ws/abc..def"
,
"application/octet-stream"
);
j
.
create
WebClient
().
goTo
(
"job/"
+
p
.
getName
()+
"/ws/abc..def"
,
"application/octet-stream"
);
// TODO: implement negative check to make sure we aren't serving unexpected directories.
// the following trivial attempt failed. Someone in between is normalizing.
...
...
@@ -70,21 +92,23 @@ public class DirectoryBrowserSupportTest extends HudsonTestCase {
* To prevent directory traversal attack, we now treat '\\' just like '/'.
*/
@Email
(
"http://www.nabble.com/Status-Code-400-viewing-or-downloading-artifact-whose-filename-contains-two-consecutive-periods-tt21407604.html"
)
public
void
testDoubleDots2
()
throws
Exception
{
@Test
public
void
doubleDots2
()
throws
Exception
{
if
(
Functions
.
isWindows
())
return
;
// can't test this on Windows
// create a problematic file name in the workspace
FreeStyleProject
p
=
createFreeStyleProject
();
FreeStyleProject
p
=
j
.
createFreeStyleProject
();
p
.
getBuildersList
().
add
(
new
Shell
(
"mkdir abc; touch abc/def.bin"
));
p
.
scheduleBuild2
(
0
).
get
();
// can we see it?
new
WebClient
().
goTo
(
"job/"
+
p
.
getName
()+
"/ws/abc%5Cdef.bin"
,
"application/octet-stream"
);
j
.
create
WebClient
().
goTo
(
"job/"
+
p
.
getName
()+
"/ws/abc%5Cdef.bin"
,
"application/octet-stream"
);
}
public
void
testNonAsciiChar
()
throws
Exception
{
@Test
public
void
nonAsciiChar
()
throws
Exception
{
// create a problematic file name in the workspace
FreeStyleProject
p
=
createFreeStyleProject
();
FreeStyleProject
p
=
j
.
createFreeStyleProject
();
p
.
getBuildersList
().
add
(
new
TestBuilder
()
{
public
boolean
perform
(
AbstractBuild
<?,
?>
build
,
Launcher
launcher
,
BuildListener
listener
)
throws
InterruptedException
,
IOException
{
build
.
getWorkspace
().
child
(
"\u6F22\u5B57.bin"
).
touch
(
0
);
// Kanji
...
...
@@ -94,11 +118,12 @@ public class DirectoryBrowserSupportTest extends HudsonTestCase {
p
.
scheduleBuild2
(
0
).
get
();
// can we see it?
new
WebClient
().
goTo
(
"job/"
+
p
.
getName
()+
"/ws/%e6%bc%a2%e5%ad%97.bin"
,
"application/octet-stream"
);
j
.
create
WebClient
().
goTo
(
"job/"
+
p
.
getName
()+
"/ws/%e6%bc%a2%e5%ad%97.bin"
,
"application/octet-stream"
);
}
public
void
testGlob
()
throws
Exception
{
FreeStyleProject
p
=
createFreeStyleProject
();
@Test
public
void
glob
()
throws
Exception
{
FreeStyleProject
p
=
j
.
createFreeStyleProject
();
p
.
getBuildersList
().
add
(
new
TestBuilder
()
{
@Override
public
boolean
perform
(
AbstractBuild
<?,
?>
build
,
Launcher
launcher
,
BuildListener
listener
)
throws
InterruptedException
,
IOException
{
FilePath
ws
=
build
.
getWorkspace
();
...
...
@@ -113,11 +138,43 @@ public class DirectoryBrowserSupportTest extends HudsonTestCase {
}
});
assertEquals
(
Result
.
SUCCESS
,
p
.
scheduleBuild2
(
0
).
get
().
getResult
());
String
text
=
new
WebClient
().
goTo
(
"job/"
+
p
.
getName
()+
"/ws/**/*.java"
).
asText
();
String
text
=
j
.
create
WebClient
().
goTo
(
"job/"
+
p
.
getName
()+
"/ws/**/*.java"
).
asText
();
assertTrue
(
text
,
text
.
contains
(
"X.java"
));
assertTrue
(
text
,
text
.
contains
(
"XTest.java"
));
assertFalse
(
text
,
text
.
contains
(
"pom.xml"
));
assertFalse
(
text
,
text
.
contains
(
"x.txt"
));
}
@Bug
(
19752
)
@Test
public
void
zipDownload
()
throws
Exception
{
FreeStyleProject
p
=
j
.
createFreeStyleProject
();
p
.
setScm
(
new
SingleFileSCM
(
"artifact.out"
,
"Hello world!"
));
p
.
getPublishersList
().
add
(
new
ArtifactArchiver
(
"*"
,
""
,
true
));
assertEquals
(
Result
.
SUCCESS
,
p
.
scheduleBuild2
(
0
).
get
().
getResult
());
HtmlPage
page
=
j
.
createWebClient
().
goTo
(
"job/"
+
p
.
getName
()+
"/lastSuccessfulBuild/artifact/"
);
Page
download
=
page
.
getAnchorByHref
(
"./*zip*/archive.zip"
).
click
();
File
zipfile
=
download
((
UnexpectedPage
)
download
);
ZipFile
readzip
=
new
ZipFile
(
zipfile
);
InputStream
is
=
readzip
.
getInputStream
(
readzip
.
getEntry
(
"artifact.out"
));
// ZipException in case of JENKINS-19752
assertFalse
(
"Downloaded zip file must not be empty"
,
is
.
read
()
==
-
1
);
is
.
close
();
readzip
.
close
();
zipfile
.
delete
();
}
private
File
download
(
UnexpectedPage
page
)
throws
IOException
{
File
file
=
File
.
createTempFile
(
"DirectoryBrowserSupport"
,
"zipDownload"
);
file
.
delete
();
Util
.
copyStreamAndClose
(
page
.
getInputStream
(),
new
FileOutputStream
(
file
));
return
file
;
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录