-
Notifications
You must be signed in to change notification settings - Fork 20
feat: 添加游戏资源链接管理工具 #71
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
UranusNo7
wants to merge
9
commits into
MuNET-OSS:main
Choose a base branch
from
UranusNo7:feat/resource-junction-manager-official
base: main
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.
Open
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
2cc64eb
feat: add game resource junction manager
UranusNo7 8336763
fix: address resource junction review feedback
UranusNo7 5f932b1
fix: address resource junction review feedback
UranusNo7 67d228b
Merge branch 'main' into pr/71
clansty dcea6fb
fix: 限制资源链接接口仅接受本地请求
clansty b103ac0
fix: 通过句柄安全移除资源 Junction
clansty fdfb860
fix: 隔离资源链接会话状态
clansty 8128e6b
fix: 明确资源链接的非 Windows 行为
clansty 4474195
fix: 保留资源链接手动选择
clansty 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
91 changes: 91 additions & 0 deletions
91
MaiChartManager.Tests/Controllers/Tools/ResourceJunctionControllerTests.cs
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 |
|---|---|---|
| @@ -0,0 +1,91 @@ | ||
| using System.Net; | ||
| using MaiChartManager.Controllers.Tools; | ||
| using MaiChartManager.Platform; | ||
| using MaiChartManager.Services; | ||
| using Microsoft.AspNetCore.Http; | ||
| using Microsoft.AspNetCore.Mvc; | ||
|
|
||
| namespace MaiChartManager.Tests.Controllers.Tools; | ||
|
|
||
| [Collection("Static settings")] | ||
| public sealed class ResourceJunctionControllerTests | ||
| { | ||
| [Fact] | ||
| public void StatusRejectsRemoteRequests() | ||
| { | ||
| var controller = CreateController(IPAddress.Parse("192.0.2.1")); | ||
|
|
||
| var result = controller.GetResourceJunctionStatus(); | ||
|
|
||
| var status = Assert.IsType<StatusCodeResult>(result.Result); | ||
| Assert.Equal(StatusCodes.Status403Forbidden, status.StatusCode); | ||
| } | ||
|
|
||
| [Fact] | ||
| public void WriteActionRejectsRemoteRequestsBeforeUsingDesktopCapabilities() | ||
| { | ||
| var dialogService = new RecordingDialogService(); | ||
| var controller = CreateController(IPAddress.Parse("192.0.2.1"), dialogService); | ||
| var result = controller.SelectResourceJunctionSource(); | ||
|
|
||
| var status = Assert.IsType<StatusCodeResult>(result.Result); | ||
| Assert.Equal(StatusCodes.Status403Forbidden, status.StatusCode); | ||
| Assert.Equal(0, dialogService.PickFolderCalls); | ||
| } | ||
|
|
||
| [Fact] | ||
| public void LocalWriteActionDoesNotRequireAnAuthenticationHeader() | ||
| { | ||
| var dialogService = new RecordingDialogService(); | ||
| var controller = CreateController(IPAddress.Loopback, dialogService); | ||
|
|
||
| var result = controller.SelectResourceJunctionSource(); | ||
|
|
||
| Assert.IsType<OkObjectResult>(result.Result); | ||
| Assert.Equal(1, dialogService.PickFolderCalls); | ||
| } | ||
|
|
||
| [Fact] | ||
| public void LinuxUnsupportedStatusDoesNotOpenFolderPicker() | ||
| { | ||
| if (OperatingSystem.IsWindows()) return; | ||
| var dialogService = new RecordingDialogService(); | ||
| var controller = CreateController(IPAddress.Loopback, dialogService); | ||
|
|
||
| var result = controller.SelectResourceJunctionSource(); | ||
|
|
||
| Assert.IsType<OkObjectResult>(result.Result); | ||
| Assert.Equal(0, dialogService.PickFolderCalls); | ||
| } | ||
|
|
||
| private static ResourceJunctionController CreateController( | ||
| IPAddress remoteAddress, | ||
| RecordingDialogService? dialogService = null) | ||
| { | ||
| StaticSettings.Config = new Config(); | ||
| var context = new DefaultHttpContext(); | ||
| context.Connection.RemoteIpAddress = remoteAddress; | ||
| return new ResourceJunctionController( | ||
| new ResourceJunctionService(() => string.Empty, () => []), | ||
| dialogService ?? new RecordingDialogService()) | ||
| { | ||
| ControllerContext = new ControllerContext { HttpContext = context }, | ||
| }; | ||
| } | ||
|
|
||
| private sealed class RecordingDialogService : IDesktopDialogService | ||
| { | ||
| public int PickFolderCalls { get; private set; } | ||
|
|
||
| public string? PickFolder(string? title = null) | ||
| { | ||
| PickFolderCalls++; | ||
| return null; | ||
| } | ||
|
|
||
| public string? PickFile(string? title = null, string? filter = null) => null; | ||
| public bool Confirm(string message, string title, bool defaultResult = false) => defaultResult; | ||
| public void ShowError(string message, string title) { } | ||
| } | ||
|
|
||
| } | ||
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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
P2: 测试
LocalWriteActionDoesNotRequireAnAuthenticationHeader缺少 Linux 平台守卫,在 Linux 构建上会失败。控制器SelectResourceJunctionSource在if (!OperatingSystem.IsWindows()) return Ok(CreateUnsupportedOverview())之前不会调用文件夹选择器,因此 Linux 上PickFolderCalls为 0 而非断言的 1。建议按LinuxUnsupportedStatusDoesNotOpenFolderPicker的方式补上if (!OperatingSystem.IsWindows()) return;守卫或把该测试限定为仅 Windows 运行。Prompt for AI agents