Skip to content

Commit

Permalink
自动截断,避免超长导致对比时不一致
Browse files Browse the repository at this point in the history
  • Loading branch information
nnhy committed Jan 24, 2024
1 parent ca39b16 commit b526d2b
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
16 changes: 16 additions & 0 deletions Stardust.Server/Services/NodeService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
using Stardust.Data.Nodes;
using Stardust.Models;
using XCode;
using XCode.Configuration;

namespace Stardust.Server.Services;

Expand Down Expand Up @@ -130,6 +131,13 @@ private static Node CheckNode(Node node, NodeInfo di, String productCode, String
var board = di.Board;
var diskid = di.DiskID;

// 自动截断,避免超长导致对比时不一致
uuid = TrimLength(uuid, Node._.Uuid);
guid = TrimLength(guid, Node._.MachineGuid);
serial = TrimLength(serial, Node._.SerialNumber);
board = TrimLength(board, Node._.Board);
diskid = TrimLength(diskid, Node._.DiskID);

var level = 5;
if (!uuid.IsNullOrEmpty() && uuid != node.Uuid)
{
Expand Down Expand Up @@ -186,6 +194,14 @@ private static Node CheckNode(Node node, NodeInfo di, String productCode, String
return node;
}

private static String TrimLength(String value, FieldItem field)
{
if (value.IsNullOrEmpty()) return value;
if (field.Length <= 0 || value.Length < field.Length) return value;

return value[..field.Length];
}

private Node AutoRegister(Node node, LoginInfo inf, String ip, StarServerSetting set)
{
if (!set.AutoRegister) throw new ApiException(12, "禁止自动注册");
Expand Down
6 changes: 3 additions & 3 deletions Stardust.ServerTests/Services/AppServiceTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public void AuthorizeTest()
var app = App.FindByName("test");
if (app != null) app.Delete();

var service = new TokenService(null);
var service = new TokenService();

// 没有自动注册
var ex = Assert.Throws<ApiException>(() => service.Authorize("test", "xxx", false));
Expand Down Expand Up @@ -46,7 +46,7 @@ public void IssueTokenTest()
var app = new App { Name = "test" };

var set = StarServerSetting.Current;
var service = new TokenService(null);
var service = new TokenService();

var model = service.IssueToken(app.Name, set.TokenSecret, set.TokenExpire);
Assert.NotNull(model);
Expand All @@ -68,7 +68,7 @@ public void DecodeTokenTest()
}

var set = StarServerSetting.Current;
var service = new TokenService(null);
var service = new TokenService();

var model = service.IssueToken(app.Name, set.TokenSecret, set.TokenExpire);
Assert.NotNull(model);
Expand Down

0 comments on commit b526d2b

Please sign in to comment.