You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

RepositoryServletNoProxyTest.java 26KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585
  1. package org.apache.archiva.webdav;
  2. /*
  3. * Licensed to the Apache Software Foundation (ASF) under one
  4. * or more contributor license agreements. See the NOTICE file
  5. * distributed with this work for additional information
  6. * regarding copyright ownership. The ASF licenses this file
  7. * to you under the Apache License, Version 2.0 (the
  8. * "License"); you may not use this file except in compliance
  9. * with the License. You may obtain a copy of the License at
  10. *
  11. * http://www.apache.org/licenses/LICENSE-2.0
  12. *
  13. * Unless required by applicable law or agreed to in writing,
  14. * software distributed under the License is distributed on an
  15. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  16. * KIND, either express or implied. See the License for the
  17. * specific language governing permissions and limitations
  18. * under the License.
  19. */
  20. import com.gargoylesoftware.htmlunit.WebRequest;
  21. import com.gargoylesoftware.htmlunit.WebResponse;
  22. import org.apache.archiva.configuration.ProxyConnectorConfiguration;
  23. import org.junit.After;
  24. import org.junit.Before;
  25. import org.junit.Test;
  26. import org.springframework.mock.web.MockHttpServletRequest;
  27. import org.springframework.mock.web.MockHttpServletResponse;
  28. import javax.servlet.http.HttpServletResponse;
  29. import java.nio.charset.Charset;
  30. import java.nio.file.Files;
  31. import java.nio.file.Path;
  32. import java.util.ArrayList;
  33. /**
  34. * RepositoryServletTest
  35. */
  36. public class RepositoryServletNoProxyTest
  37. extends AbstractRepositoryServletTestCase
  38. {
  39. @Before
  40. @Override
  41. public void setUp()
  42. throws Exception
  43. {
  44. super.setUp();
  45. archivaConfiguration.getConfiguration().setProxyConnectors( new ArrayList<ProxyConnectorConfiguration>() );
  46. startRepository();
  47. }
  48. @Override
  49. @After
  50. public void tearDown( ) throws Exception
  51. {
  52. super.tearDown( );
  53. }
  54. @Test
  55. public void testLastModifiedHeaderExists()
  56. throws Exception
  57. {
  58. String commonsLangSha1 = "commons-lang/commons-lang/2.1/commons-lang-2.1.jar.sha1";
  59. Path checksumFile = repoRootInternal.resolve( commonsLangSha1 );
  60. Files.createDirectories(checksumFile.getParent());
  61. org.apache.archiva.common.utils.FileUtils.writeStringToFile( checksumFile, Charset.defaultCharset(), "dummy-checksum" );
  62. //WebRequest request = new GetMethodWebRequest( "http://machine.com/repository/internal/" + commonsLangSha1 );
  63. WebResponse response = getWebResponse( "/repository/internal/" + commonsLangSha1 );
  64. assertNotNull( response.getResponseHeaderValue( "Last-Modified" ) );
  65. }
  66. @Test
  67. public void testGetNoProxyChecksumDefaultLayout()
  68. throws Exception
  69. {
  70. String commonsLangSha1 = "commons-lang/commons-lang/2.1/commons-lang-2.1.jar.sha1";
  71. Path checksumFile = repoRootInternal.resolve(commonsLangSha1);
  72. Files.createDirectories(checksumFile.getParent());
  73. org.apache.archiva.common.utils.FileUtils.writeStringToFile( checksumFile, Charset.defaultCharset(), "dummy-checksum");
  74. //WebRequest request = new WebRequest( "http://machine.com/repository/internal/" + commonsLangSha1 );
  75. WebResponse response = getWebResponse( "/repository/internal/" + commonsLangSha1 );
  76. assertResponseOK( response );
  77. assertEquals( "Expected file contents", "dummy-checksum", response.getContentAsString() );
  78. }
  79. @Test
  80. public void testGetNoProxyChecksumLegacyLayout()
  81. throws Exception
  82. {
  83. String commonsLangSha1 = "commons-lang/commons-lang/2.1/commons-lang-2.1.jar.sha1";
  84. Path checksumFile = repoRootInternal.resolve(commonsLangSha1);
  85. Files.createDirectories(checksumFile.getParent());
  86. org.apache.archiva.common.utils.FileUtils.writeStringToFile( checksumFile, Charset.defaultCharset() , "dummy-checksum");
  87. //WebRequest request = new GetMethodWebRequest(
  88. // "http://machine.com/repository/internal/" + "commons-lang/jars/commons-lang-2.1.jar.sha1" );
  89. WebResponse response =
  90. getWebResponse( "/repository/internal/" + "commons-lang/jars/commons-lang-2.1.jar.sha1" );
  91. assertResponseNotFound( response );
  92. }
  93. @Test
  94. public void testGetNoProxyVersionedMetadataDefaultLayout()
  95. throws Exception
  96. {
  97. String commonsLangMetadata = "commons-lang/commons-lang/2.1/maven-metadata.xml";
  98. String expectedMetadataContents = "dummy-versioned-metadata";
  99. Path metadataFile = repoRootInternal.resolve(commonsLangMetadata);
  100. Files.createDirectories(metadataFile.getParent());
  101. org.apache.archiva.common.utils.FileUtils.writeStringToFile( metadataFile, Charset.defaultCharset(), expectedMetadataContents );
  102. //WebRequest request = new GetMethodWebRequest( "http://machine.com/repository/internal/" + commonsLangMetadata );
  103. WebResponse response = getWebResponse( "/repository/internal/" + commonsLangMetadata );
  104. assertResponseOK( response );
  105. assertEquals( "Expected file contents", expectedMetadataContents, response.getContentAsString() );
  106. }
  107. @Test
  108. public void testGetNoProxyProjectMetadataDefaultLayout()
  109. throws Exception
  110. {
  111. String commonsLangMetadata = "commons-lang/commons-lang/maven-metadata.xml";
  112. String expectedMetadataContents = "dummy-project-metadata";
  113. Path metadataFile = repoRootInternal.resolve(commonsLangMetadata);
  114. Files.createDirectories(metadataFile.getParent());
  115. org.apache.archiva.common.utils.FileUtils.writeStringToFile( metadataFile, Charset.defaultCharset(), expectedMetadataContents );
  116. //WebRequest request = new GetMethodWebRequest( "http://machine.com/repository/internal/" + commonsLangMetadata );
  117. WebResponse response = getWebResponse( "/repository/internal/" + commonsLangMetadata );
  118. assertResponseOK( response );
  119. assertEquals( "Expected file contents", expectedMetadataContents, response.getContentAsString() );
  120. }
  121. @Test
  122. public void testGetNoProxyGroupMetadataDefaultLayout()
  123. throws Exception
  124. {
  125. String commonsLangMetadata = "commons-lang/maven-metadata.xml";
  126. String expectedMetadataContents = "dummy-group-metadata";
  127. Path metadataFile = repoRootInternal.resolve(commonsLangMetadata);
  128. Files.createDirectories(metadataFile.getParent());
  129. org.apache.archiva.common.utils.FileUtils.writeStringToFile( metadataFile, Charset.defaultCharset(), expectedMetadataContents );
  130. //WebRequest request = new GetMethodWebRequest( "http://machine.com/repository/internal/" + commonsLangMetadata );
  131. WebResponse response = getWebResponse( "/repository/internal/" + commonsLangMetadata );
  132. assertResponseOK( response );
  133. assertEquals( "Expected file contents", expectedMetadataContents, response.getContentAsString() );
  134. }
  135. @Test
  136. public void testGetNoProxyArtifactDefaultLayout()
  137. throws Exception
  138. {
  139. String commonsLangJar = "commons-lang/commons-lang/2.1/commons-lang-2.1.jar";
  140. String expectedArtifactContents = "dummy-commons-lang-artifact";
  141. Path artifactFile = repoRootInternal.resolve(commonsLangJar);
  142. Files.createDirectories(artifactFile.getParent());
  143. org.apache.archiva.common.utils.FileUtils.writeStringToFile( artifactFile, Charset.defaultCharset(), expectedArtifactContents );
  144. //WebRequest request = new GetMethodWebRequest( "http://machine.com/repository/internal/" + commonsLangJar );
  145. WebResponse response = getWebResponse( "/repository/internal/" + commonsLangJar );
  146. assertResponseOK( response );
  147. assertEquals( "Expected file contents", expectedArtifactContents, response.getContentAsString() );
  148. }
  149. @Test
  150. public void testGetNoProxyArtifactLegacyLayout()
  151. throws Exception
  152. {
  153. String commonsLangJar = "commons-lang/commons-lang/2.1/commons-lang-2.1.jar";
  154. String expectedArtifactContents = "dummy-commons-lang-artifact";
  155. Path artifactFile = repoRootInternal.resolve(commonsLangJar);
  156. Files.createDirectories(artifactFile.getParent());
  157. org.apache.archiva.common.utils.FileUtils.writeStringToFile( artifactFile, Charset.defaultCharset(), expectedArtifactContents );
  158. //WebRequest request = new GetMethodWebRequest(
  159. // "http://machine.com/repository/internal/" + "commons-lang/jars/commons-lang-2.1.jar" );
  160. WebResponse response = getWebResponse( "/repository/internal/" + "commons-lang/jars/commons-lang-2.1.jar" );
  161. assertResponseNotFound( response );
  162. }
  163. @Test
  164. public void testGetNoProxySnapshotArtifactDefaultLayout()
  165. throws Exception
  166. {
  167. String commonsLangJar = "commons-lang/commons-lang/2.1-SNAPSHOT/commons-lang-2.1-SNAPSHOT.jar";
  168. String expectedArtifactContents = "dummy-commons-lang-snapshot-artifact";
  169. Path artifactFile = repoRootInternal.resolve(commonsLangJar);
  170. Files.createDirectories(artifactFile.getParent());
  171. org.apache.archiva.common.utils.FileUtils.writeStringToFile( artifactFile, Charset.defaultCharset() , expectedArtifactContents);
  172. //WebRequest request = new GetMethodWebRequest( "http://machine.com/repository/internal/" + commonsLangJar );
  173. WebResponse response = getWebResponse( "/repository/internal/" + commonsLangJar );
  174. assertResponseOK( response );
  175. assertEquals( "Expected file contents", expectedArtifactContents, response.getContentAsString() );
  176. }
  177. @Test
  178. public void testGetNoProxySnapshotArtifactLegacyLayout()
  179. throws Exception
  180. {
  181. String commonsLangJar = "commons-lang/commons-lang/2.1-SNAPSHOT/commons-lang-2.1-SNAPSHOT.jar";
  182. String expectedArtifactContents = "dummy-commons-lang-snapshot-artifact";
  183. Path artifactFile = repoRootInternal.resolve(commonsLangJar);
  184. Files.createDirectories(artifactFile.getParent());
  185. org.apache.archiva.common.utils.FileUtils.writeStringToFile( artifactFile, Charset.defaultCharset() , expectedArtifactContents);
  186. //WebRequest request = new GetMethodWebRequest(
  187. // "http://machine.com/repository/internal/" + "commons-lang/jars/commons-lang-2.1-SNAPSHOT.jar" );
  188. WebResponse response = getWebResponse( "/repository/internal/commons-lang/jars/commons-lang-2.1-SNAPSHOT.jar" );
  189. assertResponseNotFound( response );
  190. }
  191. @Test
  192. public void testGetNoProxyTimestampedSnapshotArtifactDefaultLayout()
  193. throws Exception
  194. {
  195. String commonsLangJar = "commons-lang/commons-lang/2.1-SNAPSHOT/commons-lang-2.1-20050821.023400-1.jar";
  196. String expectedArtifactContents = "dummy-commons-lang-snapshot-artifact";
  197. Path artifactFile = repoRootInternal.resolve(commonsLangJar);
  198. Files.createDirectories(artifactFile.getParent());
  199. org.apache.archiva.common.utils.FileUtils.writeStringToFile(artifactFile, Charset.defaultCharset(), expectedArtifactContents);
  200. //WebRequest request = new GetMethodWebRequest( "http://machine.com/repository/internal/" + commonsLangJar );
  201. WebResponse response = getWebResponse( "/repository/internal/" + commonsLangJar );
  202. assertResponseOK( response );
  203. assertEquals( "Expected file contents", expectedArtifactContents, response.getContentAsString() );
  204. }
  205. @Test
  206. public void testGetNoProxyTimestampedSnapshotArtifactLegacyLayout()
  207. throws Exception
  208. {
  209. String commonsLangJar = "commons-lang/commons-lang/2.1-SNAPSHOT/commons-lang-2.1-20050821.023400-1.jar";
  210. String expectedArtifactContents = "dummy-commons-lang-snapshot-artifact";
  211. Path artifactFile = repoRootInternal.resolve(commonsLangJar);
  212. Files.createDirectories(artifactFile.getParent());
  213. org.apache.archiva.common.utils.FileUtils.writeStringToFile(artifactFile, Charset.defaultCharset(), expectedArtifactContents);
  214. WebRequest request = new GetMethodWebRequest(
  215. "http://machine.com/repository/internal/" + "commons-lang/jars/commons-lang-2.1-20050821.023400-1.jar" );
  216. WebResponse response = getServletUnitClient().getResponse( request );
  217. assertResponseNotFound( response );
  218. }
  219. /**
  220. * [MRM-481] Artifact requests with a .xml.zip extension fail with a 404 Error
  221. */
  222. @Test
  223. public void testGetNoProxyDualExtensionDefaultLayout()
  224. throws Exception
  225. {
  226. String expectedContents = "the-contents-of-the-dual-extension";
  227. String dualExtensionPath = "org/project/example-presentation/3.2/example-presentation-3.2.xml.zip";
  228. Path checksumFile = repoRootInternal.resolve(dualExtensionPath);
  229. Files.createDirectories(checksumFile.getParent());
  230. org.apache.archiva.common.utils.FileUtils.writeStringToFile(checksumFile, Charset.defaultCharset(), expectedContents);
  231. WebRequest request = new GetMethodWebRequest( "http://machine.com/repository/internal/" + dualExtensionPath );
  232. WebResponse response = getServletUnitClient().getResponse( request );
  233. assertResponseOK( response );
  234. assertEquals( "Expected file contents", expectedContents, response.getContentAsString() );
  235. }
  236. @Test
  237. public void testGetNoProxyDistributionLegacyLayout()
  238. throws Exception
  239. {
  240. String expectedContents = "the-contents-of-the-dual-extension";
  241. String dualExtensionPath = "org/project/example-presentation/3.2/example-presentation-3.2.zip";
  242. Path checksumFile = repoRootInternal.resolve(dualExtensionPath);
  243. Files.createDirectories(checksumFile.getParent());
  244. org.apache.archiva.common.utils.FileUtils.writeStringToFile(checksumFile, Charset.defaultCharset(), expectedContents);
  245. WebRequest request = new GetMethodWebRequest(
  246. "http://machine.com/repository/internal/" + "org.project/distributions/example-presentation-3.2.zip" );
  247. WebResponse response = getServletUnitClient().getResponse( request );
  248. assertResponseNotFound( response );
  249. }
  250. @Test
  251. public void testGetNoProxyChecksumDefaultLayoutManagedLegacy()
  252. throws Exception
  253. {
  254. String commonsLangSha1 = "commons-lang/commons-lang/2.1/commons-lang-2.1.jar.sha1";
  255. Path checksumFile = repoRootLegacy.resolve( "commons-lang/jars/commons-lang-2.1.jar.sha1" );
  256. Files.createDirectories(checksumFile.getParent());
  257. org.apache.archiva.common.utils.FileUtils.writeStringToFile( checksumFile, Charset.defaultCharset(), "dummy-checksum" );
  258. WebRequest request = new GetMethodWebRequest( "http://machine.com/repository/legacy/" + commonsLangSha1 );
  259. WebResponse response = getServletUnitClient().getResponse( request );
  260. assertResponseNotFound( response );
  261. }
  262. @Test
  263. public void testGetNoProxyChecksumLegacyLayoutManagedLegacy()
  264. throws Exception
  265. {
  266. String commonsLangSha1 = "commons-lang/jars/commons-lang-2.1.jar.sha1";
  267. Path checksumFile = repoRootLegacy.resolve(commonsLangSha1);
  268. Files.createDirectories(checksumFile.getParent());
  269. org.apache.archiva.common.utils.FileUtils.writeStringToFile(checksumFile, Charset.defaultCharset(), "dummy-checksum");
  270. WebRequest request = new GetMethodWebRequest( "http://machine.com/repository/legacy/" + commonsLangSha1 );
  271. WebResponse response = getServletUnitClient().getResponse( request );
  272. assertResponseNotFound( response );
  273. }
  274. @Test
  275. public void testGetNoProxyVersionedMetadataDefaultLayoutManagedLegacy()
  276. throws Exception
  277. {
  278. String commonsLangMetadata = "commons-lang/commons-lang/2.1/maven-metadata.xml";
  279. String expectedMetadataContents = "dummy-versioned-metadata";
  280. // TODO: find out what this should be from maven-artifact
  281. Path metadataFile = repoRootLegacy.resolve(commonsLangMetadata);
  282. Files.createDirectories(metadataFile.getParent());
  283. org.apache.archiva.common.utils.FileUtils.writeStringToFile(metadataFile, Charset.defaultCharset(), expectedMetadataContents);
  284. WebRequest request = new GetMethodWebRequest( "http://machine.com/repository/legacy/" + commonsLangMetadata );
  285. WebResponse response = getServletUnitClient().getResponse( request );
  286. assertResponseNotFound( response );
  287. }
  288. @Test
  289. public void testGetNoProxyProjectMetadataDefaultLayoutManagedLegacy()
  290. throws Exception
  291. {
  292. // TODO: find out what it is meant to be from maven-artifact
  293. String commonsLangMetadata = "commons-lang/commons-lang/maven-metadata.xml";
  294. String expectedMetadataContents = "dummy-project-metadata";
  295. Path metadataFile = repoRootLegacy.resolve(commonsLangMetadata);
  296. Files.createDirectories(metadataFile.getParent());
  297. org.apache.archiva.common.utils.FileUtils.writeStringToFile(metadataFile, Charset.defaultCharset(), expectedMetadataContents);
  298. WebRequest request = new GetMethodWebRequest( "http://machine.com/repository/legacy/" + commonsLangMetadata );
  299. WebResponse response = getServletUnitClient().getResponse( request );
  300. assertResponseNotFound( response );
  301. }
  302. @Test
  303. public void testGetNoProxyGroupMetadataDefaultLayoutManagedLegacy()
  304. throws Exception
  305. {
  306. String commonsLangMetadata = "commons-lang/maven-metadata.xml";
  307. String expectedMetadataContents = "dummy-group-metadata";
  308. Path metadataFile = repoRootLegacy.resolve(commonsLangMetadata);
  309. Files.createDirectories(metadataFile.getParent());
  310. org.apache.archiva.common.utils.FileUtils.writeStringToFile(metadataFile, Charset.defaultCharset(), expectedMetadataContents);
  311. WebRequest request = new GetMethodWebRequest( "http://machine.com/repository/legacy/" + commonsLangMetadata );
  312. WebResponse response = getServletUnitClient().getResponse( request );
  313. assertResponseNotFound( response );
  314. }
  315. @Test
  316. public void testGetNoProxyArtifactDefaultLayoutManagedLegacy()
  317. throws Exception
  318. {
  319. String commonsLangJar = "commons-lang/commons-lang/2.1/commons-lang-2.1.jar";
  320. String expectedArtifactContents = "dummy-commons-lang-artifact";
  321. Path artifactFile = repoRootLegacy.resolve("commons-lang/jars/commons-lang-2.1.jar" );
  322. Files.createDirectories(artifactFile.getParent());
  323. org.apache.archiva.common.utils.FileUtils.writeStringToFile(artifactFile, Charset.defaultCharset(), expectedArtifactContents);
  324. WebRequest request = new GetMethodWebRequest( "http://machine.com/repository/legacy/" + commonsLangJar );
  325. WebResponse response = getServletUnitClient().getResponse( request );
  326. assertResponseNotFound( response );
  327. }
  328. @Test
  329. public void testGetNoProxyArtifactLegacyLayoutManagedLegacy()
  330. throws Exception
  331. {
  332. String commonsLangJar = "commons-lang/jars/commons-lang-2.1.jar";
  333. String expectedArtifactContents = "dummy-commons-lang-artifact";
  334. Path artifactFile = repoRootLegacy.resolve(commonsLangJar);
  335. Files.createDirectories(artifactFile.getParent());
  336. org.apache.archiva.common.utils.FileUtils.writeStringToFile(artifactFile, Charset.defaultCharset(), expectedArtifactContents);
  337. WebRequest request = new GetMethodWebRequest( "http://machine.com/repository/legacy/" + commonsLangJar );
  338. WebResponse response = getServletUnitClient().getResponse( request );
  339. assertResponseNotFound( response );
  340. }
  341. @Test
  342. public void testGetNoProxySnapshotArtifactDefaultLayoutManagedLegacy()
  343. throws Exception
  344. {
  345. String commonsLangJar = "commons-lang/commons-lang/2.1-SNAPSHOT/commons-lang-2.1-SNAPSHOT.jar";
  346. String expectedArtifactContents = "dummy-commons-lang-snapshot-artifact";
  347. Path artifactFile = repoRootLegacy.resolve( "commons-lang/jars/commons-lang-2.1-SNAPSHOT.jar" );
  348. Files.createDirectories(artifactFile.getParent());
  349. org.apache.archiva.common.utils.FileUtils.writeStringToFile(artifactFile, Charset.defaultCharset(), expectedArtifactContents);
  350. WebRequest request = new GetMethodWebRequest( "http://machine.com/repository/legacy/" + commonsLangJar );
  351. WebResponse response = getServletUnitClient().getResponse( request );
  352. assertResponseNotFound( response );
  353. }
  354. @Test
  355. public void testGetNoProxySnapshotArtifactLegacyLayoutManagedLegacy()
  356. throws Exception
  357. {
  358. String commonsLangJar = "commons-lang/jars/commons-lang-2.1-SNAPSHOT.jar";
  359. String expectedArtifactContents = "dummy-commons-lang-snapshot-artifact";
  360. Path artifactFile = repoRootLegacy.resolve(commonsLangJar);
  361. Files.createDirectories(artifactFile.getParent());
  362. org.apache.archiva.common.utils.FileUtils.writeStringToFile(artifactFile, Charset.defaultCharset(), expectedArtifactContents);
  363. WebRequest request = new GetMethodWebRequest( "http://machine.com/repository/legacy/" + commonsLangJar );
  364. WebResponse response = getServletUnitClient().getResponse( request );
  365. assertResponseNotFound( response );
  366. }
  367. @Test
  368. public void testGetNoProxyTimestampedSnapshotArtifactDefaultLayoutManagedLegacy()
  369. throws Exception
  370. {
  371. String filename = "commons-lang-2.1-20050821.023400-1.jar";
  372. String commonsLangJar = "commons-lang/commons-lang/2.1-SNAPSHOT/" + filename;
  373. String expectedArtifactContents = "dummy-commons-lang-snapshot-artifact";
  374. Path artifactFile = repoRootLegacy.resolve( "commons-lang/jars/" + filename );
  375. Files.createDirectories(artifactFile.getParent());
  376. org.apache.archiva.common.utils.FileUtils.writeStringToFile(artifactFile, Charset.defaultCharset(), expectedArtifactContents);
  377. WebRequest request = new GetMethodWebRequest( "http://machine.com/repository/legacy/" + commonsLangJar );
  378. WebResponse response = getServletUnitClient().getResponse( request );
  379. assertResponseNotFound( response );
  380. }
  381. @Test
  382. public void testGetNoProxyTimestampedSnapshotArtifactLegacyLayoutManagedLegacy()
  383. throws Exception
  384. {
  385. String commonsLangJar = "commons-lang/jars/commons-lang-2.1-20050821.023400-1.jar";
  386. String expectedArtifactContents = "dummy-commons-lang-snapshot-artifact";
  387. Path artifactFile = repoRootLegacy.resolve(commonsLangJar);
  388. Files.createDirectories(artifactFile.getParent());
  389. org.apache.archiva.common.utils.FileUtils.writeStringToFile(artifactFile, Charset.defaultCharset(), expectedArtifactContents);
  390. WebRequest request = new GetMethodWebRequest( "http://machine.com/repository/legacy/" + commonsLangJar );
  391. WebResponse response = getServletUnitClient().getResponse( request );
  392. assertResponseNotFound( response );
  393. }
  394. /**
  395. * [MRM-481] Artifact requests with a .xml.zip extension fail with a 404 Error
  396. */
  397. @Test
  398. public void testGetNoProxyDualExtensionDefaultLayoutManagedLegacy()
  399. throws Exception
  400. {
  401. String expectedContents = "the-contents-of-the-dual-extension";
  402. String dualExtensionPath = "org/project/example-presentation/3.2/example-presentation-3.2.xml.zip";
  403. Path checksumFile = repoRootLegacy.resolve( "org.project/distributions/example-presentation-3.2.xml.zip" );
  404. Files.createDirectories(checksumFile.getParent());
  405. org.apache.archiva.common.utils.FileUtils.writeStringToFile(checksumFile, Charset.defaultCharset(), expectedContents);
  406. WebRequest request = new GetMethodWebRequest( "http://machine.com/repository/legacy/" + dualExtensionPath );
  407. WebResponse response = getServletUnitClient().getResponse( request );
  408. assertResponseNotFound( response );
  409. }
  410. @Test
  411. public void testGetNoProxyDistributionLegacyLayoutManagedLegacy()
  412. throws Exception
  413. {
  414. String expectedContents = "the-contents-of-the-dual-extension";
  415. String dualExtensionPath = "org.project/distributions/example-presentation-3.2.zip";
  416. Path checksumFile = repoRootLegacy.resolve(dualExtensionPath);
  417. Files.createDirectories(checksumFile.getParent());
  418. org.apache.archiva.common.utils.FileUtils.writeStringToFile(checksumFile, Charset.defaultCharset(), expectedContents);
  419. WebRequest request = new GetMethodWebRequest( "http://machine.com/repository/legacy/" + dualExtensionPath );
  420. WebResponse response = getServletUnitClient().getResponse( request );
  421. assertResponseNotFound( response );
  422. }
  423. @Test
  424. public void testGetNoProxySnapshotRedirectToTimestampedSnapshot()
  425. throws Exception
  426. {
  427. String commonsLangQuery = "commons-lang/commons-lang/2.1-SNAPSHOT/commons-lang-2.1-SNAPSHOT.jar";
  428. String commonsLangMetadata = "commons-lang/commons-lang/2.1-SNAPSHOT/maven-metadata.xml";
  429. String commonsLangJar = "commons-lang/commons-lang/2.1-SNAPSHOT/commons-lang-2.1-20050821.023400-1.jar";
  430. String expectedArtifactContents = "dummy-commons-lang-snapshot-artifact";
  431. archivaConfiguration.getConfiguration().getWebapp().getUi().setApplicationUrl("http://localhost");
  432. Path artifactFile = repoRootInternal.resolve(commonsLangJar);
  433. Files.createDirectories(artifactFile.getParent());
  434. org.apache.archiva.common.utils.FileUtils.writeStringToFile(artifactFile, Charset.defaultCharset(), expectedArtifactContents);
  435. Path metadataFile = repoRootInternal.resolve(commonsLangMetadata);
  436. Files.createDirectories(metadataFile.getParent());
  437. org.apache.archiva.common.utils.FileUtils.writeStringToFile( metadataFile, Charset.defaultCharset(), createVersionMetadata("commons-lang", "commons-lang",
  438. "2.1-SNAPSHOT", "20050821.023400", "1", "20050821.023400"));
  439. WebRequest webRequest = new GetMethodWebRequest(
  440. "http://localhost/repository/internal/" + commonsLangQuery );
  441. MockHttpServletRequest request = new MockHttpServletRequest();
  442. request.setRequestURI( webRequest.getUrl().getPath() );
  443. request.addHeader( "User-Agent", "Apache Archiva unit test" );
  444. request.setMethod( webRequest.getHttpMethod().name() );
  445. final MockHttpServletResponse response = execute( request );
  446. assertEquals( HttpServletResponse.SC_MOVED_TEMPORARILY,
  447. response.getStatus() );
  448. assertEquals( "http://localhost/repository/internal/" + commonsLangJar,
  449. response.getHeader("Location") );
  450. }
  451. }