refactor(securestore): store entire connection strings in SecureStore
Eliminates placeholder substitution (${KEY}) in favor of storing complete
connection strings as single encrypted values. SecureStore now auto-creates
entries for all connection strings defined in appsettings. ConfigManager
editor reads/writes values directly to SecureStore.
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
using JdeScoping.Core.Interfaces;
|
||||
using JdeScoping.DataAccess.Exceptions;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using NSubstitute;
|
||||
using Shouldly;
|
||||
@@ -9,15 +9,16 @@ namespace JdeScoping.DataAccess.Tests;
|
||||
|
||||
/// <summary>
|
||||
/// Unit tests for DbConnectionFactory GIW connection support.
|
||||
/// Connection strings are retrieved from ISecureStoreService.
|
||||
/// </summary>
|
||||
public class DbConnectionFactoryGiwTests
|
||||
{
|
||||
private readonly IConfiguration _configuration;
|
||||
private readonly ISecureStoreService _secureStore;
|
||||
private readonly ILogger<DbConnectionFactory> _logger;
|
||||
|
||||
public DbConnectionFactoryGiwTests()
|
||||
{
|
||||
_configuration = Substitute.For<IConfiguration>();
|
||||
_secureStore = Substitute.For<ISecureStoreService>();
|
||||
_logger = Substitute.For<ILogger<DbConnectionFactory>>();
|
||||
}
|
||||
|
||||
@@ -25,8 +26,8 @@ public class DbConnectionFactoryGiwTests
|
||||
public async Task CreateGiwConnectionAsync_MissingConnectionString_ThrowsConnectionException()
|
||||
{
|
||||
// Arrange
|
||||
_configuration.GetConnectionString("GIW").Returns((string?)null);
|
||||
var factory = new DbConnectionFactory(_configuration, _logger);
|
||||
_secureStore.Get("GIW").Returns((string?)null);
|
||||
var factory = new DbConnectionFactory(_secureStore, _logger);
|
||||
|
||||
// Act & Assert
|
||||
var ex = await Should.ThrowAsync<ConnectionException>(
|
||||
@@ -40,8 +41,8 @@ public class DbConnectionFactoryGiwTests
|
||||
public async Task CreateGiwConnectionAsync_EmptyConnectionString_ThrowsConnectionException()
|
||||
{
|
||||
// Arrange
|
||||
_configuration.GetConnectionString("GIW").Returns(string.Empty);
|
||||
var factory = new DbConnectionFactory(_configuration, _logger);
|
||||
_secureStore.Get("GIW").Returns(string.Empty);
|
||||
var factory = new DbConnectionFactory(_secureStore, _logger);
|
||||
|
||||
// Act & Assert
|
||||
var ex = await Should.ThrowAsync<ConnectionException>(
|
||||
@@ -55,8 +56,8 @@ public class DbConnectionFactoryGiwTests
|
||||
public async Task CreateGiwConnectionAsync_InvalidConnectionString_ThrowsConnectionException()
|
||||
{
|
||||
// Arrange
|
||||
_configuration.GetConnectionString("GIW").Returns("Invalid oracle connection");
|
||||
var factory = new DbConnectionFactory(_configuration, _logger);
|
||||
_secureStore.Get("GIW").Returns("Invalid oracle connection");
|
||||
var factory = new DbConnectionFactory(_secureStore, _logger);
|
||||
|
||||
// Act & Assert
|
||||
var ex = await Should.ThrowAsync<ConnectionException>(
|
||||
@@ -71,8 +72,8 @@ public class DbConnectionFactoryGiwTests
|
||||
public async Task CreateGiwConnectionAsync_CancellationRequested_ThrowsOperationCanceledException()
|
||||
{
|
||||
// Arrange
|
||||
_configuration.GetConnectionString("GIW").Returns("User Id=test;Password=test;Data Source=test");
|
||||
var factory = new DbConnectionFactory(_configuration, _logger);
|
||||
_secureStore.Get("GIW").Returns("User Id=test;Password=test;Data Source=test");
|
||||
var factory = new DbConnectionFactory(_secureStore, _logger);
|
||||
using var cts = new CancellationTokenSource();
|
||||
cts.Cancel();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user