Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
LinuxSuRen
jenkins
提交
37d1b8d7
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,发现更多精彩内容 >>
提交
37d1b8d7
编写于
9月 16, 2013
作者:
O
Oliver Gondža
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #855 from olivergondza/node-permissions
上级
7ec87871
83d5ac10
变更
11
隐藏空白更改
内联
并排
Showing
11 changed file
with
221 addition
and
35 deletion
+221
-35
changelog.html
changelog.html
+3
-0
core/src/main/java/hudson/cli/CreateNodeCommand.java
core/src/main/java/hudson/cli/CreateNodeCommand.java
+2
-1
core/src/main/java/hudson/cli/GetNodeCommand.java
core/src/main/java/hudson/cli/GetNodeCommand.java
+2
-1
core/src/main/java/hudson/model/Computer.java
core/src/main/java/hudson/model/Computer.java
+6
-4
core/src/main/resources/hudson/model/Messages.properties
core/src/main/resources/hudson/model/Messages.properties
+1
-0
test/src/main/java/hudson/cli/CLICommandInvoker.java
test/src/main/java/hudson/cli/CLICommandInvoker.java
+1
-0
test/src/test/java/hudson/cli/CreateNodeCommandTest.java
test/src/test/java/hudson/cli/CreateNodeCommandTest.java
+15
-15
test/src/test/java/hudson/cli/GetNodeCommandTest.java
test/src/test/java/hudson/cli/GetNodeCommandTest.java
+6
-6
test/src/test/java/hudson/cli/UpdateNodeCommandTest.java
test/src/test/java/hudson/cli/UpdateNodeCommandTest.java
+8
-8
test/src/test/java/hudson/model/ComputerConfigDotXmlTest.java
.../src/test/java/hudson/model/ComputerConfigDotXmlTest.java
+177
-0
test/src/test/resources/hudson/model/node.xml
test/src/test/resources/hudson/model/node.xml
+0
-0
未找到文件。
changelog.html
浏览文件 @
37d1b8d7
...
...
@@ -70,6 +70,9 @@ Upcoming changes</a>
<li
class=
'major rfe'
>
Added a new extension point to control where archived artifacts get stored.
(
<a
href=
"https://issues.jenkins-ci.org/browse/JENKINS-17236"
>
issue 17236
</a>
)
<li
class=
rfe
>
Use fine-grained permissions for node manipulation via REST API
&
CLI
(
<a
href=
"https://issues.jenkins-ci.org/browse/JENKINS-18485"
>
issue 18485
</a>
)
</ul>
</div>
<!--=TRUNK-END=-->
...
...
core/src/main/java/hudson/cli/CreateNodeCommand.java
浏览文件 @
37d1b8d7
...
...
@@ -25,6 +25,7 @@
package
hudson.cli
;
import
hudson.Extension
;
import
hudson.model.Computer
;
import
hudson.model.Node
;
import
hudson.model.Slave
;
import
hudson.model.User
;
...
...
@@ -53,7 +54,7 @@ public class CreateNodeCommand extends CLICommand {
protected
int
run
()
throws
Exception
{
final
Jenkins
jenkins
=
Jenkins
.
getInstance
();
jenkins
.
checkPermission
(
Jenkins
.
ADMINISTER
);
jenkins
.
checkPermission
(
Computer
.
CREATE
);
final
Node
newNode
=
(
Node
)
Jenkins
.
XSTREAM2
.
fromXML
(
stdin
);
...
...
core/src/main/java/hudson/cli/GetNodeCommand.java
浏览文件 @
37d1b8d7
...
...
@@ -24,6 +24,7 @@
package
hudson.cli
;
import
hudson.Extension
;
import
hudson.model.Computer
;
import
hudson.model.Node
;
import
java.io.IOException
;
...
...
@@ -51,7 +52,7 @@ public class GetNodeCommand extends CLICommand {
@Override
protected
int
run
()
throws
IOException
{
node
.
checkPermission
(
Jenkins
.
ADMINISTER
);
node
.
checkPermission
(
Computer
.
EXTENDED_READ
);
Jenkins
.
XSTREAM2
.
toXMLUTF8
(
node
,
stdout
);
...
...
core/src/main/java/hudson/model/Computer.java
浏览文件 @
37d1b8d7
...
...
@@ -1199,9 +1199,10 @@ public /*transient*/ abstract class Computer extends Actionable implements Acces
@WebMethod
(
name
=
"config.xml"
)
public
void
doConfigDotXml
(
StaplerRequest
req
,
StaplerResponse
rsp
)
throws
IOException
,
ServletException
{
checkPermission
(
Jenkins
.
ADMINISTER
);
if
(
req
.
getMethod
().
equals
(
"GET"
))
{
// read
checkPermission
(
EXTENDED_READ
);
rsp
.
setContentType
(
"application/xml"
);
Jenkins
.
XSTREAM2
.
toXMLUTF8
(
getNode
(),
rsp
.
getOutputStream
());
return
;
...
...
@@ -1241,7 +1242,7 @@ public /*transient*/ abstract class Computer extends Actionable implements Acces
* @since XXX
*/
public
void
updateByXml
(
final
InputStream
source
)
throws
IOException
,
ServletException
{
checkPermission
(
Jenkins
.
ADMINISTER
);
checkPermission
(
CONFIGURE
);
Node
result
=
(
Node
)
Jenkins
.
XSTREAM2
.
fromXML
(
source
);
replaceBy
(
result
);
}
...
...
@@ -1362,10 +1363,11 @@ public /*transient*/ abstract class Computer extends Actionable implements Acces
}
public
static
final
PermissionGroup
PERMISSIONS
=
new
PermissionGroup
(
Computer
.
class
,
Messages
.
_Computer_Permissions_Title
());
public
static
final
Permission
CONFIGURE
=
new
Permission
(
PERMISSIONS
,
"Configure"
,
Messages
.
_Computer_ConfigurePermission_Description
(),
Permission
.
CONFIGURE
,
PermissionScope
.
COMPUTER
);
/**
*
Permission to configure slaves.
*
@since 1.532
*/
public
static
final
Permission
CONFIGURE
=
new
Permission
(
PERMISSIONS
,
"Configure"
,
Messages
.
_Computer_ConfigurePermission_Description
(),
Permission
.
CONFIGURE
,
PermissionScope
.
COMPUTER
);
public
static
final
Permission
EXTENDED_READ
=
new
Permission
(
PERMISSIONS
,
"ExtendedRead"
,
Messages
.
_Computer_ExtendedReadPermission_Description
(),
CONFIGURE
,
Boolean
.
getBoolean
(
"hudson.security.ExtendedReadPermission"
),
new
PermissionScope
[]{
PermissionScope
.
COMPUTER
}
);
public
static
final
Permission
DELETE
=
new
Permission
(
PERMISSIONS
,
"Delete"
,
Messages
.
_Computer_DeletePermission_Description
(),
Permission
.
DELETE
,
PermissionScope
.
COMPUTER
);
public
static
final
Permission
CREATE
=
new
Permission
(
PERMISSIONS
,
"Create"
,
Messages
.
_Computer_CreatePermission_Description
(),
Permission
.
CREATE
,
PermissionScope
.
COMPUTER
);
public
static
final
Permission
DISCONNECT
=
new
Permission
(
PERMISSIONS
,
"Disconnect"
,
Messages
.
_Computer_DisconnectPermission_Description
(),
Jenkins
.
ADMINISTER
,
PermissionScope
.
COMPUTER
);
...
...
core/src/main/resources/hudson/model/Messages.properties
浏览文件 @
37d1b8d7
...
...
@@ -102,6 +102,7 @@ CLI.wait-node-offline.shortDescription=Wait for a node to become offline
Computer.Caption
=
Slave {0}
Computer.NoSuchSlaveExists
=
No such slave "{0}" exists. Did you mean "{1}"?
Computer.Permissions.Title
=
Slave
Computer.ExtendedReadPermission.Description
=
This permission allows users to read slave configuration.
Computer.ConfigurePermission.Description
=
This permission allows users to configure slaves.
Computer.DeletePermission.Description
=
This permission allows users to delete existing slaves.
Computer.CreatePermission.Description
=
This permission allows users to create slaves.
...
...
test/src/main/java/hudson/cli/CLICommandInvoker.java
浏览文件 @
37d1b8d7
...
...
@@ -107,6 +107,7 @@ public class CLICommandInvoker {
GlobalMatrixAuthorizationStrategy
auth
=
new
GlobalMatrixAuthorizationStrategy
();
for
(
Permission
p:
permissions
)
{
p
.
setEnabled
(
true
);
auth
.
add
(
p
,
username
);
}
rule
.
jenkins
.
setAuthorizationStrategy
(
auth
);
...
...
test/src/test/java/hudson/cli/CreateNodeCommandTest.java
浏览文件 @
37d1b8d7
...
...
@@ -29,9 +29,9 @@ import static org.hamcrest.Matchers.containsString;
import
static
org
.
hamcrest
.
Matchers
.
equalTo
;
import
static
org
.
hamcrest
.
Matchers
.
nullValue
;
import
static
org
.
hamcrest
.
text
.
IsEmptyString
.
isEmptyString
;
import
hudson.model.Computer
;
import
hudson.model.Node
;
import
hudson.model.Slave
;
import
hudson.security.Permission
;
import
jenkins.model.Jenkins
;
import
org.junit.Before
;
...
...
@@ -50,15 +50,15 @@ public class CreateNodeCommandTest {
command
=
new
CLICommandInvoker
(
j
,
new
CreateNodeCommand
());
}
@Test
public
void
createNodeShouldFailWithout
AdministerPermi
sion
()
throws
Exception
{
@Test
public
void
createNodeShouldFailWithout
ComputerCreatePermis
sion
()
throws
Exception
{
final
CLICommandInvoker
.
Result
result
=
command
.
authorizedTo
(
Permission
.
READ
)
.
withStdin
(
getClass
()
.
getResourceAsStream
(
"node.xml"
))
.
authorizedTo
(
Jenkins
.
READ
)
.
withStdin
(
Computer
.
class
.
getResourceAsStream
(
"node.xml"
))
.
invoke
()
;
assertThat
(
result
.
stderr
(),
containsString
(
"user is missing the
Overall/Administer
permission"
));
assertThat
(
result
.
stderr
(),
containsString
(
"user is missing the
Slave/Create
permission"
));
assertThat
(
"No output expected"
,
result
.
stdout
(),
isEmptyString
());
assertThat
(
"Command is expected to fail"
,
result
.
returnCode
(),
equalTo
(-
1
));
}
...
...
@@ -66,8 +66,8 @@ public class CreateNodeCommandTest {
@Test
public
void
createNode
()
throws
Exception
{
final
CLICommandInvoker
.
Result
result
=
command
.
authorizedTo
(
Jenkins
.
ADMINISTER
)
.
withStdin
(
getClass
()
.
getResourceAsStream
(
"node.xml"
))
.
authorizedTo
(
Computer
.
CREATE
,
Jenkins
.
READ
)
.
withStdin
(
Computer
.
class
.
getResourceAsStream
(
"node.xml"
))
.
invoke
()
;
...
...
@@ -83,8 +83,8 @@ public class CreateNodeCommandTest {
@Test
public
void
createNodeSpecifyingNameExplicitly
()
throws
Exception
{
final
CLICommandInvoker
.
Result
result
=
command
.
authorizedTo
(
Jenkins
.
ADMINISTER
)
.
withStdin
(
getClass
()
.
getResourceAsStream
(
"node.xml"
))
.
authorizedTo
(
Computer
.
CREATE
,
Jenkins
.
READ
)
.
withStdin
(
Computer
.
class
.
getResourceAsStream
(
"node.xml"
))
.
invokeWithArgs
(
"CustomSlaveName"
)
;
...
...
@@ -104,8 +104,8 @@ public class CreateNodeCommandTest {
final
Node
originalSlave
=
j
.
createSlave
(
"SlaveFromXml"
,
null
,
null
);
final
CLICommandInvoker
.
Result
result
=
command
.
authorizedTo
(
Jenkins
.
ADMINISTER
)
.
withStdin
(
getClass
()
.
getResourceAsStream
(
"node.xml"
))
.
authorizedTo
(
Computer
.
CREATE
,
Jenkins
.
READ
)
.
withStdin
(
Computer
.
class
.
getResourceAsStream
(
"node.xml"
))
.
invokeWithArgs
(
"CustomSlaveName"
)
;
...
...
@@ -125,8 +125,8 @@ public class CreateNodeCommandTest {
j
.
createSlave
(
"SlaveFromXML"
,
null
,
null
);
final
CLICommandInvoker
.
Result
result
=
command
.
authorizedTo
(
Jenkins
.
ADMINISTER
)
.
withStdin
(
getClass
()
.
getResourceAsStream
(
"node.xml"
))
.
authorizedTo
(
Computer
.
CREATE
,
Jenkins
.
READ
)
.
withStdin
(
Computer
.
class
.
getResourceAsStream
(
"node.xml"
))
.
invoke
()
;
...
...
@@ -140,8 +140,8 @@ public class CreateNodeCommandTest {
j
.
createSlave
(
"ExistingSlave"
,
null
,
null
);
final
CLICommandInvoker
.
Result
result
=
command
.
authorizedTo
(
Jenkins
.
ADMINISTER
)
.
withStdin
(
getClass
()
.
getResourceAsStream
(
"node.xml"
))
.
authorizedTo
(
Computer
.
CREATE
,
Jenkins
.
READ
)
.
withStdin
(
Computer
.
class
.
getResourceAsStream
(
"node.xml"
))
.
invokeWithArgs
(
"ExistingSlave"
)
;
...
...
test/src/test/java/hudson/cli/GetNodeCommandTest.java
浏览文件 @
37d1b8d7
...
...
@@ -29,7 +29,7 @@ import static org.hamcrest.Matchers.containsString;
import
static
org
.
hamcrest
.
Matchers
.
equalTo
;
import
static
org
.
hamcrest
.
Matchers
.
startsWith
;
import
static
org
.
hamcrest
.
text
.
IsEmptyString
.
isEmptyString
;
import
hudson.
security.Permission
;
import
hudson.
model.Computer
;
import
jenkins.model.Jenkins
;
import
org.junit.Before
;
...
...
@@ -48,16 +48,16 @@ public class GetNodeCommandTest {
command
=
new
CLICommandInvoker
(
j
,
new
GetNodeCommand
());
}
@Test
public
void
getNodeShouldFailWithout
AdministerPermi
sion
()
throws
Exception
{
@Test
public
void
getNodeShouldFailWithout
ComputerReadPermis
sion
()
throws
Exception
{
j
.
createSlave
(
"MySlave"
,
null
,
null
);
final
CLICommandInvoker
.
Result
result
=
command
.
authorizedTo
(
Permission
.
READ
)
.
authorizedTo
(
Jenkins
.
READ
)
.
invokeWithArgs
(
"MySlave"
)
;
assertThat
(
result
.
stderr
(),
containsString
(
"user is missing the
Overall/Administer
permission"
));
assertThat
(
result
.
stderr
(),
containsString
(
"user is missing the
Slave/ExtendedRead
permission"
));
assertThat
(
"No output expected"
,
result
.
stdout
(),
isEmptyString
());
assertThat
(
"Command is expected to fail"
,
result
.
returnCode
(),
equalTo
(-
1
));
}
...
...
@@ -67,7 +67,7 @@ public class GetNodeCommandTest {
j
.
createSlave
(
"MySlave"
,
null
,
null
);
final
CLICommandInvoker
.
Result
result
=
command
.
authorizedTo
(
Jenkins
.
ADMINISTER
)
.
authorizedTo
(
Computer
.
EXTENDED_READ
,
Jenkins
.
READ
)
.
invokeWithArgs
(
"MySlave"
)
;
...
...
@@ -80,7 +80,7 @@ public class GetNodeCommandTest {
@Test
public
void
getNodeShouldFailIfNodeDoesNotExist
()
throws
Exception
{
final
CLICommandInvoker
.
Result
result
=
command
.
authorizedTo
(
Jenkins
.
ADMINISTER
)
.
authorizedTo
(
Computer
.
EXTENDED_READ
,
Jenkins
.
READ
)
.
invokeWithArgs
(
"MySlave"
)
;
...
...
test/src/test/java/hudson/cli/UpdateNodeCommandTest.java
浏览文件 @
37d1b8d7
...
...
@@ -29,8 +29,8 @@ import static org.hamcrest.Matchers.containsString;
import
static
org
.
hamcrest
.
Matchers
.
equalTo
;
import
static
org
.
hamcrest
.
Matchers
.
nullValue
;
import
static
org
.
hamcrest
.
text
.
IsEmptyString
.
isEmptyString
;
import
hudson.model.Computer
;
import
hudson.model.Node
;
import
hudson.security.Permission
;
import
jenkins.model.Jenkins
;
import
org.junit.Before
;
...
...
@@ -49,16 +49,16 @@ public class UpdateNodeCommandTest {
command
=
new
CLICommandInvoker
(
j
,
new
UpdateNodeCommand
());
}
@Test
public
void
updateNodeShouldFailWithout
AdministerPermi
sion
()
throws
Exception
{
@Test
public
void
updateNodeShouldFailWithout
ComputerConfigurePermis
sion
()
throws
Exception
{
j
.
createSlave
(
"MySlave"
,
null
,
null
);
final
CLICommandInvoker
.
Result
result
=
command
.
authorizedTo
(
Permission
.
READ
)
.
authorizedTo
(
Jenkins
.
READ
)
.
invokeWithArgs
(
"MySlave"
)
;
assertThat
(
result
.
stderr
(),
containsString
(
"user is missing the
Overall/Administer
permission"
));
assertThat
(
result
.
stderr
(),
containsString
(
"user is missing the
Slave/Configure
permission"
));
assertThat
(
"No output expected"
,
result
.
stdout
(),
isEmptyString
());
assertThat
(
"Command is expected to fail"
,
result
.
returnCode
(),
equalTo
(-
1
));
}
...
...
@@ -68,8 +68,8 @@ public class UpdateNodeCommandTest {
j
.
createSlave
(
"MySlave"
,
null
,
null
);
final
CLICommandInvoker
.
Result
result
=
command
.
authorizedTo
(
Jenkins
.
ADMINISTER
)
.
withStdin
(
getClass
()
.
getResourceAsStream
(
"node.xml"
))
.
authorizedTo
(
Computer
.
CONFIGURE
,
Jenkins
.
READ
)
.
withStdin
(
Computer
.
class
.
getResourceAsStream
(
"node.xml"
))
.
invokeWithArgs
(
"MySlave"
)
;
...
...
@@ -86,8 +86,8 @@ public class UpdateNodeCommandTest {
@Test
public
void
updateNodeShouldFailIfNodeDoesNotExist
()
throws
Exception
{
final
CLICommandInvoker
.
Result
result
=
command
.
authorizedTo
(
Jenkins
.
ADMINISTER
)
.
withStdin
(
getClass
()
.
getResourceAsStream
(
"node.xml"
))
.
authorizedTo
(
Computer
.
CONFIGURE
,
Jenkins
.
READ
)
.
withStdin
(
Computer
.
class
.
getResourceAsStream
(
"node.xml"
))
.
invokeWithArgs
(
"MySlave"
)
;
...
...
test/src/test/java/hudson/model/ComputerConfigDotXmlTest.java
0 → 100644
浏览文件 @
37d1b8d7
/*
* The MIT License
*
* Copyright (c) 2013 Red Hat, Inc.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package
hudson.model
;
import
static
org
.
hamcrest
.
MatcherAssert
.
assertThat
;
import
static
org
.
hamcrest
.
Matchers
.
containsString
;
import
static
org
.
hamcrest
.
Matchers
.
equalTo
;
import
static
org
.
hamcrest
.
Matchers
.
startsWith
;
import
static
org
.
mockito
.
Mockito
.
spy
;
import
static
org
.
mockito
.
Mockito
.
when
;
import
hudson.security.ACL
;
import
hudson.security.AccessDeniedException2
;
import
hudson.security.GlobalMatrixAuthorizationStrategy
;
import
java.io.ByteArrayOutputStream
;
import
java.io.IOException
;
import
java.io.InputStream
;
import
java.io.OutputStream
;
import
javax.servlet.ServletInputStream
;
import
javax.servlet.ServletOutputStream
;
import
org.acegisecurity.context.SecurityContext
;
import
org.acegisecurity.context.SecurityContextHolder
;
import
org.junit.After
;
import
org.junit.Before
;
import
org.junit.Rule
;
import
org.junit.Test
;
import
org.jvnet.hudson.test.JenkinsRule
;
import
org.kohsuke.stapler.StaplerRequest
;
import
org.kohsuke.stapler.StaplerResponse
;
import
org.mockito.Mock
;
import
org.mockito.MockitoAnnotations
;
/**
* @author ogondza
*/
public
class
ComputerConfigDotXmlTest
{
@Rule
public
final
JenkinsRule
rule
=
new
JenkinsRule
();
@Mock
private
StaplerRequest
req
;
@Mock
private
StaplerResponse
rsp
;
private
Computer
computer
;
private
SecurityContext
oldSecurityContext
;
@Before
public
void
setUp
()
throws
Exception
{
MockitoAnnotations
.
initMocks
(
this
);
computer
=
spy
(
rule
.
createSlave
().
toComputer
());
oldSecurityContext
=
ACL
.
impersonate
(
User
.
get
(
"user"
).
impersonate
());
}
@After
public
void
tearDown
()
{
SecurityContextHolder
.
setContext
(
oldSecurityContext
);
}
@Test
(
expected
=
AccessDeniedException2
.
class
)
public
void
configXmlGetShouldFailForUnauthorized
()
throws
Exception
{
when
(
req
.
getMethod
()).
thenReturn
(
"GET"
);
rule
.
jenkins
.
setAuthorizationStrategy
(
new
GlobalMatrixAuthorizationStrategy
());
computer
.
doConfigDotXml
(
req
,
rsp
);
}
@Test
(
expected
=
AccessDeniedException2
.
class
)
public
void
configXmlPostShouldFailForUnauthorized
()
throws
Exception
{
when
(
req
.
getMethod
()).
thenReturn
(
"POST"
);
rule
.
jenkins
.
setAuthorizationStrategy
(
new
GlobalMatrixAuthorizationStrategy
());
computer
.
doConfigDotXml
(
req
,
rsp
);
}
@Test
public
void
configXmlGetShouldYieldNodeConfiguration
()
throws
Exception
{
when
(
req
.
getMethod
()).
thenReturn
(
"GET"
);
GlobalMatrixAuthorizationStrategy
auth
=
new
GlobalMatrixAuthorizationStrategy
();
rule
.
jenkins
.
setAuthorizationStrategy
(
auth
);
Computer
.
EXTENDED_READ
.
setEnabled
(
true
);
auth
.
add
(
Computer
.
EXTENDED_READ
,
"user"
);
final
OutputStream
outputStream
=
captureOutput
();
computer
.
doConfigDotXml
(
req
,
rsp
);
final
String
out
=
outputStream
.
toString
();
assertThat
(
out
,
startsWith
(
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
));
assertThat
(
out
,
containsString
(
"<name>slave0</name>"
));
assertThat
(
out
,
containsString
(
"<description>dummy</description>"
));
}
@Test
public
void
configXmlPostShouldUpdateNodeConfiguration
()
throws
Exception
{
when
(
req
.
getMethod
()).
thenReturn
(
"POST"
);
GlobalMatrixAuthorizationStrategy
auth
=
new
GlobalMatrixAuthorizationStrategy
();
rule
.
jenkins
.
setAuthorizationStrategy
(
auth
);
auth
.
add
(
Computer
.
CONFIGURE
,
"user"
);
when
(
req
.
getInputStream
()).
thenReturn
(
xmlNode
(
"node.xml"
));
computer
.
doConfigDotXml
(
req
,
rsp
);
final
Node
updatedSlave
=
rule
.
jenkins
.
getNode
(
"SlaveFromXML"
);
assertThat
(
updatedSlave
.
getNodeName
(),
equalTo
(
"SlaveFromXML"
));
assertThat
(
updatedSlave
.
getNumExecutors
(),
equalTo
(
42
));
}
private
OutputStream
captureOutput
()
throws
IOException
{
final
ByteArrayOutputStream
baos
=
new
ByteArrayOutputStream
();
when
(
rsp
.
getOutputStream
()).
thenReturn
(
new
ServletOutputStream
()
{
@Override
public
void
write
(
int
b
)
throws
IOException
{
baos
.
write
(
b
);
}
});
return
baos
;
}
private
ServletInputStream
xmlNode
(
final
String
name
)
{
class
Stream
extends
ServletInputStream
{
private
final
InputStream
inner
;
public
Stream
(
final
InputStream
inner
)
{
this
.
inner
=
inner
;
}
@Override
public
int
read
()
throws
IOException
{
return
inner
.
read
();
}
}
return
new
Stream
(
Computer
.
class
.
getResourceAsStream
(
name
));
}
}
test/src/test/resources/hudson/
cli
/node.xml
→
test/src/test/resources/hudson/
model
/node.xml
浏览文件 @
37d1b8d7
文件已移动
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录