-
-
Notifications
You must be signed in to change notification settings - Fork 190
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
Showing
8 changed files
with
120 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
81 changes: 81 additions & 0 deletions
81
...silite-backend/src/integration/kotlin/com/reposilite/maven/MavenMirrorsIntegrationTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
@file:Suppress("FunctionName") | ||
|
||
package com.reposilite.maven | ||
|
||
import com.reposilite.RecommendedLocalSpecificationJunitExtension | ||
import com.reposilite.RecommendedRemoteSpecificationJunitExtension | ||
import com.reposilite.maven.api.LookupRequest | ||
import com.reposilite.maven.specification.MavenIntegrationSpecification | ||
import com.reposilite.storage.api.toLocation | ||
import kong.unirest.Unirest | ||
import kotlinx.coroutines.runBlocking | ||
import org.assertj.core.api.Assertions.assertThat | ||
import org.junit.jupiter.api.Test | ||
import org.junit.jupiter.api.extension.ExtendWith | ||
|
||
@ExtendWith(RecommendedLocalSpecificationJunitExtension::class) | ||
internal class LocalMavenMirrorsIntegrationTest : MavenMirrorsIntegrationTest() | ||
|
||
@ExtendWith(RecommendedRemoteSpecificationJunitExtension::class) | ||
internal class RemoteMavenMirrorsIntegrationTest : MavenMirrorsIntegrationTest() | ||
|
||
internal abstract class MavenMirrorsIntegrationTest : MavenIntegrationSpecification() { | ||
|
||
@Test | ||
fun `should proxy remote file`() = runBlocking { | ||
// given: a remote server and artifact | ||
useProxiedHost("releases", "com/reposilite/remote.jar", "content") { gav, content -> | ||
// when: non-existing file is requested | ||
val notFoundResponse = Unirest.get("$base/proxied/not/found.jar").asString() | ||
|
||
// then: service responds with 404 status page | ||
assertThat(notFoundResponse.isSuccess).isFalse | ||
|
||
// when: file that exists in remote repository is requested | ||
val response = Unirest.get("$base/proxied/$gav").asString() | ||
|
||
// then: service responds with its content | ||
assertThat(response.body).isEqualTo(content) | ||
assertThat(response.isSuccess).isTrue | ||
} | ||
} | ||
|
||
@Test | ||
fun `should not proxy file with forbidden extension`() = runBlocking { | ||
// given: a remote server and artifact | ||
useProxiedHost("releases", "com/reposilite/remote.file", "content") { gav, _ -> | ||
// when: file that exists in remote repository is requested | ||
val response = Unirest.get("$base/proxied/$gav").asString() | ||
// then: service responds with 404 status page as .file extension is not allowed | ||
assertThat(response.isSuccess).isFalse | ||
} | ||
} | ||
|
||
@Test | ||
fun `should prioritize upstream metadata file over local copy`() = runBlocking { | ||
// given: a remote server and artifact | ||
useProxiedHost("releases", "com/reposilite/maven-metadata.xml", "upstream") { gav, _ -> | ||
// and: local repository with cached metadata file | ||
useDocument("proxied", "com/reposilite", "maven-metadata.xml", "local", true) | ||
|
||
// when: metadata file is requested | ||
val response = Unirest.get("$base/proxied/$gav").asString() | ||
|
||
// then: service responds with upstream metadata file | ||
assertThat(response.body).isEqualTo("upstream") | ||
assertThat(response.isSuccess).isTrue | ||
|
||
// and: local metadata file is updated | ||
val localFile = mavenFacade.findFile( | ||
LookupRequest( | ||
accessToken = null, | ||
repository = "proxied", | ||
gav = "com/reposilite/maven-metadata.xml".toLocation(), | ||
) | ||
) | ||
assertThat(localFile.isOk).isTrue | ||
assertThat(localFile.get().second.readAllBytes().decodeToString()).isEqualTo("upstream") | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters