Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
[JENKINS-20785] Added tests for MatrixProject. They fails now.
- Loading branch information
Showing
1 changed file
with
160 additions
and
0 deletions.
There are no files selected for viewing
160 changes: 160 additions & 0 deletions
160
src/test/java/org/jenkinsci/plugins/authorizeproject/ProjectQueueItemAuthenticatorTest.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,160 @@ | ||
/* | ||
* The MIT License | ||
* | ||
* Copyright (c) 2013 IKEDA Yasuyuki | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to deal | ||
* in the Software without restriction, including without limitation the rights | ||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
* copies of the Software, and to permit persons to whom the Software is | ||
* furnished to do so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included in | ||
* all copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
* THE SOFTWARE. | ||
*/ | ||
|
||
package org.jenkinsci.plugins.authorizeproject; | ||
|
||
import static org.junit.Assert.*; | ||
import jenkins.model.Jenkins; | ||
import hudson.matrix.AxisList; | ||
import hudson.matrix.MatrixProject; | ||
import hudson.matrix.TextAxis; | ||
import hudson.model.AbstractProject; | ||
import hudson.model.FreeStyleProject; | ||
import hudson.model.Queue; | ||
import hudson.security.ACL; | ||
|
||
import org.acegisecurity.Authentication; | ||
import org.jenkinsci.plugins.authorizeproject.strategy.AnonymousAuthorizationStrategy; | ||
import org.jenkinsci.plugins.authorizeproject.testutil.AuthorizationCheckBuilder; | ||
import org.jenkinsci.plugins.authorizeproject.testutil.AuthorizeProjectJenkinsRule; | ||
import org.junit.Rule; | ||
import org.junit.Test; | ||
import org.jvnet.hudson.test.JenkinsRule; | ||
|
||
/** | ||
* | ||
*/ | ||
public class ProjectQueueItemAuthenticatorTest { | ||
@Rule | ||
public JenkinsRule j = new AuthorizeProjectJenkinsRule(); | ||
|
||
public static class NullAuthorizeProjectStrategy extends AuthorizeProjectStrategy { | ||
@Override | ||
public Authentication authenticate(AbstractProject<?, ?> project, Queue.Item item) { | ||
return null; | ||
} | ||
} | ||
|
||
@Test | ||
public void testWorkForFreeStyleProject() throws Exception { | ||
// if not configured, run in SYSTEM privilege. | ||
{ | ||
FreeStyleProject p = j.createFreeStyleProject(); | ||
AuthorizationCheckBuilder checker = new AuthorizationCheckBuilder(); | ||
p.getBuildersList().add(checker); | ||
|
||
j.assertBuildStatusSuccess(p.scheduleBuild2(0)); | ||
assertEquals(ACL.SYSTEM, checker.authentication); | ||
} | ||
|
||
// if configured, AuthorizeProjectStrategy takes effect | ||
{ | ||
FreeStyleProject p = j.createFreeStyleProject(); | ||
AuthorizationCheckBuilder checker = new AuthorizationCheckBuilder(); | ||
p.getBuildersList().add(checker); | ||
|
||
p.addProperty(new AuthorizeProjectProperty(new AnonymousAuthorizationStrategy())); | ||
|
||
j.assertBuildStatusSuccess(p.scheduleBuild2(0)); | ||
assertEquals(Jenkins.ANONYMOUS, checker.authentication); | ||
} | ||
|
||
// if configured wrong, run in SYSTEM privilege. | ||
{ | ||
FreeStyleProject p = j.createFreeStyleProject(); | ||
AuthorizationCheckBuilder checker = new AuthorizationCheckBuilder(); | ||
p.getBuildersList().add(checker); | ||
|
||
p.addProperty(new AuthorizeProjectProperty(null)); | ||
|
||
j.assertBuildStatusSuccess(p.scheduleBuild2(0)); | ||
assertEquals(ACL.SYSTEM, checker.authentication); | ||
} | ||
|
||
// if the strategy returns null, run in SYSTEM privilege. | ||
{ | ||
FreeStyleProject p = j.createFreeStyleProject(); | ||
AuthorizationCheckBuilder checker = new AuthorizationCheckBuilder(); | ||
p.getBuildersList().add(checker); | ||
|
||
p.addProperty(new AuthorizeProjectProperty(new NullAuthorizeProjectStrategy())); | ||
|
||
j.assertBuildStatusSuccess(p.scheduleBuild2(0)); | ||
assertEquals(ACL.SYSTEM, checker.authentication); | ||
} | ||
} | ||
|
||
@Test | ||
public void testWorkForMatrixProject() throws Exception { | ||
// if not configured, run in SYSTEM privilege. | ||
{ | ||
MatrixProject p = j.createMatrixProject(); | ||
p.setAxes(new AxisList(new TextAxis("axis1", "value1"))); | ||
AuthorizationCheckBuilder checker = new AuthorizationCheckBuilder(); | ||
p.getBuildersList().add(checker); | ||
|
||
j.assertBuildStatusSuccess(p.scheduleBuild2(0)); | ||
assertEquals(ACL.SYSTEM, checker.authentication); | ||
} | ||
|
||
// if configured, AuthorizeProjectStrategy takes effect | ||
{ | ||
MatrixProject p = j.createMatrixProject(); | ||
p.setAxes(new AxisList(new TextAxis("axis1", "value1"))); | ||
AuthorizationCheckBuilder checker = new AuthorizationCheckBuilder(); | ||
p.getBuildersList().add(checker); | ||
|
||
p.addProperty(new AuthorizeProjectProperty(new AnonymousAuthorizationStrategy())); | ||
|
||
j.assertBuildStatusSuccess(p.scheduleBuild2(0)); | ||
assertEquals(Jenkins.ANONYMOUS, checker.authentication); | ||
} | ||
|
||
// if configured wrong, run in SYSTEM privilege. | ||
{ | ||
MatrixProject p = j.createMatrixProject(); | ||
p.setAxes(new AxisList(new TextAxis("axis1", "value1"))); | ||
AuthorizationCheckBuilder checker = new AuthorizationCheckBuilder(); | ||
p.getBuildersList().add(checker); | ||
|
||
p.addProperty(new AuthorizeProjectProperty(null)); | ||
|
||
j.assertBuildStatusSuccess(p.scheduleBuild2(0)); | ||
assertEquals(ACL.SYSTEM, checker.authentication); | ||
} | ||
|
||
// if the strategy returns null, run in SYSTEM privilege. | ||
{ | ||
MatrixProject p = j.createMatrixProject(); | ||
p.setAxes(new AxisList(new TextAxis("axis1", "value1"))); | ||
AuthorizationCheckBuilder checker = new AuthorizationCheckBuilder(); | ||
p.getBuildersList().add(checker); | ||
|
||
p.addProperty(new AuthorizeProjectProperty(new NullAuthorizeProjectStrategy())); | ||
|
||
j.assertBuildStatusSuccess(p.scheduleBuild2(0)); | ||
assertEquals(ACL.SYSTEM, checker.authentication); | ||
} | ||
} | ||
} |