Initial commit: Client Doc docs Server Tools
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -0,0 +1,60 @@
|
||||
using System;
|
||||
using System.Text;
|
||||
using Xunit;
|
||||
using XWorld.Server.Auth;
|
||||
|
||||
namespace XWorld.Server.Auth.Tests
|
||||
{
|
||||
public class AccountStoreTests
|
||||
{
|
||||
// 用共享缓存的内存库(连接保持打开期间存活)
|
||||
static AccountStore NewStore() => new AccountStore("Data Source=acct_" + Guid.NewGuid().ToString("N") + ";Mode=Memory;Cache=Shared");
|
||||
|
||||
[Fact]
|
||||
public void CreateAccount_returns_positive_id()
|
||||
{
|
||||
using var s = NewStore();
|
||||
int id = s.CreateAccount("alice", "pw123456");
|
||||
Assert.True(id > 0);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void CreateAccount_duplicate_username_rejected_case_insensitive()
|
||||
{
|
||||
using var s = NewStore();
|
||||
s.CreateAccount("Bob", "pw123456");
|
||||
Assert.Throws<DuplicateUsernameException>(() => s.CreateAccount("bob", "other123"));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Verify_correct_password_returns_same_id()
|
||||
{
|
||||
using var s = NewStore();
|
||||
int id = s.CreateAccount("carol", "secret-pw");
|
||||
Assert.Equal(id, s.VerifyCredentials("carol", "secret-pw"));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Verify_wrong_password_returns_null()
|
||||
{
|
||||
using var s = NewStore();
|
||||
s.CreateAccount("dave", "secret-pw");
|
||||
Assert.Null(s.VerifyCredentials("dave", "WRONG"));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Verify_unknown_user_returns_null()
|
||||
{
|
||||
using var s = NewStore();
|
||||
Assert.Null(s.VerifyCredentials("nobody", "x"));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Password_not_stored_in_plaintext()
|
||||
{
|
||||
using var s = NewStore();
|
||||
s.CreateAccount("erin", "plaintext-marker");
|
||||
Assert.False(s.DebugRawContains(Encoding.UTF8.GetBytes("plaintext-marker")));
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user