Skip to content

Conversation

@daniel-beck
Copy link
Member

@daniel-beck daniel-beck commented Sep 12, 2017

@Issue("JENKINS-20520")
public void ensureSavingAfterInitialUser() {
r.addStep(new Statement() {
@Override
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

BTW once you are on 2.60.x+ you can make this a lot prettier with lambdas.

public void evaluate() throws Throwable {
r.j.jenkins.setSecurityRealm(new HudsonPrivateSecurityRealm(true));
r.j.jenkins.setAuthorizationStrategy(new GlobalMatrixAuthorizationStrategy());
r.j.jenkins.save();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

BTW in 2.51+ this is unnecessary: jenkinsci/jenkins#2790

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I want this to be explicit.

import hudson.security.ACLContext;
import hudson.security.GlobalMatrixAuthorizationStrategy;
import hudson.security.HudsonPrivateSecurityRealm;
import hudson.security.pages.SignupPage;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wow, never heard of this before. Once the private realm gets moved into a plugin (?), I guess this should go into a test-jar.

HtmlPage success = signup.submit(r.j);

try (ACLContext _ = ACL.as(User.get("alice"))) {
Assert.assertTrue(r.j.jenkins.getACL().hasPermission(Jenkins.ADMINISTER));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

More simply:

assertTrue(r.j.jenkins.hasPermission(Jenkins.ADMINISTER));

More simply still, delete the try block and:

assertTrue(r.j.jenkins.getACL().hasPermission(User.get("alice").impersonate(), Jenkins.ADMINISTER));

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, used this in #22 but forgot to update it here when I remembered how this works.

@daniel-beck daniel-beck merged commit 9ab8cc8 into jenkinsci:master Sep 14, 2017
@daniel-beck daniel-beck deleted the JENKINS-20520 branch October 29, 2019 23:05
signup.enterFullName("Alice User");
HtmlPage success = signup.submit(r.j);

Assert.assertTrue(r.j.jenkins.getACL().hasPermission(User.get("alice").impersonate(), Jenkins.ADMINISTER));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Failing in jenkinsci/bom#359 for reasons I am still struggling to understand: User.get("alice", false, Collections.emptyMap()) returns null. Only when jth.jenkins-war.path is set to the megawar.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants