Skip to content

Commit

Permalink
Fixed test—stray rparen broke authentication.
Browse files Browse the repository at this point in the history
Also switching to ACL.as here for safety; 26 other tests ought to do the same.
  • Loading branch information
jglick committed Sep 8, 2017
1 parent 7b1f8e9 commit 1b90346
Showing 1 changed file with 12 additions and 9 deletions.
21 changes: 12 additions & 9 deletions test/src/test/java/hudson/model/UserTest.java
Expand Up @@ -30,6 +30,7 @@
import com.gargoylesoftware.htmlunit.html.HtmlPage;

import hudson.security.ACL;
import hudson.security.ACLContext;
import hudson.security.AbstractPasswordBasedSecurityRealm;
import hudson.security.AccessDeniedException2;
import hudson.security.GlobalMatrixAuthorizationStrategy;
Expand Down Expand Up @@ -690,7 +691,7 @@ public void resolveById() throws Exception {
@Issue("SECURITY-514")
public void getAllPropertiesRequiresAdmin() {
j.jenkins.setAuthorizationStrategy(new MockAuthorizationStrategy()
.grant(Jenkins.ADMINISTER).everywhere().to("admin)")
.grant(Jenkins.ADMINISTER).everywhere().to("admin")
.grant(Jenkins.READ).everywhere().toEveryone());
j.jenkins.setSecurityRealm(j.createDummySecurityRealm());

Expand All @@ -699,16 +700,18 @@ public void getAllPropertiesRequiresAdmin() {
User bob = User.get("bob");

// Admin can access user properties for all users
ACL.impersonate(admin.impersonate());
assertThat(alice.getAllProperties(), not(empty()));
assertThat(bob.getAllProperties(), not(empty()));
assertThat(admin.getAllProperties(), not(empty()));
try (ACLContext as = ACL.as(admin)) {
assertThat(alice.getAllProperties(), not(empty()));
assertThat(bob.getAllProperties(), not(empty()));
assertThat(admin.getAllProperties(), not(empty()));
}

// Non admins can only view their own
ACL.impersonate(alice.impersonate());
assertThat(alice.getAllProperties(), not(empty()));
assertThat(bob.getAllProperties(), empty());
assertThat(admin.getAllProperties(), empty());
try (ACLContext as = ACL.as(alice)) {
assertThat(alice.getAllProperties(), not(empty()));
assertThat(bob.getAllProperties(), empty());
assertThat(admin.getAllProperties(), empty());
}
}

public static class SomeUserProperty extends UserProperty {
Expand Down

0 comments on commit 1b90346

Please sign in to comment.