Commit 0aa2253b authored by Martin Lowe's avatar Martin Lowe 🇨🇦 Committed by Martin Lowe
Browse files

Removed Signed-off-by footer requirement


Signed-off-by: Martin Lowe's avatarMartin Lowe <martin.lowe@eclipse-foundation.org>
parent 14ac9f78
......@@ -9,9 +9,6 @@
******************************************************************************/
package org.eclipsefoundation.git.eca.helper;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.eclipsefoundation.git.eca.model.Commit;
/**
......@@ -21,7 +18,6 @@ import org.eclipsefoundation.git.eca.model.Commit;
*
*/
public class CommitHelper {
private static final Pattern SIGNED_OFF_BY_FOOTER = Pattern.compile("Signed-off-by:(.*)<(.*@.*)>");
/**
* Validate the commits fields.
......@@ -51,27 +47,6 @@ public class CommitHelper {
return valid;
}
/**
* Retrieves the email address associated with a commit message. This is done by
* processing the body and parsing out the given footer knowing its format.
*
* @param c the commit to retrieve the signed off by footer for
* @return true if an email address matching the authors was found in the signed-off by footer lines
*/
public static boolean getSignedOffByEmail(Commit c) {
if (c == null) {
return false;
}
Matcher m = SIGNED_OFF_BY_FOOTER.matcher(c.getBody());
while (m.find()) {
String signOffEmail = m.group(2);
if (signOffEmail != null && signOffEmail.equalsIgnoreCase(c.getAuthor().getMail())) {
return true;
}
}
return false;
}
private CommitHelper() {
}
}
......@@ -242,22 +242,6 @@ public class ValidationResource {
c.getHash());
addError(r, "An Eclipse Contributor Agreement is required.", c.getHash());
}
// check if one of the signed off by footer lines matches the author email.
if (CommitHelper.getSignedOffByEmail(c)) {
addMessage(r, "The author has signed-off on the contribution.", c.getHash());
} else {
addMessage(
r,
"The author has not signed-off on the contribution.\n"
+ "If there are multiple commits, please ensure that each commit is signed-off.",
c.getHash());
addError(
r,
"The contributor must sign-off on the contribution.",
c.getHash(),
APIStatusCode.ERROR_SIGN_OFF);
}
}
}
......@@ -347,6 +331,7 @@ public class ValidationResource {
// check for all projects that make use of the given repo
List<Project> availableProjects = projects.getProjects();
if (availableProjects == null || availableProjects.isEmpty()) {
LOGGER.warn("Could not find any projects to match against");
return Collections.emptyList();
}
LOGGER.debug("Checking projects for repos that end with: {}", repoUrl);
......
......@@ -93,7 +93,7 @@ public class MockAccountsAPI implements AccountsAPI {
if (name != null && !user.getName().equals(name)) {
matches = false;
}
if (mail != null && !user.getMail().equals(mail)) {
if (mail != null && !user.getMail().equalsIgnoreCase(mail)) {
matches = false;
}
return matches;
......
......@@ -51,66 +51,6 @@ class CommitHelperTest {
baseCommit.setCommitter(testUser);
}
@Test
void getSignedOffByEmailNullCommit() {
Assertions.assertFalse(CommitHelper.getSignedOffByEmail(null), "Expected null return for null commit");
}
@Test
void getSignedOffByEmailOnlyFooter() {
baseCommit.setBody(String.format("Signed-off-by: %s <%s>", testUser.getName(), testUser.getMail()));
boolean actual = CommitHelper.getSignedOffByEmail(baseCommit);
Assertions.assertTrue(actual);
}
@Test
void getSignedOffByEmailWithDifferentCasing() {
baseCommit.setBody(String.format("Signed-off-by: %s <%s>", testUser.getName(), testUser.getMail().toUpperCase()));
boolean actual = CommitHelper.getSignedOffByEmail(baseCommit);
Assertions.assertTrue(actual);
}
@Test
void getSignedOffByEmailBodyAndFooter() {
baseCommit.setBody(
String.format("Sample body content\n\nSigned-off-by: %s <%s>", testUser.getName(), testUser.getMail()));
boolean actualMail = CommitHelper.getSignedOffByEmail(baseCommit);
Assertions.assertTrue(actualMail);
}
@Test
void getSignedOffByEmailNoNameFooter() {
baseCommit.setBody(
String.format("Sample body content\n\nSigned-off-by:<%s>", testUser.getMail()));
boolean actual = CommitHelper.getSignedOffByEmail(baseCommit);
Assertions.assertTrue(actual);
}
@Test
void getSignedOffByEmailNoBrackets() {
baseCommit.setBody(
String.format("Sample body content\n\nSigned-off-by:%s", testUser.getMail()));
boolean actual = CommitHelper.getSignedOffByEmail(baseCommit);
Assertions.assertFalse(actual);
}
@Test
void getSignedOffByEmailBadFooterName() {
baseCommit.setBody(
String.format("Sample body content\n\nSign-off-by: %s <%s>", testUser.getName(), testUser.getMail()));
Assertions.assertFalse(CommitHelper.getSignedOffByEmail(baseCommit), "Expected false with typo in footer name");
baseCommit.setBody(
String.format("Sample body content\n\nSIGNED-OFF-BY: %s <%s>", testUser.getName(), testUser.getMail()));
Assertions.assertFalse(CommitHelper.getSignedOffByEmail(baseCommit), "Expected false with bad casing");
}
@Test
void getSignedOffByEmailBadAuthorEmail() {
baseCommit.setBody(
String.format("Sample body content\n\nSigned-off-by: %s <%s>", testUser.getName(), "known_bad@email.org"));
Assertions.assertFalse(CommitHelper.getSignedOffByEmail(baseCommit), "Expected false with typo in footer name");
}
@Test
void validateCommitKnownGood() {
Assertions.assertTrue(CommitHelper.validateCommit(baseCommit), "Expected basic commit to pass validation");
......
......@@ -18,11 +18,15 @@ import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import javax.inject.Inject;
import org.eclipsefoundation.git.eca.model.Commit;
import org.eclipsefoundation.git.eca.model.GitUser;
import org.eclipsefoundation.git.eca.model.ValidationRequest;
import org.eclipsefoundation.git.eca.namespace.APIStatusCode;
import org.eclipsefoundation.git.eca.namespace.ProviderType;
import org.eclipsefoundation.git.eca.service.CachingService;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import io.quarkus.test.junit.QuarkusTest;
......@@ -37,6 +41,15 @@ import io.restassured.http.ContentType;
@QuarkusTest
class ValidationResourceTest {
@Inject
CachingService cs;
@BeforeAll
void cacheClear() {
// if dev servers are run on the same machine, some values may live in the cache
cs.removeAll();
}
@Test
void validate() throws URISyntaxException {
// set up test users
......@@ -214,21 +227,15 @@ class ValidationResourceTest {
vr.setCommits(commits);
// test output w/ assertions
// Should be invalid as Wizard is not a committer on the prototype project
// Should be valid as wizard has signed ECA
given()
.body(vr)
.contentType(ContentType.JSON)
.when()
.post("/eca")
.then()
.statusCode(403)
.body(
"passed",
is(false),
"errorCount",
is(1),
"commits.123456789abcdefghijklmnop.errors[0].code",
is(APIStatusCode.ERROR_SIGN_OFF.getValue()));
.statusCode(200)
.body("passed", is(true), "errorCount", is(0));
}
@Test
......@@ -255,21 +262,15 @@ class ValidationResourceTest {
vr.setCommits(commits);
// test output w/ assertions
// Should be invalid as a different email was associated with the footer
// Should be valid as signed off by footer is no longer checked
given()
.body(vr)
.contentType(ContentType.JSON)
.when()
.post("/eca")
.then()
.statusCode(403)
.body(
"passed",
is(false),
"errorCount",
is(1),
"commits.123456789abcdefghijklmnop.errors[0].code",
is(APIStatusCode.ERROR_SIGN_OFF.getValue()));
.statusCode(200)
.body("passed", is(true), "errorCount", is(0));
}
@Test
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment