Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/jenkinsci/mailer-plugin i…
Browse files Browse the repository at this point in the history
…nto javamail-migrate
  • Loading branch information
jglick committed Jul 19, 2022
2 parents a7940d9 + c8b085a commit 0f623d4
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 92 deletions.
54 changes: 5 additions & 49 deletions .github/workflows/cd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,52 +8,8 @@ on:
- completed

jobs:
validate:
runs-on: ubuntu-latest
outputs:
should_release: ${{ steps.verify-ci-status.outputs.result == 'success' && steps.interesting-categories.outputs.interesting == 'true' }}
steps:
- name: Verify CI status
uses: jenkins-infra/verify-ci-status-action@v1.2.0
id: verify-ci-status
with:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
output_result: true

- name: Release Drafter
uses: release-drafter/release-drafter@v5
if: steps.verify-ci-status.outputs.result == 'success'
with:
name: next
tag: next
version: next
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Check interesting categories
uses: jenkins-infra/interesting-category-action@v1.0.0
id: interesting-categories
if: steps.verify-ci-status.outputs.result == 'success'
with:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

release:
runs-on: ubuntu-latest
needs: [validate]
if: needs.validate.outputs.should_release == 'true'
steps:
- name: Check out
uses: actions/checkout@v2.3.4
with:
fetch-depth: 0
- name: Set up JDK 8
uses: actions/setup-java@v2
with:
distribution: 'adopt'
java-version: 8
- name: Release
uses: jenkins-infra/jenkins-maven-cd-action@v1.1.0
with:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
MAVEN_USERNAME: ${{ secrets.MAVEN_USERNAME }}
MAVEN_TOKEN: ${{ secrets.MAVEN_TOKEN }}
maven-cd:
uses: jenkins-infra/github-reusable-workflows/.github/workflows/maven-cd.yml@v1
secrets:
MAVEN_USERNAME: ${{ secrets.MAVEN_USERNAME }}
MAVEN_TOKEN: ${{ secrets.MAVEN_TOKEN }}
2 changes: 1 addition & 1 deletion Jenkinsfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
buildPlugin(configurations: [
[ platform: "linux", jdk: "8", jenkins: null ],
[ platform: "windows", jdk: "8", jenkins: null ],
[ platform: "linux", jdk: "11", jenkins: null, javaLevel: 8 ]
[ platform: "linux", jdk: "11", jenkins: null ]
])
12 changes: 6 additions & 6 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<parent>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>plugin</artifactId>
<version>4.32</version>
<version>4.40</version>
<relativePath />
</parent>

Expand All @@ -22,17 +22,17 @@
</licenses>
<properties>
<changelist>999999-SNAPSHOT</changelist>
<java.level>8</java.level>
<jenkins.version>2.331</jenkins.version>
<jenkins.version>2.332.1</jenkins.version>
<gitHubRepo>jenkinsci/${project.artifactId}-plugin</gitHubRepo>
<useBeta>true</useBeta>
</properties>

<dependencyManagement>
<dependencies>
<dependency>
<groupId>io.jenkins.tools.bom</groupId>
<artifactId>bom-weekly</artifactId>
<version>1117.v62a_f6a_01de98</version>
<artifactId>bom-2.332.x</artifactId>
<version>1155.v77b_fd92a_26fc</version>
<scope>import</scope>
<type>pom</type>
</dependency>
Expand Down Expand Up @@ -143,7 +143,7 @@
</dependency>
</dependencies>
<scm>
<connection>scm:git:git://github.com/${gitHubRepo}.git</connection>
<connection>scm:git:https://github.com/${gitHubRepo}.git</connection>
<developerConnection>scm:git:git@github.com:${gitHubRepo}.git</developerConnection>
<url>https://github.com/${gitHubRepo}</url>
<tag>${scmTag}</tag>
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/hudson/cli/MailCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public String getShortDescription() {
}

protected int run() throws Exception {
Jenkins.get().checkPermission(Mailer.DescriptorImpl.getJenkinsManageOrAdmin());
Jenkins.get().checkPermission(Jenkins.MANAGE);
Transport.send(new MimeMessage(Mailer.descriptor().createSession(), stdin));
return 0;
}
Expand Down
22 changes: 4 additions & 18 deletions src/main/java/hudson/tasks/Mailer.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
import edu.umd.cs.findbugs.annotations.CheckForNull;
import edu.umd.cs.findbugs.annotations.NonNull;
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import hudson.Util;

import hudson.BulkChange;
import hudson.EnvVars;
Expand All @@ -41,7 +40,6 @@
import jenkins.plugins.mailer.tasks.i18n.Messages;
import hudson.security.Permission;
import hudson.util.FormValidation;
import hudson.util.ReflectionUtils;
import hudson.util.Secret;
import hudson.util.XStream2;

Expand All @@ -53,7 +51,6 @@
import java.io.File;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.lang.reflect.InvocationTargetException;
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.Date;
Expand Down Expand Up @@ -325,20 +322,9 @@ public DescriptorImpl() {
}

@NonNull
// TODO: Add @Override when Jenkins core baseline is 2.222+
@Override
public Permission getRequiredGlobalConfigPagePermission() {
return getJenkinsManageOrAdmin();
}

// TODO: remove when Jenkins core baseline is 2.222+
public static Permission getJenkinsManageOrAdmin() {
Permission manage;
try { // Manage is available starting from Jenkins 2.222 (https://jenkins.io/changelog/#v2.222). See JEP-223 for more info
manage = (Permission) ReflectionUtils.getPublicProperty(Jenkins.get(), "MANAGE");
} catch (IllegalArgumentException | InvocationTargetException | NoSuchMethodException | IllegalAccessException e) {
manage = Jenkins.ADMINISTER;
}
return manage;
return Jenkins.MANAGE;
}

public String getDisplayName() {
Expand Down Expand Up @@ -670,7 +656,7 @@ public FormValidation doAddressCheck(@QueryParameter String value) {

@RequirePOST
public FormValidation doCheckSmtpHost(@QueryParameter String value) {
Jenkins.get().checkPermission(getJenkinsManageOrAdmin());
Jenkins.get().checkPermission(Jenkins.MANAGE);
try {
if (Util.fixEmptyAndTrim(value)!=null)
InetAddress.getByName(value);
Expand Down Expand Up @@ -709,7 +695,7 @@ public FormValidation doSendTestMail(
@QueryParameter boolean useSsl, @QueryParameter boolean useTls, @QueryParameter String smtpPort, @QueryParameter String charset,
@QueryParameter String sendTestMailTo) throws IOException {
try {
Jenkins.get().checkPermission(DescriptorImpl.getJenkinsManageOrAdmin());
Jenkins.get().checkPermission(Jenkins.MANAGE);
if (!authentication) {
username = null;
password = null;
Expand Down
21 changes: 4 additions & 17 deletions src/test/java/hudson/tasks/MailerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,8 @@
import hudson.model.*;
import hudson.security.ACL;
import hudson.security.ACLContext;
import hudson.security.Permission;
import hudson.slaves.DumbSlave;
import hudson.tasks.Mailer.DescriptorImpl;
import hudson.util.ReflectionUtils;
import hudson.util.Secret;
import org.hamcrest.MatcherAssert;
import org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition;
Expand Down Expand Up @@ -72,6 +70,7 @@
import static org.hamcrest.Matchers.empty;
import static org.hamcrest.Matchers.hasSize;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.nullValue;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNotSame;
Expand Down Expand Up @@ -260,6 +259,8 @@ public void testGlobalConfigRoundtrip() throws Exception {

@Test
public void globalConfig() throws Exception {
Assume.assumeThat("TODO the form elements for email-ext have the same names", rule.getPluginManager().getPlugin("email-ext"), is(nullValue()));

WebClient webClient = rule.createWebClient();
HtmlPage cp = webClient.goTo("configure");
HtmlForm form = cp.getFormByName("config");
Expand Down Expand Up @@ -445,13 +446,6 @@ public void testMigrateOldData() {

@Test
public void managePermissionShouldAccessGlobalConfig() {
Permission jenkinsManage;
try {
jenkinsManage = getJenkinsManage();
} catch (Exception e) {
Assume.assumeTrue("Jenkins baseline is too old for this test (requires Jenkins.MANAGE)", false);
return;
}
final String USER = "user";
final String MANAGER = "manager";
rule.jenkins.setSecurityRealm(rule.createDummySecurityRealm());
Expand All @@ -461,7 +455,7 @@ public void managePermissionShouldAccessGlobalConfig() {

// Read and Manage
.grant(Jenkins.READ).everywhere().to(MANAGER)
.grant(jenkinsManage).everywhere().to(MANAGER)
.grant(Jenkins.MANAGE).everywhere().to(MANAGER)
);

try (ACLContext c = ACL.as(User.getById(USER, true))) {
Expand Down Expand Up @@ -509,13 +503,6 @@ public void doCheckSmtpServerShouldNotThrowForUserWithManagePermissions() {
}
}

// TODO: remove when Jenkins core baseline is 2.222+
private Permission getJenkinsManage() throws NoSuchMethodException, IllegalAccessException,
InvocationTargetException {
// Jenkins.MANAGE is available starting from Jenkins 2.222 (https://jenkins.io/changelog/#v2.222). See JEP-223 for more info
return (Permission) ReflectionUtils.getPublicProperty(Jenkins.get(), "MANAGE");
}

private final class TestProject {
private final FakeChangeLogSCM scm = new FakeChangeLogSCM();
private final FreeStyleProject project;
Expand Down

0 comments on commit 0f623d4

Please sign in to comment.