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
15 changes: 2 additions & 13 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@
<oauth2.revision>151</oauth2.revision>
<google.http.version>1.42.2</google.http.version>
<spotbugs.effort>Max</spotbugs.effort>
<runSuite>**/GoogleOAuthPluginTestSuite.class</runSuite>
<spotless.check.skip>false</spotless.check.skip>
</properties>

Expand All @@ -85,7 +84,7 @@
<dependency>
<groupId>io.jenkins.tools.bom</groupId>
<artifactId>bom-${jenkins.baseline}.x</artifactId>
<version>3944.v1a_e4f8b_452db_</version>
<version>4136.vca_c3202a_7fd1</version>
<type>pom</type>
<scope>import</scope>
</dependency>
Expand Down Expand Up @@ -284,7 +283,7 @@
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<artifactId>mockito-junit-jupiter</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
Expand Down Expand Up @@ -343,16 +342,6 @@
</formats>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<includes>
<include>${runSuite}</include>
</includes>
<reuseForks>false</reuseForks>
</configuration>
</plugin>
</plugins>
</build>
</project>
26 changes: 0 additions & 26 deletions src/test/java/com/google/jenkins/GoogleOAuthPluginTestSuite.java

This file was deleted.

This file was deleted.

36 changes: 0 additions & 36 deletions src/test/java/com/google/jenkins/plugins/UtilTestSuite.java

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -16,34 +16,32 @@

package com.google.jenkins.plugins.credentials.oauth;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertNull;

import com.cloudbees.plugins.credentials.CredentialsProvider;
import com.cloudbees.plugins.credentials.SecretBytes;
import io.jenkins.plugins.casc.misc.ConfiguredWithCode;
import io.jenkins.plugins.casc.misc.JenkinsConfiguredWithCodeRule;
import io.jenkins.plugins.casc.misc.junit.jupiter.WithJenkinsConfiguredWithCode;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.util.List;
import org.apache.commons.io.IOUtils;
import org.junit.Rule;
import org.junit.Test;
import org.junit.jupiter.api.Test;

/** Tests that the credentials are correctly processed by the Configuration as Code plugin. */
public class ConfigurationAsCodeTest {

@Rule
public JenkinsConfiguredWithCodeRule r = new JenkinsConfiguredWithCodeRule();
@WithJenkinsConfiguredWithCode
class ConfigurationAsCodeTest {

@Test
@ConfiguredWithCode("json-service-account-config.yml")
public void supportsConfigurationWithJsonServiceAccountConfig() throws IOException {
void supportsConfigurationWithJsonServiceAccountConfig(JenkinsConfiguredWithCodeRule r) throws IOException {
List<GoogleRobotPrivateKeyCredentials> credentialsList =
CredentialsProvider.lookupCredentials(GoogleRobotPrivateKeyCredentials.class);
assertNotNull(credentialsList);
assertEquals("No credentials created", 1, credentialsList.size());
assertEquals(1, credentialsList.size(), "No credentials created");
GoogleRobotPrivateKeyCredentials credentials = credentialsList.get(0);
assertNotNull(credentials);
JsonServiceAccountConfig config = (JsonServiceAccountConfig) credentials.getServiceAccountConfig();
Expand All @@ -57,16 +55,16 @@ public void supportsConfigurationWithJsonServiceAccountConfig() throws IOExcepti
String actualBytes = new String(bytes.getPlainData(), StandardCharsets.UTF_8);
String expectedBytes =
IOUtils.toString(this.getClass().getResourceAsStream("test-key.json"), StandardCharsets.UTF_8);
assertEquals("Failed to configure secretJsonKey correctly.", expectedBytes, actualBytes);
assertEquals(expectedBytes, actualBytes, "Failed to configure secretJsonKey correctly.");
}

@Test
@ConfiguredWithCode("p12-service-account-config.yml")
public void supportsConfigurationWithP12ServiceAccountConfig() {
void supportsConfigurationWithP12ServiceAccountConfig(JenkinsConfiguredWithCodeRule r) {
List<GoogleRobotPrivateKeyCredentials> credentialsList =
CredentialsProvider.lookupCredentials(GoogleRobotPrivateKeyCredentials.class);
assertNotNull(credentialsList);
assertEquals("No credentials created", 1, credentialsList.size());
assertEquals(1, credentialsList.size(), "No credentials created");
GoogleRobotPrivateKeyCredentials credentials = credentialsList.get(0);
assertNotNull(credentials);
P12ServiceAccountConfig config = (P12ServiceAccountConfig) credentials.getServiceAccountConfig();
Expand All @@ -81,6 +79,6 @@ public void supportsConfigurationWithP12ServiceAccountConfig() {
SecretBytes bytes = config.getSecretP12Key();
String actualBytes = new String(bytes.getPlainData(), StandardCharsets.UTF_8);
String expectedBytes = "test-p12-key";
assertEquals("Failed to configure secretP12Key correctly", expectedBytes, actualBytes);
assertEquals(expectedBytes, actualBytes, "Failed to configure secretP12Key correctly");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,41 +15,41 @@
*/
package com.google.jenkins.plugins.credentials.oauth;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.hasItems;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertThat;
import static org.junit.jupiter.api.Assertions.assertEquals;

import com.cloudbees.plugins.credentials.domains.DomainSpecification.Result;
import com.google.common.collect.ImmutableList;
import java.util.Collection;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import java.util.List;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.jvnet.hudson.test.JenkinsRule;
import org.jvnet.hudson.test.WithoutJenkins;
import org.mockito.MockitoAnnotations;
import org.jvnet.hudson.test.junit.jupiter.WithJenkins;
import org.mockito.junit.jupiter.MockitoExtension;

/** Tests for {@link GoogleOAuth2ScopeSpecification}. */
public class GoogleOAuth2ScopeSpecificationTest {
// Allow for testing using JUnit4, instead of JUnit3.
@Rule
public JenkinsRule jenkins = new JenkinsRule();
@WithJenkins
@ExtendWith(MockitoExtension.class)
class GoogleOAuth2ScopeSpecificationTest {

@Before
public void setUp() throws Exception {
MockitoAnnotations.initMocks(this);
}
private static final String GOOD_SCOPE1 = "foo";
private static final String GOOD_SCOPE2 = "baz";
private static final String BAD_SCOPE = "bar";
private static final Collection<String> GOOD_SCOPES = List.of(GOOD_SCOPE1, GOOD_SCOPE2);
private static final Collection<String> BAD_SCOPES = List.of(GOOD_SCOPE1, BAD_SCOPE);

@Test
@WithoutJenkins
public void testBasics() throws Exception {
void testBasics() {
GoogleOAuth2ScopeSpecification spec = new GoogleOAuth2ScopeSpecification(GOOD_SCOPES);

assertThat(spec.getSpecifiedScopes(), hasItems(GOOD_SCOPE1, GOOD_SCOPE2));
}

@Test
public void testUnknownRequirement() throws Exception {
void testUnknownRequirement(JenkinsRule jenkins) {
GoogleOAuth2ScopeSpecification spec = new GoogleOAuth2ScopeSpecification(GOOD_SCOPES);

OAuth2ScopeRequirement requirement = new OAuth2ScopeRequirement() {
Expand All @@ -65,7 +65,7 @@ public Collection<String> getScopes() {
}

@Test
public void testKnownRequirements() throws Exception {
void testKnownRequirements(JenkinsRule jenkins) throws Exception {
GoogleOAuth2ScopeSpecification spec = new GoogleOAuth2ScopeSpecification(GOOD_SCOPES);

GoogleOAuth2ScopeRequirement goodReq = new GoogleOAuth2ScopeRequirement() {
Expand All @@ -86,10 +86,4 @@ public Collection<String> getScopes() {
assertEquals(Result.POSITIVE, spec.test(goodReq));
assertEquals(Result.NEGATIVE, spec.test(badReq));
}

private static String GOOD_SCOPE1 = "foo";
private static String GOOD_SCOPE2 = "baz";
private static String BAD_SCOPE = "bar";
private static Collection<String> GOOD_SCOPES = ImmutableList.of(GOOD_SCOPE1, GOOD_SCOPE2);
private static Collection<String> BAD_SCOPES = ImmutableList.of(GOOD_SCOPE1, BAD_SCOPE);
}
Loading