Fix false positive in DockerImageName.isCompatibleWith for library/-prefixed images#11922
Open
TimurRakhmatullin86 wants to merge 1 commit into
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Broken behaviour
DockerImageName.isCompatibleWith()returnstruefor any image whose repository starts withlibrary/, regardless of what it is compared against:The library-prefix handling introduced in #6174 derives
imageWithLibraryPrefixfromthisonly and then compares it back againstthis:othernever takes part in that comparison, so for any registry-lesslibrary/…name the check degenerates toparse(this.repository).equals(this), which is always true (parsedrops the tag andAnyVersionequals everything). SinceassertCompatibleWith(...)guards the constructors of essentially every module (~96 call sites), it silently accepts wrong images instead of failing fast with theasCompatibleSubstituteForguidance. The existing testtestAssertMethodAcceptsCompatibleLibraryPrefixkept passing for this same wrong reason.Fix
Normalize both sides to the
library/-prefixed form before comparing, and only for names without a registry (Docker Hub official images):library/foo:1.2.3 ~ bar→false(wastrue)library/foo ~ foo→true(as before, now for the right reason)foo ~ library/foo→true(previouslyfalse; same image, now symmetric)otherstays on the left-hand side ofequals, so a tag present inothermust still match exactly and an untaggedotherstill acts as a wildcard (library/foo:1.2.3 ~ foo:4.5.6→false).some.registry/foo≠library/foo).Images named
library/…that previously passed the check only because of the false positive now fail with the standard compatibility error — that is the intended behaviour of the guard.Related to #9958: the
library/postgrescase reported there is what #6174 targeted; thedocker.io/…registry-qualified cases from that issue are out of scope for this PR.Testing
Added regression tests to
DockerImageNameCompatibilityTestcovering the false positive, prefix symmetry in both directions (with and without tags), registry exclusion, andasCompatibleSubstituteForinteraction. The new tests fail onmainand pass with this change; all pre-existing tests pass,checkstyleandspotlessare clean.