Add a test for user authentication of draft and published comments
Draft comments require user authentication and should throw AuthException for anonymous users. However published comments should be visible for both identified and anonymous users. Change-Id: I435529e5e78414686fadcf266426c2f14fe1f343
This commit is contained in:
@@ -57,12 +57,10 @@ public class ListChangeComments implements RestReadView<ChangeResource> {
|
||||
@Override
|
||||
public Response<Map<String, List<CommentInfo>>> apply(ChangeResource rsrc)
|
||||
throws AuthException, PermissionBackendException {
|
||||
/** List change comments does not require authentication */
|
||||
return Response.ok(getAsMap(listComments(rsrc), rsrc));
|
||||
}
|
||||
|
||||
public List<CommentInfo> getComments(ChangeResource rsrc) throws PermissionBackendException {
|
||||
/** List change comments does not require authentication */
|
||||
return getAsList(listComments(rsrc), rsrc);
|
||||
}
|
||||
|
||||
|
||||
@@ -682,6 +682,15 @@ public class CommentsIT extends AbstractDaemonTest {
|
||||
assertThat(c2.line).isEqualTo(1);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void listChangeDraftsAnonymousThrowsAuthException() throws Exception {
|
||||
PushOneCommit.Result r = createChange();
|
||||
String changeId = r.getChangeId();
|
||||
|
||||
requestScopeOperations.setApiUserAnonymous();
|
||||
assertThrows(AuthException.class, () -> gApi.changes().id(changeId).draftsAsList());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void listChangeComments() throws Exception {
|
||||
PushOneCommit.Result r1 = createChange();
|
||||
@@ -715,6 +724,28 @@ public class CommentsIT extends AbstractDaemonTest {
|
||||
assertThat(c2.line).isEqualTo(1);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void listChangeCommentsAnonymousDoesNotRequireAuth() throws Exception {
|
||||
PushOneCommit.Result r1 = createChange();
|
||||
|
||||
PushOneCommit.Result r2 =
|
||||
pushFactory
|
||||
.create(admin.newIdent(), testRepo, SUBJECT, FILE_NAME, "new cntent", r1.getChangeId())
|
||||
.to("refs/for/master");
|
||||
|
||||
addComment(r1, "nit: trailing whitespace");
|
||||
addComment(r2, "typo: content");
|
||||
|
||||
List<CommentInfo> comments = gApi.changes().id(r1.getChangeId()).commentsAsList();
|
||||
assertThat(comments.stream().map(c -> c.message).collect(toList()))
|
||||
.containsExactly("nit: trailing whitespace", "typo: content");
|
||||
|
||||
requestScopeOperations.setApiUserAnonymous();
|
||||
comments = gApi.changes().id(r1.getChangeId()).commentsAsList();
|
||||
assertThat(comments.stream().map(c -> c.message).collect(toList()))
|
||||
.containsExactly("nit: trailing whitespace", "typo: content");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void listChangeWithDrafts() throws Exception {
|
||||
for (Integer line : lines) {
|
||||
|
||||
Reference in New Issue
Block a user