Skip to content

Commit

Permalink
Add outright prohibited symbols (by Artifactory rules) (#14)
Browse files Browse the repository at this point in the history
  • Loading branch information
pgorbachev committed Sep 5, 2023
1 parent 4b4d349 commit 79f98f7
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,9 @@ class GroovySlurperConfigValidator {
public static final String SECURITY_GROUPS = 'securityGroups'
public static final String SECURITY_GROUPS_READ = "read"
private static final String FILE_PATTERN = "(file:)(/|/{3})([^/\\\\0,]+(/)?)+"
private static final String PROHIBITED_SYMBOLS = ":,\\s/"
private static final String GAV_MAVEN_PATTERN = "[^$PROHIBITED_SYMBOLS]+(:[^$PROHIBITED_SYMBOLS]+){1,3}"
private static final String PROHIBITED_SYMBOLS = "\\\\\\s:|\\?\\*\"'<>\\+"
private static final String GAV_PROHIBITED_SYMBOLS = "/$PROHIBITED_SYMBOLS"
private static final String GAV_MAVEN_PATTERN = "[^$GAV_PROHIBITED_SYMBOLS]+(:[^$GAV_PROHIBITED_SYMBOLS]+){1,3}"
private static final String GAV_ENTRY_PATTERN = "($FILE_PATTERN)|($GAV_MAVEN_PATTERN)"
public static final Pattern GAV_PATTERN = Pattern.compile("^($GAV_ENTRY_PATTERN)(,($GAV_ENTRY_PATTERN))*\$")
private static final String DEB_ENTRY_PATTERN = "[^$PROHIBITED_SYMBOLS]+\\.deb"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
package org.octopusden.octopus.escrow.configuration.validation


import static org.octopusden.octopus.escrow.configuration.validation.GroovySlurperConfigValidator.GAV_PATTERN
import static org.octopusden.octopus.escrow.configuration.validation.GroovySlurperConfigValidator.DEB_PATTERN
import static org.octopusden.octopus.escrow.configuration.validation.GroovySlurperConfigValidator.GAV_PATTERN
import static org.octopusden.octopus.escrow.configuration.validation.GroovySlurperConfigValidator.RPM_PATTERN


class GroovySlurperConfigValidatorTest extends GroovyTestCase {

void testGAVPattern() {
Expand All @@ -17,15 +15,15 @@ class GroovySlurperConfigValidatorTest extends GroovyTestCase {

void testDEBPattern() {
assert DEB_PATTERN.matcher("foundationdb-clients_1.0.amd64.deb").matches()
assert DEB_PATTERN.matcher("logcomp_1.0.54-1_amd64.deb,mesh-agent2_2.0.101-1_amd64.deb").matches()
assert DEB_PATTERN.matcher("pool/l/logcomp/logcomp_1.0.54-1_amd64.deb,mesh-agent2_2.0.101-1_amd64.deb").matches()
assert !DEB_PATTERN.matcher("logcomp_1.0.54-1_amd64.deb,file:///dir/file").matches()
assert !DEB_PATTERN.matcher("foundationdb clients_1.0.amd64.deb").matches()
}

void testRPMPattern() {
assert RPM_PATTERN.matcher("ansible-2.11.6-7.el8.noarch.rpm").matches()
assert RPM_PATTERN.matcher("ansible-2.11.6-7.el8.noarch.rpm,ansible-core-2.11.6-7.el8.noarch.rpm").matches()
assert RPM_PATTERN.matcher("ansible/ansible-2.11.6-7.el8.noarch.rpm,ansible-core-2.11.6-7.el8.noarch.rpm").matches()
assert !RPM_PATTERN.matcher("ansible-2.11.6-7.el8.noarch.rpm,file:///dir/file").matches()
assert !RPM_PATTERN.matcher("ansible-2.11.6/7.el8.noarch.rpm").matches()
assert !RPM_PATTERN.matcher("ansible-2.11.6+7.el8.noarch.rpm").matches()
}
}

0 comments on commit 79f98f7

Please sign in to comment.