-
-
Notifications
You must be signed in to change notification settings - Fork 67
[FIX JENKINS-20520] Save Jenkins after adding global user permission #23
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,51 @@ | ||
| package org.jenkinsci.plugins.matrixauth; | ||
|
|
||
| import com.gargoylesoftware.htmlunit.html.HtmlPage; | ||
| import hudson.model.User; | ||
| import hudson.security.ACL; | ||
| import hudson.security.ACLContext; | ||
| import hudson.security.GlobalMatrixAuthorizationStrategy; | ||
| import hudson.security.HudsonPrivateSecurityRealm; | ||
| import hudson.security.pages.SignupPage; | ||
| import jenkins.model.Jenkins; | ||
| import org.junit.Assert; | ||
| import org.junit.Rule; | ||
| import org.junit.Test; | ||
| import org.junit.runners.model.Statement; | ||
| import org.jvnet.hudson.test.Issue; | ||
| import org.jvnet.hudson.test.JenkinsRule; | ||
| import org.jvnet.hudson.test.RestartableJenkinsRule; | ||
|
|
||
| public class PermissionAdderTest { | ||
|
|
||
| @Rule | ||
| public RestartableJenkinsRule r = new RestartableJenkinsRule(); | ||
|
|
||
| @Test | ||
| @Issue("JENKINS-20520") | ||
| public void ensureSavingAfterInitialUser() { | ||
| r.addStep(new Statement() { | ||
| @Override | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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(); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. BTW in 2.51+ this is unnecessary: jenkinsci/jenkins#2790
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I want this to be explicit. |
||
|
|
||
| JenkinsRule.WebClient wc = r.j.createWebClient(); | ||
| SignupPage signup = new SignupPage(wc.goTo("signup")); | ||
| signup.enterUsername("alice"); | ||
| signup.enterPassword("alice"); | ||
| signup.enterFullName("Alice User"); | ||
| HtmlPage success = signup.submit(r.j); | ||
|
|
||
| Assert.assertTrue(r.j.jenkins.getACL().hasPermission(User.get("alice").impersonate(), Jenkins.ADMINISTER)); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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: |
||
| } | ||
| }); | ||
| r.addStep(new Statement() { | ||
| @Override | ||
| public void evaluate() throws Throwable { | ||
| Assert.assertTrue(r.j.jenkins.getACL().hasPermission(User.get("alice").impersonate(), Jenkins.ADMINISTER)); | ||
| } | ||
| }); | ||
| } | ||
| } | ||
There was a problem hiding this comment.
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.