Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions internal/app/yaam/artifact/validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,17 @@ func validate(requestURI string) error {
log.Debugf("requestURI: '%s'", requestURI)
dir := filepath.Dir(requestURI)
ext := filepath.Ext(requestURI)
if dir == "/" || ext == "" {

regex := `/-/npm/v1/security/audits/quick$`
re := regexp.MustCompile(regex)
npmAudit := re.MatchString(requestURI)
log.Debugf("determine whether requestURI: '%s' represents a npmAudit file. Outcome: '%t'", requestURI, npmAudit)
if (dir == "/" || ext == "") && !npmAudit {
return fmt.Errorf("requestURI: '%s' should start with a: '/' and contain an extension", requestURI)
}

regex := `^/([a-z]+)/([0-9a-z-]+)/`
re := regexp.MustCompile(regex)
regex = `^/([a-z]+)/([0-9a-z-]+)/`
re = regexp.MustCompile(regex)
repoTypeAndName := re.FindStringSubmatch(requestURI)
if len(repoTypeAndName) <= 2 {
return fmt.Errorf("no repo type or name detected. Verify whether the regex: '%s' matches the URL: '%s'", regex, requestURI)
Expand Down
1 change: 1 addition & 0 deletions internal/app/yaam/artifact/validate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ func init() {
}

func TestValidate(t *testing.T) {
///npm/3rdparty-npm/-/npm/v1/security/audits/quick
expDir := filepath.Join("/maven", "releases", "world")
err := validate(filepath.Join(expDir, "hola.mundo"))
if err != nil {
Expand Down