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.

RepositoryServletProxiedPassthroughTest.java 6.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  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.junit.After;
  23. import org.junit.Before;
  24. import org.junit.Test;
  25. import java.nio.file.Files;
  26. import java.nio.file.Path;
  27. import java.nio.file.attribute.FileTime;
  28. /**
  29. * RepositoryServlet Tests, Proxied, Get of resources that are not artifacts or metadata, with varying policy settings.
  30. *
  31. */
  32. public class RepositoryServletProxiedPassthroughTest
  33. extends AbstractRepositoryServletProxiedTestCase
  34. {
  35. private static final String CONTENT_SHA1 = "2aab0a51c04c9023636852f3e63a68034ba10142";
  36. private static final String PATH_SHA1 = "org/apache/archiva/test/1.0/test-1.0.jar.sha1";
  37. private static final String CONTENT_ASC =
  38. "-----BEGIN PGP SIGNATURE-----\n" + "Version: GnuPG v1.4.8 (Darwin)\n" + "\n"
  39. + "iEYEABECAAYFAkiAIVgACgkQxbsDNW2stZZjyACeK3LW+ZDeawCyJj4XgvUaJkNh\n"
  40. + "qIEAoIUiijY4Iw82RWOT75Rt3yZuY6ZI\n" + "=WLkm\n" + "-----END PGP SIGNATURE-----\n";
  41. private static final String PATH_ASC = "org/apache/archiva/test/1.0/test-1.0.jar.asc";
  42. @Before
  43. public void setup()
  44. throws Exception
  45. {
  46. super.setUp();
  47. }
  48. @After
  49. @Override
  50. public void tearDown()
  51. throws Exception
  52. {
  53. super.tearDown();
  54. }
  55. @Test
  56. public void testGetProxiedManagedNewerSha1()
  57. throws Exception
  58. {
  59. assertGetProxiedResource( EXPECT_MANAGED_CONTENTS, HAS_MANAGED_COPY, ( NEWER * OVER_ONE_DAY ), PATH_SHA1,
  60. CONTENT_SHA1 );
  61. }
  62. @Test
  63. public void testGetProxiedManagedOlderSha1()
  64. throws Exception
  65. {
  66. assertGetProxiedResource( EXPECT_REMOTE_CONTENTS, HAS_MANAGED_COPY, ( OLDER * OVER_ONE_DAY ), PATH_SHA1,
  67. CONTENT_SHA1 );
  68. }
  69. @Test
  70. public void testGetProxiedNoManagedContentSha1()
  71. throws Exception
  72. {
  73. assertGetProxiedResource( EXPECT_REMOTE_CONTENTS, NO_MANAGED_COPY, PATH_SHA1, CONTENT_SHA1 );
  74. }
  75. @Test
  76. public void testGetProxiedEqualSha1()
  77. throws Exception
  78. {
  79. assertGetProxiedResource( EXPECT_MANAGED_CONTENTS, HAS_MANAGED_COPY, PATH_SHA1, CONTENT_SHA1 );
  80. }
  81. @Test
  82. public void testGetProxiedManagedNewerAsc()
  83. throws Exception
  84. {
  85. assertGetProxiedResource( EXPECT_MANAGED_CONTENTS, HAS_MANAGED_COPY, ( NEWER * OVER_ONE_DAY ), PATH_ASC,
  86. CONTENT_ASC );
  87. }
  88. @Test
  89. public void testGetProxiedManagedOlderAsc()
  90. throws Exception
  91. {
  92. assertGetProxiedResource( EXPECT_REMOTE_CONTENTS, HAS_MANAGED_COPY, ( OLDER * OVER_ONE_DAY ), PATH_ASC,
  93. CONTENT_ASC );
  94. }
  95. @Test
  96. public void testGetProxiedNoManagedContentAsc()
  97. throws Exception
  98. {
  99. assertGetProxiedResource( EXPECT_REMOTE_CONTENTS, NO_MANAGED_COPY, PATH_ASC, CONTENT_ASC );
  100. }
  101. @Test
  102. public void testGetProxiedEqualAsc()
  103. throws Exception
  104. {
  105. assertGetProxiedResource( EXPECT_MANAGED_CONTENTS, HAS_MANAGED_COPY, PATH_ASC, CONTENT_ASC );
  106. }
  107. private void assertGetProxiedResource( int expectation, boolean hasManagedCopy, String path, String content )
  108. throws Exception
  109. {
  110. assertGetProxiedResource( expectation, hasManagedCopy, 0, path, content );
  111. }
  112. private void assertGetProxiedResource( int expectation, boolean hasManagedCopy, long deltaManagedToRemoteTimestamp,
  113. String path, String contents )
  114. throws Exception
  115. {
  116. // --- Setup
  117. setupCentralRemoteRepo();
  118. setupCleanInternalRepo();
  119. String expectedRemoteContents = contents;
  120. String expectedManagedContents = null;
  121. Path remoteFile = populateRepo( remoteCentral, path, expectedRemoteContents );
  122. if ( hasManagedCopy )
  123. {
  124. expectedManagedContents = contents;
  125. Path managedFile = populateRepo( repoRootInternal, path, expectedManagedContents );
  126. Files.setLastModifiedTime( managedFile, FileTime.fromMillis( Files.getLastModifiedTime( remoteFile ).toMillis() + deltaManagedToRemoteTimestamp ));
  127. }
  128. setupConnector( REPOID_INTERNAL, remoteCentral );
  129. saveConfiguration();
  130. // --- Execution
  131. // process the response code later, not via an exception.
  132. //HttpUnitOptions.setExceptionsThrownOnErrorStatus( false );
  133. WebRequest request = new GetMethodWebRequest( "http://machine.com/repository/internal/" + path );
  134. WebResponse response = getServletUnitClient().getResponse( request );
  135. // --- Verification
  136. switch ( expectation )
  137. {
  138. case EXPECT_MANAGED_CONTENTS:
  139. assertResponseOK( response );
  140. assertTrue( "Invalid Test Case: Can't expect managed contents with "
  141. + "test that doesn't have a managed copy in the first place.", hasManagedCopy );
  142. assertEquals( "Expected managed file contents", expectedManagedContents, response.getContentAsString() );
  143. break;
  144. case EXPECT_REMOTE_CONTENTS:
  145. assertResponseOK( response, path );
  146. assertEquals( "Expected remote file contents", expectedRemoteContents, response.getContentAsString() );
  147. break;
  148. case EXPECT_NOT_FOUND:
  149. assertResponseNotFound( response );
  150. assertManagedFileNotExists( repoRootInternal, path );
  151. break;
  152. }
  153. }
  154. }