Skip to content
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

HWW Validate String Path Platform specific fixes #12781

Open
wants to merge 7 commits into
base: master
Choose a base branch
from

Conversation

Whem
Copy link
Collaborator

@Whem Whem commented Apr 8, 2024

related: #12713.

While the main idea is commendable, HWI has assigned different device paths to different platforms. At present, ValidatePathString only functions on Windows, except for Trezor, which has the same device path on all platforms.

This pull request has undergone testing on all platforms with a range of branded HWWs.

@turbolay
Copy link
Collaborator

turbolay commented Apr 8, 2024

Tests are failing, this PR is also unreviewable

@pull-request-size pull-request-size bot added size/M and removed size/S labels Apr 9, 2024
@Whem Whem requested a review from adamPetho April 9, 2024 14:12
/// <returns><c>true</c> if the path matches the model's regex, <c>false</c> otherwise.</returns>
public static bool ValidatePathString(HardwareWalletModels model, string path)
public static bool ValidatePathString(HardwareWalletModels model, string path, OSPlatform? osPlatform = null)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we need this new parameter anymore, it can be reverted. Same for the mocked tests.

Also, you can remove these extra checks || (osPlatform != null && osPlatform == OSPlatform.Windows).
No need for them.

Copy link
Collaborator Author

@Whem Whem Apr 9, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mock tests are only compatible with Windows operating system. You can check predefined paths. In that case, osplatform parameter is needed as the mocktest may fail.

Assert.True(HwiValidationHelper.ValidatePathString(entry.Model, @"\\?\hid#vid_03eb&pid_2403#6&229ae20&0&0000#{4d1e55b2-f16f-11cf-88cb-001111000030}"));

It's important to note that at this time we do not have the capability to separate mock tests for multiple platforms.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We do not write code only for the tests, please remove this parameter,
If the test is working only on Windows, then disable it on other platforms:

if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{
	return;
}

Here you are forcing the tests to act like they were running on Windows which is an extremely bad practice.

Copy link
Collaborator Author

@Whem Whem Apr 9, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The HwiKatas test is compatible with all platforms. However, the predefined data used in the mock test is specifically designed for Windows.

Initially, I thought that passing Windows as a parameter in the mocktest would display the expected results since it's only a mock test and not real data.

However, if required, I could expand the mock bridge test to a platform-specific approach.

@Whem Whem requested a review from molnard April 22, 2024 08:58
Copy link
Collaborator

@molnard molnard left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cACK

@@ -562,7 +563,7 @@ public async Task JadeMockTestsAsync(Network network)
IEnumerable<HwiEnumerateEntry> enumerate = await client.EnumerateAsync(cts.Token);
HwiEnumerateEntry entry = Assert.Single(enumerate);
Assert.Equal(HardwareWalletModels.Jade, entry.Model);
Assert.True(HwiValidationHelper.ValidatePathString(entry.Model, "COM3"));
Assert.True(HwiValidationHelper.ValidatePathString(entry.Model, "COM3", OSPlatform.Windows));
Copy link
Collaborator

@molnard molnard Apr 23, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree with @turbolay comment. Possible implementation idea:
remove this entirely or add a method called GetPlatformSpecificDevicePath which will return an example of what would a device give back on a specific platform.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants