Skip to content
Merged
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
28 changes: 27 additions & 1 deletion clomonitor-core/src/linter/checks/artifacthub_badge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ pub(crate) const WEIGHT: usize = 1;
pub(crate) const CHECK_SETS: [CheckSet; 1] = [CheckSet::Code];

static ARTIFACTHUB_URL: LazyLock<Regex> = LazyLock::new(|| {
Regex::new(r#"(https://artifacthub.io/packages/[^"'\)]+)"#)
Regex::new(r#"(https://artifacthub.io/packages/[^"'\)\s]+)"#)
.expect("exprs in ARTIFACTHUB_URL to be valid")
});

Expand All @@ -46,4 +46,30 @@ mod tests {
"https://artifacthub.io/packages/helm/artifact-hub/artifact-hub"
);
}

#[test]
fn artifacthub_url_extract_md_ref() {
assert_eq!(
ARTIFACTHUB_URL
.captures(
"[artifacthub]: https://artifacthub.io/packages/search?repo=jaegertracing\n\n[community-badge]:",
)
.unwrap()[1]
.to_string(),
"https://artifacthub.io/packages/search?repo=jaegertracing"
);
}

#[test]
fn artifacthub_url_extract_rst() {
assert_eq!(
ARTIFACTHUB_URL
.captures(
" :target: https://artifacthub.io/packages/helm/cilium/cilium\n\n.. |fossa|",
)
.unwrap()[1]
.to_string(),
"https://artifacthub.io/packages/helm/cilium/cilium"
);
}
}
41 changes: 39 additions & 2 deletions clomonitor-core/src/linter/checks/license_scanning.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ pub(crate) const WEIGHT: usize = 5;
pub(crate) const CHECK_SETS: [CheckSet; 1] = [CheckSet::Code];

pub(crate) static FOSSA_URL: LazyLock<Regex> = LazyLock::new(|| {
Regex::new(r#"(https://app.fossa.(?:io|com)/projects/[^"'\)]+)"#)
Regex::new(r#"(https://app.fossa.(?:io|com)/projects/[^"'\)\s]+)"#)
.expect("exprs in FOSSA_URL to be valid")
});

pub(crate) static SNYK_URL: LazyLock<Regex> = LazyLock::new(|| {
Regex::new(r#"(https://snyk.io/test/github/[^/]+/[^/"]+)"#)
Regex::new(r#"(https://snyk.io/test/github/[^/\s]+/[^/"\s]+)"#)
.expect("exprs in SNYK_URL to be valid")
});

Expand Down Expand Up @@ -126,6 +126,32 @@ mod tests {
);
}

#[test]
fn fossa_url_extract_md_ref() {
assert_eq!(
FOSSA_URL
.captures(
"[fossa]: https://app.fossa.io/projects/git%2Bgithub.com%2Fjaegertracing%2Fjaeger?ref=badge_shield\n[openssf]:",
)
.unwrap()[1]
.to_string(),
"https://app.fossa.io/projects/git%2Bgithub.com%2Fjaegertracing%2Fjaeger?ref=badge_shield"
);
}

#[test]
fn fossa_url_extract_rst() {
assert_eq!(
FOSSA_URL
.captures(
" :target: https://app.fossa.com/projects/custom%2B162%2Fgit%40github.com%3Acilium%2Fcilium.git?ref=badge_shield\n\n.. |gateway-api|",
)
.unwrap()[1]
.to_string(),
"https://app.fossa.com/projects/custom%2B162%2Fgit%40github.com%3Acilium%2Fcilium.git?ref=badge_shield"
);
}

#[test]
fn snyk_url_extract() {
assert_eq!(
Expand All @@ -140,4 +166,15 @@ mod tests {
"https://snyk.io/test/github/{username}/{repo}"
);
}

#[test]
fn snyk_url_extract_md_ref() {
assert_eq!(
SNYK_URL
.captures("[snyk]: https://snyk.io/test/github/username/repo\n[next-badge]:",)
.unwrap()[1]
.to_string(),
"https://snyk.io/test/github/username/repo"
);
}
}
30 changes: 28 additions & 2 deletions clomonitor-core/src/linter/checks/openssf_scorecard_badge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ pub(crate) const WEIGHT: usize = 5;
pub(crate) const CHECK_SETS: [CheckSet; 1] = [CheckSet::Code];

static OPENSSF_SCORECARD_URL_OLD: LazyLock<Regex> = LazyLock::new(|| {
Regex::new(r"(https://api.securityscorecards.dev/projects/github.com/[^/]+/[^/]+)/badge")
Regex::new(r"(https://api.securityscorecards.dev/projects/github.com/[^/\s]+/[^/\s]+)/badge")
.expect("exprs in OPENSSF_SCORECARD_URL_OLD to be valid")
});

static OPENSSF_SCORECARD_URL: LazyLock<Regex> = LazyLock::new(|| {
Regex::new(r"(https://api.scorecard.dev/projects/github.com/[^/]+/[^/]+)/badge")
Regex::new(r"(https://api.scorecard.dev/projects/github.com/[^/\s]+/[^/\s]+)/badge")
.expect("exprs in OPENSSF_SCORECARD_URL to be valid")
});

Expand Down Expand Up @@ -60,4 +60,30 @@ mod tests {
"https://api.scorecard.dev/projects/github.com/owner/repo"
);
}

#[test]
fn old_openssf_scorecard_url_extract_md_ref() {
assert_eq!(
OPENSSF_SCORECARD_URL_OLD
.captures(
"[openssf-img]: https://api.securityscorecards.dev/projects/github.com/owner/repo/badge\n[openssf]:",
)
.unwrap()[1]
.to_string(),
"https://api.securityscorecards.dev/projects/github.com/owner/repo"
);
}

#[test]
fn new_openssf_scorecard_url_extract_md_ref() {
assert_eq!(
OPENSSF_SCORECARD_URL
.captures(
"[openssf-img]: https://api.scorecard.dev/projects/github.com/owner/repo/badge\n[openssf]:",
)
.unwrap()[1]
.to_string(),
"https://api.scorecard.dev/projects/github.com/owner/repo"
);
}
}
2 changes: 1 addition & 1 deletion clomonitor-core/src/linter/checks/util/content.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ mod tests {
patterns: &["README*"],
case_sensitive: true,
},
&[&Regex::new(r#"(https://snyk.io/test/github/[^/]+/[^/"]+)"#).unwrap()]
&[&Regex::new(r#"(https://snyk.io/test/github/[^/\s]+/[^/"\s]+)"#).unwrap()]
)
.unwrap()
.unwrap(),
Expand Down
10 changes: 5 additions & 5 deletions docs/checks.md
Original file line number Diff line number Diff line change
Expand Up @@ -370,8 +370,8 @@ This check passes if:
- A `FOSSA` or `Snyk` link is found in the repository's `README` file. Regexps used:

```sh
"(https://app.fossa.(?:io|com)/projects/[^"'\)]+)"
"(https://snyk.io/test/github/[^/]+/[^/"]+)"
"(https://app.fossa.(?:io|com)/projects/[^"'\)\s]+)"
"(https://snyk.io/test/github/[^/\s]+/[^/"\s]+)"
```

- A *link* pointing to the license scanning results is provided in the [.clomonitor.yml](https://github.com/cncf/clomonitor/blob/main/docs/metadata/.clomonitor.yml) metadata file.
Expand Down Expand Up @@ -427,7 +427,7 @@ This check passes if:
- An `Artifact Hub` badge is found in the repository's `README` file. Regexps used:

```sh
"(https://artifacthub.io/packages/[^"'\)]+)"
"(https://artifacthub.io/packages/[^"'\)\s]+)"
```

### Contributor license agreement
Expand Down Expand Up @@ -521,13 +521,13 @@ This check passes if:
- An `OpenSSF` Scorecard badge is found in the repository's `README` file. Regexps used (old):

```sh
"(https://api.securityscorecards.dev/projects/github.com/[^/]+/[^/]+)/badge"
"(https://api.securityscorecards.dev/projects/github.com/[^/\s]+/[^/\s]+)/badge"
```

- An `OpenSSF` Scorecard badge is found in the repository's `README` file. Regexps used (new):

```sh
"(https://api.scorecard.dev/projects/github.com/[^/]+/[^/]+)/badge"
"(https://api.scorecard.dev/projects/github.com/[^/\s]+/[^/\s]+)/badge"
```

### Recent release
Expand Down