Refactor project files for improved readability and structure
- Cleaned up whitespace in Directory.Build.props and Directory.Packages.props for consistency. - Reformatted project file references in PnvPanel.Api.csproj for better clarity. - Enhanced code readability in various endpoint files by adjusting line breaks and indentation. - Standardized method signatures and improved formatting in ResultExtensions and multiple endpoint classes for better maintainability.
This commit is contained in:
@@ -8,11 +8,28 @@ namespace PnvPanel.IntegrationTests.Admin;
|
||||
[Collection(IntegrationTestCollection.Name)]
|
||||
public class NodeInboundCrudTests(PnvPanelWebApplicationFactory factory)
|
||||
{
|
||||
private sealed record NodeResponse(Guid Id, string Name, string BaseAddress, string Username, string? Location, string Status, bool IsEnabled);
|
||||
private sealed record NodeResponse(
|
||||
Guid Id,
|
||||
string Name,
|
||||
string BaseAddress,
|
||||
string Username,
|
||||
string? Location,
|
||||
string Status,
|
||||
bool IsEnabled
|
||||
);
|
||||
|
||||
private sealed record InboundResponse(
|
||||
Guid Id, Guid NodeId, string RemoteInboundId, string Protocol, string Remark, int Port,
|
||||
bool IsPublished, string? DisplayName, int? MaxClients, IReadOnlyList<Guid> AllowedRoleIds);
|
||||
Guid Id,
|
||||
Guid NodeId,
|
||||
string RemoteInboundId,
|
||||
string Protocol,
|
||||
string Remark,
|
||||
int Port,
|
||||
bool IsPublished,
|
||||
string? DisplayName,
|
||||
int? MaxClients,
|
||||
IReadOnlyList<Guid> AllowedRoleIds
|
||||
);
|
||||
|
||||
private sealed record SyncNodeResponse(int InboundsSynced, string Status);
|
||||
|
||||
@@ -23,14 +40,17 @@ public class NodeInboundCrudTests(PnvPanelWebApplicationFactory factory)
|
||||
var adminToken = await LoginAsAdminAsync(adminClient);
|
||||
adminClient.UseBearerToken(adminToken);
|
||||
|
||||
var registerResponse = await adminClient.PostJsonAsync("/api/admin/nodes", new
|
||||
{
|
||||
name = $"Node-{Guid.NewGuid():N}"[..20],
|
||||
baseAddress = "https://node.example.com:2053",
|
||||
username = "admin",
|
||||
password = "node-panel-password",
|
||||
location = "Germany",
|
||||
});
|
||||
var registerResponse = await adminClient.PostJsonAsync(
|
||||
"/api/admin/nodes",
|
||||
new
|
||||
{
|
||||
name = $"Node-{Guid.NewGuid():N}"[..20],
|
||||
baseAddress = "https://node.example.com:2053",
|
||||
username = "admin",
|
||||
password = "node-panel-password",
|
||||
location = "Germany",
|
||||
}
|
||||
);
|
||||
Assert.Equal(HttpStatusCode.OK, registerResponse.StatusCode);
|
||||
var node = await registerResponse.ReadAsAsync<NodeResponse>();
|
||||
Assert.NotNull(node);
|
||||
@@ -40,24 +60,32 @@ public class NodeInboundCrudTests(PnvPanelWebApplicationFactory factory)
|
||||
var nodes = await listNodesResponse.ReadAsAsync<List<NodeResponse>>();
|
||||
Assert.Contains(nodes!, n => n.Id == node!.Id);
|
||||
|
||||
var syncResponse = await adminClient.PostAsync($"/api/admin/nodes/{node!.Id}/sync", content: null);
|
||||
var syncResponse = await adminClient.PostAsync(
|
||||
$"/api/admin/nodes/{node!.Id}/sync",
|
||||
content: null
|
||||
);
|
||||
Assert.Equal(HttpStatusCode.OK, syncResponse.StatusCode);
|
||||
var sync = await syncResponse.ReadAsAsync<SyncNodeResponse>();
|
||||
Assert.Equal(1, sync!.InboundsSynced);
|
||||
|
||||
var listInboundsResponse = await adminClient.GetAsync($"/api/admin/inbounds?nodeId={node.Id}");
|
||||
var listInboundsResponse = await adminClient.GetAsync(
|
||||
$"/api/admin/inbounds?nodeId={node.Id}"
|
||||
);
|
||||
Assert.Equal(HttpStatusCode.OK, listInboundsResponse.StatusCode);
|
||||
var inbounds = await listInboundsResponse.ReadAsAsync<List<InboundResponse>>();
|
||||
var inbound = Assert.Single(inbounds!);
|
||||
Assert.False(inbound.IsPublished);
|
||||
|
||||
var publishResponse = await adminClient.SendPutJsonAsync($"/api/admin/inbounds/{inbound.Id}/publish", new
|
||||
{
|
||||
isPublished = true,
|
||||
displayName = "Germany (VLESS)",
|
||||
allowedRoleIds = Array.Empty<Guid>(),
|
||||
maxClients = (int?)null,
|
||||
});
|
||||
var publishResponse = await adminClient.SendPutJsonAsync(
|
||||
$"/api/admin/inbounds/{inbound.Id}/publish",
|
||||
new
|
||||
{
|
||||
isPublished = true,
|
||||
displayName = "Germany (VLESS)",
|
||||
allowedRoleIds = Array.Empty<Guid>(),
|
||||
maxClients = (int?)null,
|
||||
}
|
||||
);
|
||||
Assert.Equal(HttpStatusCode.OK, publishResponse.StatusCode);
|
||||
var published = await publishResponse.ReadAsAsync<InboundResponse>();
|
||||
Assert.True(published!.IsPublished);
|
||||
@@ -72,10 +100,17 @@ public class NodeInboundCrudTests(PnvPanelWebApplicationFactory factory)
|
||||
var (_, userToken) = await RegisterAndLoginAsync(userClient, userName, "P@ssw0rd123");
|
||||
userClient.UseBearerToken(userToken);
|
||||
|
||||
var response = await userClient.PostJsonAsync("/api/admin/nodes", new
|
||||
{
|
||||
name = "Node", baseAddress = "https://node.example.com", username = "admin", password = "pw", location = (string?)null,
|
||||
});
|
||||
var response = await userClient.PostJsonAsync(
|
||||
"/api/admin/nodes",
|
||||
new
|
||||
{
|
||||
name = "Node",
|
||||
baseAddress = "https://node.example.com",
|
||||
username = "admin",
|
||||
password = "pw",
|
||||
location = (string?)null,
|
||||
}
|
||||
);
|
||||
|
||||
Assert.Equal(HttpStatusCode.Forbidden, response.StatusCode);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user