Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
Eclipse Foundation
IT
APIs
git-eca-rest-api
Commits
16a65865
Commit
16a65865
authored
Jun 07, 2021
by
Martin Lowe
🇨🇦
Committed by
Martin Lowe
Jun 07, 2021
Browse files
Add tests for allow list and fix author allow list check
parent
29e26739
Changes
2
Hide whitespace changes
Inline
Side-by-side
src/main/java/org/eclipsefoundation/git/eca/resource/ValidationResource.java
View file @
16a65865
...
...
@@ -185,7 +185,15 @@ public class ValidationResource {
EclipseUser
eclipseAuthor
=
getIdentifiedUser
(
author
);
if
(
eclipseAuthor
==
null
)
{
// if the user is a bot, generate a stubbed user
if
(!
userIsABot
(
author
.
getMail
(),
filteredProjects
))
{
if
(
isAllowedUser
(
author
.
getMail
()))
{
addMessage
(
response
,
String
.
format
(
"Automated user '%1$s' detected for author of commit %2$s"
,
author
.
getMail
(),
c
.
getHash
()),
c
.
getHash
());
eclipseAuthor
=
EclipseUser
.
createBotStub
(
author
);
}
else
if
(!
userIsABot
(
author
.
getMail
(),
filteredProjects
))
{
addMessage
(
response
,
String
.
format
(
...
...
src/test/java/org/eclipsefoundation/git/eca/resource/ValidationResourceTest.java
View file @
16a65865
...
...
@@ -1064,4 +1064,62 @@ class ValidationResourceTest {
// Should be invalid as no user exists with "Github" handle that matches some_guy
given
().
body
(
vr
).
contentType
(
ContentType
.
JSON
).
when
().
post
(
"/eca"
).
then
().
statusCode
(
403
);
}
@Test
void
validateAllowListAuthor_success
()
throws
URISyntaxException
{
GitUser
g1
=
new
GitUser
();
g1
.
setName
(
"grunter"
);
g1
.
setMail
(
"grunter+123456789@users.noreply.github.com"
);
GitUser
g2
=
new
GitUser
();
g2
.
setName
(
"grunter"
);
g2
.
setMail
(
"noreply@github.com"
);
List
<
Commit
>
commits
=
new
ArrayList
<>();
// create sample commits
Commit
c1
=
new
Commit
();
c1
.
setAuthor
(
g2
);
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
.
GERRIT
);
vr
.
setRepoUrl
(
new
URI
(
"/gitroot/sample/gerrit.other-project"
));
vr
.
setCommits
(
commits
);
vr
.
setStrictMode
(
true
);
// test output w/ assertions
// Should be valid as grunter used a no-reply Github account and has a matching GH handle
given
().
body
(
vr
).
contentType
(
ContentType
.
JSON
).
when
().
post
(
"/eca"
).
then
().
statusCode
(
200
);
}
@Test
void
validateAllowListCommitter_success
()
throws
URISyntaxException
{
GitUser
g1
=
new
GitUser
();
g1
.
setName
(
"grunter"
);
g1
.
setMail
(
"grunter+123456789@users.noreply.github.com"
);
GitUser
g2
=
new
GitUser
();
g2
.
setName
(
"grunter"
);
g2
.
setMail
(
"noreply@github.com"
);
List
<
Commit
>
commits
=
new
ArrayList
<>();
// create sample commits
Commit
c1
=
new
Commit
();
c1
.
setAuthor
(
g1
);
c1
.
setCommitter
(
g2
);
c1
.
setHash
(
"123456789abcdefghijklmnop"
);
c1
.
setSubject
(
"All of the things"
);
c1
.
setParents
(
Arrays
.
asList
(
"46bb69bf6aa4ed26b2bf8c322ae05bef0bcc5c10"
));
commits
.
add
(
c1
);
ValidationRequest
vr
=
new
ValidationRequest
();
vr
.
setProvider
(
ProviderType
.
GERRIT
);
vr
.
setRepoUrl
(
new
URI
(
"/gitroot/sample/gerrit.other-project"
));
vr
.
setCommits
(
commits
);
vr
.
setStrictMode
(
true
);
// test output w/ assertions
// Should be valid as grunter used a no-reply Github account and has a matching GH handle
given
().
body
(
vr
).
contentType
(
ContentType
.
JSON
).
when
().
post
(
"/eca"
).
then
().
statusCode
(
200
);
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment