Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
LinuxSuRen
jenkins
提交
fab0938e
J
jenkins
项目概览
LinuxSuRen
/
jenkins
与 Fork 源项目一致
从无法访问的项目Fork
通知
2
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,发现更多精彩内容 >>
提交
fab0938e
编写于
8月 05, 2016
作者:
K
Kohsuke Kawaguchi
提交者:
GitHub
8月 05, 2016
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #2496 from jenkinsci/JENKINS-37223
[FIXED JENKINS-37223]
上级
55203ebe
57846475
变更
2
显示空白变更内容
内联
并排
Showing
2 changed file
with
86 addition
and
3 deletion
+86
-3
core/src/main/java/hudson/TcpSlaveAgentListener.java
core/src/main/java/hudson/TcpSlaveAgentListener.java
+61
-1
test/src/test/java/hudson/TcpSlaveAgentListenerTest.java
test/src/test/java/hudson/TcpSlaveAgentListenerTest.java
+25
-2
未找到文件。
core/src/main/java/hudson/TcpSlaveAgentListener.java
浏览文件 @
fab0938e
...
...
@@ -23,6 +23,9 @@
*/
package
hudson
;
import
java.io.ByteArrayInputStream
;
import
java.io.SequenceInputStream
;
import
java.io.Writer
;
import
java.nio.charset.Charset
;
import
java.security.interfaces.RSAPublicKey
;
import
javax.annotation.Nullable
;
...
...
@@ -50,7 +53,9 @@ import java.nio.channels.ServerSocketChannel;
import
java.util.logging.Level
;
import
java.util.logging.Logger
;
import
org.apache.commons.codec.binary.Base64
;
import
org.apache.commons.io.Charsets
;
import
org.apache.commons.io.IOUtils
;
import
org.apache.commons.io.output.NullOutputStream
;
import
org.apache.commons.lang.StringUtils
;
/**
...
...
@@ -202,7 +207,19 @@ public final class TcpSlaveAgentListener extends Thread {
new
BufferedWriter
(
new
OutputStreamWriter
(
s
.
getOutputStream
(),
"UTF-8"
)),
true
);
// DEPRECATED: newer protocol shouldn't use PrintWriter but should use DataOutputStream
String
s
=
in
.
readUTF
();
// peek the first few bytes to determine what to do with this client
byte
[]
head
=
new
byte
[
10
];
in
.
readFully
(
head
);
String
header
=
new
String
(
head
,
Charsets
.
US_ASCII
);
if
(
header
.
startsWith
(
"GET "
))
{
// this looks like an HTTP client
respondHello
(
header
,
s
);
return
;
}
// otherwise assume this is AgentProtocol and start from the beginning
String
s
=
new
DataInputStream
(
new
SequenceInputStream
(
new
ByteArrayInputStream
(
head
),
in
)).
readUTF
();
if
(
s
.
startsWith
(
"Protocol:"
))
{
String
protocol
=
s
.
substring
(
9
);
...
...
@@ -235,6 +252,49 @@ public final class TcpSlaveAgentListener extends Thread {
}
}
/**
* Respond to HTTP request with simple diagnostics.
* Primarily used to test the low-level connectivity.
*/
private
void
respondHello
(
String
header
,
Socket
s
)
throws
IOException
{
try
{
Writer
o
=
new
OutputStreamWriter
(
s
.
getOutputStream
(),
"UTF-8"
);
if
(
header
.
startsWith
(
"GET / "
))
{
o
.
write
(
"HTTP/1.0 200 OK\r\n"
);
o
.
write
(
"Content-Type: text/plain;charset=UTF-8\r\n"
);
o
.
write
(
"\r\n"
);
o
.
write
(
"Jenkins-Agent-Protocols: "
);
boolean
first
=
true
;
for
(
AgentProtocol
p
:
AgentProtocol
.
all
())
{
if
(
first
)
first
=
false
;
else
o
.
write
(
","
);
o
.
write
(
p
.
getName
());
}
o
.
write
(
"\r\n"
);
o
.
write
(
"Jenkins-Version: "
+
Jenkins
.
VERSION
+
"\r\n"
);
o
.
write
(
"Jenkins-Session: "
+
Jenkins
.
SESSION_HASH
+
"\r\n"
);
o
.
write
(
"Client: "
+
s
.
getInetAddress
().
getHostAddress
()
+
"\r\n"
);
o
.
write
(
"Server: "
+
s
.
getLocalAddress
().
getHostAddress
()
+
"\r\n"
);
o
.
flush
();
s
.
shutdownOutput
();
}
else
{
o
.
write
(
"HTTP/1.0 404 Not Found\r\n"
);
o
.
write
(
"Content-Type: text/plain;charset=UTF-8\r\n"
);
o
.
write
(
"\r\n"
);
o
.
write
(
"Not Found\r\n"
);
o
.
flush
();
s
.
shutdownOutput
();
}
InputStream
i
=
s
.
getInputStream
();
IOUtils
.
copy
(
i
,
new
NullOutputStream
());
s
.
shutdownInput
();
}
finally
{
s
.
close
();
}
}
private
void
error
(
PrintWriter
out
,
String
msg
)
throws
IOException
{
out
.
println
(
msg
);
LOGGER
.
log
(
Level
.
WARNING
,
"Connection #"
+
id
+
" is aborted: "
+
msg
);
...
...
test/src/test/java/hudson/TcpSlaveAgentListenerTest.java
浏览文件 @
fab0938e
...
...
@@ -2,8 +2,11 @@ package hudson;
import
com.gargoylesoftware.htmlunit.FailingHttpStatusCodeException
;
import
com.gargoylesoftware.htmlunit.Page
;
import
com.gargoylesoftware.htmlunit.TextPage
;
import
com.gargoylesoftware.htmlunit.html.HtmlPage
;
import
hudson.remoting.Base64
;
import
java.io.IOException
;
import
java.security.KeyFactory
;
import
java.security.KeyPair
;
import
java.security.KeyPairGenerator
;
...
...
@@ -14,14 +17,17 @@ import java.security.interfaces.RSAPublicKey;
import
java.security.spec.InvalidKeySpecException
;
import
java.security.spec.PKCS8EncodedKeySpec
;
import
javax.annotation.Nullable
;
import
jenkins.model.Jenkins
;
import
jenkins.model.identity.InstanceIdentityProvider
;
import
jenkins.security.security218.ysoserial.ExecBlockingSecurityManager.ExecException
;
import
org.junit.Rule
;
import
org.junit.Test
;
import
org.jvnet.hudson.test.JenkinsRule
;
import
org.jvnet.hudson.test.JenkinsRule.WebClient
;
import
org.jvnet.hudson.test.TestExtension
;
import
static
org
.
hamcrest
.
Matchers
.
is
;
import
static
org
.
hamcrest
.
Matchers
.
notNullValue
;
import
static
org
.
hamcrest
.
Matchers
.*;
import
static
org
.
junit
.
Assert
.
assertThat
;
import
static
org
.
junit
.
Assert
.
fail
;
...
...
@@ -43,4 +49,21 @@ public class TcpSlaveAgentListenerTest {
Page
p
=
r
.
createWebClient
().
goTo
(
"tcpSlaveAgentListener"
,
"text/plain"
);
assertThat
(
p
.
getWebResponse
().
getResponseHeaderValue
(
"X-Instance-Identity"
),
notNullValue
());
}
@Test
public
void
diagnostics
()
throws
Exception
{
r
.
getInstance
().
setSlaveAgentPort
(
0
);
int
p
=
r
.
jenkins
.
getTcpSlaveAgentListener
().
getPort
();
WebClient
wc
=
r
.
createWebClient
();
TextPage
text
=
(
TextPage
)
wc
.
getPage
(
"http://localhost:"
+
p
+
"/"
);
String
c
=
text
.
getContent
();
assertThat
(
c
,
containsString
(
Jenkins
.
VERSION
));
try
{
wc
.
getPage
(
"http://localhost:"
+
p
+
"/xxx"
);
fail
(
"Expected 404"
);
}
catch
(
FailingHttpStatusCodeException
e
)
{
assertThat
(
e
.
getStatusCode
(),
equalTo
(
404
));
}
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录