/** Test that spaces are encoded as %20 for project name, axis name and axis value. */ @Test public void spaceInUrl() { MatrixProject mp = new MatrixProject("matrix test"); MatrixConfiguration mc = new MatrixConfiguration(mp, Combination.fromString("foo bar=baz bat")); assertEquals("job/matrix%20test/", mp.getUrl()); assertEquals("job/matrix%20test/foo%20bar=baz%20bat/", mc.getUrl()); }
@Test public void api() throws Exception { MatrixProject project = j.createMatrixProject(); project.setAxes(new AxisList(new Axis("FOO", "abc", "def"), new Axis("BAR", "uvw", "xyz"))); XmlPage xml = j.createWebClient().goToXml(project.getUrl() + "api/xml"); assertEquals(4, xml.getByXPath("//matrixProject/activeConfiguration").size()); }
/** Fingerprinter failed to work on the matrix project. */ @Email("http://www.nabble.com/1.286-version-and-fingerprints-option-broken-.-td22236618.html") public void testFingerprinting() throws Exception { MatrixProject p = createMatrixProject(); p.getBuildersList().add(new Shell("touch p")); p.getPublishersList().add(new ArtifactArchiver("p", null, false)); p.getPublishersList().add(new Fingerprinter("", true)); assertBuildStatusSuccess(p.scheduleBuild2(0).get()); }
@Issue("JENKINS-27162") @Test public void completedLogging() throws Exception { MatrixProject project = j.createMatrixProject(); project.setAxes(new AxisList(new Axis("axis", "a", "b"))); ((DefaultMatrixExecutionStrategyImpl) project.getExecutionStrategy()) .setTouchStoneCombinationFilter("axis == 'a'"); MatrixBuild build = project.scheduleBuild2(0).get(); j.assertLogContains("test0 » a completed with result SUCCESS", build); j.assertLogContains("test0 » b completed with result SUCCESS", build); }
@Override protected MatrixProject createMatrixProject() throws IOException { MatrixProject p = super.createMatrixProject(); // set up 2x2 matrix AxisList axes = new AxisList(); axes.add(new Axis("db", "mysql", "oracle")); axes.add(new Axis("direction", "north", "south")); p.setAxes(axes); return p; }
@Issue("SECURITY-125") @Test public void combinationFilterSecurity() throws Exception { MatrixProject project = j.createMatrixProject(); String combinationFilter = "jenkins.model.Jenkins.getInstance().setSystemMessage('hacked')"; expectRejection(project, combinationFilter, "staticMethod jenkins.model.Jenkins getInstance"); assertNull(j.jenkins.getSystemMessage()); expectRejection( project, combinationFilter, "method jenkins.model.Jenkins setSystemMessage java.lang.String"); assertNull(j.jenkins.getSystemMessage()); project.setCombinationFilter(combinationFilter); assertEquals("you asked for it", "hacked", j.jenkins.getSystemMessage()); }
/** Test that project level permissions apply to child configurations as well. */ @Issue("JENKINS-9293") @Test public void configurationACL() throws Exception { j.jenkins.setAuthorizationStrategy(new ProjectMatrixAuthorizationStrategy()); MatrixProject mp = j.createMatrixProject(); mp.setAxes(new AxisList(new Axis("foo", "a", "b"))); MatrixConfiguration mc = mp.getItem("foo=a"); assertNotNull(mc); SecurityContextHolder.clearContext(); assertFalse(mc.getACL().hasPermission(Item.READ)); mp.addProperty( new AuthorizationMatrixProperty( Collections.singletonMap(Item.READ, Collections.singleton("anonymous")))); // Project-level permission should apply to single configuration too: assertTrue(mc.getACL().hasPermission(Item.READ)); }
/** Tests that axes are available as build variables in the Maven builds. */ public void testBuildAxisInMaven() throws Exception { MatrixProject p = createMatrixProject(); p.getBuildersList().add(new Maven("-Dprop=${db} validate", null)); // we need a dummy build script that echos back our property p.setScm(new SingleFileSCM("pom.xml", getClass().getResource("echo-property.pom"))); MatrixBuild build = p.scheduleBuild2(0).get(); List<MatrixRun> runs = build.getRuns(); assertEquals(4, runs.size()); for (MatrixRun run : runs) { assertBuildStatus(Result.SUCCESS, run); String expectedDb = run.getParent().getCombination().get("db"); System.out.println(run.getLog()); assertLogContains("assertion " + expectedDb + "=" + expectedDb, run); // also make sure that the variables are expanded at the command line level. assertFalse(run.getLog().contains("-Dprop=${db}")); } }
/** Tests that axes are available as build variables in the Ant builds. */ public void testBuildAxisInAnt() throws Exception { MatrixProject p = createMatrixProject(); Ant.AntInstallation ant = configureDefaultAnt(); p.getBuildersList().add(new Ant("-Dprop=${db} test", ant.getName(), null, null, null)); // we need a dummy build script that echos back our property p.setScm( new SingleFileSCM( "build.xml", "<project default='test'><target name='test'><echo>assertion ${prop}=${db}</echo></target></project>")); MatrixBuild build = p.scheduleBuild2(0, new Cause.UserCause()).get(); List<MatrixRun> runs = build.getRuns(); assertEquals(4, runs.size()); for (MatrixRun run : runs) { assertBuildStatus(Result.SUCCESS, run); String expectedDb = run.getParent().getCombination().get("db"); assertLogContains("assertion " + expectedDb + "=" + expectedDb, run); } }
private static void expectRejection( MatrixProject project, String combinationFilter, String signature) throws IOException { ScriptApproval scriptApproval = ScriptApproval.get(); assertEquals(Collections.emptySet(), scriptApproval.getPendingSignatures()); try { project.setCombinationFilter(combinationFilter); } catch (RejectedAccessException x) { assertEquals(Functions.printThrowable(x), signature, x.getSignature()); } Set<ScriptApproval.PendingSignature> pendingSignatures = scriptApproval.getPendingSignatures(); assertEquals(1, pendingSignatures.size()); assertEquals(signature, pendingSignatures.iterator().next().signature); scriptApproval.approveSignature(signature); assertEquals(Collections.emptySet(), scriptApproval.getPendingSignatures()); }