Skip to content
This repository was archived by the owner on May 7, 2025. It is now read-only.

Commit 1a51cc8

Browse files
authored
Merge pull request #202 from xjusko/verify_repo_format
[Issue #200]Fixes regex that verifies repository format
2 parents 04f77af + a0bbc1b commit 1a51cc8

File tree

3 files changed

+32
-1
lines changed

3 files changed

+32
-1
lines changed

tyr-core/src/main/java/org/jboss/tyr/model/Utils.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,10 @@ public class Utils {
5050
public static final String MESSAGE = "message";
5151
public static final String URL = "url";
5252

53+
//Repository verification regex
54+
public static final String REPOSITORY_FORMAT_VERIFICATION_REGEX =
55+
"^([a-zA-Z0-9](?:-?[a-zA-Z0-9]){0,38})/[a-zA-Z0-9_.-]{1,100}$";
56+
5357
public static String getConfigDirectory() {
5458
String path = System.getProperty(TYR_CONFIG_DIR);
5559
if (path == null) {

tyr-core/src/main/java/org/jboss/tyr/verification/RepositoryFormatVerification.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,14 @@
1515
*/
1616
package org.jboss.tyr.verification;
1717

18+
import org.jboss.tyr.model.Utils;
1819
import org.jboss.tyr.model.yaml.FormatYaml;
1920

2021
public class RepositoryFormatVerification implements Verification {
2122

2223
@Override
2324
public void verify(FormatYaml formatYaml) throws InvalidConfigurationException {
24-
if (!formatYaml.getRepository().matches("^[a-zA-Z0-9_]*/[a-zA-Z0-9_-]*$"))
25+
if (!formatYaml.getRepository().matches(Utils.REPOSITORY_FORMAT_VERIFICATION_REGEX))
2526
throw new InvalidConfigurationException("Wrong repository format in configuration file");
2627
}
2728
}

tyr-core/src/test/java/org/jboss/tyr/verification/VerificationsTest.java

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
*/
1616
package org.jboss.tyr.verification;
1717

18+
import org.jboss.tyr.model.Utils;
1819
import org.jboss.tyr.model.yaml.FormatYaml;
1920
import org.junit.jupiter.api.Assertions;
2021
import org.junit.jupiter.api.BeforeAll;
@@ -47,4 +48,29 @@ public void testReadInvalidFormatConfiguration() {
4748
public void testNullParameterToVerify() {
4849
Assertions.assertThrows(NullPointerException.class, () -> VerificationHandler.verifyConfiguration(null));
4950
}
51+
@Test
52+
public void testRepositoryFormatVerificationRegex() {
53+
//Valid examples
54+
Assertions.assertTrue("a/repo".matches(Utils.REPOSITORY_FORMAT_VERIFICATION_REGEX));
55+
Assertions.assertTrue("a/.".matches(Utils.REPOSITORY_FORMAT_VERIFICATION_REGEX));
56+
Assertions.assertTrue("a/_".matches(Utils.REPOSITORY_FORMAT_VERIFICATION_REGEX));
57+
Assertions.assertTrue("a/-".matches(Utils.REPOSITORY_FORMAT_VERIFICATION_REGEX));
58+
Assertions.assertTrue("a-a123/.test.repo.".matches(Utils.REPOSITORY_FORMAT_VERIFICATION_REGEX));
59+
Assertions.assertTrue("a-A-a/_test_repo_".matches(Utils.REPOSITORY_FORMAT_VERIFICATION_REGEX));
60+
Assertions.assertTrue(("a".repeat(39)+"/-Test-repo-123-").matches(Utils.REPOSITORY_FORMAT_VERIFICATION_REGEX));
61+
Assertions.assertTrue(("a/" + "-".repeat(100)).matches(Utils.REPOSITORY_FORMAT_VERIFICATION_REGEX));
62+
63+
//Invalid username
64+
Assertions.assertFalse("-a/test-repo".matches(Utils.REPOSITORY_FORMAT_VERIFICATION_REGEX));
65+
Assertions.assertFalse("/test-repo".matches(Utils.REPOSITORY_FORMAT_VERIFICATION_REGEX));
66+
Assertions.assertFalse("a-/test-repo".matches(Utils.REPOSITORY_FORMAT_VERIFICATION_REGEX));
67+
Assertions.assertFalse("a_a/test-repo".matches(Utils.REPOSITORY_FORMAT_VERIFICATION_REGEX));
68+
Assertions.assertFalse("a.a/test-repo".matches(Utils.REPOSITORY_FORMAT_VERIFICATION_REGEX));
69+
Assertions.assertFalse("a--a/test-repo".matches(Utils.REPOSITORY_FORMAT_VERIFICATION_REGEX));
70+
Assertions.assertFalse(("a".repeat(40) + "/test-repo").matches(Utils.REPOSITORY_FORMAT_VERIFICATION_REGEX));
71+
72+
//Invalid repository names
73+
Assertions.assertFalse(("a/" + ".".repeat(101)).matches(Utils.REPOSITORY_FORMAT_VERIFICATION_REGEX));
74+
Assertions.assertFalse("a/".matches(Utils.REPOSITORY_FORMAT_VERIFICATION_REGEX));
75+
}
5076
}

0 commit comments

Comments
 (0)