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
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,20 @@
import org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition;
import org.jenkinsci.plugins.workflow.job.WorkflowJob;
import org.jenkinsci.plugins.workflow.job.WorkflowRun;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.jvnet.hudson.test.JenkinsRule;
import org.jvnet.hudson.test.junit.jupiter.WithJenkins;

import java.io.IOException;
import java.nio.charset.Charset;

import static com.onepassword.jenkins.plugins.util.TestConstants.*;

public class OnePasswordWithSecretsTest {
@WithJenkins
class OnePasswordWithSecretsTest {

@Rule
public JenkinsRule j = new JenkinsRule();
private JenkinsRule j;

private final String basePath = "src/test/resources/com/onepassword/jenkins/plugins/pipeline/";

Expand All @@ -31,16 +31,17 @@ public class OnePasswordWithSecretsTest {
CredentialsScope.GLOBAL, "connect-credential-id",
"1Password Connect Credential", Secret.fromString(System.getenv("OP_TOKEN")));

@Before
public void init() throws IOException {
@BeforeEach
void init(JenkinsRule j) throws IOException {
this.j = j;
CredentialsProvider.lookupStores(j.jenkins)
.iterator()
.next()
.addCredentials(Domain.global(), c);
}

@Test
public void testSecretsFunction() throws Exception {
void testSecretsFunction() throws Exception {
WorkflowJob project = j.createProject(WorkflowJob.class);
project.setDefinition(new CpsFlowDefinition(readFile(basePath + "testSecretsFunction.groovy",
Charset.defaultCharset())
Expand All @@ -53,7 +54,7 @@ public void testSecretsFunction() throws Exception {
}

@Test
public void testSecretsPipeline() throws Exception {
void testSecretsPipeline() throws Exception {
WorkflowJob project = j.createProject(WorkflowJob.class);
project.setDefinition(new CpsFlowDefinition(readFile(basePath + "testSecretsPipeline.groovy",
Charset.defaultCharset())
Expand All @@ -67,7 +68,7 @@ public void testSecretsPipeline() throws Exception {
}

@Test
public void testSecretsMultiline() throws Exception {
void testSecretsMultiline() throws Exception {
WorkflowJob project = j.createProject(WorkflowJob.class);
project.setDefinition(new CpsFlowDefinition(readFile(basePath + "testSecretsMultiline.groovy",
Charset.defaultCharset())
Expand All @@ -81,7 +82,7 @@ public void testSecretsMultiline() throws Exception {
}

@Test
public void testSecretsFromEnv() throws Exception {
void testSecretsFromEnv() throws Exception {
WorkflowJob project = j.createProject(WorkflowJob.class);
project.setDefinition(new CpsFlowDefinition(readFile(basePath + "testSecretsFromEnv.groovy",
Charset.defaultCharset())
Expand All @@ -95,7 +96,7 @@ public void testSecretsFromEnv() throws Exception {
}

@Test
public void testSecretsWrongReference() throws Exception {
void testSecretsWrongReference() throws Exception {
WorkflowJob project = j.createProject(WorkflowJob.class);
project.setDefinition(new CpsFlowDefinition(readFile(basePath + "testSecretsWrongReference.groovy",
Charset.defaultCharset())
Expand All @@ -109,7 +110,7 @@ public void testSecretsWrongReference() throws Exception {
}

@Test
public void testSecretsMasked() throws Exception {
void testSecretsMasked() throws Exception {
WorkflowJob project = j.createProject(WorkflowJob.class);
project.setDefinition(new CpsFlowDefinition(readFile(basePath + "testSecretsMasked.groovy",
Charset.defaultCharset())
Expand All @@ -122,7 +123,7 @@ public void testSecretsMasked() throws Exception {
}

@Test
public void testSecretsMultilineMasked() throws Exception {
void testSecretsMultilineMasked() throws Exception {
WorkflowJob project = j.createProject(WorkflowJob.class);
project.setDefinition(new CpsFlowDefinition(readFile(basePath + "testSecretsMultilineMasked.groovy",
Charset.defaultCharset())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,20 @@
import org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition;
import org.jenkinsci.plugins.workflow.job.WorkflowJob;
import org.jenkinsci.plugins.workflow.job.WorkflowRun;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.jvnet.hudson.test.JenkinsRule;
import org.jvnet.hudson.test.junit.jupiter.WithJenkins;

import java.io.IOException;
import java.nio.charset.Charset;

import static com.onepassword.jenkins.plugins.util.TestConstants.*;

public class OnePasswordConfigConnectTest {
@WithJenkins
class OnePasswordConfigConnectTest {

@Rule
public JenkinsRule j = new JenkinsRule();
private JenkinsRule j;

private final String basePath = "src/test/resources/com/onepassword/jenkins/plugins/config/connect/";

Expand All @@ -32,16 +32,17 @@ public class OnePasswordConfigConnectTest {
CredentialsScope.GLOBAL, "connect-credential-id",
"1Password Connect Credential", Secret.fromString(System.getenv("OP_TOKEN")));

@Before
public void init() throws IOException {
@BeforeEach
void init(JenkinsRule j) throws IOException {
this.j = j;
CredentialsProvider.lookupStores(j.jenkins)
.iterator()
.next()
.addCredentials(Domain.global(), c);
}

@Test
public void testConfigFunction() throws Exception {
void testConfigFunction() throws Exception {
WorkflowJob project = j.createProject(WorkflowJob.class);
project.setDefinition(new CpsFlowDefinition(readFile(basePath + "testConfigFunction.groovy",
Charset.defaultCharset())
Expand All @@ -55,7 +56,7 @@ public void testConfigFunction() throws Exception {
}

@Test
public void testConfigPipeline() throws Exception {
void testConfigPipeline() throws Exception {
WorkflowJob project = j.createProject(WorkflowJob.class);
project.setDefinition(new CpsFlowDefinition(readFile(basePath + "testConfigPipeline.groovy",
Charset.defaultCharset())
Expand All @@ -69,7 +70,7 @@ public void testConfigPipeline() throws Exception {
}

@Test
public void testConfigGlobal() throws Exception {
void testConfigGlobal() throws Exception {
OnePasswordGlobalConfig globalConfig = GlobalConfiguration.all().get(OnePasswordGlobalConfig.class);
OnePasswordConfig config = new OnePasswordConfig();
config.setConnectHost(TEST_CONNECT_HOST);
Expand All @@ -93,7 +94,7 @@ public void testConfigGlobal() throws Exception {
}

@Test
public void testConfigMergeHost() throws Exception {
void testConfigMergeHost() throws Exception {
OnePasswordGlobalConfig globalConfig = GlobalConfiguration.all().get(OnePasswordGlobalConfig.class);
OnePasswordConfig config = new OnePasswordConfig();
config.setConnectHost(TEST_CONNECT_HOST);
Expand All @@ -115,7 +116,7 @@ public void testConfigMergeHost() throws Exception {
}

@Test
public void testConfigMergeTokenId() throws Exception {
void testConfigMergeTokenId() throws Exception {
OnePasswordGlobalConfig globalConfig = GlobalConfiguration.all().get(OnePasswordGlobalConfig.class);
OnePasswordConfig config = new OnePasswordConfig();
config.setConnectCredentialId("connect-credential-id");
Expand All @@ -138,7 +139,7 @@ public void testConfigMergeTokenId() throws Exception {
}

@Test
public void testConfigFromEnv() throws Exception {
void testConfigFromEnv() throws Exception {
WorkflowJob project = j.createProject(WorkflowJob.class);
project.setDefinition(new CpsFlowDefinition(readFile(basePath + "testConfigFromEnv.groovy",
Charset.defaultCharset())
Expand All @@ -152,7 +153,7 @@ public void testConfigFromEnv() throws Exception {
}

@Test
public void testConfigPriorityHost() throws Exception {
void testConfigPriorityHost() throws Exception {
WorkflowJob project = j.createProject(WorkflowJob.class);
project.setDefinition(new CpsFlowDefinition(readFile(basePath + "testConfigPriorityHost.groovy",
Charset.defaultCharset())
Expand All @@ -166,7 +167,7 @@ public void testConfigPriorityHost() throws Exception {
}

@Test
public void testConfigPriorityToken() throws Exception {
void testConfigPriorityToken() throws Exception {
WorkflowJob project = j.createProject(WorkflowJob.class);
project.setDefinition(new CpsFlowDefinition(readFile(basePath + "testConfigPriorityToken.groovy",
Charset.defaultCharset())
Expand All @@ -180,7 +181,7 @@ public void testConfigPriorityToken() throws Exception {
}

@Test
public void testConfigNoHost() throws Exception {
void testConfigNoHost() throws Exception {
WorkflowJob project = j.createProject(WorkflowJob.class);
project.setDefinition(new CpsFlowDefinition(readFile(basePath + "testConfigNoHost.groovy",
Charset.defaultCharset())
Expand All @@ -194,7 +195,7 @@ public void testConfigNoHost() throws Exception {
}

@Test
public void testConfigNoToken() throws Exception {
void testConfigNoToken() throws Exception {
CredentialsProvider.lookupStores(j.jenkins)
.iterator()
.next()
Expand All @@ -212,7 +213,7 @@ public void testConfigNoToken() throws Exception {
}

@Test
public void testConfigNoConfig() throws Exception {
void testConfigNoConfig() throws Exception {
WorkflowJob project = j.createProject(WorkflowJob.class);
project.setDefinition(new CpsFlowDefinition(readFile(basePath + "testConfigNoConfig.groovy",
Charset.defaultCharset())
Expand All @@ -226,7 +227,7 @@ public void testConfigNoConfig() throws Exception {
}

@Test
public void testConfigNoSpecifiedToken() throws Exception {
void testConfigNoSpecifiedToken() throws Exception {
WorkflowJob project = j.createProject(WorkflowJob.class);
project.setDefinition(new CpsFlowDefinition(readFile(basePath + "testConfigNoSpecifiedToken.groovy",
Charset.defaultCharset())
Expand All @@ -240,7 +241,7 @@ public void testConfigNoSpecifiedToken() throws Exception {
}

@Test
public void testConfigWrongHost() throws Exception {
void testConfigWrongHost() throws Exception {
WorkflowJob project = j.createProject(WorkflowJob.class);
project.setDefinition(new CpsFlowDefinition(readFile(basePath + "testConfigWrongHost.groovy",
Charset.defaultCharset())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,20 @@
import org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition;
import org.jenkinsci.plugins.workflow.job.WorkflowJob;
import org.jenkinsci.plugins.workflow.job.WorkflowRun;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.jvnet.hudson.test.JenkinsRule;
import org.jvnet.hudson.test.junit.jupiter.WithJenkins;

import java.io.IOException;
import java.nio.charset.Charset;

import static com.onepassword.jenkins.plugins.util.TestConstants.*;

public class OnePasswordConfigServiceAccountTest {
@WithJenkins
class OnePasswordConfigServiceAccountTest {

@Rule
public JenkinsRule j = new JenkinsRule();
private JenkinsRule j;

private final String basePath = "src/test/resources/com/onepassword/jenkins/plugins/config/serviceaccount/";
private final String serviceAccountCredentialId = "service-account-credential-id";
Expand All @@ -33,16 +33,17 @@ public class OnePasswordConfigServiceAccountTest {
CredentialsScope.GLOBAL, serviceAccountCredentialId,
"1Password Service Account Credential", Secret.fromString(System.getenv("OP_SA_TOKEN")));

@Before
public void init() throws IOException {
@BeforeEach
void init(JenkinsRule j) throws IOException {
this.j = j;
CredentialsProvider.lookupStores(j.jenkins)
.iterator()
.next()
.addCredentials(Domain.global(), c);
}

@Test
public void testConfigFunction() throws Exception {
void testConfigFunction() throws Exception {
WorkflowJob project = j.createProject(WorkflowJob.class);
project.setDefinition(new CpsFlowDefinition(readFile(basePath + "testConfigFunction.groovy",
Charset.defaultCharset())
Expand All @@ -55,7 +56,7 @@ public void testConfigFunction() throws Exception {
}

@Test
public void testConfigPipeline() throws Exception {
void testConfigPipeline() throws Exception {
WorkflowJob project = j.createProject(WorkflowJob.class);
project.setDefinition(new CpsFlowDefinition(readFile(basePath + "testConfigPipeline.groovy",
Charset.defaultCharset())
Expand All @@ -68,7 +69,7 @@ public void testConfigPipeline() throws Exception {
}

@Test
public void testConfigGlobal() throws Exception {
void testConfigGlobal() throws Exception {
OnePasswordGlobalConfig globalConfig = GlobalConfiguration.all().get(OnePasswordGlobalConfig.class);
OnePasswordConfig config = new OnePasswordConfig();
config.setServiceAccountCredentialId(serviceAccountCredentialId);
Expand All @@ -91,7 +92,7 @@ public void testConfigGlobal() throws Exception {
}

@Test
public void testConfigMergeTokenId() throws Exception {
void testConfigMergeTokenId() throws Exception {
OnePasswordGlobalConfig globalConfig = GlobalConfiguration.all().get(OnePasswordGlobalConfig.class);
OnePasswordConfig config = new OnePasswordConfig();
config.setServiceAccountCredentialId(serviceAccountCredentialId);
Expand All @@ -113,7 +114,7 @@ public void testConfigMergeTokenId() throws Exception {
}

@Test
public void testConfigFromEnv() throws Exception {
void testConfigFromEnv() throws Exception {
WorkflowJob project = j.createProject(WorkflowJob.class);
project.setDefinition(new CpsFlowDefinition(readFile(basePath + "testConfigFromEnv.groovy",
Charset.defaultCharset())
Expand All @@ -126,7 +127,7 @@ public void testConfigFromEnv() throws Exception {
}

@Test
public void testConfigPriorityToken() throws Exception {
void testConfigPriorityToken() throws Exception {
WorkflowJob project = j.createProject(WorkflowJob.class);
project.setDefinition(new CpsFlowDefinition(readFile(basePath + "testConfigPriorityToken.groovy",
Charset.defaultCharset())
Expand All @@ -139,7 +140,7 @@ public void testConfigPriorityToken() throws Exception {
}

@Test
public void testConfigNoToken() throws Exception {
void testConfigNoToken() throws Exception {
CredentialsProvider.lookupStores(j.jenkins)
.iterator()
.next()
Expand Down
Loading