-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Correctly handle import errors in LoadImage() and ImportImage(), fix broken ExportContainer test case #14483
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
OneBlue
wants to merge
1
commit into
feature/wsl-for-apps
Choose a base branch
from
user/oneblue/load-errors
base: feature/wsl-for-apps
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+89
−22
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -744,7 +744,6 @@ class WSLATests | |
| ExpectImagePresent(*m_defaultSession, "debian:latest", true); | ||
| } | ||
|
|
||
| // TODO: Test that invalid tars are correctly handled. | ||
| TEST_METHOD(LoadImage) | ||
| { | ||
| WSL2_TEST_ONLY(); | ||
|
|
@@ -768,9 +767,18 @@ class WSLATests | |
|
|
||
| VERIFY_ARE_EQUAL(0, result.Code); | ||
| VERIFY_IS_TRUE(result.Output[1].find("Hello from Docker!") != std::string::npos); | ||
|
|
||
| // Validate that invalid tars fail with proper error message and code. | ||
| { | ||
| auto currentExecutableHandle = wil::open_file(wil::GetModuleFileNameW<std::wstring>().c_str()); | ||
| VERIFY_IS_TRUE(GetFileSizeEx(currentExecutableHandle.get(), &fileSize)); | ||
|
|
||
| VERIFY_ARE_EQUAL(m_defaultSession->LoadImage(HandleToULong(currentExecutableHandle.get()), nullptr, fileSize.QuadPart), E_FAIL); | ||
|
|
||
| ValidateCOMErrorMessage(L"archive/tar: invalid tar header"); | ||
| } | ||
OneBlue marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
|
|
||
| // TODO: Test that invalid tars are correctly handled. | ||
| TEST_METHOD(ImportImage) | ||
| { | ||
| WSL2_TEST_ONLY(); | ||
|
|
@@ -802,6 +810,20 @@ class WSLATests | |
| VERIFY_ARE_EQUAL( | ||
| m_defaultSession->ImportImage(HandleToULong(imageTarFileHandle.get()), "my-hello-world", nullptr, fileSize.QuadPart), E_INVALIDARG); | ||
| } | ||
|
|
||
| // Validate that invalid tars fail with proper error message and code. | ||
| { | ||
| auto currentExecutableHandle = wil::open_file(wil::GetModuleFileNameW<std::wstring>().c_str()); | ||
|
|
||
| VERIFY_IS_TRUE(GetFileSizeEx(currentExecutableHandle.get(), &fileSize)); | ||
|
|
||
| VERIFY_ARE_EQUAL( | ||
| m_defaultSession->ImportImage( | ||
| HandleToULong(currentExecutableHandle.get()), "invalid-image:test", nullptr, fileSize.QuadPart), | ||
| E_FAIL); | ||
|
|
||
| ValidateCOMErrorMessage(L"archive/tar: invalid tar header"); | ||
OneBlue marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
| } | ||
|
|
||
| TEST_METHOD(DeleteImage) | ||
|
|
@@ -1785,10 +1807,19 @@ class WSLATests | |
| VERIFY_IS_FALSE(INVALID_HANDLE_VALUE == containerTarFileHandle.get()); | ||
| LARGE_INTEGER fileSize{}; | ||
| VERIFY_IS_TRUE(GetFileSizeEx(containerTarFileHandle.get(), &fileSize)); | ||
|
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This test case was actually silently failing to load the image and was reusing an image from another test case |
||
| VERIFY_SUCCEEDED(m_defaultSession->LoadImage(HandleToULong(containerTarFileHandle.get()), nullptr, fileSize.QuadPart)); | ||
|
|
||
| auto cleanup = wil::scope_exit_log(WI_DIAGNOSTICS_INFO, [&]() { | ||
| WSLADeleteImageOptions options{.Image = "test-imported-container:latest", .Flags = WSLADeleteImageFlagsNone}; | ||
OneBlue marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| wil::unique_cotaskmem_array_ptr<WSLADeletedImageInformation> deletedImages; | ||
| LOG_IF_FAILED(m_defaultSession->DeleteImage(&options, &deletedImages, deletedImages.size_address<ULONG>())); | ||
| }); | ||
|
|
||
| VERIFY_SUCCEEDED(m_defaultSession->ImportImage( | ||
| HandleToULong(containerTarFileHandle.get()), "test-imported-container:latest", nullptr, fileSize.QuadPart)); | ||
|
|
||
| // Verify that the image is in the list of images. | ||
| ExpectImagePresent(*m_defaultSession, "hello-world:latest"); | ||
| WSLAContainerLauncher launcher("hello-world:latest", "wsla-hello-world-container"); | ||
| ExpectImagePresent(*m_defaultSession, "test-imported-container:latest"); | ||
| WSLAContainerLauncher launcher("test-imported-container:latest", "wsla-hello-world-container", {"/hello"}); | ||
| auto container = launcher.Launch(*m_defaultSession); | ||
| auto result = container.GetInitProcess().WaitAndCaptureOutput(); | ||
| VERIFY_ARE_EQUAL(0, result.Code); | ||
|
|
||
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.