Skip to content

Commit

Permalink
fixed the existing test and added new test
Browse files Browse the repository at this point in the history
  • Loading branch information
dhiren-singh-007 committed Jan 10, 2025
1 parent 77691ce commit 3a51e9a
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@ public OfferProviderBusinessLogic(
{
throw new ConflictException("Country should be set for the company");
}
var cryptoConfig = _settings.EncryptionConfigs.SingleOrDefault(x => x.Index == data.AuthDetails.EncryptionMode) ?? throw new ConfigurationException($"EncryptionModeIndex {data.AuthDetails.EncryptionMode} is not configured");
var secret = CryptoHelper.Decrypt(data.AuthDetails.ClientSecret, data.AuthDetails.InitializationVector, Convert.FromHexString(cryptoConfig.EncryptionKey), cryptoConfig.CipherMode, cryptoConfig.PaddingMode);
var cryptoConfig = _settings.EncryptionConfigs.SingleOrDefault(x => x.Index == data.AuthDetails!.EncryptionMode) ?? throw new ConfigurationException($"EncryptionModeIndex {data.AuthDetails!.EncryptionMode} is not configured");
var secret = CryptoHelper.Decrypt(data.AuthDetails!.ClientSecret, data.AuthDetails.InitializationVector, Convert.FromHexString(cryptoConfig.EncryptionKey), cryptoConfig.CipherMode, cryptoConfig.PaddingMode);

var triggerProvider = !string.IsNullOrWhiteSpace(data.AutoSetupUrl) && !data.IsSingleInstance;
if (triggerProvider)
Expand Down Expand Up @@ -159,8 +159,8 @@ await _offerProviderService
technicalUserInfoData,
new CallbackClientInfoData(data.ClientId)
);
var cryptoConfig = _settings.EncryptionConfigs.SingleOrDefault(x => x.Index == data.AuthDetails.EncryptionMode) ?? throw new ConfigurationException($"EncryptionModeIndex {data.AuthDetails.EncryptionMode} is not configured");
var secret = CryptoHelper.Decrypt(data.AuthDetails.ClientSecret, data.AuthDetails.InitializationVector, Convert.FromHexString(cryptoConfig.EncryptionKey), cryptoConfig.CipherMode, cryptoConfig.PaddingMode);
var cryptoConfig = _settings.EncryptionConfigs.SingleOrDefault(x => x.Index == data.AuthDetails!.EncryptionMode) ?? throw new ConfigurationException($"EncryptionModeIndex {data.AuthDetails!.EncryptionMode} is not configured");
var secret = CryptoHelper.Decrypt(data.AuthDetails!.ClientSecret, data.AuthDetails.InitializationVector, Convert.FromHexString(cryptoConfig.EncryptionKey), cryptoConfig.CipherMode, cryptoConfig.PaddingMode);

await _offerProviderService
.TriggerOfferProviderCallback(callbackData, data.CallbackUrl, data.AuthDetails.AuthUrl, data.AuthDetails.ClientId, secret, cancellationToken)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public record TriggerProviderInformation(
Guid OfferId,
string? OfferName,
string? AutoSetupUrl,
ProviderAuthInformation AuthDetails,
ProviderAuthInformation? AuthDetails,
CompanyInformationData CompanyInformationData,
OfferTypeId OfferTypeId,
Guid? SalesManagerId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ public interface IOfferSubscriptionsRepository
Task<VerifyProcessData?> GetProcessStepData(Guid offerSubscriptionId, IEnumerable<ProcessStepTypeId> processStepTypeIds);
Task<OfferSubscriptionClientCreationData?> GetClientCreationData(Guid offerSubscriptionId);
Task<OfferSubscriptionTechnicalUserCreationData?> GetTechnicalUserCreationData(Guid offerSubscriptionId);
Task<(IEnumerable<(Guid TechnicalUserId, string? TechnicalClientId, TechnicalUserKindId TechnicalUserKindId)> ServiceAccounts, string? ClientId, string? CallbackUrl, ProviderAuthInformation AuthDetails, OfferSubscriptionStatusId Status)> GetTriggerProviderCallbackInformation(Guid offerSubscriptionId);
Task<(IEnumerable<(Guid TechnicalUserId, string? TechnicalClientId, TechnicalUserKindId TechnicalUserKindId)> ServiceAccounts, string? ClientId, string? CallbackUrl, ProviderAuthInformation? AuthDetails, OfferSubscriptionStatusId Status)> GetTriggerProviderCallbackInformation(Guid offerSubscriptionId);
OfferSubscriptionProcessData CreateOfferSubscriptionProcessData(Guid offerSubscriptionId, string offerUrl);
void RemoveOfferSubscriptionProcessData(Guid offerSubscriptionProcessDataId);
IAsyncEnumerable<ProcessStepData> GetProcessStepsForSubscription(Guid offerSubscriptionId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@ public Task<Guid> GetOfferSubscriptionDataForProcessIdAsync(Guid processId) =>

/// <inheritdoc />
public Task<TriggerProviderInformation?> GetTriggerProviderInformation(Guid offerSubscriptionId) =>
dbContext.OfferSubscriptions
dbContext.OfferSubscriptions
.Where(x => x.Id == offerSubscriptionId)
.Select(x => new
{
Expand All @@ -334,7 +334,7 @@ public Task<Guid> GetOfferSubscriptionDataForProcessIdAsync(Guid processId) =>
x.OfferId,
x.OfferName,
x.AutoSetupUrl,
new ProviderAuthInformation(
x.AuthUrl == null ? null : new ProviderAuthInformation(
x.AuthUrl,
x.ClientId,
x.ClientSecret,
Expand All @@ -355,6 +355,7 @@ public Task<Guid> GetOfferSubscriptionDataForProcessIdAsync(Guid processId) =>
))
.SingleOrDefaultAsync();

Check warning on line 357 in src/portalbackend/PortalBackend.DBAccess/Repositories/OfferSubscriptionsRepository.cs

View workflow job for this annotation

GitHub Actions / Build, check and test services (8.0)

Avoid multiple blank lines

/// <inheritdoc />
public Task<SubscriptionActivationData?> GetSubscriptionActivationDataByIdAsync(Guid offerSubscriptionId) =>
dbContext.OfferSubscriptions
Expand Down Expand Up @@ -435,14 +436,14 @@ public Task<Guid> GetOfferSubscriptionDataForProcessIdAsync(Guid processId) =>
.SingleOrDefaultAsync();

/// <inheritdoc />
public Task<(IEnumerable<(Guid TechnicalUserId, string? TechnicalClientId, TechnicalUserKindId TechnicalUserKindId)> ServiceAccounts, string? ClientId, string? CallbackUrl, ProviderAuthInformation AuthDetails, OfferSubscriptionStatusId Status)> GetTriggerProviderCallbackInformation(Guid offerSubscriptionId) =>
public Task<(IEnumerable<(Guid TechnicalUserId, string? TechnicalClientId, TechnicalUserKindId TechnicalUserKindId)> ServiceAccounts, string? ClientId, string? CallbackUrl, ProviderAuthInformation? AuthDetails, OfferSubscriptionStatusId Status)> GetTriggerProviderCallbackInformation(Guid offerSubscriptionId) =>
dbContext.OfferSubscriptions
.Where(x => x.Id == offerSubscriptionId)
.Select(x => new ValueTuple<IEnumerable<(Guid, string?, TechnicalUserKindId)>, string?, string?, ProviderAuthInformation, OfferSubscriptionStatusId>(
.Select(x => new ValueTuple<IEnumerable<(Guid, string?, TechnicalUserKindId)>, string?, string?, ProviderAuthInformation?, OfferSubscriptionStatusId>(
x.Technicalusers.Select(sa => new ValueTuple<Guid, string?, TechnicalUserKindId>(sa.Id, sa.ClientClientId, sa.TechnicalUserKindId)),
x.AppSubscriptionDetail!.AppInstance!.IamClient!.ClientClientId,
x.Offer!.ProviderCompany!.ProviderCompanyDetail!.AutoSetupCallbackUrl,
new ProviderAuthInformation(x.Offer!.ProviderCompany!.ProviderCompanyDetail!.AuthUrl,
x.Offer.ProviderCompany.ProviderCompanyDetail!.AuthUrl == null ? null : new ProviderAuthInformation(x.Offer!.ProviderCompany!.ProviderCompanyDetail!.AuthUrl,
x.Offer!.ProviderCompany!.ProviderCompanyDetail!.ClientId,
x.Offer!.ProviderCompany!.ProviderCompanyDetail!.ClientSecret,
x.Offer!.ProviderCompany!.ProviderCompanyDetail!.InitializationVector,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,10 @@ public async Task CreateServiceProviderCompanyDetail_ReturnsExpectedResult()
var (sut, context) = await CreateSut();
const string authUrl = "https://auth-url.com";
const string clientId = "client-id";
var secret = A<byte[]>._;
var encryptionMode = A<int>._;
var initializationVector = A<byte[]>._;
var secret = Convert.FromHexString("2b7e151628aed2a6abf715892b7e151628aed2a6abf715892b7e151628aed2a6");
var initializationVector = Convert.FromBase64String("JHcycHPDfRwjT1J1NqBJtQ==");
var encryptionMode = 5;

Check warning on line 67 in tests/portalbackend/PortalBackend.DBAccess.Tests/CompanyRepositoryTests.cs

View workflow job for this annotation

GitHub Actions / Build, check and test services (8.0)

Avoid multiple blank lines

// Act
var results = sut.CreateProviderCompanyDetail(_validCompanyId, new ProviderDetailsCreationData(url, authUrl, clientId, secret, encryptionMode), entity =>
Expand Down Expand Up @@ -163,7 +164,7 @@ public async Task GetServiceProviderCompanyDetailAsync_WithExistingUser_ReturnsE
var (sut, _) = await CreateSut();

// Act
var result = await sut.GetProviderCompanyDetailAsync(A<IEnumerable<CompanyRoleId>>._, new Guid("3390c2d7-75c1-4169-aa27-6ce00e1f3cdd"));
var result = await sut.GetProviderCompanyDetailAsync([CompanyRoleId.SERVICE_PROVIDER, CompanyRoleId.APP_PROVIDER], new Guid("3390c2d7-75c1-4169-aa27-6ce00e1f3cdd"));

// Assert
result.Should().NotBe(default);
Expand All @@ -179,7 +180,7 @@ public async Task GetServiceProviderCompanyDetailAsync_WithNotExistingDetails_Re
var (sut, _) = await CreateSut();

// Act
var result = await sut.GetProviderCompanyDetailAsync(A<IEnumerable<CompanyRoleId>>._, Guid.NewGuid());
var result = await sut.GetProviderCompanyDetailAsync([CompanyRoleId.SERVICE_PROVIDER, CompanyRoleId.APP_PROVIDER], Guid.NewGuid());

// Assert
result.Should().Be(default);
Expand All @@ -192,7 +193,7 @@ public async Task GetServiceProviderCompanyDetailAsync_WithExistingUserAndNotPro
var (sut, _) = await CreateSut();

// Act
var result = await sut.GetProviderCompanyDetailAsync(A<IEnumerable<CompanyRoleId>>._, new("ac861325-bc54-4583-bcdc-9e9f2a38ff84"));
var result = await sut.GetProviderCompanyDetailAsync([CompanyRoleId.SERVICE_PROVIDER, CompanyRoleId.APP_PROVIDER], new("41fd2ab8-71cd-4546-9bef-a388d91b2542"));

// Assert
result.Should().NotBe(default);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -428,6 +428,23 @@ public async Task GetTriggerProviderInformation_WithValidData_ReturnsExpectedRes
result.IsSingleInstance.Should().BeTrue();
}

[Fact]
public async Task GetTriggerProviderInformation_WithValidData_And_WithProviderDetails_ReturnsExpectedResult()
{
// Arrange
var (sut, _) = await CreateSut();

// Act
var result = await sut.GetTriggerProviderInformation(new Guid("81a8211d-6261-4969-8123-a420364ae997"));

// Assert
result.Should().NotBeNull();
result!.OfferName.Should().Be("Test App 1");
result!.AuthDetails.Should().NotBeNull();
result!.AuthDetails!.AuthUrl.Should().Be("https://auth-url.com");
result.IsSingleInstance.Should().BeFalse();
}

[Fact]
public async Task GetTriggerProviderInformation_WithNotExistingId_ReturnsNull()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
"id": "3c0a31d2-7743-402c-af02-f0cc3cc3ca6d",
"date_created": "2022-10-10 11:50:54.709881 +00:00",
"auto_setup_url": "https://orchestrator.cx.dih-cloud.com",
"auth_url": "https://auth-url.com",
"client_id": "test",
"client_secret": "/UJ0wr5w1HiXaLo25QfxqXWhyq6Pa9w+CvBFNs1782s=",
"encryption_mode": 1,
"company_id": "3390c2d7-75c1-4169-aa27-6ce00e1f3cdd"
}
]

0 comments on commit 3a51e9a

Please sign in to comment.