-
Notifications
You must be signed in to change notification settings - Fork 272
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[release-v1.58] Check content-type in importer to warn against unexpe…
…cted kubevirt imports (#2975) * Check content-type before importing to warn against unexpected content imports This commit adds a check in the http-datasource format reader to trigger a warning when importing unexpected content-types. Signed-off-by: Alvaro Romero <[email protected]> * Test import with unexpected content-type This commit adds a test to cover a import with unexpected content-type. It also updates the badserver to allow mocking this behavior. Signed-off-by: Alvaro Romero <[email protected]> --------- Signed-off-by: Alvaro Romero <[email protected]> Co-authored-by: Alvaro Romero <[email protected]>
- Loading branch information
1 parent
cf62f42
commit 33773a7
Showing
4 changed files
with
75 additions
and
16 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,9 +2,14 @@ package tests | |
|
||
import ( | ||
"fmt" | ||
"strings" | ||
"time" | ||
|
||
. "github.com/onsi/ginkgo/v2" | ||
. "github.com/onsi/gomega" | ||
|
||
"kubevirt.io/containerized-data-importer/pkg/common" | ||
controller "kubevirt.io/containerized-data-importer/pkg/controller/common" | ||
"kubevirt.io/containerized-data-importer/tests/framework" | ||
"kubevirt.io/containerized-data-importer/tests/utils" | ||
|
||
|
@@ -31,6 +36,31 @@ var _ = Describe("Problematic server responses", func() { | |
Entry("[rfe_id:4326][test_id:5076][crit:low][vendor:[email protected]][level:component] Should succeed even if Accept-Ranges doesn't exist", "/no-accept-ranges/cirros-qcow2.img"), | ||
) | ||
|
||
It("Should warn against unexpected content-types when importing a kubevirt img", func() { | ||
cdiBadServer := fmt.Sprintf("http://cdi-bad-webserver.%s:9090", f.CdiInstallNs) | ||
pathname := "/bad-content-type/cirros-qcow2.img" | ||
dataVolume = utils.NewDataVolumeWithHTTPImport("badserver-dv", "1Gi", cdiBadServer+pathname) | ||
dataVolume.Annotations[controller.AnnPodRetainAfterCompletion] = "true" | ||
By("creating DataVolume") | ||
dataVolume, err := utils.CreateDataVolumeFromDefinition(f.CdiClient, f.Namespace.Name, dataVolume) | ||
Expect(err).ToNot(HaveOccurred()) | ||
f.ForceBindPvcIfDvIsWaitForFirstConsumer(dataVolume) | ||
|
||
err = utils.WaitForDataVolumePhase(f, f.Namespace.Name, cdiv1.Succeeded, dataVolume.Name) | ||
Expect(err).ToNot(HaveOccurred()) | ||
|
||
By("Find importer pod after completion") | ||
importer, err := utils.FindPodByPrefixOnce(f.K8sClient, dataVolume.Namespace, common.ImporterPodName, common.CDILabelSelector) | ||
Expect(err).ToNot(HaveOccurred()) | ||
Expect(importer.DeletionTimestamp).To(BeNil()) | ||
|
||
By("Verify HTTP request error in importer log") | ||
Eventually(func() bool { | ||
log, _ := f.RunKubectlCommand("logs", importer.Name, "-n", importer.Namespace) | ||
return strings.Contains(log, "Unexpected content type 'text/html'. Content might not be a KubeVirt image.") | ||
}, time.Minute, pollingInterval).Should(BeTrue()) | ||
}) | ||
|
||
AfterEach(func() { | ||
By("deleting DataVolume") | ||
err := utils.DeleteDataVolume(f.CdiClient, f.Namespace.Name, dataVolumeName) | ||
|
This file contains 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