Commit 4d3e3e77 authored by Martin Lowe's avatar Martin Lowe 🇨🇦 Committed by Martin Lowe
Browse files

Revert "Fix tests associated with changes to bot detection logic"

This reverts commit 2eb52040.
parent 84e06175
...@@ -291,7 +291,6 @@ public class ValidationResource { ...@@ -291,7 +291,6 @@ public class ValidationResource {
List<JsonNode> botObjs = getBots(); List<JsonNode> botObjs = getBots();
// for each of the matched projects, check the bot for the matching project ID // for each of the matched projects, check the bot for the matching project ID
for (Project p : filteredProjects) { for (Project p : filteredProjects) {
LOGGER.debug("Checking project {} for matching bots", p.getProjectId());
for (JsonNode bot : botObjs) { for (JsonNode bot : botObjs) {
// if the project ID match, and one of the email fields matches, then user is bot // if the project ID match, and one of the email fields matches, then user is bot
if (p.getProjectId().equalsIgnoreCase(bot.get("projectId").asText()) if (p.getProjectId().equalsIgnoreCase(bot.get("projectId").asText())
......
...@@ -16,11 +16,8 @@ import javax.annotation.PostConstruct; ...@@ -16,11 +16,8 @@ import javax.annotation.PostConstruct;
import javax.enterprise.context.ApplicationScoped; import javax.enterprise.context.ApplicationScoped;
import org.eclipse.microprofile.rest.client.inject.RestClient; import org.eclipse.microprofile.rest.client.inject.RestClient;
import org.eclipsefoundation.git.eca.model.BotUser;
import com.fasterxml.jackson.databind.JsonNode; import org.eclipsefoundation.git.eca.model.BotUser.SiteSpecificBot;
import com.fasterxml.jackson.databind.node.JsonNodeFactory;
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.fasterxml.jackson.databind.node.TextNode;
import io.quarkus.test.Mock; import io.quarkus.test.Mock;
...@@ -29,43 +26,43 @@ import io.quarkus.test.Mock; ...@@ -29,43 +26,43 @@ import io.quarkus.test.Mock;
@ApplicationScoped @ApplicationScoped
public class MockBotsAPI implements BotsAPI { public class MockBotsAPI implements BotsAPI {
private List<JsonNode> src; private List<BotUser> src;
@PostConstruct @PostConstruct
public void build() { public void build() {
this.src = new ArrayList<>(); this.src = new ArrayList<>();
ObjectNode b1 = new ObjectNode(JsonNodeFactory.instance); BotUser b1 = new BotUser();
b1.set("id", new TextNode("1")); b1.setId("1");
b1.set("email", new TextNode("1.bot@eclipse.org")); b1.setEmail("1.bot@eclipse.org");
b1.set("projectId", new TextNode("sample.proj")); b1.setProjectId("sample.proj");
b1.set("username", new TextNode("projbot")); b1.setUsername("projbot");
src.add(b1); src.add(b1);
ObjectNode b2 = new ObjectNode(JsonNodeFactory.instance); BotUser b2 = new BotUser();
b2.set("id", new TextNode("10")); b2.setId("10");
b2.set("email", new TextNode("2.bot@eclipse.org")); b2.setEmail("2.bot@eclipse.org");
b2.set("projectId", new TextNode("sample.proto")); b2.setProjectId("sample.proto");
b2.set("username", new TextNode("protobot")); b2.setUsername("protobot");
ObjectNode ssbGH = new ObjectNode(JsonNodeFactory.instance); SiteSpecificBot ssbGH = new SiteSpecificBot();
ssbGH.set("email", new TextNode("2.bot-github@eclipse.org")); ssbGH.setEmail("2.bot-github@eclipse.org");
ssbGH.set("username", new TextNode("protobot-gh")); ssbGH.setUsername("protobot-gh");
b2.set("github.com", ssbGH); b2.setGithubBot(ssbGH);
src.add(b2); src.add(b2);
ObjectNode b3 = new ObjectNode(JsonNodeFactory.instance); BotUser b3 = new BotUser();
b3.set("id", new TextNode("11")); b3.setId("11");
b3.set("email", new TextNode("3.bot@eclipse.org")); b3.setEmail("3.bot@eclipse.org");
b3.set("projectId", new TextNode("spec.proj")); b3.setProjectId("spec.proj");
b3.set("username", new TextNode("specbot")); b3.setUsername("specbot");
ObjectNode ssbGL = new ObjectNode(JsonNodeFactory.instance); SiteSpecificBot ssbGL = new SiteSpecificBot();
ssbGL.set("email", new TextNode("3.bot-gitlab@eclipse.org")); ssbGL.setEmail("3.bot-gitlab@eclipse.org");
ssbGL.set("username", new TextNode("protobot-gl")); ssbGL.setUsername("protobot-gl");
b3.set("gitlab.eclipse.org",ssbGL); b3.setGitlabBot(ssbGL);
src.add(b3); src.add(b3);
} }
@Override @Override
public List<JsonNode> getBots() { public List<BotUser> getBots() {
return new ArrayList<>(src); return new ArrayList<>(src);
} }
} }
...@@ -77,8 +77,8 @@ public class MockProjectsAPI implements ProjectsAPI { ...@@ -77,8 +77,8 @@ public class MockProjectsAPI implements ProjectsAPI {
p2.setProjectId("sample.proto"); p2.setProjectId("sample.proto");
p2.setSpecWorkingGroup(null); p2.setSpecWorkingGroup(null);
p2.setGithubRepos(Arrays.asList(r3)); p2.setGithubRepos(Arrays.asList(r3));
p2.setGerritRepos(Arrays.asList(r6)); p1.setGerritRepos(Arrays.asList(r6));
p2.setGitlabRepos(Arrays.asList(r8)); p1.setGitlabRepos(Arrays.asList(r8));
p2.setCommitters(Arrays.asList(u2)); p2.setCommitters(Arrays.asList(u2));
src.add(p2); src.add(p2);
...@@ -87,7 +87,7 @@ public class MockProjectsAPI implements ProjectsAPI { ...@@ -87,7 +87,7 @@ public class MockProjectsAPI implements ProjectsAPI {
p3.setProjectId("spec.proj"); p3.setProjectId("spec.proj");
p3.setSpecWorkingGroup("proj1"); p3.setSpecWorkingGroup("proj1");
p3.setGithubRepos(Arrays.asList(r4)); p3.setGithubRepos(Arrays.asList(r4));
p3.setGitlabRepos(Arrays.asList(r7)); p1.setGitlabRepos(Arrays.asList(r7));
p3.setCommitters(Arrays.asList(u1, u2)); p3.setCommitters(Arrays.asList(u1, u2));
src.add(p3); src.add(p3);
} }
......
...@@ -669,32 +669,6 @@ class ValidationResourceTest { ...@@ -669,32 +669,6 @@ class ValidationResourceTest {
@Test @Test
void validateBotCommiterAccessGithub() throws URISyntaxException { void validateBotCommiterAccessGithub() throws URISyntaxException {
// set up test users
GitUser g1 = new GitUser();
g1.setName("grunter");
g1.setMail("grunt@important.co");
List<Commit> commits = new ArrayList<>();
// create sample commits
Commit c1 = new Commit();
c1.setAuthor(g1);
c1.setCommitter(g1);
c1.setHash("123456789abcdefghijklmnop");
c1.setSubject("All of the things");
c1.setParents(Arrays.asList("46bb69bf6aa4ed26b2bf8c322ae05bef0bcc5c10"));
commits.add(c1);
ValidationRequest vr = new ValidationRequest();
vr.setProvider(ProviderType.GITHUB);
vr.setRepoUrl(new URI("http://www.github.com/eclipsefdn/sample"));
vr.setCommits(commits);
// test output w/ assertions
// Should be valid as user is a committer
given().body(vr).contentType(ContentType.JSON).when().post("/eca").then().statusCode(200);
}
@Test
void validateBotCommiterAccessGithub_invalidBot() throws URISyntaxException {
// set up test users // set up test users
GitUser g1 = new GitUser(); GitUser g1 = new GitUser();
g1.setName("protobot-gh"); g1.setName("protobot-gh");
...@@ -715,8 +689,8 @@ class ValidationResourceTest { ...@@ -715,8 +689,8 @@ class ValidationResourceTest {
vr.setRepoUrl(new URI("http://www.github.com/eclipsefdn/sample")); vr.setRepoUrl(new URI("http://www.github.com/eclipsefdn/sample"));
vr.setCommits(commits); vr.setCommits(commits);
// test output w/ assertions // test output w/ assertions
// Should be invalid as bots should only commit on their own projects (including aliases) // Should be valid as bots don't need sign off and should be valid on any proj
given().body(vr).contentType(ContentType.JSON).when().post("/eca").then().statusCode(403); given().body(vr).contentType(ContentType.JSON).when().post("/eca").then().statusCode(200);
} }
@Test @Test
...@@ -749,7 +723,7 @@ class ValidationResourceTest { ...@@ -749,7 +723,7 @@ class ValidationResourceTest {
void validateBotCommiterAccessGitlab() throws URISyntaxException { void validateBotCommiterAccessGitlab() throws URISyntaxException {
// set up test users // set up test users
GitUser g1 = new GitUser(); GitUser g1 = new GitUser();
g1.setName("specbot-gl"); g1.setName("specbot-gh");
g1.setMail("3.bot-gitlab@eclipse.org"); g1.setMail("3.bot-gitlab@eclipse.org");
List<Commit> commits = new ArrayList<>(); List<Commit> commits = new ArrayList<>();
...@@ -767,13 +741,13 @@ class ValidationResourceTest { ...@@ -767,13 +741,13 @@ class ValidationResourceTest {
vr.setRepoUrl(new URI("https://gitlab.eclipse.org/eclipse/dash/dash.handbook.test")); vr.setRepoUrl(new URI("https://gitlab.eclipse.org/eclipse/dash/dash.handbook.test"));
vr.setCommits(commits); vr.setCommits(commits);
// test output w/ assertions // test output w/ assertions
// Should be invalid as bots should only commit on their own projects // Should be valid as bots don't need sign off and should be valid on any proj
given().body(vr).contentType(ContentType.JSON).when().post("/eca").then().statusCode(403); given().body(vr).contentType(ContentType.JSON).when().post("/eca").then().statusCode(200);
} }
@Test @Test
void validateBotCommiterAccessGitlab_wrongEmail() throws URISyntaxException { void validateBotCommiterAccessGitlab_wrongEmail() throws URISyntaxException {
// set up test users - uses Gerrit/LDAP email (expects Gitlab email) // set up test users - uses Gerrit/LDAP email (wrong for case)
GitUser g1 = new GitUser(); GitUser g1 = new GitUser();
g1.setName("specbot"); g1.setName("specbot");
g1.setMail("3.bot@eclipse.org"); g1.setMail("3.bot@eclipse.org");
...@@ -794,7 +768,7 @@ class ValidationResourceTest { ...@@ -794,7 +768,7 @@ class ValidationResourceTest {
vr.setCommits(commits); vr.setCommits(commits);
// test output w/ assertions // test output w/ assertions
// Should be invalid as wrong email was used for bot (uses Gerrit bot email) // Should be invalid as wrong email was used for bot (uses Gerrit bot email)
given().body(vr).contentType(ContentType.JSON).when().post("/eca").then().statusCode(200); given().body(vr).contentType(ContentType.JSON).when().post("/eca").then().statusCode(403);
} }
@Test @Test
...@@ -820,13 +794,13 @@ class ValidationResourceTest { ...@@ -820,13 +794,13 @@ class ValidationResourceTest {
vr.setCommits(commits); vr.setCommits(commits);
vr.setStrictMode(true); vr.setStrictMode(true);
// test output w/ assertions // test output w/ assertions
// Should be valid as bots should only commit on their own projects (including aliases) // Should be valid as bots don't need sign off and should be valid on any proj
given().body(vr).contentType(ContentType.JSON).when().post("/eca").then().statusCode(200); given().body(vr).contentType(ContentType.JSON).when().post("/eca").then().statusCode(200);
} }
@Test @Test
void validateBotCommiterAccessGerrit_aliasEmail() throws URISyntaxException { void validateBotCommiterAccessGerrit_wrongEmail() throws URISyntaxException {
// set up test users - uses GH (instead of expected Gerrit/LDAP email) // set up test users - uses Gerrit/LDAP email (wrong for case)
GitUser g1 = new GitUser(); GitUser g1 = new GitUser();
g1.setName("protobot-gh"); g1.setName("protobot-gh");
g1.setMail("2.bot-github@eclipse.org"); g1.setMail("2.bot-github@eclipse.org");
...@@ -847,7 +821,7 @@ class ValidationResourceTest { ...@@ -847,7 +821,7 @@ class ValidationResourceTest {
vr.setCommits(commits); vr.setCommits(commits);
vr.setStrictMode(true); vr.setStrictMode(true);
// test output w/ assertions // test output w/ assertions
// Should be valid as bots should only commit on their own projects (including aliases) // Should be invalid as wrong email was used for bot (uses Gerrit bot email)
given().body(vr).contentType(ContentType.JSON).when().post("/eca").then().statusCode(200); given().body(vr).contentType(ContentType.JSON).when().post("/eca").then().statusCode(403);
} }
} }
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