Skip to content

Commit

Permalink
Refresh plugin for August 2023
Browse files Browse the repository at this point in the history
  • Loading branch information
basil authored and jakub-bochenski committed Aug 30, 2023
1 parent faa65fc commit 0aff8fe
Show file tree
Hide file tree
Showing 15 changed files with 127 additions and 95 deletions.
1 change: 1 addition & 0 deletions .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* @jenkinsci/logstash-plugin-developers
12 changes: 12 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# https://help.github.com/github/administering-a-repository/configuration-options-for-dependency-updates

version: 2
updates:
- package-ecosystem: "maven"
directory: "/"
schedule:
interval: "weekly"
- package-ecosystem: "github-actions"
directory: "/"
schedule:
interval: "weekly"
1 change: 0 additions & 1 deletion .github/release-drafter.yml

This file was deleted.

24 changes: 24 additions & 0 deletions .github/workflows/jenkins-security-scan.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Jenkins Security Scan
# For more information, see: https://www.jenkins.io/doc/developer/security/scan/

name: Jenkins Security Scan

on:
push:
branches:
- master
pull_request:
types: [opened, synchronize, reopened]
workflow_dispatch:

permissions:
security-events: write
contents: read
actions: read

jobs:
security-scan:
uses: jenkins-infra/jenkins-security-scan/.github/workflows/jenkins-security-scan.yaml@v2
with:
java-cache: 'maven'
java-version: 17
2 changes: 1 addition & 1 deletion .mvn/extensions.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
<extension>
<groupId>io.jenkins.tools.incrementals</groupId>
<artifactId>git-changelist-maven-extension</artifactId>
<version>1.3</version>
<version>1.7</version>
</extension>
</extensions>
9 changes: 4 additions & 5 deletions Jenkinsfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
// Builds a module using https://github.com/jenkins-infra/pipeline-library
def configurations = [
[ platform: "linux", jdk: "8", jenkins: null ],
[ platform: "linux", jdk: "11", jenkins: null ]
]
buildPlugin(configurations: configurations, useContainerAgent: true)
buildPlugin(useContainerAgent: true, configurations: [
[platform: 'linux', jdk: 21],
[platform: 'windows', jdk: 17],
])
21 changes: 4 additions & 17 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>plugin</artifactId>
<version>4.46</version>
<version>4.72</version>
</parent>

<artifactId>logstash</artifactId>
Expand Down Expand Up @@ -64,17 +64,16 @@
<changelist>-SNAPSHOT</changelist>
<gitHubRepo>jenkinsci/logstash-plugin</gitHubRepo>
<skipIntegrationTests>true</skipIntegrationTests>
<jenkins.version>2.332.4</jenkins.version>
<jenkins.version>2.387.3</jenkins.version>
<hpi.compatibleSinceVersion>2.0</hpi.compatibleSinceVersion>
<mockito.version>3.12.4</mockito.version>
</properties>

<dependencyManagement>
<dependencies>
<dependency>
<groupId>io.jenkins.tools.bom</groupId>
<artifactId>bom-2.332.x</artifactId>
<version>1595.v8c71c13cc3a_9</version>
<artifactId>bom-2.387.x</artifactId>
<version>2357.v1043f8578392</version>
<type>pom</type>
<scope>import</scope>
</dependency>
Expand Down Expand Up @@ -148,18 +147,6 @@
<artifactId>mockito-core</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.powermock</groupId>
<artifactId>powermock-api-mockito2</artifactId>
<version>2.0.9</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.powermock</groupId>
<artifactId>powermock-module-junit4</artifactId>
<version>2.0.9</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.awaitility</groupId>
<artifactId>awaitility</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@
import org.junit.Test;
import org.jvnet.hudson.test.JenkinsRule;

import com.gargoylesoftware.htmlunit.FailingHttpStatusCodeException;
import com.gargoylesoftware.htmlunit.HttpMethod;
import com.gargoylesoftware.htmlunit.WebRequest;
import org.htmlunit.FailingHttpStatusCodeException;
import org.htmlunit.HttpMethod;
import org.htmlunit.WebRequest;

import hudson.model.Project;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,24 @@
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.is;
import static org.junit.Assert.assertThat;
import static org.powermock.api.mockito.PowerMockito.mockStatic;
import static org.powermock.api.mockito.PowerMockito.when;
import static org.mockito.Mockito.mockStatic;
import static org.mockito.Mockito.when;

import java.io.File;
import java.net.MalformedURLException;
import java.net.URI;
import java.net.URISyntaxException;

import org.hamcrest.core.IsInstanceOf;
import org.junit.After;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.jvnet.hudson.test.JenkinsRule;
import org.mockito.Mock;
import org.powermock.core.classloader.annotations.PowerMockIgnore;
import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.modules.junit4.PowerMockRunner;
import org.mockito.MockedStatic;
import org.mockito.junit.MockitoJUnitRunner;

import com.cloudbees.syslog.MessageFormat;

Expand All @@ -33,12 +33,12 @@
import jenkins.plugins.logstash.persistence.LogstashIndexerDao.IndexerType;
import jenkins.plugins.logstash.persistence.LogstashIndexerDao.SyslogFormat;

@RunWith(PowerMockRunner.class)
@PrepareForTest({ LogstashInstallation.class, Descriptor.class })
@PowerMockIgnore({"com.sun.org.apache.xerces.*", "javax.crypto.*", "javax.xml.*", "org.xml.*"})
@RunWith(MockitoJUnitRunner.class)
public class LogstashConfigurationMigrationTest extends LogstashConfigurationTestBase
{

private MockedStatic<LogstashInstallation> mockedLogstashInstallation;

@Rule
public JenkinsRule j = new JenkinsRule();

Expand All @@ -50,9 +50,9 @@ public class LogstashConfigurationMigrationTest extends LogstashConfigurationTes
@Before
public void setup()
{
mockStatic(LogstashInstallation.class);
configFile = new File("notExisting.xml");
when(LogstashInstallation.getLogstashDescriptor()).thenAnswer(invocationOnMock -> descriptor);
mockedLogstashInstallation = mockStatic(LogstashInstallation.class);
mockedLogstashInstallation.when(LogstashInstallation::getLogstashDescriptor).thenAnswer(invocationOnMock -> descriptor);
when(descriptor.getHost()).thenReturn("localhost");
when(descriptor.getPort()).thenReturn(4567);
when(descriptor.getKey()).thenReturn("logstash");
Expand All @@ -61,6 +61,11 @@ public void setup()
configuration = new LogstashConfigurationForTest();
}

@After
public void after() throws Exception {
mockedLogstashInstallation.closeOnDemand();
}

@Test
public void NoConfigMigration()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
import org.junit.Test;
import org.jvnet.hudson.test.JenkinsRule;

import com.gargoylesoftware.htmlunit.html.HtmlForm;
import com.gargoylesoftware.htmlunit.html.HtmlPage;
import org.htmlunit.html.HtmlForm;
import org.htmlunit.html.HtmlPage;

import jenkins.plugins.logstash.configuration.ElasticSearch;
import jenkins.plugins.logstash.configuration.RabbitMq;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package jenkins.plugins.logstash;

import static org.junit.Assert.*;
import static org.mockito.Mockito.verifyNoMoreInteractions;
import static org.powermock.api.mockito.PowerMockito.when;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.verifyNoMoreInteractions;
import static org.mockito.Mockito.when;

import hudson.model.AbstractBuild;
import hudson.model.Project;
Expand All @@ -20,16 +20,15 @@
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.powermock.api.mockito.PowerMockito;
import org.powermock.core.classloader.annotations.PowerMockIgnore;
import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.modules.junit4.PowerMockRunner;

@RunWith(PowerMockRunner.class)
@PowerMockIgnore({"com.sun.org.apache.xerces.*", "javax.crypto.*", "javax.xml.*", "org.xml.*"})
@PrepareForTest(LogstashConfiguration.class)
import org.mockito.MockedStatic;
import org.mockito.Mockito;
import org.mockito.junit.MockitoJUnitRunner;

@RunWith(MockitoJUnitRunner.class)
public class LogstashConsoleLogFilterTest {

private MockedStatic<LogstashConfiguration> mockedLogstashConfiguration;

@Mock
private LogstashConfiguration logstashConfiguration;

Expand Down Expand Up @@ -64,8 +63,8 @@ LogstashWriter getLogStashWriter(Run<?, ?> build, OutputStream errorStream) {

@Before
public void before() throws Exception {
PowerMockito.mockStatic(LogstashConfiguration.class);
when(LogstashConfiguration.getInstance()).thenAnswer(invocationOnMock -> logstashConfiguration);
mockedLogstashConfiguration = Mockito.mockStatic(LogstashConfiguration.class);
mockedLogstashConfiguration.when(LogstashConfiguration::getInstance).thenAnswer(invocationOnMock -> logstashConfiguration);
when(logstashConfiguration.isEnableGlobally()).thenReturn(false);
when(logstashConfiguration.isEnabled()).thenReturn(true);

Expand All @@ -81,6 +80,7 @@ public void after() throws Exception {
verifyNoMoreInteractions(mockWriter);
verifyNoMoreInteractions(mockBuildData);
buffer.close();
mockedLogstashConfiguration.closeOnDemand();
}

@Test
Expand Down
27 changes: 14 additions & 13 deletions src/test/java/jenkins/plugins/logstash/LogstashNotifierTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@

import static org.hamcrest.core.StringContains.containsString;
import static org.junit.Assert.*;
import static org.mockito.Mockito.*;
import static org.powermock.api.mockito.PowerMockito.when;
import static org.mockito.Mockito.anyInt;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.verifyNoMoreInteractions;
import static org.mockito.Mockito.when;

import hudson.Launcher;
import hudson.model.BuildListener;
Expand All @@ -25,20 +28,17 @@
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.MockedStatic;
import org.mockito.Mockito;
import org.mockito.invocation.InvocationOnMock;
import org.mockito.junit.MockitoJUnitRunner;
import org.mockito.stubbing.Answer;
import org.powermock.api.mockito.PowerMockito;
import org.powermock.core.classloader.annotations.PowerMockIgnore;
import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.modules.junit4.PowerMockRunner;

@SuppressWarnings("rawtypes")
@RunWith(PowerMockRunner.class)
@PowerMockIgnore({"com.sun.org.apache.xerces.*", "javax.crypto.*", "javax.xml.*", "org.xml.*"})
@PrepareForTest(LogstashConfiguration.class)

@RunWith(MockitoJUnitRunner.class)
public class LogstashNotifierTest {

private MockedStatic<LogstashConfiguration> mockedLogstashConfiguration;

// Extension of the unit under test that avoids making calls to Jenkins.getInstance() to get the DAO singleton
static class MockLogstashNotifier extends LogstashNotifier {
LogstashWriter writer;
Expand Down Expand Up @@ -99,8 +99,8 @@ public void before() throws Exception {
errorBuffer = new ByteArrayOutputStream();
errorStream = new PrintStream(errorBuffer, true);

PowerMockito.mockStatic(LogstashConfiguration.class);
when(LogstashConfiguration.getInstance()).thenAnswer(invocationOnMock -> logstashConfiguration);
mockedLogstashConfiguration = Mockito.mockStatic(LogstashConfiguration.class);
mockedLogstashConfiguration.when(LogstashConfiguration::getInstance).thenAnswer(invocationOnMock -> logstashConfiguration);
when(logstashConfiguration.isEnabled()).thenReturn(true);


Expand All @@ -123,6 +123,7 @@ public void after() throws Exception {
verifyNoMoreInteractions(mockListener);
verifyNoMoreInteractions(mockWriter);
errorStream.close();
mockedLogstashConfiguration.closeOnDemand();
}

@Test
Expand Down
20 changes: 10 additions & 10 deletions src/test/java/jenkins/plugins/logstash/LogstashWriterTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.verifyNoMoreInteractions;
import static org.powermock.api.mockito.PowerMockito.when;
import static org.mockito.Mockito.when;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
Expand All @@ -30,11 +30,9 @@
import org.mockito.ArgumentCaptor;
import org.mockito.Captor;
import org.mockito.Mock;
import org.mockito.MockedStatic;
import org.mockito.Mockito;
import org.powermock.api.mockito.PowerMockito;
import org.powermock.core.classloader.annotations.PowerMockIgnore;
import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.modules.junit4.PowerMockRunner;
import org.mockito.junit.MockitoJUnitRunner;

import hudson.EnvVars;
import hudson.model.AbstractBuild;
Expand All @@ -48,10 +46,11 @@
import jenkins.plugins.logstash.persistence.LogstashIndexerDao;
import net.sf.json.JSONObject;

@RunWith(PowerMockRunner.class)
@PowerMockIgnore({"com.sun.org.apache.xerces.*", "javax.crypto.*", "javax.xml.*", "org.xml.*"})
@PrepareForTest(LogstashConfiguration.class)
@RunWith(MockitoJUnitRunner.class)
public class LogstashWriterTest {

private MockedStatic<LogstashConfiguration> mockedLogstashConfiguration;

// Extension of the unit under test that avoids making calls to getInstance() to get the DAO singleton
static LogstashWriter createLogstashWriter(final AbstractBuild<?, ?> testBuild,
OutputStream error,
Expand Down Expand Up @@ -103,8 +102,8 @@ String getJenkinsUrl() {
@Before
public void before() throws Exception {

PowerMockito.mockStatic(LogstashConfiguration.class);
when(LogstashConfiguration.getInstance()).thenAnswer(invocationOnMock -> logstashConfiguration);
mockedLogstashConfiguration = Mockito.mockStatic(LogstashConfiguration.class);
mockedLogstashConfiguration.when(LogstashConfiguration::getInstance).thenAnswer(invocationOnMock -> logstashConfiguration);
when(logstashConfiguration.getDateFormatter()).thenCallRealMethod();

when(mockBuild.getResult()).thenReturn(Result.SUCCESS);
Expand Down Expand Up @@ -150,6 +149,7 @@ public void after() throws Exception {
verifyNoMoreInteractions(mockTestResultAction);
verifyNoMoreInteractions(mockProject);
errorBuffer.close();
mockedLogstashConfiguration.closeOnDemand();
}

@Test
Expand Down
Loading

0 comments on commit 0aff8fe

Please sign in to comment.