Skip to content

Commit e35e1f4

Browse files
authored
fix: normalize tenant and technical user names in process retrieval methods (#188)
Reviewed-by: Phil Schneider <info@philschneider.de> Refs: #187
1 parent c9f6277 commit e35e1f4

File tree

2 files changed

+48
-22
lines changed

2 files changed

+48
-22
lines changed

src/web/Dim.Web/BusinessLogic/DimBusinessLogic.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,8 @@ private static string GetName(string name, string? additionalName = null)
186186

187187
public async Task<ProcessData> GetSetupProcess(string bpn, string companyName)
188188
{
189-
var processData = await dimRepositories.GetInstance<ITenantRepository>().GetWalletProcessForTenant(bpn, companyName)
189+
var tenant = GetName(companyName, bpn);
190+
var processData = await dimRepositories.GetInstance<ITenantRepository>().GetWalletProcessForTenant(bpn, tenant)
190191
.ConfigureAwait(ConfigureAwaitOptions.None);
191192
if (processData == null)
192193
{
@@ -198,7 +199,9 @@ public async Task<ProcessData> GetSetupProcess(string bpn, string companyName)
198199

199200
public async Task<ProcessData> GetTechnicalUserProcess(string bpn, string companyName, string technicalUserName)
200201
{
201-
var processData = await dimRepositories.GetInstance<ITechnicalUserRepository>().GetTechnicalUserProcess(bpn, companyName, technicalUserName)
202+
var tenant = GetName(companyName, bpn);
203+
var techUserName = GetName(technicalUserName, bpn);
204+
var processData = await dimRepositories.GetInstance<ITechnicalUserRepository>().GetTechnicalUserProcess(bpn, tenant, techUserName)
202205
.ConfigureAwait(ConfigureAwaitOptions.None);
203206
if (processData == null)
204207
{

tests/web/Dim.Web.Tests/DimBusinessLogicTests.cs

Lines changed: 43 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -430,6 +430,21 @@ private WalletData GetWalletData()
430430
return new WalletData("https://example.org/token", "cl1", secret, initializationVector, 0);
431431
}
432432

433+
private static string GetName(string name, string additionalName)
434+
{
435+
// Use reflection to call the private GetName method
436+
var getNameMethod = typeof(DimBusinessLogic)
437+
.GetMethod("GetName", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Static);
438+
439+
if (getNameMethod == null)
440+
throw new InvalidOperationException("GetName method not found on DimBusinessLogic.");
441+
442+
var normalizedTenantObj = getNameMethod.Invoke(null, new object[] { name, additionalName });
443+
if (normalizedTenantObj is not string normalizedName)
444+
throw new InvalidOperationException("GetName method did not return a string.");
445+
return normalizedName;
446+
}
447+
433448
#region GetSetupProcess
434449

435450
[Fact]
@@ -439,16 +454,16 @@ public async Task GetSetupProcess_WithValidBpnAndCompanyName_ReturnsExpectedProc
439454
const string Bpn = "BPNL00000001TEST";
440455
const string CompanyName = "testCompany";
441456
var expectedProcessData = _fixture.Create<ProcessData>();
442-
443-
A.CallTo(() => _tenantRepository.GetWalletProcessForTenant(Bpn, CompanyName))
457+
var normalizedName = GetName(CompanyName, Bpn);
458+
A.CallTo(() => _tenantRepository.GetWalletProcessForTenant(Bpn, normalizedName))
444459
.Returns(expectedProcessData);
445460

446461
// Act
447462
var result = await _sut.GetSetupProcess(Bpn, CompanyName);
448463

449464
// Assert
450465
result.Should().BeEquivalentTo(expectedProcessData);
451-
A.CallTo(() => _tenantRepository.GetWalletProcessForTenant(Bpn, CompanyName))
466+
A.CallTo(() => _tenantRepository.GetWalletProcessForTenant(Bpn, normalizedName))
452467
.MustHaveHappenedOnceExactly();
453468
}
454469

@@ -460,7 +475,8 @@ public async Task GetSetupProcess_WithValidBpnAndCompanyName_ReturnsExpectedProc
460475
public async Task GetSetupProcess_WithInvalidInput_ThrowsNotFoundException(string bpn, string companyName)
461476
{
462477
// Arrange
463-
A.CallTo(() => _tenantRepository.GetWalletProcessForTenant(bpn, companyName))
478+
var normalizedName = GetName(companyName, bpn);
479+
A.CallTo(() => _tenantRepository.GetWalletProcessForTenant(bpn, normalizedName))
464480
.Returns(Task.FromResult<ProcessData?>(null));
465481

466482
// Act
@@ -469,7 +485,7 @@ public async Task GetSetupProcess_WithInvalidInput_ThrowsNotFoundException(strin
469485
// Assert
470486
var exception = await Assert.ThrowsAsync<NotFoundException>(Act);
471487
exception.Message.Should().Be(nameof(DimErrors.NO_PROCESS_FOR_COMPANY));
472-
A.CallTo(() => _tenantRepository.GetWalletProcessForTenant(bpn, companyName))
488+
A.CallTo(() => _tenantRepository.GetWalletProcessForTenant(bpn, normalizedName))
473489
.MustHaveHappenedOnceExactly();
474490
}
475491

@@ -479,8 +495,8 @@ public async Task GetSetupProcess_WithNonExistingProcess_ThrowsNotFoundException
479495
// Arrange
480496
const string Bpn = "BPNL00000001TEST";
481497
const string CompanyName = "nonExistingCompany";
482-
483-
A.CallTo(() => _tenantRepository.GetWalletProcessForTenant(Bpn, CompanyName))
498+
var normalizedName = GetName(CompanyName, Bpn);
499+
A.CallTo(() => _tenantRepository.GetWalletProcessForTenant(Bpn, normalizedName))
484500
.Returns(Task.FromResult<ProcessData?>(null));
485501

486502
// Act
@@ -489,7 +505,7 @@ public async Task GetSetupProcess_WithNonExistingProcess_ThrowsNotFoundException
489505
// Assert
490506
var exception = await Assert.ThrowsAsync<NotFoundException>(Act);
491507
exception.Message.Should().Be(nameof(DimErrors.NO_PROCESS_FOR_COMPANY));
492-
A.CallTo(() => _tenantRepository.GetWalletProcessForTenant(Bpn, CompanyName))
508+
A.CallTo(() => _tenantRepository.GetWalletProcessForTenant(Bpn, normalizedName))
493509
.MustHaveHappenedOnceExactly();
494510
}
495511

@@ -501,16 +517,16 @@ public async Task GetSetupProcess_WithDifferentValidInputs_ReturnsCorrectProcess
501517
{
502518
// Arrange
503519
var expectedProcessData = _fixture.Create<ProcessData>();
504-
505-
A.CallTo(() => _tenantRepository.GetWalletProcessForTenant(bpn, companyName))
520+
var normalizedName = GetName(companyName, bpn);
521+
A.CallTo(() => _tenantRepository.GetWalletProcessForTenant(bpn, normalizedName))
506522
.Returns(expectedProcessData);
507523

508524
// Act
509525
var result = await _sut.GetSetupProcess(bpn, companyName);
510526

511527
// Assert
512528
result.Should().BeEquivalentTo(expectedProcessData);
513-
A.CallTo(() => _tenantRepository.GetWalletProcessForTenant(bpn, companyName))
529+
A.CallTo(() => _tenantRepository.GetWalletProcessForTenant(bpn, normalizedName))
514530
.MustHaveHappenedOnceExactly();
515531
}
516532

@@ -525,17 +541,19 @@ public async Task GetTechnicalUserProcess_WithValidBpnAndCompanyName_ReturnsExpe
525541
const string Bpn = "BPNL00000001TEST";
526542
const string CompanyName = "testCompany";
527543
const string TechnicalUserName = "testUser";
544+
var normalizedName = GetName(CompanyName, Bpn);
545+
var normalizedTechName = GetName(TechnicalUserName, Bpn);
528546
var expectedProcessData = _fixture.Create<ProcessData>();
529547

530-
A.CallTo(() => _technicalUserRepository.GetTechnicalUserProcess(Bpn, CompanyName, TechnicalUserName))
548+
A.CallTo(() => _technicalUserRepository.GetTechnicalUserProcess(Bpn, normalizedName, normalizedTechName))
531549
.Returns(expectedProcessData);
532550

533551
// Act
534552
var result = await _sut.GetTechnicalUserProcess(Bpn, CompanyName, TechnicalUserName);
535553

536554
// Assert
537555
result.Should().BeEquivalentTo(expectedProcessData);
538-
A.CallTo(() => _technicalUserRepository.GetTechnicalUserProcess(Bpn, CompanyName, TechnicalUserName))
556+
A.CallTo(() => _technicalUserRepository.GetTechnicalUserProcess(Bpn, normalizedName, normalizedTechName))
539557
.MustHaveHappenedOnceExactly();
540558
}
541559

@@ -549,7 +567,9 @@ public async Task GetTechnicalUserProcess_WithValidBpnAndCompanyName_ReturnsExpe
549567
public async Task GetTechnicalUserProcess_WithInvalidInput_ThrowsNotFoundException(string bpn, string companyName, string technicalUserName)
550568
{
551569
// Arrange
552-
A.CallTo(() => _technicalUserRepository.GetTechnicalUserProcess(bpn, companyName, technicalUserName))
570+
var normalizedName = GetName(companyName, bpn);
571+
var normalizedTechName = GetName(technicalUserName, bpn);
572+
A.CallTo(() => _technicalUserRepository.GetTechnicalUserProcess(bpn, normalizedName, normalizedTechName))
553573
.Returns(Task.FromResult<ProcessData?>(null));
554574

555575
// Act
@@ -558,7 +578,7 @@ public async Task GetTechnicalUserProcess_WithInvalidInput_ThrowsNotFoundExcepti
558578
// Assert
559579
var exception = await Assert.ThrowsAsync<NotFoundException>(Act);
560580
exception.Message.Should().Be(nameof(DimErrors.NO_PROCESS_FOR_TECHNICAL_USER));
561-
A.CallTo(() => _technicalUserRepository.GetTechnicalUserProcess(bpn, companyName, technicalUserName))
581+
A.CallTo(() => _technicalUserRepository.GetTechnicalUserProcess(bpn, normalizedName, normalizedTechName))
562582
.MustHaveHappenedOnceExactly();
563583
}
564584

@@ -569,8 +589,9 @@ public async Task GetTechnicalUserProcess_WithNonExistingProcess_ThrowsNotFoundE
569589
const string Bpn = "BPNL00000001TEST";
570590
const string CompanyName = "testCompany";
571591
const string TechnicalUserName = "nonExistingTechUser";
572-
573-
A.CallTo(() => _technicalUserRepository.GetTechnicalUserProcess(Bpn, CompanyName, TechnicalUserName))
592+
var normalizedName = GetName(CompanyName, Bpn);
593+
var normalizedTechName = GetName(TechnicalUserName, Bpn);
594+
A.CallTo(() => _technicalUserRepository.GetTechnicalUserProcess(Bpn, normalizedName, normalizedTechName))
574595
.Returns(Task.FromResult<ProcessData?>(null));
575596

576597
// Act
@@ -579,7 +600,7 @@ public async Task GetTechnicalUserProcess_WithNonExistingProcess_ThrowsNotFoundE
579600
// Assert
580601
var exception = await Assert.ThrowsAsync<NotFoundException>(Act);
581602
exception.Message.Should().Be(nameof(DimErrors.NO_PROCESS_FOR_TECHNICAL_USER));
582-
A.CallTo(() => _technicalUserRepository.GetTechnicalUserProcess(Bpn, CompanyName, TechnicalUserName))
603+
A.CallTo(() => _technicalUserRepository.GetTechnicalUserProcess(Bpn, normalizedName, normalizedTechName))
583604
.MustHaveHappenedOnceExactly();
584605
}
585606

@@ -590,17 +611,19 @@ public async Task GetTechnicalUserProcess_WithNonExistingProcess_ThrowsNotFoundE
590611
public async Task GetTechnicalUserProcess_WithDifferentValidInputs_ReturnsCorrectProcessData(string bpn, string companyName, string technicalUserName)
591612
{
592613
// Arrange
614+
var normalizedName = GetName(companyName, bpn);
615+
var normalizedTechName = GetName(technicalUserName, bpn);
593616
var expectedProcessData = _fixture.Create<ProcessData>();
594617

595-
A.CallTo(() => _technicalUserRepository.GetTechnicalUserProcess(bpn, companyName, technicalUserName))
618+
A.CallTo(() => _technicalUserRepository.GetTechnicalUserProcess(bpn, normalizedName, normalizedTechName))
596619
.Returns(expectedProcessData);
597620

598621
// Act
599622
var result = await _sut.GetTechnicalUserProcess(bpn, companyName, technicalUserName);
600623

601624
// Assert
602625
result.Should().BeEquivalentTo(expectedProcessData);
603-
A.CallTo(() => _technicalUserRepository.GetTechnicalUserProcess(bpn, companyName, technicalUserName))
626+
A.CallTo(() => _technicalUserRepository.GetTechnicalUserProcess(bpn, normalizedName, normalizedTechName))
604627
.MustHaveHappenedOnceExactly();
605628
}
606629

0 commit comments

Comments
 (0)