| Ronald Bhuleskar | fbe16e8 | 2020-12-18 20:15:26 -0800 | [diff] [blame] | 1 | // Copyright 2021 Google LLC. All Rights Reserved. |
| 2 | // |
| 3 | // Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | // you may not use this file except in compliance with the License. |
| 5 | // You may obtain a copy of the License at |
| 6 | // |
| 7 | // http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | // |
| 9 | // Unless required by applicable law or agreed to in writing, software |
| 10 | // distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | // See the License for the specific language governing permissions and |
| 13 | // limitations under the License. |
| 14 | |
| 15 | package com.google.gitiles; |
| 16 | |
| 17 | import static com.google.common.truth.Truth.assertThat; |
| Ronald Bhuleskar | fbe16e8 | 2020-12-18 20:15:26 -0800 | [diff] [blame] | 18 | import static javax.servlet.http.HttpServletResponse.SC_MOVED_TEMPORARILY; |
| 19 | import static javax.servlet.http.HttpServletResponse.SC_OK; |
| 20 | |
| Ronald Bhuleskar | 5764066 | 2021-02-05 11:53:17 -0800 | [diff] [blame] | 21 | import com.google.common.base.Strings; |
| Ronald Bhuleskar | fbe16e8 | 2020-12-18 20:15:26 -0800 | [diff] [blame] | 22 | import com.google.common.net.HttpHeaders; |
| 23 | import java.util.Optional; |
| Ronald Bhuleskar | 5764066 | 2021-02-05 11:53:17 -0800 | [diff] [blame] | 24 | import javax.annotation.Nullable; |
| Ronald Bhuleskar | fbe16e8 | 2020-12-18 20:15:26 -0800 | [diff] [blame] | 25 | import org.eclipse.jgit.internal.storage.dfs.DfsRepository; |
| 26 | import org.eclipse.jgit.internal.storage.dfs.DfsRepositoryDescription; |
| 27 | import org.eclipse.jgit.internal.storage.dfs.InMemoryRepository; |
| 28 | import org.eclipse.jgit.junit.TestRepository; |
| Ronald Bhuleskar | ffc9a33 | 2021-05-06 10:20:41 -0700 | [diff] [blame] | 29 | import org.eclipse.jgit.lib.Constants; |
| Ronald Bhuleskar | fbe16e8 | 2020-12-18 20:15:26 -0800 | [diff] [blame] | 30 | import org.eclipse.jgit.lib.Repository; |
| 31 | import org.eclipse.jgit.revwalk.RevCommit; |
| 32 | import org.junit.Before; |
| Ronald Bhuleskar | fbe16e8 | 2020-12-18 20:15:26 -0800 | [diff] [blame] | 33 | import org.junit.Test; |
| 34 | import org.junit.runner.RunWith; |
| 35 | import org.junit.runners.JUnit4; |
| 36 | |
| 37 | /** Tests for BranchRedirect. */ |
| 38 | @RunWith(JUnit4.class) |
| Ronald Bhuleskar | 999a71d | 2021-11-19 15:24:51 -0800 | [diff] [blame] | 39 | public class BranchRedirectTest { |
| Ronald Bhuleskar | fbe16e8 | 2020-12-18 20:15:26 -0800 | [diff] [blame] | 40 | private static final String MASTER = "refs/heads/master"; |
| 41 | private static final String MAIN = "refs/heads/main"; |
| 42 | private static final String DEVELOP = "refs/heads/develop"; |
| 43 | private static final String FOO = "refs/heads/foo"; |
| 44 | private static final String BAR = "refs/heads/bar"; |
| 45 | private static final String ORIGIN = "http://localhost"; |
| 46 | private static final String QUERY_STRING_HTML = "format=html"; |
| 47 | private static final String QUERY_STRING_JSON = "format=json"; |
| 48 | |
| 49 | private TestRepository<DfsRepository> repo; |
| 50 | private GitilesServlet servlet; |
| 51 | |
| 52 | @Before |
| 53 | public void setUp() throws Exception { |
| 54 | repo = new TestRepository<>(new InMemoryRepository(new DfsRepositoryDescription("repo"))); |
| Ronald Bhuleskar | 999a71d | 2021-11-19 15:24:51 -0800 | [diff] [blame] | 55 | BranchRedirect branchRedirect = |
| 56 | new BranchRedirect() { |
| Ronald Bhuleskar | fbe16e8 | 2020-12-18 20:15:26 -0800 | [diff] [blame] | 57 | @Override |
| 58 | protected Optional<String> getRedirectBranch(Repository repo, String sourceBranch) { |
| Ronald Bhuleskar | ffc9a33 | 2021-05-06 10:20:41 -0700 | [diff] [blame] | 59 | if (MASTER.equals(toFullBranchName(sourceBranch))) { |
| Ronald Bhuleskar | fbe16e8 | 2020-12-18 20:15:26 -0800 | [diff] [blame] | 60 | return Optional.of(MAIN); |
| 61 | } |
| Ronald Bhuleskar | ffc9a33 | 2021-05-06 10:20:41 -0700 | [diff] [blame] | 62 | if (FOO.equals(toFullBranchName(sourceBranch))) { |
| Ronald Bhuleskar | fbe16e8 | 2020-12-18 20:15:26 -0800 | [diff] [blame] | 63 | return Optional.of(BAR); |
| 64 | } |
| 65 | return Optional.empty(); |
| 66 | } |
| 67 | }; |
| Ronald Bhuleskar | 999a71d | 2021-11-19 15:24:51 -0800 | [diff] [blame] | 68 | servlet = TestGitilesServlet.create(repo, new GitwebRedirectFilter(), branchRedirect); |
| Ronald Bhuleskar | fbe16e8 | 2020-12-18 20:15:26 -0800 | [diff] [blame] | 69 | } |
| 70 | |
| 71 | @Test |
| 72 | public void show_withoutRedirect() throws Exception { |
| 73 | repo.branch("develop").commit().add("foo", "contents").create(); |
| 74 | |
| 75 | String path = "/repo/+/refs/heads/develop/foo"; |
| 76 | FakeHttpServletRequest req = newHttpRequest(path, ORIGIN, QUERY_STRING_HTML); |
| 77 | FakeHttpServletResponse res = new FakeHttpServletResponse(); |
| 78 | |
| 79 | servlet.service(req, res); |
| 80 | assertThat(res.getStatus()).isEqualTo(SC_OK); |
| 81 | } |
| 82 | |
| 83 | @Test |
| 84 | public void show_withRedirect() throws Exception { |
| Ronald Bhuleskar | 999a71d | 2021-11-19 15:24:51 -0800 | [diff] [blame] | 85 | RevCommit master = repo.branch(MASTER).commit().add("foo", "contents").create(); |
| 86 | repo.branch(MAIN).commit().parent(master).create(); |
| Ronald Bhuleskar | fbe16e8 | 2020-12-18 20:15:26 -0800 | [diff] [blame] | 87 | |
| 88 | String path = "/repo/+/refs/heads/master/foo"; |
| 89 | FakeHttpServletRequest req = newHttpRequest(path, ORIGIN, QUERY_STRING_HTML); |
| 90 | FakeHttpServletResponse res = new FakeHttpServletResponse(); |
| 91 | |
| 92 | servlet.service(req, res); |
| Ronald Bhuleskar | 999a71d | 2021-11-19 15:24:51 -0800 | [diff] [blame] | 93 | assertThat(res.getActualBodyString()).contains("repo/+/refs/heads/main/foo"); |
| 94 | assertThat(res.getActualBodyString()).doesNotContain("repo/+/refs/heads/master/foo"); |
| Ronald Bhuleskar | fbe16e8 | 2020-12-18 20:15:26 -0800 | [diff] [blame] | 95 | } |
| 96 | |
| 97 | @Test |
| Ronald Bhuleskar | 5764066 | 2021-02-05 11:53:17 -0800 | [diff] [blame] | 98 | public void show_withRedirect_onDefaultFormatType() throws Exception { |
| Ronald Bhuleskar | 999a71d | 2021-11-19 15:24:51 -0800 | [diff] [blame] | 99 | RevCommit master = repo.branch(MASTER).commit().add("foo", "contents").create(); |
| 100 | repo.branch(MAIN).commit().parent(master).create(); |
| Ronald Bhuleskar | 5764066 | 2021-02-05 11:53:17 -0800 | [diff] [blame] | 101 | |
| 102 | String path = "/repo/+/refs/heads/master/foo"; |
| 103 | FakeHttpServletRequest req = newHttpRequest(path, ORIGIN, null); |
| 104 | FakeHttpServletResponse res = new FakeHttpServletResponse(); |
| 105 | |
| 106 | servlet.service(req, res); |
| Ronald Bhuleskar | 999a71d | 2021-11-19 15:24:51 -0800 | [diff] [blame] | 107 | assertThat(res.getStatus()).isEqualTo(SC_OK); |
| 108 | assertThat(res.getActualBodyString()).contains("repo/+/refs/heads/main/foo"); |
| 109 | assertThat(res.getActualBodyString()).doesNotContain("repo/+/refs/heads/master/foo"); |
| Ronald Bhuleskar | 5764066 | 2021-02-05 11:53:17 -0800 | [diff] [blame] | 110 | } |
| 111 | |
| 112 | @Test |
| Ronald Bhuleskar | ffc9a33 | 2021-05-06 10:20:41 -0700 | [diff] [blame] | 113 | public void show_withRedirect_usingShortRefInUrl() throws Exception { |
| Ronald Bhuleskar | 999a71d | 2021-11-19 15:24:51 -0800 | [diff] [blame] | 114 | RevCommit master = repo.branch(MASTER).commit().add("foo", "contents").create(); |
| 115 | repo.branch(MAIN).commit().parent(master).create(); |
| Ronald Bhuleskar | ffc9a33 | 2021-05-06 10:20:41 -0700 | [diff] [blame] | 116 | |
| 117 | String path = "/repo/+/master/foo"; |
| 118 | FakeHttpServletRequest req = newHttpRequest(path, ORIGIN, QUERY_STRING_HTML); |
| 119 | FakeHttpServletResponse res = new FakeHttpServletResponse(); |
| 120 | |
| 121 | servlet.service(req, res); |
| Ronald Bhuleskar | 999a71d | 2021-11-19 15:24:51 -0800 | [diff] [blame] | 122 | assertThat(res.getStatus()).isEqualTo(SC_OK); |
| 123 | assertThat(res.getActualBodyString()).contains("repo/+/refs/heads/main/foo"); |
| 124 | assertThat(res.getActualBodyString()).doesNotContain("repo/+/master/foo"); |
| Ronald Bhuleskar | ffc9a33 | 2021-05-06 10:20:41 -0700 | [diff] [blame] | 125 | } |
| 126 | |
| 127 | @Test |
| Ronald Bhuleskar | fbe16e8 | 2020-12-18 20:15:26 -0800 | [diff] [blame] | 128 | public void show_onAutomationRequest() throws Exception { |
| Ronald Bhuleskar | 999a71d | 2021-11-19 15:24:51 -0800 | [diff] [blame] | 129 | RevCommit master = repo.branch(MASTER).commit().add("foo", "contents").create(); |
| 130 | repo.branch(MAIN).commit().parent(master).create(); |
| Ronald Bhuleskar | fbe16e8 | 2020-12-18 20:15:26 -0800 | [diff] [blame] | 131 | |
| 132 | String path = "/repo/+/refs/heads/master/foo"; |
| 133 | FakeHttpServletRequest req = newHttpRequest(path, ORIGIN, QUERY_STRING_JSON); |
| 134 | FakeHttpServletResponse res = new FakeHttpServletResponse(); |
| 135 | |
| 136 | servlet.service(req, res); |
| 137 | assertThat(res.getStatus()).isEqualTo(SC_OK); |
| Ronald Bhuleskar | 999a71d | 2021-11-19 15:24:51 -0800 | [diff] [blame] | 138 | assertThat(res.getActualBodyString()).contains("\"revision\": \"refs/heads/master\""); |
| 139 | assertThat(res.getActualBodyString()).contains("\"path\": \"foo\""); |
| Ronald Bhuleskar | fbe16e8 | 2020-12-18 20:15:26 -0800 | [diff] [blame] | 140 | } |
| 141 | |
| 142 | @Test |
| 143 | public void showParent_withRedirect() throws Exception { |
| 144 | RevCommit parent = repo.branch(MASTER).commit().add("foo", "contents").create(); |
| 145 | repo.branch(MASTER).commit().add("bar", "contents").parent(parent).create(); |
| Ronald Bhuleskar | 999a71d | 2021-11-19 15:24:51 -0800 | [diff] [blame] | 146 | repo.branch(MAIN).commit().parent(parent).create(); |
| Ronald Bhuleskar | fbe16e8 | 2020-12-18 20:15:26 -0800 | [diff] [blame] | 147 | |
| 148 | String path = "/repo/+/refs/heads/master^"; |
| 149 | FakeHttpServletRequest req = newHttpRequest(path, ORIGIN, QUERY_STRING_HTML); |
| 150 | FakeHttpServletResponse res = new FakeHttpServletResponse(); |
| 151 | |
| 152 | servlet.service(req, res); |
| 153 | // It is resolved to the object id by ViewFilter. |
| 154 | assertThat(res.getStatus()).isEqualTo(SC_MOVED_TEMPORARILY); |
| 155 | assertThat(res.getHeader(HttpHeaders.LOCATION)) |
| 156 | .isEqualTo("/b/repo/+/" + parent.toObjectId().name() + "?format=html"); |
| 157 | } |
| 158 | |
| 159 | @Test |
| 160 | public void diff_withRedirect_onSingleBranch() throws Exception { |
| Ronald Bhuleskar | 999a71d | 2021-11-19 15:24:51 -0800 | [diff] [blame] | 161 | RevCommit master = repo.branch(MASTER).commit().add("foo", "contents").create(); |
| 162 | repo.branch(MAIN).commit().parent(master).create(); |
| Ronald Bhuleskar | fbe16e8 | 2020-12-18 20:15:26 -0800 | [diff] [blame] | 163 | repo.branch(DEVELOP).commit().add("foo", "contents").create(); |
| 164 | |
| 165 | String path = "/repo/+/refs/heads/master..refs/heads/develop"; |
| 166 | FakeHttpServletRequest req = newHttpRequest(path, ORIGIN, QUERY_STRING_HTML); |
| 167 | FakeHttpServletResponse res = new FakeHttpServletResponse(); |
| 168 | |
| 169 | servlet.service(req, res); |
| Ronald Bhuleskar | 999a71d | 2021-11-19 15:24:51 -0800 | [diff] [blame] | 170 | assertThat(res.getStatus()).isEqualTo(SC_OK); |
| 171 | assertThat(res.getActualBodyString()) |
| 172 | .contains("/b/repo/+/refs/heads/main..refs/heads/develop/?format=html"); |
| Ronald Bhuleskar | fbe16e8 | 2020-12-18 20:15:26 -0800 | [diff] [blame] | 173 | } |
| 174 | |
| 175 | @Test |
| Ronald Bhuleskar | fbe16e8 | 2020-12-18 20:15:26 -0800 | [diff] [blame] | 176 | public void diff_withRedirect_onBothBranch() throws Exception { |
| Ronald Bhuleskar | 999a71d | 2021-11-19 15:24:51 -0800 | [diff] [blame] | 177 | RevCommit master = repo.branch(MASTER).commit().add("foo", "contents").create(); |
| 178 | repo.branch(MAIN).commit().parent(master).create(); |
| 179 | RevCommit foo = repo.branch(FOO).commit().add("foo", "contents").create(); |
| 180 | repo.branch(BAR).commit().parent(foo).create(); |
| Ronald Bhuleskar | fbe16e8 | 2020-12-18 20:15:26 -0800 | [diff] [blame] | 181 | |
| 182 | String path = "/repo/+/refs/heads/foo..refs/heads/master"; |
| 183 | FakeHttpServletRequest req = newHttpRequest(path, ORIGIN, QUERY_STRING_HTML); |
| 184 | FakeHttpServletResponse res = new FakeHttpServletResponse(); |
| 185 | |
| 186 | servlet.service(req, res); |
| Ronald Bhuleskar | 999a71d | 2021-11-19 15:24:51 -0800 | [diff] [blame] | 187 | assertThat(res.getStatus()).isEqualTo(SC_OK); |
| 188 | assertThat(res.getActualBodyString()) |
| 189 | .contains("/b/repo/+/refs/heads/bar..refs/heads/main/?format=html"); |
| Ronald Bhuleskar | fbe16e8 | 2020-12-18 20:15:26 -0800 | [diff] [blame] | 190 | } |
| 191 | |
| 192 | @Test |
| 193 | public void diff_withRedirect() throws Exception { |
| Ronald Bhuleskar | 999a71d | 2021-11-19 15:24:51 -0800 | [diff] [blame] | 194 | RevCommit master = repo.branch(MASTER).commit().add("foo", "contents").create(); |
| 195 | repo.branch(MAIN).commit().parent(master).create(); |
| Ronald Bhuleskar | fbe16e8 | 2020-12-18 20:15:26 -0800 | [diff] [blame] | 196 | |
| 197 | String path = "/repo/+diff/refs/heads/master^!"; |
| 198 | FakeHttpServletRequest req = newHttpRequest(path, ORIGIN, QUERY_STRING_HTML); |
| 199 | FakeHttpServletResponse res = new FakeHttpServletResponse(); |
| 200 | |
| 201 | servlet.service(req, res); |
| Ronald Bhuleskar | 999a71d | 2021-11-19 15:24:51 -0800 | [diff] [blame] | 202 | assertThat(res.getStatus()).isEqualTo(SC_OK); |
| 203 | assertThat(res.getActualBodyString()).contains("/b/repo/+/refs/heads/main%5E%21/?format=html"); |
| Ronald Bhuleskar | fbe16e8 | 2020-12-18 20:15:26 -0800 | [diff] [blame] | 204 | } |
| 205 | |
| 206 | @Test |
| 207 | public void log_withRedirect() throws Exception { |
| 208 | repo.branch(MASTER).commit().add("foo", "contents").create(); |
| Ronald Bhuleskar | 999a71d | 2021-11-19 15:24:51 -0800 | [diff] [blame] | 209 | RevCommit main = repo.branch(MAIN).commit().create(); |
| Ronald Bhuleskar | fbe16e8 | 2020-12-18 20:15:26 -0800 | [diff] [blame] | 210 | |
| 211 | String path = "/repo/+log/refs/heads/master"; |
| 212 | FakeHttpServletRequest req = newHttpRequest(path, ORIGIN, QUERY_STRING_HTML); |
| 213 | FakeHttpServletResponse res = new FakeHttpServletResponse(); |
| 214 | |
| 215 | servlet.service(req, res); |
| Ronald Bhuleskar | 999a71d | 2021-11-19 15:24:51 -0800 | [diff] [blame] | 216 | assertThat(res.getStatus()).isEqualTo(SC_OK); |
| 217 | assertThat(res.getActualBodyString()).contains("Log - refs/heads/main"); |
| 218 | assertThat(res.getActualBodyString()).contains("/b/repo/+/" + main.toObjectId().getName()); |
| Ronald Bhuleskar | fbe16e8 | 2020-12-18 20:15:26 -0800 | [diff] [blame] | 219 | } |
| 220 | |
| 221 | @Test |
| Ronald Bhuleskar | fbe16e8 | 2020-12-18 20:15:26 -0800 | [diff] [blame] | 222 | public void diff_withGrandParent_redirect() throws Exception { |
| 223 | RevCommit parent1 = repo.branch(MASTER).commit().add("foo", "contents").create(); |
| 224 | RevCommit parent2 = |
| 225 | repo.branch(MASTER).commit().add("bar", "contents").parent(parent1).create(); |
| Ronald Bhuleskar | 999a71d | 2021-11-19 15:24:51 -0800 | [diff] [blame] | 226 | RevCommit master = repo.branch(MASTER).commit().add("bar", "contents").parent(parent2).create(); |
| 227 | repo.branch(MAIN).commit().parent(master).create(); |
| Ronald Bhuleskar | fbe16e8 | 2020-12-18 20:15:26 -0800 | [diff] [blame] | 228 | |
| 229 | String path = "/repo/+diff/refs/heads/master^^..refs/heads/master"; |
| 230 | FakeHttpServletRequest req = newHttpRequest(path, ORIGIN, QUERY_STRING_HTML); |
| 231 | FakeHttpServletResponse res = new FakeHttpServletResponse(); |
| 232 | |
| 233 | servlet.service(req, res); |
| Ronald Bhuleskar | 999a71d | 2021-11-19 15:24:51 -0800 | [diff] [blame] | 234 | assertThat(res.getStatus()).isEqualTo(SC_OK); |
| 235 | assertThat(res.getActualBodyString()) |
| 236 | .contains("/b/repo/+/refs/heads/main%5E%5E..refs/heads/main/?format=html"); |
| Ronald Bhuleskar | fbe16e8 | 2020-12-18 20:15:26 -0800 | [diff] [blame] | 237 | } |
| 238 | |
| 239 | @Test |
| Ronald Bhuleskar | fbe16e8 | 2020-12-18 20:15:26 -0800 | [diff] [blame] | 240 | public void diff_withRelativeParent_redirect() throws Exception { |
| 241 | RevCommit parent1 = repo.branch(MASTER).commit().add("foo", "contents").create(); |
| 242 | RevCommit parent2 = |
| 243 | repo.branch(MASTER).commit().add("bar", "contents").parent(parent1).create(); |
| Ronald Bhuleskar | 999a71d | 2021-11-19 15:24:51 -0800 | [diff] [blame] | 244 | RevCommit master = repo.branch(MASTER).commit().add("bar", "contents").parent(parent2).create(); |
| 245 | repo.branch(MAIN).commit().parent(master).create(); |
| Ronald Bhuleskar | fbe16e8 | 2020-12-18 20:15:26 -0800 | [diff] [blame] | 246 | |
| 247 | String path = "/repo/+diff/refs/heads/master~1..refs/heads/master"; |
| 248 | FakeHttpServletRequest req = newHttpRequest(path, ORIGIN, QUERY_STRING_HTML); |
| 249 | FakeHttpServletResponse res = new FakeHttpServletResponse(); |
| 250 | |
| 251 | servlet.service(req, res); |
| Ronald Bhuleskar | 999a71d | 2021-11-19 15:24:51 -0800 | [diff] [blame] | 252 | assertThat(res.getStatus()).isEqualTo(SC_OK); |
| 253 | assertThat(res.getActualBodyString()).contains("/b/repo/+/refs/heads/main%5E%21/?format=html"); |
| Ronald Bhuleskar | fbe16e8 | 2020-12-18 20:15:26 -0800 | [diff] [blame] | 254 | } |
| 255 | |
| 256 | @Test |
| Ronald Bhuleskar | fbe16e8 | 2020-12-18 20:15:26 -0800 | [diff] [blame] | 257 | public void diff_withRelativeGrandParent_redirect() throws Exception { |
| 258 | RevCommit parent1 = repo.branch(MASTER).commit().add("foo", "contents").create(); |
| 259 | RevCommit parent2 = |
| 260 | repo.branch(MASTER).commit().add("bar", "contents").parent(parent1).create(); |
| Ronald Bhuleskar | 999a71d | 2021-11-19 15:24:51 -0800 | [diff] [blame] | 261 | RevCommit master = repo.branch(MASTER).commit().add("bar", "contents").parent(parent2).create(); |
| 262 | repo.branch(MAIN).commit().parent(master).create(); |
| Ronald Bhuleskar | fbe16e8 | 2020-12-18 20:15:26 -0800 | [diff] [blame] | 263 | |
| 264 | String path = "/repo/+diff/refs/heads/master~2..refs/heads/master"; |
| 265 | FakeHttpServletRequest req = newHttpRequest(path, ORIGIN, QUERY_STRING_HTML); |
| 266 | FakeHttpServletResponse res = new FakeHttpServletResponse(); |
| 267 | |
| 268 | servlet.service(req, res); |
| Ronald Bhuleskar | 999a71d | 2021-11-19 15:24:51 -0800 | [diff] [blame] | 269 | assertThat(res.getStatus()).isEqualTo(SC_OK); |
| 270 | assertThat(res.getActualBodyString()) |
| 271 | .contains("/b/repo/+/refs/heads/main%7E2..refs/heads/main/?format=html"); |
| Ronald Bhuleskar | fbe16e8 | 2020-12-18 20:15:26 -0800 | [diff] [blame] | 272 | } |
| 273 | |
| Ronald Bhuleskar | ffc9a33 | 2021-05-06 10:20:41 -0700 | [diff] [blame] | 274 | private static String toFullBranchName(String sourceBranch) { |
| 275 | if (sourceBranch.startsWith(Constants.R_REFS)) { |
| 276 | return sourceBranch; |
| 277 | } |
| 278 | return Constants.R_HEADS + sourceBranch; |
| 279 | } |
| 280 | |
| Ronald Bhuleskar | fbe16e8 | 2020-12-18 20:15:26 -0800 | [diff] [blame] | 281 | private static FakeHttpServletRequest newHttpRequest( |
| Ronald Bhuleskar | 5764066 | 2021-02-05 11:53:17 -0800 | [diff] [blame] | 282 | String path, String origin, @Nullable String queryString) { |
| Ronald Bhuleskar | fbe16e8 | 2020-12-18 20:15:26 -0800 | [diff] [blame] | 283 | FakeHttpServletRequest req = FakeHttpServletRequest.newRequest(); |
| 284 | req.setHeader(HttpHeaders.ORIGIN, origin); |
| 285 | req.setPathInfo(path); |
| Ronald Bhuleskar | 5764066 | 2021-02-05 11:53:17 -0800 | [diff] [blame] | 286 | if (!Strings.isNullOrEmpty(queryString)) { |
| 287 | req.setQueryString(queryString); |
| 288 | } |
| Ronald Bhuleskar | fbe16e8 | 2020-12-18 20:15:26 -0800 | [diff] [blame] | 289 | return req; |
| 290 | } |
| 291 | } |