do not allow "." as part of repository ids

This commit is contained in:
Sebastian Sdorra
2018-11-30 11:04:33 +01:00
parent 2383702417
commit f74a89c9d8
2 changed files with 15 additions and 10 deletions

View File

@@ -23,7 +23,7 @@ public class InitialRepositoryLocationResolver {
private static final String DEFAULT_REPOSITORY_PATH = "repositories";
private static final CharMatcher ID_MATCHER = CharMatcher.anyOf("/\\");
private static final CharMatcher ID_MATCHER = CharMatcher.anyOf("/\\.");
/**
* Returns the initial path to repository.

View File

@@ -13,9 +13,10 @@ import static org.assertj.core.api.Assertions.assertThat;
@ExtendWith({MockitoExtension.class})
class InitialRepositoryLocationResolverTest {
private InitialRepositoryLocationResolver resolver = new InitialRepositoryLocationResolver();
@Test
void shouldComputeInitialPath() {
InitialRepositoryLocationResolver resolver = new InitialRepositoryLocationResolver();
Path path = resolver.getPath("42");
assertThat(path).isRelative();
@@ -24,17 +25,21 @@ class InitialRepositoryLocationResolverTest {
@Test
void shouldThrowIllegalArgumentExceptionIfIdHasASlash() {
InitialRepositoryLocationResolver resolver = new InitialRepositoryLocationResolver();
Assertions.assertThrows(IllegalArgumentException.class, () -> {
resolver.getPath("../../../passwd");
});
Assertions.assertThrows(IllegalArgumentException.class, () -> resolver.getPath("../../../passwd"));
}
@Test
void shouldThrowIllegalArgumentExceptionIfIdHasABackSlash() {
InitialRepositoryLocationResolver resolver = new InitialRepositoryLocationResolver();
Assertions.assertThrows(IllegalArgumentException.class, () -> {
resolver.getPath("..\\..\\..\\users.ntlm");
});
Assertions.assertThrows(IllegalArgumentException.class, () -> resolver.getPath("..\\..\\..\\users.ntlm"));
}
@Test
void shouldThrowIllegalArgumentExceptionIfIdIsDotDot() {
Assertions.assertThrows(IllegalArgumentException.class, () -> resolver.getPath(".."));
}
@Test
void shouldThrowIllegalArgumentExceptionIfIdIsDot() {
Assertions.assertThrows(IllegalArgumentException.class, () -> resolver.getPath("."));
}
}