test/system: Tighten the regular expression used to detect the image ID

An OCI image's identifier (or ID) is a SHA-256 hash [1] whose length is
64 hexadecimal digits.  The ID can be abbreviated to a smaller number of
digits but the minimum is 6.  The regular expression being used to parse
the image ID wasn't checking the number of digits, and would even accept
an empty string as a valid ID, which was clearly wrong.

The format of a image reference is defined in:
https://github.com/moby/moby/blob/master/image/spec/v1.1.md
https://github.com/distribution/distribution/blob/main/reference/reference.go
https://github.com/distribution/distribution/blob/main/reference/regexp.go

Fallout from c6c2e426e0

[1] https://en.wikipedia.org/wiki/SHA-2

https://github.com/containers/toolbox/pull/1209
This commit is contained in:
Debarshi Ray 2023-01-11 13:09:32 +01:00
parent 07bc3bb42b
commit cac6b25f19

View file

@ -233,7 +233,7 @@ function build_image_without_name() {
assert_line --index 0 --partial "FROM scratch"
assert_line --index 1 --partial "LABEL com.github.containers.toolbox=\"true\""
assert_line --index 2 --partial "COMMIT"
assert_line --index 3 --regexp "^--> [a-z0-9]*$"
assert_line --index 3 --regexp "^--> [a-f0-9]{6,64}$"
last=$((${#lines[@]}-1))
assert_line --index "$last" --regexp "^[a-f0-9]{64}$"