org.jvnet.hudson.test.Issue Java Examples
The following examples show how to use
org.jvnet.hudson.test.Issue.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: PipelineNodeTest.java From blueocean-plugin with MIT License | 6 votes |
@Issue("JENKINS-47158") @Test public void syntheticParallelFlowNodeNotSaved() throws Exception { WorkflowJob p = j.jenkins.createProject(WorkflowJob.class, "pipeline1"); p.setDefinition(new CpsFlowDefinition("parallel a: {\n" + " node {\n" + " echo 'a'\n" + " }\n" + "}, b: {\n" + " node {\n" + " echo 'b'\n" + " }\n" + "}\n", true)); WorkflowRun b = j.buildAndAssertSuccess(p); get("/organizations/jenkins/pipelines/pipeline1/runs/1/nodes/", List.class); FlowExecution rawExec = b.getExecution(); assert (rawExec instanceof CpsFlowExecution); CpsFlowExecution execution = (CpsFlowExecution) rawExec; File storage = execution.getStorageDir(); // Nodes 5 and 6 are the parallel branch start nodes. Make sure no "5-parallel-synthetic.xml" and "6..." files // exist in the storage directory, showing we haven't saved them. assertFalse(new File(storage, "5-parallel-synthetic.xml").exists()); assertFalse(new File(storage, "6-parallel-synthetic.xml").exists()); }
Example #2
Source File: AbsolutePathGeneratorITest.java From warnings-ng-plugin with MIT License | 6 votes |
/** * Verifies that the affected files will be copied even if the file name uses the wrong case (Windows only). */ @Test @Issue("JENKINS-58824") public void shouldMapIssueToAffectedFileIfPathIsInWrongCase() { assumeThat(isWindows()).as("Running not on Windows").isTrue(); Slave agent = createAgentWithWrongWorkspaceFolder(); FreeStyleProject project = createJobForAgent(agent); FilePath folder = createFolder(agent, project); createFileInAgentWorkspace(agent, project, "Folder/Test.java", SOURCE_CODE); createFileInAgentWorkspace(agent, project, "warnings.txt", "[javac] " + getAbsolutePathInLowerCase(folder) + ":1: warning: Test Warning for Jenkins"); Java javaJob = new Java(); javaJob.setPattern("warnings.txt"); enableWarnings(project, javaJob); AnalysisResult result = scheduleSuccessfulBuild(project); assertThat(result).hasTotalSize(1); assertThat(result).hasInfoMessages("-> resolved paths in source directory (1 found, 0 not found)"); assertThat(result).doesNotHaveInfoMessages("-> 0 copied, 1 not in workspace, 0 not-found, 0 with I/O error"); }
Example #3
Source File: SummaryTest.java From warnings-ng-plugin with MIT License | 6 votes |
@Test @Issue("SECURITY-1373") void shouldSanitizeName() { AnalysisResult analysisResult = createAnalysisResult(EMPTY_ORIGINS, 0, 0, Lists.immutable.of("Error 1", "Error 2"), 0); Locale.setDefault(Locale.ENGLISH); LabelProviderFactoryFacade facade = mock(LabelProviderFactoryFacade.class); StaticAnalysisLabelProvider checkStyleLabelProvider = createLabelProvider("checkstyle", "<b>CheckStyle</b> <script>execute</script>"); when(facade.get("checkstyle")).thenReturn(checkStyleLabelProvider); Summary summary = new Summary(checkStyleLabelProvider, analysisResult, facade); setResetReferenceAction(summary, false); String createdHtml = summary.create(); assertThat(createdHtml).contains("<b>CheckStyle</b>"); assertThat(createdHtml).doesNotContain("<script>execute</script>"); }
Example #4
Source File: RunMultiThreadLoadTest.java From blueocean-plugin with MIT License | 6 votes |
@Test @Issue( "JENKINS-52101" ) public void load_runs_multi_threaded_no_runs() throws Exception { URL resource = Resources.getResource( getClass(), "RunMultiThreadLoadTest.jenkinsfile"); String jenkinsFile = Resources.toString( resource, Charsets.UTF_8); WorkflowJob p = j.createProject( WorkflowJob.class, "project2"); p.setDefinition(new CpsFlowDefinition( jenkinsFile, false)); p.save(); Iterable<BlueRun> blueRuns = RunSearch.findRuns( p, null, 0, 0 ); List<BlueRun> runs = StreamSupport.stream( blueRuns.spliterator(), false ) .collect(Collectors.toList()); Assert.assertTrue( runs.isEmpty() ); Assert.assertEquals( 0, runs.size() ); }
Example #5
Source File: S3UploadStepIntegrationTest.java From pipeline-aws-plugin with Apache License 2.0 | 6 votes |
@Issue("JENKINS-49025") @Test public void smokes() throws Exception { String globalCredentialsId = "x"; StandardUsernamePasswordCredentials key = new UsernamePasswordCredentialsImpl(CredentialsScope.GLOBAL, globalCredentialsId, "x", "x", "x"); SystemCredentialsProvider.getInstance().getCredentials().add(key); WorkflowJob p = r.jenkins.createProject(WorkflowJob.class, "p"); p.setDefinition(new CpsFlowDefinition( "node('" + r.createSlave().getNodeName() + "') {\n" + " withAWS (credentials: '" + globalCredentialsId + "') {\n" + " writeFile file: 'x', text: ''\n" + " try {\n" + " s3Upload bucket: 'x', file: 'x', path: 'x'\n" + " fail 'should not have worked'\n" + " } catch (com.amazonaws.services.s3.model.AmazonS3Exception x) {\n" + " echo(/got $x as expected/)\n" + " }\n" + " }\n" + "}\n", true) ); r.assertBuildStatusSuccess(p.scheduleBuild2(0)); }
Example #6
Source File: GraphBuilderTest.java From blueocean-plugin with MIT License | 6 votes |
@Test @Issue("JENKINS-56383") public void multipleParallelsRegression() throws Exception { WorkflowRun run = createAndRunJob("JENKINS-56383", "JENKINS-56383.jenkinsfile"); NodeGraphBuilder graph = NodeGraphBuilder.NodeGraphBuilderFactory.getInstance(run); List<FlowNodeWrapper> nodes = graph.getPipelineNodes(); assertStageAndEdges(nodes, "Top1", "TOP1-P1", "TOP1-P2"); assertStageAndEdges(nodes, "TOP1-P1", "TOP2"); assertStageAndEdges(nodes, "TOP1-P2", "TOP2"); assertStageAndEdges(nodes, "TOP2", "TOP2-P1", "TOP2-P2"); assertStageAndEdges(nodes, "TOP2-P1", "TOP3"); assertStageAndEdges(nodes, "TOP2-P2", "TOP3"); assertStageAndEdges(nodes, "TOP3"); assertEquals("Unexpected stages in graph", 7, nodes.size()); }
Example #7
Source File: ModelValidationTest.java From warnings-ng-plugin with MIT License | 6 votes |
@Test @Issue("JENKINS-55293") void doCheckHealthyShouldBeNotOkWithInvalidValues() { ModelValidation model = new ModelValidation(); assertThat(model.validateHealthy(-1, 0)) .isError().hasMessage(Messages.FieldValidator_Error_NegativeThreshold()); assertThat(model.validateUnhealthy(-1, 0)).isOk(); assertThat(model.validateHealthy(0, 1)) .isError().hasMessage(Messages.FieldValidator_Error_NegativeThreshold()); assertThat(model.validateUnhealthy(0, 1)).isOk(); assertThat(model.validateHealthy(1, 0)).isOk(); assertThat(model.validateUnhealthy(1, 0)) .isError().hasMessage(Messages.FieldValidator_Error_ThresholdUnhealthyMissing()); assertThat(model.validateHealthy(1, 1)) .isError().hasMessage(Messages.FieldValidator_Error_ThresholdOrder()); assertThat(model.validateUnhealthy(1, 1)) .isError().hasMessage(Messages.FieldValidator_Error_ThresholdOrder()); assertThat(model.validateHealthy(1, -1)).isOk(); assertThat(model.validateUnhealthy(1, -1)) .isError().hasMessage(Messages.FieldValidator_Error_NegativeThreshold()); }
Example #8
Source File: PipelineMavenPluginDaoAbstractTest.java From pipeline-maven-plugin with MIT License | 6 votes |
/** * Verify backward compatibility: some old entries have `generated_artifact.version == null` */ @Issue("JENKINS-57332") @Test public void get_generated_artifacts_with_null_version() { dao.getOrCreateBuildPrimaryKey("my-upstream-pipeline-1", 1); dao.recordGeneratedArtifact("my-upstream-pipeline-1", 1, "com.mycompany", "core", null, "jar", "1.0-SNAPSHOT", null, false, "jar", null); dao.updateBuildOnCompletion("my-upstream-pipeline-1", 1, Result.SUCCESS.ordinal, System.currentTimeMillis()-100, 11); List<MavenArtifact> generatedArtifacts = dao.getGeneratedArtifacts("my-upstream-pipeline-1", 1); System.out.println("GeneratedArtifacts " + generatedArtifacts.stream().map(mavenArtifact -> mavenArtifact.getId() + ", version: " + mavenArtifact.getVersion() + ", baseVersion: " + mavenArtifact.getBaseVersion()).collect(Collectors.joining(", "))); assertThat(generatedArtifacts.size(), is(1)); MavenArtifact jar = generatedArtifacts.get(0); assertThat(jar.getId(), is("com.mycompany:core:jar:1.0-SNAPSHOT")); assertThat(jar.getVersion(), is("1.0-SNAPSHOT")); assertThat(jar.getBaseVersion(), is("1.0-SNAPSHOT")); }
Example #9
Source File: PipelineMavenPluginDaoAbstractTest.java From pipeline-maven-plugin with MIT License | 6 votes |
@Issue("JENKINS-57332") @Test public void get_generated_artifacts_with_timestamped_snapshot_version() { dao.getOrCreateBuildPrimaryKey("my-upstream-pipeline-1", 1); dao.recordGeneratedArtifact("my-upstream-pipeline-1", 1, "com.mycompany", "core", "1.0-20170808.155524-63", "jar", "1.0-SNAPSHOT", null, false, "jar", null); dao.updateBuildOnCompletion("my-upstream-pipeline-1", 1, Result.SUCCESS.ordinal, System.currentTimeMillis()-100, 11); List<MavenArtifact> generatedArtifacts = dao.getGeneratedArtifacts("my-upstream-pipeline-1", 1); System.out.println("GeneratedArtifacts " + generatedArtifacts.stream().map(mavenArtifact -> mavenArtifact.getId() + ", version: " + mavenArtifact.getVersion() + ", baseVersion: " + mavenArtifact.getBaseVersion()).collect(Collectors.joining(", "))); assertThat(generatedArtifacts.size(), is(1)); MavenArtifact jar = generatedArtifacts.get(0); assertThat(jar.getId(), is("com.mycompany:core:jar:1.0-SNAPSHOT")); assertThat(jar.getVersion(), is("1.0-20170808.155524-63")); assertThat(jar.getBaseVersion(), is("1.0-SNAPSHOT")); }
Example #10
Source File: Security1446Test.java From configuration-as-code-plugin with MIT License | 6 votes |
@Test @Issue("SECURITY-1446") public void testExportWithEnvVar() throws Exception { final String message = "Hello, world! PATH=${PATH} JAVA_HOME=^${JAVA_HOME}"; ConfiguratorRegistry registry = ConfiguratorRegistry.get(); ConfigurationContext context = new ConfigurationContext(registry); DataBoundConfigurator<UsernamePasswordCredentialsImpl> configurator = new DataBoundConfigurator<>(UsernamePasswordCredentialsImpl.class); UsernamePasswordCredentialsImpl creds = new UsernamePasswordCredentialsImpl(CredentialsScope.GLOBAL, "test", message, "foo", "bar"); final CNode config = configurator.describe(creds, context); final Node valueNode = ConfigurationAsCode.get().toYaml(config); final String exported; try (StringWriter writer = new StringWriter()) { ConfigurationAsCode.serializeYamlNode(valueNode, writer); exported = writer.toString(); } catch (IOException e) { throw new YAMLException(e); } assertThat("Message was not escaped", exported, not(containsString(message))); assertThat("Improper masking for PATH", exported, containsString("^${PATH}")); assertThat("Improper masking for JAVA_HOME", exported, containsString("^^${JAVA_HOME}")); }
Example #11
Source File: DataBoundConfiguratorTest.java From configuration-as-code-plugin with MIT License | 6 votes |
@Test @Issue("PR #838, Issue #222") public void export_mapping_should_not_be_null() throws Exception { j.createFreeStyleProject("testJob1"); ConfigurationAsCode casc = ConfigurationAsCode.get(); casc.configure(this.getClass().getResource("DataBoundDescriptorNonNull.yml") .toString()); ConfiguratorRegistry registry = ConfiguratorRegistry.get(); ConfigurationContext context = new ConfigurationContext(registry); final Mapping configNode = getJenkinsRoot(context); final CNode viewsNode = configNode.get("views"); Mapping listView = viewsNode.asSequence().get(1).asMapping().get("list").asMapping(); Mapping otherListView = viewsNode.asSequence().get(2).asMapping().get("list").asMapping(); Sequence listViewColumns = listView.get("columns").asSequence(); Sequence otherListViewColumns = otherListView.get("columns").asSequence(); assertNotNull(listViewColumns); assertEquals(6, listViewColumns.size()); assertNotNull(otherListViewColumns); assertEquals(7, otherListViewColumns.size()); assertEquals("loggedInUsersCanDoAnything", configNode.getScalarValue("authorizationStrategy")); assertEquals("plainText", configNode.getScalarValue("markupFormatter")); }
Example #12
Source File: SGECloudTest.java From configuration-as-code-plugin with MIT License | 6 votes |
@Test @Issue("SECURITY-1458") public void shouldNotExportPassword() throws Exception { ConfigurationAsCode casc = ConfigurationAsCode.get(); final String passwordText = "Hello, world!"; BatchCloud cloud = new BatchCloud("testBatchCloud", "whatever", "sge", 5, "sge.acmecorp.com", 8080, "username", passwordText); j.jenkins.clouds.add(cloud); StringWriter writer = new StringWriter(); casc.export(new WriterOutputStream(writer, StandardCharsets.UTF_8)); String exported = writer.toString(); assertThat("Password should not have been exported", exported, not(containsString(passwordText))); }
Example #13
Source File: SSHCredentialsTest.java From configuration-as-code-plugin with MIT License | 6 votes |
@Test @ConfiguredWithCode("SSHCredentialsTest.yml") @Issue("SECURITY-1279") public void shouldNotExportOrLogCredentials() throws Exception { StandardUsernamePasswordCredentials creds = getCredentials(StandardUsernamePasswordCredentials.class); assertEquals(CREDENTIALS_PASSWORD, creds.getPassword().getPlainText()); assertNotInLog(logging, CREDENTIALS_PASSWORD); BasicSSHUserPrivateKey certKey = getCredentials(BasicSSHUserPrivateKey.class); // JENKINS-50181 made getPrivateKey always append a trailing newline. assertEquals(PRIVATE_KEY + "\n", certKey.getPrivateKey()); assertNotInLog(logging, PRIVATE_KEY); // Verify that the password does not get exported String exportedConfig = j.exportToString(false); assertThat("There should be no password in the exported YAML", exportedConfig, not(containsString(CREDENTIALS_PASSWORD))); assertThat("There should be no private key in the exported YAML", exportedConfig, not(containsString(PRIVATE_KEY))); }
Example #14
Source File: PipelineNodeTest.java From blueocean-plugin with MIT License | 6 votes |
@Test @Issue("JENKINS-49050") public void parallelStagesNonNested() throws Exception { WorkflowJob p = createWorkflowJobWithJenkinsfile(getClass(), "parallelStagesNonNested.jenkinsfile"); Slave s = j.createOnlineSlave(); s.setLabelString("foo"); s.setNumExecutors(2); // Run until completed WorkflowRun run = p.scheduleBuild2(0).waitForStart(); j.waitForCompletion(run); PipelineNodeGraphVisitor pipelineNodeGraphVisitor = new PipelineNodeGraphVisitor(run); List<FlowNodeWrapper> wrappers = pipelineNodeGraphVisitor.getPipelineNodes(); assertEquals(3, wrappers.size()); List<Map> nodes = get("/organizations/jenkins/pipelines/" + p.getName() + "/runs/1/nodes/", List.class); assertEquals(3, nodes.size()); }
Example #15
Source File: PipelineImplTest.java From blueocean-plugin with MIT License | 6 votes |
@Test @Issue("JENKINS-55497") public void testPipelineRunSummaryHasChangeSet() throws Exception { String jenkinsFile = Resources.toString(Resources.getResource(getClass(), "singleScm.jenkinsfile"), Charsets.UTF_8).replaceAll("%REPO%", sampleRepo.toString()); WorkflowJob p = j.createProject(WorkflowJob.class, "project"); p.setDefinition(new CpsFlowDefinition(jenkinsFile, true)); p.save(); sampleRepo.init(); j.assertBuildStatus(Result.SUCCESS, p.scheduleBuild2(0)); // create a commit to populate the changeSet for the second run sampleRepo.write("file1", ""); sampleRepo.git("add", "file1"); sampleRepo.git("commit", "--message=init"); Run r = j.assertBuildStatus(Result.SUCCESS, p.scheduleBuild2(0)); // confirm the changeSet retrieved from the latestRun details for the project is not empty Map<String, Object> runDetails = get("/organizations/jenkins/pipelines/" + p.getName() + "/runs/" + r.getId() + "/"); List<Object> changeSet = (ArrayList) runDetails.get("changeSet"); assertTrue(!changeSet.isEmpty()); }
Example #16
Source File: GlobalLibrariesTest.java From configuration-as-code-plugin with MIT License | 6 votes |
@Issue("JENKINS-57557") @Test @ConfiguredWithCode("GlobalLibrariesGitHubTest.yml") public void configure_global_library_using_github() throws Exception { assertEquals(1, GlobalLibraries.get().getLibraries().size()); final LibraryConfiguration library = GlobalLibraries.get().getLibraries().get(0); assertEquals("jenkins-pipeline-lib", library.getName()); final SCMSourceRetriever retriever = (SCMSourceRetriever) library.getRetriever(); final GitHubSCMSource scm = (GitHubSCMSource) retriever.getScm(); assertEquals("e43d6600-ba0e-46c5-8eae-3989bf654055", scm.getId()); assertEquals("jenkins-infra", scm.getRepoOwner()); assertEquals("pipeline-library", scm.getRepository()); assertEquals(3, scm.getTraits().size()); final BranchDiscoveryTrait branchDiscovery = (BranchDiscoveryTrait) scm.getTraits().get(0); assertEquals(1, branchDiscovery.getStrategyId()); final OriginPullRequestDiscoveryTrait prDiscovery = (OriginPullRequestDiscoveryTrait) scm.getTraits().get(1); assertEquals(2, prDiscovery.getStrategyId()); final ForkPullRequestDiscoveryTrait forkDiscovery = (ForkPullRequestDiscoveryTrait) scm.getTraits().get(2); assertEquals(3, forkDiscovery.getStrategyId()); assertThat(forkDiscovery.getTrust(), instanceOf(TrustPermission.class)); }
Example #17
Source File: AdminWhitelistRuleConfiguratorTest.java From configuration-as-code-plugin with MIT License | 5 votes |
@Test @Issue("Issue #28") @ConfiguredWithCode("AdminWhitelistRuleConfigurator/Agent2MasterSecurityKillSwitch_enabled.yml") public void checkM2ASecurityKillSwitch_disabled() { final Jenkins jenkins = Jenkins.get(); AdminWhitelistRule rule = jenkins.getInjector().getInstance(AdminWhitelistRule.class); Assert.assertFalse("MasterToAgent Security should be disabled", rule.getMasterKillSwitch()); }
Example #18
Source File: DataBoundConfiguratorTest.java From configuration-as-code-plugin with MIT License | 5 votes |
@Test @Issue("#1025") public void packageParametersAreNonnullByDefaultButCanBeNullable() throws Exception { Mapping config = new Mapping(); ConfiguratorRegistry registry = ConfiguratorRegistry.get(); final PackageParametersNonNullCheckForNull configured = (PackageParametersNonNullCheckForNull) registry .lookupOrFail(PackageParametersNonNullCheckForNull.class) .configure(config, new ConfigurationContext(registry)); assertNull(configured.getSecret()); }
Example #19
Source File: DataBoundConfiguratorTest.java From configuration-as-code-plugin with MIT License | 5 votes |
@Test @Issue("SECURITY-1497") public void shouldNotLogSecretsForUndefinedConstructors() throws Exception { Mapping config = new Mapping(); config.put("secret", "mySecretValue"); ConfiguratorRegistry registry = ConfiguratorRegistry.get(); registry.lookupOrFail(SecretHolderWithString.class).configure(config, new ConfigurationContext(registry)); assertLogContains(logging, "secret"); assertNotInLog(logging, "mySecretValue"); }
Example #20
Source File: AdminWhitelistRuleConfiguratorTest.java From configuration-as-code-plugin with MIT License | 5 votes |
@Test @Issue("Issue #172") @ConfiguredWithCode("AdminWhitelistRuleConfigurator/Agent2MasterSecurityKillSwitch_disabled.yml") public void checkA2MAccessControl_disable() throws Exception { final Jenkins jenkins = Jenkins.get(); MasterKillSwitchConfiguration config = jenkins.getDescriptorByType(MasterKillSwitchConfiguration.class); Assert.assertFalse("Agent → Master Access Control should be disabled", config.getMasterToSlaveAccessControl()); AdminWhitelistRule rule = jenkins.getInjector().getInstance(AdminWhitelistRule.class); ConfiguratorRegistry registry = ConfiguratorRegistry.get(); ConfigurationContext context = new ConfigurationContext(registry); final Configurator c = context.lookupOrFail(AdminWhitelistRule.class); final CNode node = c.describe(rule, context); final Mapping agent = node.asMapping(); assertEquals("false", agent.get("enabled").toString()); }
Example #21
Source File: JenkinsConfiguratorTest.java From configuration-as-code-plugin with MIT License | 5 votes |
@Test @Issue("Issue #173") @ConfiguredWithCode("SetEnvironmentVariable.yml") public void shouldSetEnvironmentVariable() throws Exception { final DescribableList<NodeProperty<?>, NodePropertyDescriptor> properties = Jenkins.get().getNodeProperties(); EnvVars env = new EnvVars(); for (NodeProperty<?> property : properties) { property.buildEnvVars(env, TaskListener.NULL); } assertEquals("BAR", env.get("FOO")); }
Example #22
Source File: ArtifactsSecurity564.java From blueocean-plugin with MIT License | 5 votes |
/** * Uses matrix-auth to provide artifacts permission. * * If hudson.security.ArtifactsPermission is set then the user must have Run.ARTIFACTS set. * * @throws Exception */ @Issue("SECURITY-564") @Test public void testArtifactsWithPermissions() throws Exception { String JOB_NAME = "artifactPermissions"; String artifactPath = "a/b/c"; HudsonPrivateSecurityRealm realm = new HudsonPrivateSecurityRealm(false); realm.createAccount("alice","alice"); realm.createAccount("bob","bob"); j.jenkins.setSecurityRealm(realm); GlobalMatrixAuthorizationStrategy as = new GlobalMatrixAuthorizationStrategy(); j.jenkins.setAuthorizationStrategy(as); as.add(Hudson.READ,"alice"); as.add(Item.READ,"alice"); as.add(Run.ARTIFACTS,"alice"); as.add(Hudson.READ,"bob"); as.add(Item.READ,"bob"); FreeStyleProject p = j.createFreeStyleProject(JOB_NAME); p.getBuildersList().add(new ArtifactBuilder(artifactPath, 100)); p.getPublishersList().add(new ArtifactArchiver("**/*")); Run r = p.scheduleBuild2(0).waitForStart(); r = j.waitForCompletion(r); List artifacts = request().authAlice().get("/organizations/jenkins/pipelines/"+JOB_NAME+"/runs/"+r.getId()+"/artifacts").build(List.class); Assert.assertEquals(100, artifacts.size()); Assert.assertEquals(0, ((Map) artifacts.get(0)).get("size")); Assert.assertEquals(artifactPath + "/0.txt", ((Map) artifacts.get(0)).get("path")); Assert.assertEquals("/job/artifactPermissions/1/artifact/"+ artifactPath +"/0.txt", ((Map) artifacts.get(0)).get("url")); List artifactsBob = request().auth("bob", "bob").get("/organizations/jenkins/pipelines/"+JOB_NAME+"/runs/"+r.getId()+"/artifacts").build(List.class); Assert.assertEquals(0, artifactsBob.size()); }
Example #23
Source File: CustomToolsTest.java From configuration-as-code-plugin with MIT License | 5 votes |
@Test @Issue("#97") @Ignore @ConfiguredWithCode(value = "CustomToolsTest.yml") public void configure_custom_tools() throws Exception { DescriptorImpl descriptor = (DescriptorImpl) j.jenkins.getDescriptorOrDie(CustomTool.class); assertEquals(1, descriptor.getInstallations().length); final CustomTool customTool = descriptor.getInstallations()[0]; final InstallSourceProperty source = customTool.getProperties().get(InstallSourceProperty.class); assertNotNull(source); final CommandInstaller installer = source.installers.get(CommandInstaller.class); assertNotNull(installer); assertEquals("/bin/my-tool", installer.getToolHome()); }
Example #24
Source File: RoleStrategyTest.java From configuration-as-code-plugin with MIT License | 5 votes |
@Test @Issue("Issue #214") @ConfiguredWithCode("RoleStrategy2.yml") public void shouldHandleNullItemsAndAgentsCorrectly() throws Exception { AuthorizationStrategy s = j.jenkins.getAuthorizationStrategy(); assertThat("Authorization Strategy has been read incorrectly", s, instanceOf(RoleBasedAuthorizationStrategy.class)); RoleBasedAuthorizationStrategy rbas = (RoleBasedAuthorizationStrategy) s; Map<Role, Set<String>> globalRoles = rbas.getGrantedRoles(RoleBasedAuthorizationStrategy.GLOBAL); assertThat(globalRoles.size(), equalTo(2)); }
Example #25
Source File: WithMavenStepTest.java From pipeline-maven-plugin with MIT License | 5 votes |
@Issue("SECURITY-441") @Test public void maven_build_on_remote_agent_with_settings_file_on_master_fails() throws Exception { File onMaster = new File(jenkinsRule.jenkins.getRootDir(), "onmaster"); String secret = "secret content on master"; FileUtils.writeStringToFile(onMaster, secret); String pipelineScript = "node('remote') {withMaven(mavenSettingsFilePath: '" + onMaster + "') {echo readFile(MVN_SETTINGS)}}"; WorkflowJob p = jenkinsRule.createProject(WorkflowJob.class, "p"); p.setDefinition(new CpsFlowDefinition(pipelineScript, true)); WorkflowRun b = jenkinsRule.assertBuildStatus(Result.FAILURE, p.scheduleBuild2(0)); jenkinsRule.assertLogNotContains(secret, b); }
Example #26
Source File: FreeStylePipelineTest.java From blueocean-plugin with MIT License | 5 votes |
@Test @Issue("JENKINS-51716") public void findNonNumericRun() throws Exception { FreeStyleProject freestyle = Mockito.spy(j.createProject(FreeStyleProject.class, "freestyle")); FreeStyleBuild build1 = Mockito.mock(FreeStyleBuild.class); FreeStyleBuild build2 = Mockito.mock(FreeStyleBuild.class); Mockito.when(build1.getId()).thenReturn("build1"); Mockito.when(build1.getParent()).thenReturn(freestyle); Mockito.when(build1.getNextBuild()).thenReturn(build2); Mockito.when(build2.getId()).thenReturn("build2"); Mockito.when(build2.getParent()).thenReturn(freestyle); Mockito.when(build2.getPreviousBuild()).thenReturn(build1); RunList<FreeStyleBuild> runs = RunList.fromRuns(Arrays.asList(build1, build2)); Mockito.doReturn(runs).when(freestyle).getBuilds(); Mockito.doReturn(build2).when(freestyle).getLastBuild(); FreeStylePipeline freeStylePipeline = (FreeStylePipeline) BluePipelineFactory.resolve(freestyle); assertNotNull(freeStylePipeline); BlueRun blueRun = freeStylePipeline.getLatestRun(); assertNotNull(blueRun); Links links = blueRun.getLinks(); assertNotNull(links); assertNotNull(links.get("self")); }
Example #27
Source File: MailExtTest.java From configuration-as-code-plugin with MIT License | 5 votes |
@Test @ConfiguredWithCode("MailExtTest.yml") @Issue("SECURITY-1404") public void shouldNotExportOrLogCredentials() throws Exception { assertEquals(SMTP_PASSWORD, ExtendedEmailPublisher.descriptor().getSmtpPassword().getPlainText()); assertLogContains(logging, "smtpPassword ="); assertNotInLog(logging, SMTP_PASSWORD); // Verify that the password does not get exported String exportedConfig = j.exportToString(false); assertThat("No entry was exported for SMTP credentials", exportedConfig, containsString("smtpPassword")); assertThat("There should be no SMTP password in the exported YAML", exportedConfig, not(containsString(SMTP_PASSWORD))); }
Example #28
Source File: DockerWorkflowSymbolTest.java From configuration-as-code-plugin with MIT License | 5 votes |
@Test @Issue("1260") public void export_global_definition() throws Exception { ConfiguratorRegistry registry = ConfiguratorRegistry.get(); ConfigurationContext context = new ConfigurationContext(registry); CNode yourAttribute = getUnclassifiedRoot(context).get("pipeline-model-docker"); String exported = toYamlString(yourAttribute); String expected = toStringFromYamlFile(this, "DockerWorkflowSymbolExpected.yml"); assertThat(exported, is(expected)); }
Example #29
Source File: PipelineRunImplTest.java From blueocean-plugin with MIT License | 5 votes |
@Test @Issue("JENKINS-53019") public void changelogFromReplayDeleted() throws Exception { String jenkinsFile = Resources.toString(Resources.getResource(getClass(), "mulitpleScms.jenkinsfile"), Charsets.UTF_8).replaceAll("%REPO1%", sampleRepo1.toString()).replaceAll("%REPO2%", sampleRepo2.toString()); WorkflowJob p = j.createProject(WorkflowJob.class, "project"); p.setDefinition(new CpsFlowDefinition(jenkinsFile, true)); p.save(); sampleRepo1.init(); sampleRepo2.init(); j.assertBuildStatus(Result.SUCCESS, p.scheduleBuild2(0)); updateREADME(sampleRepo1); updateREADME(sampleRepo2); TimeUnit.SECONDS.sleep( 1); updateREADME(sampleRepo2); TimeUnit.SECONDS.sleep(1); Run run2 = j.assertBuildStatus(Result.SUCCESS, p.scheduleBuild2(0)); ReplayAction replayAction = run2.getAction(ReplayAction.class); Run run3 = j.assertBuildStatus(Result.SUCCESS, replayAction.run(replayAction.getOriginalScript(), replayAction.getOriginalLoadedScripts())); run2.delete(); Map<String, Object> runDetails = get("/organizations/jenkins/pipelines/" + p.getName() + "/runs/" + run3.getId() + "/"); assertEquals(0, ((ArrayList) runDetails.get("changeSet")).size()); }
Example #30
Source File: GraphBuilderTest.java From blueocean-plugin with MIT License | 5 votes |
@Test @Issue("JENKINS-43292") public void parallelFailFast() throws Exception { WorkflowRun run = createAndRunJob("parallelFailFast", "parallelFailFast.jenkinsfile", Result.FAILURE); NodeGraphBuilder graph = NodeGraphBuilder.NodeGraphBuilderFactory.getInstance(run); List<FlowNodeWrapper> nodes = graph.getPipelineNodes(); assertStageAndEdges(nodes, "Parallel", BlueRun.BlueRunState.FINISHED, BlueRun.BlueRunResult.FAILURE, "aborts", "fails", "succeeds"); assertStageAndEdges(nodes, "aborts", BlueRun.BlueRunState.FINISHED, BlueRun.BlueRunResult.ABORTED); assertStageAndEdges(nodes, "fails", BlueRun.BlueRunState.FINISHED, BlueRun.BlueRunResult.FAILURE); assertStageAndEdges(nodes, "succeeds", BlueRun.BlueRunState.FINISHED, BlueRun.BlueRunResult.SUCCESS); assertEquals("Unexpected stages in graph", 4, nodes.size()); }