Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -175,9 +175,25 @@
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.testcontainers</groupId>
<artifactId>junit-jupiter</artifactId>
<version>1.20.1</version>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.apache.commons</groupId>
<artifactId>commons-compress</artifactId>
</exclusion>
<exclusion>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<artifactId>mockito-junit-jupiter</artifactId>
<scope>test</scope>
</dependency>
<dependency>
Expand Down
17 changes: 6 additions & 11 deletions src/test/java/com/datapipe/jenkins/vault/AwsHelperTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,7 @@
import java.util.List;
import java.util.Map;
import org.apache.commons.lang.StringUtils;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.junit.jupiter.api.Test;
import org.mockito.ArgumentCaptor;

import static org.hamcrest.MatcherAssert.assertThat;
Expand All @@ -33,35 +31,32 @@
import static org.mockito.Mockito.when;
import static org.mockito.Mockito.verify;

public class AwsHelperTest {
class AwsHelperTest {

private static final String awsAccessKey = "ASIAIOSFODNN7EXAMPLE";
private static final String awsSecretKey = "wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY";
private static final String sessionToken = "sometoken";

@Rule
public ExpectedException thrown = ExpectedException.none();

@Test
public void testGetTokenBasicDefaults() throws VaultException {
void testGetTokenBasicDefaults() throws VaultException {
BasicAWSCredentials credentials = new BasicAWSCredentials(awsAccessKey, awsSecretKey);
doTestGetToken(credentials, "", "", "");
}

@Test
public void testGetTokenBasicCustom() throws VaultException {
void testGetTokenBasicCustom() throws VaultException {
BasicAWSCredentials credentials = new BasicAWSCredentials(awsAccessKey, awsSecretKey);
doTestGetToken(credentials, "somerole", "someserverid", "somemount");
}

@Test
public void testGetTokenSessionDefaults() throws VaultException {
void testGetTokenSessionDefaults() throws VaultException {
BasicSessionCredentials credentials = new BasicSessionCredentials(awsAccessKey, awsSecretKey, sessionToken);
doTestGetToken(credentials, "", "", "");
}

@Test
public void testGetTokenSessionCustom() throws VaultException {
void testGetTokenSessionCustom() throws VaultException {
BasicSessionCredentials credentials = new BasicSessionCredentials(awsAccessKey, awsSecretKey, sessionToken);
doTestGetToken(credentials, "somerole", "someserverid", "somemount");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,20 @@
import hudson.EnvVars;
import java.util.Arrays;
import java.util.List;
import org.junit.Test;
import org.junit.jupiter.api.Test;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.equalTo;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

public class VaultAccessorTest {
class VaultAccessorTest {

private static final String POLICIES_STR =
"\npol1\n\nbase_${job_base_name}\njob/${job_name}\n job_${job_name_us}\nfolder/${job_folder}\nfolder_${job_folder_us}\nnode_${node_name}\n";

@Test
public void testGeneratePolicies() {
void testGeneratePolicies() {
EnvVars envVars = mock(EnvVars.class);
when(envVars.get("JOB_NAME")).thenReturn("job1");
when(envVars.get("JOB_BASE_NAME")).thenReturn("job1");
Expand All @@ -29,7 +29,7 @@ public void testGeneratePolicies() {
}

@Test
public void testGeneratePoliciesWithFolder() {
void testGeneratePoliciesWithFolder() {
EnvVars envVars = mock(EnvVars.class);
when(envVars.get("JOB_NAME")).thenReturn("folder1/folder2/job1");
when(envVars.get("JOB_BASE_NAME")).thenReturn("job1");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public VaultBindingStepWithMockAccessor(List<VaultSecret> vaultSecrets) {
}

@Override
public StepExecution start(StepContext context) throws Exception {
public StepExecution start(StepContext context) {
Execution execution = new Execution(this, context);
execution.setVaultAccessor(new VaultAccessor() {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,13 @@
import io.github.jopenlibs.vault.response.LogicalResponse;
import io.github.jopenlibs.vault.rest.RestResponse;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.PrintStream;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import jenkins.tasks.SimpleBuildWrapper;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.junit.jupiter.api.Test;

import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.is;
Expand All @@ -30,13 +27,10 @@
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;

public class VaultBuildWrapperTest {

@Rule
public ExpectedException thrown = ExpectedException.none();
class VaultBuildWrapperTest {

@Test
public void testWithNonExistingPath() throws IOException, InterruptedException {
void testWithNonExistingPath() {
String path = "not/existing";
VaultAccessor mockAccessor = mock(VaultAccessor.class);
doReturn(mockAccessor).when(mockAccessor).init();
Expand Down Expand Up @@ -67,7 +61,7 @@ public void testWithNonExistingPath() throws IOException, InterruptedException {
}

@Test
public void testWithAccessDeniedPath() throws IOException, InterruptedException {
void testWithAccessDeniedPath() {
String path = "not/allowed";
VaultAccessor mockAccessor = mock(VaultAccessor.class);
doReturn(mockAccessor).when(mockAccessor).init();
Expand Down Expand Up @@ -121,7 +115,7 @@ private LogicalResponse getAccessDeniedResponse() {
return resp;
}

class TestWrapper extends VaultBuildWrapper {
static class TestWrapper extends VaultBuildWrapper {

VaultConfiguration vaultConfig = new VaultConfiguration();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,26 +7,26 @@
import java.nio.file.attribute.AclEntryType;
import java.nio.file.attribute.AclFileAttributeView;
import java.nio.file.attribute.UserPrincipal;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

import static com.datapipe.jenkins.vault.WindowsFilePermissionHelper.ACL_ENTRY_PERMISSIONS;
import static com.datapipe.jenkins.vault.WindowsFilePermissionHelper.fixSshKeyOnWindows;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNotSame;
import static org.junit.Assert.assertTrue;
import static org.junit.Assume.assumeTrue;
import static org.junit.jupiter.api.Assumptions.assumeTrue;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertNotSame;
import static org.junit.jupiter.api.Assertions.assertTrue;

public class WindowsFilePermissionsTest {
class WindowsFilePermissionsTest {

private Path file;
private AclFileAttributeView fileAttributeView;
private UserPrincipal userPrincipal;

@Before
public void beforeEach() throws Exception {
@BeforeEach
void beforeEach() throws Exception {
assumeTrue(isWindows());
file = Files.createTempFile("permission-test-", "");
fileAttributeView = Files.getFileAttributeView(file, AclFileAttributeView.class);
Expand All @@ -35,15 +35,15 @@ public void beforeEach() throws Exception {
assertNotNull(userPrincipal);
}

@After
public void afterEach() throws Exception {
@AfterEach
void afterEach() throws Exception {
if (file != null) {
Files.deleteIfExists(file);
}
}

@Test
public void test_windows_file_permission_is_set_correctly() throws Exception {
void test_windows_file_permission_is_set_correctly() throws Exception {
fixSshKeyOnWindows(file);
assertEquals(1, fileAttributeView.getAcl().size());
AclEntry aclEntry = fileAttributeView.getAcl().get(0);
Expand All @@ -54,7 +54,7 @@ public void test_windows_file_permission_is_set_correctly() throws Exception {
}

@Test
public void test_windows_file_permission_are_incorrect() throws Exception {
void test_windows_file_permission_are_incorrect() throws Exception {
// By default files include System and builtin administrators
assertNotSame(1, fileAttributeView.getAcl().size());
for (AclEntry entry : fileAttributeView.getAcl()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@
import hudson.util.DescribableList;
import java.util.SortedMap;
import jenkins.model.Jenkins;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.junit.MockitoJUnitRunner;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.junit.jupiter.MockitoExtension;

import static com.datapipe.jenkins.vault.configuration.VaultConfigurationSpec.completeTestConfig;
import static org.hamcrest.Matchers.nullValue;
Expand All @@ -21,8 +21,8 @@
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

@RunWith(MockitoJUnitRunner.class)
public class FolderVaultConfigurationSpec {
@ExtendWith(MockitoExtension.class)
class FolderVaultConfigurationSpec {

private FolderVaultConfiguration completeTestConfigFolder(String identifier) {
return new FolderVaultConfiguration(completeTestConfig(identifier));
Expand All @@ -34,7 +34,7 @@ private FolderVaultConfiguration completeTestConfigFolder(String identifier,
}

@Test
public void resolverShouldNotFailIfNotInFolder() {
void resolverShouldNotFailIfNotInFolder() {
VaultConfigResolver folderResolver = new FolderVaultConfiguration.ForJob();
Job job = mock(Job.class);
when(job.getParent()).thenReturn(mock(Jenkins.class));
Expand All @@ -45,7 +45,7 @@ public void resolverShouldNotFailIfNotInFolder() {
}

@Test
public void resolverShouldCorrectlyMerge() {
void resolverShouldCorrectlyMerge() {
final DescribableList firstFolderProperties = mock(DescribableList.class);
when(firstFolderProperties.get(FolderVaultConfiguration.class))
.thenReturn(completeTestConfigFolder("firstParent", null));
Expand All @@ -72,8 +72,7 @@ public void resolverShouldCorrectlyMerge() {


@Test
public void resolverShouldHandleAbsentConfigurationOnFolders() {

void resolverShouldHandleAbsentConfigurationOnFolders() {
final DescribableList firstFolderProperties = mock(DescribableList.class);
when(firstFolderProperties.get(FolderVaultConfiguration.class))
.thenReturn(completeTestConfigFolder("firstParent"));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package com.datapipe.jenkins.vault.configuration;

import org.junit.Test;
import org.junit.jupiter.api.Test;

import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;

public class VaultConfigurationSpec {
class VaultConfigurationSpec {

public static VaultConfiguration completeTestConfig(String identifier, Integer engineVersion) {
VaultConfiguration result = new VaultConfiguration();
Expand All @@ -32,7 +32,7 @@ public static VaultConfiguration credentialOnlyConfig(String identifier) {
}

@Test
public void childShouldCompletlyOverwriteParent() {
void childShouldCompletelyOverwriteParent() {
VaultConfiguration parent = completeTestConfig("parent");
VaultConfiguration child = completeTestConfig("child");
VaultConfiguration result = child.mergeWithParent(parent);
Expand All @@ -42,7 +42,7 @@ public void childShouldCompletlyOverwriteParent() {
}

@Test
public void childShouldPartlyOverwriteParent() {
void childShouldPartlyOverwriteParent() {
VaultConfiguration parent = completeTestConfig("parent");
VaultConfiguration child = urlOnlyConfig("child");
VaultConfiguration result = child.mergeWithParent(parent);
Expand All @@ -59,7 +59,7 @@ public void childShouldPartlyOverwriteParent() {
}

@Test
public void emptyChildShouldBeOverriden() {
void emptyChildShouldBeOverridden() {
VaultConfiguration parent = completeTestConfig("parent");
VaultConfiguration child = new VaultConfiguration();
VaultConfiguration result = child.mergeWithParent(parent);
Expand All @@ -69,7 +69,7 @@ public void emptyChildShouldBeOverriden() {
}

@Test
public void emptyParentShouldBeIgnored() {
void emptyParentShouldBeIgnored() {
VaultConfiguration parent = new VaultConfiguration();
VaultConfiguration child = completeTestConfig("child");
VaultConfiguration result = child.mergeWithParent(parent);
Expand All @@ -79,7 +79,7 @@ public void emptyParentShouldBeIgnored() {
}

@Test
public void shouldHandleNull() {
void shouldHandleNull() {
VaultConfiguration dummy = completeTestConfig("dummy");
VaultConfiguration result = dummy.mergeWithParent(null);

Expand All @@ -88,7 +88,7 @@ public void shouldHandleNull() {
}

@Test
public void shouldNotStoreTrailingSlashesInUrl() {
void shouldNotStoreTrailingSlashesInUrl() {
VaultConfiguration parent = new VaultConfiguration();
parent.setVaultUrl("http://vault-url.com/");
parent.setFailIfNotFound(false);
Expand All @@ -98,7 +98,7 @@ public void shouldNotStoreTrailingSlashesInUrl() {
}

@Test
public void shouldStoreFailureHandling() {
void shouldStoreFailureHandling() {
VaultConfiguration parent = new VaultConfiguration();
parent.setVaultUrl("http://vault-url.com/");
parent.setFailIfNotFound(false);
Expand All @@ -108,7 +108,7 @@ public void shouldStoreFailureHandling() {
}

@Test
public void shouldStorePrefixPath() {
void shouldStorePrefixPath() {
VaultConfiguration parent = new VaultConfiguration();
parent.setVaultUrl("http://vault-url.com/");
parent.setFailIfNotFound(false);
Expand Down
Loading