fix: reject unsupported hypervisor values in host resource validation - #337
Open
nagaboinaramgopal wants to merge 1 commit into
Open
fix: reject unsupported hypervisor values in host resource validation#337nagaboinaramgopal wants to merge 1 commit into
nagaboinaramgopal wants to merge 1 commit into
Conversation
The hypervisor ValidateFunc used sort.SearchStrings as if it returned a found flag, but it returns the insertion index (0..len). The check only rejected a value that sorts after every supported entry, so typos such as foo, docker or esxi passed plan-time validation and failed later with an opaque server-side error at apply. Treat a value as valid only when the element at the returned index equals it. Adds a unit test for the validator. Signed-off-by: Ramgopal Nagaboina <ramgopal.nagaboina.dev@gmail.com>
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.
Description
The
hypervisorValidateFuncon thecloudstack_hostresource usedsort.SearchStringsas if it returned a "found" flag, butsort.SearchStringsreturns the insertion index (0..len). The check>= len(validHypervisors)therefore only rejected a value that sorts after every supported entry, so unsupported values such asfoo,docker,esxi, orkvm2passed plan-time validation and failed later with an opaque server-side error at apply.Fixed by treating a value as valid only when the element at the returned index actually equals it, which is the standard
sort.SearchStringsidiom.Testing
Added a unit test
TestResourceCloudStackHostHypervisorValidationasserting the supported hypervisors are accepted and unsupported values are rejected. It needs no live CloudStack:The test fails against the current code (bad values are accepted) and passes with the fix.