Authorize 测试通过

This commit is contained in:
大石头 2020-08-23 22:26:33 +08:00
parent 209bb79437
commit 20caeb49bd
6 changed files with 94 additions and 4 deletions

View File

@ -18,7 +18,7 @@ namespace Stardust.Server.Controllers
// 密码模式
if (grant_type == "password")
{
var app = _service.Authorize(username, password, set);
var app = _service.Authorize(username, password, set.AutoRegister);
return _service.IssueToken(app, set);
}
// 刷新令牌

View File

@ -14,9 +14,9 @@ namespace Stardust.Server.Services
/// <summary>验证应用密码</summary>
/// <param name="username"></param>
/// <param name="password"></param>
/// <param name="set"></param>
/// <param name="autoRegister"></param>
/// <returns></returns>
public App Authorize(String username, String password, Setting set)
public App Authorize(String username, String password, Boolean autoRegister)
{
if (username.IsNullOrEmpty()) throw new ArgumentNullException(nameof(username));
if (password.IsNullOrEmpty()) throw new ArgumentNullException(nameof(password));
@ -29,7 +29,7 @@ namespace Stardust.Server.Services
{
Name = username,
Secret = password,
Enable = set.AutoRegister,
Enable = autoRegister,
};
// 先保存

View File

@ -0,0 +1,18 @@
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Stardust.Server.Controllers;
using System;
using System.Collections.Generic;
using System.Text;
namespace Stardust.Server.Controllers.Tests
{
[TestClass()]
public class OAuthControllerTests
{
[TestMethod()]
public void TokenTest()
{
Assert.Fail();
}
}
}

View File

@ -0,0 +1,40 @@
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Stardust.Data;
using Stardust.Server.Services;
using System;
using System.Collections.Generic;
using System.Text;
namespace Stardust.Server.Services.Tests
{
[TestClass()]
public class AppServiceTests
{
[TestMethod()]
public void AuthorizeTest()
{
var app = App.FindByName("test");
if (app != null) app.Delete();
var service = new AppService();
var rs = service.Authorize("test", "xxx", true);
Assert.IsNotNull(rs);
app = App.FindByName("test");
Assert.IsNotNull(app);
Assert.AreEqual(app.ID, rs.ID);
}
[TestMethod()]
public void IssueTokenTest()
{
Assert.Fail();
}
[TestMethod()]
public void DecodeTokenTest()
{
Assert.Fail();
}
}
}

View File

@ -0,0 +1,20 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
<IsPackable>false</IsPackable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.5.0" />
<PackageReference Include="MSTest.TestAdapter" Version="2.1.0" />
<PackageReference Include="MSTest.TestFramework" Version="2.1.0" />
<PackageReference Include="coverlet.collector" Version="1.2.0" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Stardust.Server\Stardust.Server.csproj" />
</ItemGroup>
</Project>

View File

@ -27,6 +27,10 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ClientTest", "ClientTest\ClientTest.csproj", "{7DE10A4D-1749-4474-A6B2-F52CA8462813}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "UnitTest", "UnitTest", "{48B9E6E7-289F-42F2-8ACA-E7DF8E7C9059}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Stardust.ServerTests", "Stardust.ServerTests\Stardust.ServerTests.csproj", "{677C6502-2C9C-4907-AD82-670BE77B0AE6}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@ -61,10 +65,18 @@ Global
{7DE10A4D-1749-4474-A6B2-F52CA8462813}.Debug|Any CPU.Build.0 = Debug|Any CPU
{7DE10A4D-1749-4474-A6B2-F52CA8462813}.Release|Any CPU.ActiveCfg = Release|Any CPU
{7DE10A4D-1749-4474-A6B2-F52CA8462813}.Release|Any CPU.Build.0 = Release|Any CPU
{677C6502-2C9C-4907-AD82-670BE77B0AE6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{677C6502-2C9C-4907-AD82-670BE77B0AE6}.Debug|Any CPU.Build.0 = Debug|Any CPU
{677C6502-2C9C-4907-AD82-670BE77B0AE6}.Release|Any CPU.ActiveCfg = Release|Any CPU
{677C6502-2C9C-4907-AD82-670BE77B0AE6}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{7DE10A4D-1749-4474-A6B2-F52CA8462813} = {48B9E6E7-289F-42F2-8ACA-E7DF8E7C9059}
{677C6502-2C9C-4907-AD82-670BE77B0AE6} = {48B9E6E7-289F-42F2-8ACA-E7DF8E7C9059}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {9337283C-C795-479F-A2F1-C892EBE2490C}
EndGlobalSection