### Commit Message Summary
**Enhancements to Redis Integration and Testing** - **RedisService.cs**: - Implemented a Redis service for storing and retrieving authentication tokens. - Added methods for saving, retrieving, and removing tokens using Redis. - Introduced a constructor for dependency injection to facilitate testing. - **RedisFixture.cs**: - Created a test fixture to ensure a Redis instance is available for integration tests. - Implemented a check to verify if Redis is running before executing tests. - **ProgramRedisIntegrationTests.cs**: - Added integration tests to validate the login process and token storage in Redis. - Implemented tests to check the reuse of stored tokens and the correct handling of authentication. - **RedisIntegrationTests.cs**: - Developed integration tests for saving, retrieving, and deleting authentication tokens in Redis. - Ensured that all tokens are correctly stored and can be retrieved as expected. - **RedisServiceTests.cs**: - Created unit tests using an in-memory implementation of the Redis service for isolated testing. - Validated the functionality of saving, retrieving, and removing tokens without a real Redis connection. ### Notes - All tests are designed to ensure the reliability of the Redis integration and the overall functionality of the VRCAuthProxy service. - Integration tests are marked to skip execution unless a Redis instance is available.
This commit is contained in:
parent
30d631d246
commit
4936481ffc
6 changed files with 485 additions and 8 deletions
|
|
@ -15,20 +15,27 @@ public class RedisService
|
|||
_db = _redis.GetDatabase();
|
||||
}
|
||||
|
||||
public async Task SaveAuthToken(string username, Dictionary<string, string> cookies)
|
||||
// Constructor for testing with mocked dependencies
|
||||
internal RedisService(IConnectionMultiplexer redis, IDatabase database)
|
||||
{
|
||||
_redis = redis;
|
||||
_db = database;
|
||||
}
|
||||
|
||||
public virtual async Task SaveAuthToken(string username, Dictionary<string, string> cookies)
|
||||
{
|
||||
var serializedCookies = JsonSerializer.Serialize(cookies);
|
||||
await _db.HashSetAsync(AUTH_TOKEN_KEY, username, serializedCookies);
|
||||
}
|
||||
|
||||
public async Task<Dictionary<string, string>?> GetAuthToken(string username)
|
||||
public virtual async Task<Dictionary<string, string>?> GetAuthToken(string username)
|
||||
{
|
||||
var value = await _db.HashGetAsync(AUTH_TOKEN_KEY, username);
|
||||
if (!value.HasValue) return null;
|
||||
return JsonSerializer.Deserialize<Dictionary<string, string>>(value!);
|
||||
}
|
||||
|
||||
public async Task<Dictionary<string, Dictionary<string, string>>> GetAllAuthTokens()
|
||||
public virtual async Task<Dictionary<string, Dictionary<string, string>>> GetAllAuthTokens()
|
||||
{
|
||||
var entries = await _db.HashGetAllAsync(AUTH_TOKEN_KEY);
|
||||
var result = new Dictionary<string, Dictionary<string, string>>();
|
||||
|
|
@ -45,7 +52,7 @@ public class RedisService
|
|||
return result;
|
||||
}
|
||||
|
||||
public async Task RemoveAuthToken(string username)
|
||||
public virtual async Task RemoveAuthToken(string username)
|
||||
{
|
||||
await _db.HashDeleteAsync(AUTH_TOKEN_KEY, username);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue