Skip to content

Commit

Permalink
lint: add E71 for checking if the same checksum algorithm is used sev…
Browse files Browse the repository at this point in the history
…eral times for a given url in url section
  • Loading branch information
rjbou committed Aug 26, 2024
1 parent 38eab2f commit b199050
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 2 deletions.
2 changes: 2 additions & 0 deletions master_changes.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ users)

## Lint
* Add E70 to check `extra-files:` duplicated fields [#5561 @rjbou]
* Add E71 to check if the same checksum algorithm is used several times for a given url in `url` section [#5561 @rjbou]

## Repository
* Mitigate curl/curl#13845 by falling back from --write-out to --fail if exit code 43 is returned by curl [#6168 @dra27 - fix #6120]
Expand Down Expand Up @@ -181,6 +182,7 @@ users)
* lint: add an additional test case for W37 [#5561 @rjbou]
* lint: update W37 to test other urls scheme [#5561 @rjbou]
* lint: add E70 test [#5561 @rjbou]
* lint: add E71 test [#5561 @rjbou]

### Engine
* Add a test filtering mechanism [#6105 @Keryan-dev]
Expand Down
10 changes: 10 additions & 0 deletions src/state/opamFileTools.ml
Original file line number Diff line number Diff line change
Expand Up @@ -1042,6 +1042,16 @@ let t_lint ?check_extra_files ?(check_upstream=false) ?(all=false) t =
"Field 'extra-files' contains duplicated files"
?detail
has_double);
(let has_double, detail =
check_double OpamHash.compare_kind OpamHash.string_of_kind
(match OpamFile.OPAM.url t with
| Some url ->
List.map OpamHash.kind (OpamFile.URL.checksum url)
| None -> [])
in
cond 71 `Error
"Field 'url.checksum' contains duplicated checksums"
?detail has_double);
]
in
format_errors @
Expand Down
10 changes: 8 additions & 2 deletions tests/reftests/archive.test
Original file line number Diff line number Diff line change
Expand Up @@ -475,12 +475,15 @@ Successfully extracted to ${BASEDIR}/no-checksum.1
Clearing cache of downloaded files
### :I:6: multiple md5
### opam lint --package multiple-md5
<default>/multiple-md5.1: Passed.
<default>/multiple-md5.1: Errors.
error 71: Field 'url.checksum' contains duplicated checksums: "md5: 2 occurences"
# Return code 1 #
### opam lint --package multiple-md5 --check-upstream | '[0-9a-z]{32}' -> 'hash'
<default>/multiple-md5.1: Errors.
error 60: Upstream check failed: "The archive doesn't match checksum:
- archive: md5=hash, in opam file: md5=hash
."
error 71: Field 'url.checksum' contains duplicated checksums: "md5: 2 occurences"
# Return code 1 #
### opam install multiple-md5 | '[0-9a-z]{32}' -> 'hash'
The following actions will be performed:
Expand Down Expand Up @@ -781,7 +784,9 @@ OpamSolution.Fetch_fail("Checksum mismatch")
Clearing cache of downloaded files
### :I:10: clash with all md5
### opam lint --package clash-with-all-md5s
<default>/clash-with-all-md5s.666: Passed.
<default>/clash-with-all-md5s.666: Errors.
error 71: Field 'url.checksum' contains duplicated checksums: "md5: 17 occurences"
# Return code 1 #
### opam lint --package clash-with-all-md5s --check-upstream | '[0-9a-z]{32,64}' -> 'hash'
<default>/clash-with-all-md5s.666: Errors.
error 60: Upstream check failed: "The archive doesn't match checksums:
Expand All @@ -803,6 +808,7 @@ Clearing cache of downloaded files
- archive: md5=hash, in opam file: md5=hash
- archive: sha256=hash, in opam file: sha256=hash
."
error 71: Field 'url.checksum' contains duplicated checksums: "md5: 17 occurences"
# Return code 1 #
### opam install clash-with-all-md5s | '[0-9a-z]{32}' -> 'hash'
The following actions will be performed:
Expand Down
26 changes: 26 additions & 0 deletions tests/reftests/lint.test
Original file line number Diff line number Diff line change
Expand Up @@ -1090,3 +1090,29 @@ extra-source "double-file" {
${BASEDIR}/lint.opam: Errors.
error 3: File format error in 'extra-source': Duplicate section extra-source
# Return code 1 #
### : E71: Field 'url.checksum' contains duplicated checksums
### <lint.opam>
opam-version: "2.0"
synopsis: "A word"
description: "Two words."
authors: "the testing team"
homepage: "egapemoh"
maintainer: "[email protected]"
license: "ISC"
dev-repo: "hg+https://[email protected]"
bug-reports: "https://nobug"
url {
src:"an-archive.tgz"
checksum:[
"md5=00000000000000000000000000000000"
"md5=11111111111111111111111111111111"
"sha256=2222222222222222222222222222222222222222222222222222222222222222"
"sha256=3333333333333333333333333333333333333333333333333333333333333333"
"sha256=4444444444444444444444444444444444444444444444444444444444444444"
"sha512=55555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555"
]
}
### opam lint ./lint.opam
${BASEDIR}/lint.opam: Errors.
error 71: Field 'url.checksum' contains duplicated checksums: "md5: 2 occurences", "sha256: 3 occurences"
# Return code 1 #

0 comments on commit b199050

Please sign in to comment.