-
Notifications
You must be signed in to change notification settings - Fork 148
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
Configurable anonymous access to the list of failure causes #31
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
ffbede3
Configurable anonymous access to the list of failure causes
dcoraboeuf 5f3e14e
Correction of checkstyle issue
dcoraboeuf 03f1894
Adding the view permission as a safety
dcoraboeuf 4686648
Creating unit tests for pull request #31 (work in progress)
dcoraboeuf 5742313
Creating unit tests for pull request #31
dcoraboeuf File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 2 additions & 0 deletions
2
src/main/resources/com/sonyericsson/jenkins/plugins/bfa/Messages.properties
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
131 changes: 131 additions & 0 deletions
131
src/test/java/com/sonyericsson/jenkins/plugins/bfa/CauseManagementPermissionTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,131 @@ | ||
package com.sonyericsson.jenkins.plugins.bfa; | ||
|
||
import com.gargoylesoftware.htmlunit.FailingHttpStatusCodeException; | ||
import com.gargoylesoftware.htmlunit.html.HtmlPage; | ||
import hudson.model.Hudson; | ||
import hudson.security.GlobalMatrixAuthorizationStrategy; | ||
import hudson.security.SecurityRealm; | ||
import org.junit.Before; | ||
import org.junit.Rule; | ||
import org.junit.Test; | ||
import org.jvnet.hudson.test.JenkinsRule; | ||
|
||
import javax.servlet.http.HttpServletResponse; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
import static org.junit.Assert.assertNotNull; | ||
import static org.junit.Assert.assertNull; | ||
import static org.junit.Assert.fail; | ||
|
||
/** | ||
* Tests the permissions for the Cause Management. | ||
* | ||
* @author Damien Coraboeuf | ||
*/ | ||
public class CauseManagementPermissionTest { | ||
|
||
/** | ||
* The Jenkins Rule. | ||
*/ | ||
@Rule | ||
//CS IGNORE VisibilityModifier FOR NEXT 1 LINES. REASON: Jenkins Rule | ||
public JenkinsRule j = new JenkinsRule(); | ||
|
||
/** | ||
* Configures Jenkins to use security and defines several users with different rights for the | ||
* management or view of failure causes. | ||
*/ | ||
@Before | ||
public void jenkinsConfiguration() { | ||
SecurityRealm securityRealm = j.createDummySecurityRealm(); | ||
j.getInstance().setSecurityRealm(securityRealm); | ||
|
||
GlobalMatrixAuthorizationStrategy authorizationStrategy = new GlobalMatrixAuthorizationStrategy(); | ||
authorizationStrategy.add(Hudson.READ, "anonymous"); | ||
authorizationStrategy.add(PluginImpl.VIEW_PERMISSION, "view"); | ||
authorizationStrategy.add(PluginImpl.UPDATE_PERMISSION, "update"); | ||
authorizationStrategy.add(PluginImpl.VIEW_PERMISSION, "all"); | ||
authorizationStrategy.add(PluginImpl.UPDATE_PERMISSION, "all"); | ||
j.getInstance().setAuthorizationStrategy(authorizationStrategy); | ||
} | ||
|
||
/** | ||
* Checks that a non authorised user cannot access the failure management page at all. | ||
* | ||
* @throws java.lang.Exception If Jenkins cannot be accessed | ||
*/ | ||
@Test | ||
public void notAllowedToUpdateCausesWhenNotGrantedAnything() throws Exception { | ||
JenkinsRule.WebClient webClient = j.createWebClient(); | ||
// Logs in | ||
webClient.goTo(""); | ||
webClient.login("none"); | ||
// Gets to the Failure Cause page | ||
try { | ||
webClient.goTo("failure-cause-management"); | ||
fail("Access to the page should have failed"); | ||
} catch (FailingHttpStatusCodeException ex) { | ||
assertEquals(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, ex.getStatusCode()); | ||
} | ||
} | ||
|
||
/** | ||
* Checks that a user granted with "viewCauses" only can access the failure management page | ||
* <i>but not</i> create a new failure. | ||
* | ||
* @throws java.lang.Exception If Jenkins cannot be accessed | ||
*/ | ||
@Test | ||
public void allowedToViewCausesWhenGrantedOnlyView() throws Exception { | ||
JenkinsRule.WebClient webClient = j.createWebClient(); | ||
// Logs in | ||
webClient.goTo(""); | ||
webClient.login("view"); | ||
// Gets to the Failure Cause page | ||
HtmlPage page = webClient.goTo("failure-cause-management"); | ||
// Checks we are actually on the page | ||
assertNotNull(page.selectSingleNode("//h1[.='List of Failure Causes']")); | ||
// Checks the "Create New" button is NOT available | ||
assertNull(page.selectSingleNode("//a[.='Create new']")); | ||
} | ||
|
||
/** | ||
* Checks that a user granted with "updateCauses" only can access the failure management page | ||
* <i>and</i> create a new failure. | ||
* | ||
* @throws java.lang.Exception If Jenkins cannot be accessed | ||
*/ | ||
@Test | ||
public void allowedToUpdateCausesWhenGrantedOnlyUpdate() throws Exception { | ||
JenkinsRule.WebClient webClient = j.createWebClient(); | ||
// Logs in | ||
webClient.goTo(""); | ||
webClient.login("update"); | ||
// Gets to the Failure Cause page | ||
HtmlPage page = webClient.goTo("failure-cause-management"); | ||
// Checks we are actually on the page | ||
assertNotNull(page.selectSingleNode("//h1[.='Update Failure Causes']")); | ||
// Checks the "Create New" button is available | ||
assertNotNull(page.selectSingleNode("//a[.='Create new']")); | ||
} | ||
|
||
/** | ||
* Checks that a user granted with "updateCauses" and "viewCauses" only can access the failure management page | ||
* <i>and</i> create a new failure. | ||
* | ||
* @throws java.lang.Exception If Jenkins cannot be accessed | ||
*/ | ||
@Test | ||
public void allowedToUpdateCausesWhenGrantedBothUpdateAndView() throws Exception { | ||
JenkinsRule.WebClient webClient = j.createWebClient(); | ||
// Logs in | ||
webClient.goTo(""); | ||
webClient.login("all"); | ||
// Gets to the Failure Cause page | ||
HtmlPage page = webClient.goTo("failure-cause-management"); | ||
// Checks we are actually on the page | ||
assertNotNull(page.selectSingleNode("//h1[.='Update Failure Causes']")); | ||
// Checks the "Create New" button is available | ||
assertNotNull(page.selectSingleNode("//a[.='Create new']")); | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Since VIEW_PERMISSION is inferred by UPDATE_PERMISSION you should be able to put
permission: PluginImpl.VIEW_PERMISSION
here for safety.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.
Done.