Limit the maximum length of topic
Since our internal change index has an upper limit 1MiB for EXACT Text field, this change prevents users to put topic which is larger than 2048. Bug: Issue 7197 Change-Id: I705869995627820be3a49e157fa8c81dae96faf0
This commit is contained in:
		@@ -149,6 +149,7 @@ import java.util.Optional;
 | 
			
		||||
import java.util.Set;
 | 
			
		||||
import java.util.function.Function;
 | 
			
		||||
import java.util.stream.Collectors;
 | 
			
		||||
import java.util.stream.Stream;
 | 
			
		||||
import org.eclipse.jgit.internal.storage.dfs.InMemoryRepository;
 | 
			
		||||
import org.eclipse.jgit.junit.TestRepository;
 | 
			
		||||
import org.eclipse.jgit.lib.Constants;
 | 
			
		||||
@@ -3288,6 +3289,16 @@ public class ChangeIT extends AbstractDaemonTest {
 | 
			
		||||
    gApi.changes().id(createChange().getChangeId()).pureRevert();
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  @Test
 | 
			
		||||
  public void putTopicExceedLimitFails() throws Exception {
 | 
			
		||||
    String changeId = createChange().getChangeId();
 | 
			
		||||
    String topic = Stream.generate(() -> "t").limit(2049).collect(Collectors.joining());
 | 
			
		||||
 | 
			
		||||
    exception.expect(BadRequestException.class);
 | 
			
		||||
    exception.expectMessage("topic length exceeds the limit");
 | 
			
		||||
    gApi.changes().id(changeId).topic(topic);
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  private String getCommitMessage(String changeId) throws RestApiException, IOException {
 | 
			
		||||
    return gApi.changes().id(changeId).current().file("/COMMIT_MSG").content().asString();
 | 
			
		||||
  }
 | 
			
		||||
 
 | 
			
		||||
@@ -88,6 +88,8 @@ import java.util.Map;
 | 
			
		||||
import java.util.Optional;
 | 
			
		||||
import java.util.Set;
 | 
			
		||||
import java.util.regex.Pattern;
 | 
			
		||||
import java.util.stream.Collectors;
 | 
			
		||||
import java.util.stream.Stream;
 | 
			
		||||
import org.eclipse.jgit.api.errors.GitAPIException;
 | 
			
		||||
import org.eclipse.jgit.junit.TestRepository;
 | 
			
		||||
import org.eclipse.jgit.lib.ObjectId;
 | 
			
		||||
@@ -344,6 +346,20 @@ public abstract class AbstractPushForReview extends AbstractDaemonTest {
 | 
			
		||||
    r.assertPushOptions(pushOptions);
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  @Test
 | 
			
		||||
  public void pushForMasterWithTopicInRefExceedLimitFails() throws Exception {
 | 
			
		||||
    String topic = Stream.generate(() -> "t").limit(2049).collect(Collectors.joining());
 | 
			
		||||
    PushOneCommit.Result r = pushTo("refs/for/master/" + topic);
 | 
			
		||||
    r.assertErrorStatus("topic length exceeds the limit (2048)");
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  @Test
 | 
			
		||||
  public void pushForMasterWithTopicAsOptionExceedLimitFails() throws Exception {
 | 
			
		||||
    String topic = Stream.generate(() -> "t").limit(2049).collect(Collectors.joining());
 | 
			
		||||
    PushOneCommit.Result r = pushTo("refs/for/master%topic=" + topic);
 | 
			
		||||
    r.assertErrorStatus("topic length exceeds the limit (2048)");
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  @Test
 | 
			
		||||
  public void pushForMasterWithNotify() throws Exception {
 | 
			
		||||
    // create a user that watches the project
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user