提交 cefc52cb 编写于 作者: J Jesse Glick

Merge branch 'security' into security-stable-1.596

...@@ -508,33 +508,33 @@ public class UserTest { ...@@ -508,33 +508,33 @@ public class UserTest {
public void security180() throws Exception { public void security180() throws Exception {
final GlobalMatrixAuthorizationStrategy auth = new GlobalMatrixAuthorizationStrategy(); final GlobalMatrixAuthorizationStrategy auth = new GlobalMatrixAuthorizationStrategy();
j.jenkins.setAuthorizationStrategy(auth); j.jenkins.setAuthorizationStrategy(auth);
j.jenkins.setSecurityRealm(new HudsonPrivateSecurityRealm(false)); j.jenkins.setSecurityRealm(j.createDummySecurityRealm());
User alice = User.get("alice"); User alice = User.get("alice");
User bob = User.get("bob"); User bob = User.get("bob");
User anonymous = User.get("anonymous");
User admin = User.get("admin"); User admin = User.get("admin");
auth.add(Jenkins.READ, alice.getId()); auth.add(Jenkins.READ, alice.getId());
auth.add(Jenkins.READ, bob.getId()); auth.add(Jenkins.READ, bob.getId());
auth.add(Jenkins.ADMINISTER, admin.getId()); auth.add(Jenkins.ADMINISTER, admin.getId());
// Admin can change everyone's token
SecurityContextHolder.getContext().setAuthentication(admin.impersonate()); SecurityContextHolder.getContext().setAuthentication(admin.impersonate());
// Change token by admin
admin.getProperty(ApiTokenProperty.class).changeApiToken(); admin.getProperty(ApiTokenProperty.class).changeApiToken();
alice.getProperty(ApiTokenProperty.class).changeApiToken(); alice.getProperty(ApiTokenProperty.class).changeApiToken();
// User can change only own token
SecurityContextHolder.getContext().setAuthentication(bob.impersonate()); SecurityContextHolder.getContext().setAuthentication(bob.impersonate());
// Change own token
bob.getProperty(ApiTokenProperty.class).changeApiToken(); bob.getProperty(ApiTokenProperty.class).changeApiToken();
try { try {
alice.getProperty(ApiTokenProperty.class).changeApiToken(); alice.getProperty(ApiTokenProperty.class).changeApiToken();
fail("Bob should not be authorized to change alice's token"); fail("Bob should not be authorized to change alice's token");
} catch (AccessDeniedException expected) { } } catch (AccessDeniedException expected) { }
// ANONYMOUS can not change any token
SecurityContextHolder.getContext().setAuthentication(Jenkins.ANONYMOUS);
try { try {
anonymous.getProperty(ApiTokenProperty.class).changeApiToken(); alice.getProperty(ApiTokenProperty.class).changeApiToken();
fail("Anonymous should not be authorized to change alice's token"); fail("Anonymous should not be authorized to change alice's token");
} catch (AccessDeniedException expected) { } } catch (AccessDeniedException expected) { }
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册