Skip to content

Commit

Permalink
Renamed gateway settings file #GCPActive (#12)
Browse files Browse the repository at this point in the history
* Added logging on failure for sms client #GCPActive

* renamed gateway config file

* fixed test
  • Loading branch information
acn-sbuad authored Feb 2, 2024
1 parent e993600 commit 4a7f585
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ public static IServiceCollection AddIntegrationServices(this IServiceCollection
{
throw new ArgumentNullException(nameof(config), "Required Kafka settings is missing from application configuration");
}
SmsGatewayConfiguration smsGatewaySettings = config!.GetSection(nameof(SmsGatewayConfiguration)).Get<SmsGatewayConfiguration>()!;

SmsGatewaySettings smsGatewaySettings = config!.GetSection(nameof(SmsGatewaySettings)).Get<SmsGatewaySettings>()!;

if (smsGatewaySettings == null)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public class AltinnGatewayClient : IAltinnGatewayClient
/// <summary>
/// Initializes a new instance of the <see cref="AltinnGatewayClient"/> class.
/// </summary>
public AltinnGatewayClient(SmsGatewayConfiguration gatewayConfig)
public AltinnGatewayClient(SmsGatewaySettings gatewayConfig)
{
_client = new(new XmlTransport(gatewayConfig.Username, gatewayConfig.Password, new Uri(gatewayConfig.Endpoint)));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@
using Altinn.Notifications.Sms.Core.Sending;
using Altinn.Notifications.Sms.Core.Shared;
using Altinn.Notifications.Sms.Core.Status;

using LinkMobility.PSWin.Client.Model;

using Microsoft.Extensions.Logging;

using LinkMobilityModel = global::LinkMobility.PSWin.Client.Model;

namespace Altinn.Notifications.Sms.Integrations.LinkMobility
Expand All @@ -15,14 +18,17 @@ namespace Altinn.Notifications.Sms.Integrations.LinkMobility
public class SmsClient : ISmsClient
{
private readonly IAltinnGatewayClient _client;
private readonly ILogger<ISmsClient> _logger;

/// <summary>
/// Initializes a new instance of the <see cref="SmsClient"/> class.
/// </summary>
/// <param name="client">Gateway Client</param>
public SmsClient(IAltinnGatewayClient client)
/// <param name="logger">Logger</param>
public SmsClient(IAltinnGatewayClient client, ILogger<ISmsClient> logger)
{
_client = client;
_logger = logger;
}

/// <inheritdoc />
Expand All @@ -40,6 +46,7 @@ public async Task<Result<string, SmsClientErrorResponse>> SendAsync(Core.Sending
return new SmsClientErrorResponse { SendResult = SmsSendResult.Failed_InvalidReceiver, ErrorMessage = result.StatusText };
}

_logger.LogInformation("// SmsClient // SendAsync // Failed to send SMS. Status: {StatusText}", result.StatusText);
return new SmsClientErrorResponse { SendResult = SmsSendResult.Failed };
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
/// <summary>
/// Configuration for the LinkMobility SMS gateway
/// </summary>
public class SmsGatewayConfiguration
public class SmsGatewaySettings
{
/// <summary>
/// Username to use for authentication towards the SMS gateway
Expand Down
2 changes: 1 addition & 1 deletion src/Altinn.Notifications.Sms/appsettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
"SendSmsQueueRetryTopicName": "altinn.notifications.sms.queue.retry",
"AltinnServiceUpdateTopicName ": "altinn.platform.service.updated"
},
"SmsGatewayConfiguration": {
"SmsGatewaySettings": {
"Username": "<populated-during-deploy>",
"Password": "<populated-during-deploy>",

Check warning on line 31 in src/Altinn.Notifications.Sms/appsettings.json

View workflow job for this annotation

GitHub Actions / Build, test & analyze

"password" detected here, make sure this is not a hard-coded credential. (https://rules.sonarsource.com/csharp/RSPEC-2068)

Check warning on line 31 in src/Altinn.Notifications.Sms/appsettings.json

View workflow job for this annotation

GitHub Actions / Build, test & analyze

"password" detected here, make sure this is not a hard-coded credential. (https://rules.sonarsource.com/csharp/RSPEC-2068)

Check warning on line 31 in src/Altinn.Notifications.Sms/appsettings.json

View workflow job for this annotation

GitHub Actions / Build, test & analyze

"password" detected here, make sure this is not a hard-coded credential. (https://rules.sonarsource.com/csharp/RSPEC-2068)
"Endpoint": "https://xml-test.pswin.com"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public void AddIntegrationServices_MissingKafkaConfig_ThrowsException()
{
// Arrange
Environment.SetEnvironmentVariable("KafkaSettings__BrokerAddress", null, EnvironmentVariableTarget.Process);
Environment.SetEnvironmentVariable("SmsGatewayConfiguration__Endpoint", "https://vg.no", EnvironmentVariableTarget.Process);
Environment.SetEnvironmentVariable("SmsGatewaySettings__Endpoint", "https://vg.no", EnvironmentVariableTarget.Process);
string expectedExceptionMessage = "Required Kafka settings is missing from application configuration (Parameter 'config')";

var config = new ConfigurationBuilder().AddEnvironmentVariables().Build();
Expand All @@ -48,7 +48,7 @@ public void AddIntegrationServices_MissingKafkaConfig_ThrowsException()
public void AddIntegrationServices_SmsGatewayConfigIncluded_NoException()
{
// Arrange
Environment.SetEnvironmentVariable("SmsGatewayConfiguration__Endpoint", "https://vg.no", EnvironmentVariableTarget.Process);
Environment.SetEnvironmentVariable("SmsGatewaySettings__Endpoint", "https://vg.no", EnvironmentVariableTarget.Process);
Environment.SetEnvironmentVariable("KafkaSettings__BrokerAddress", "localhost:9092", EnvironmentVariableTarget.Process);
var config = new ConfigurationBuilder().AddEnvironmentVariables().Build();

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
using Altinn.Notifications.Sms.Core.Status;
using Altinn.Notifications.Sms.Core.Dependencies;
using Altinn.Notifications.Sms.Core.Status;

using Altinn.Notifications.Sms.Integrations.LinkMobility;

using LinkMobility.PSWin.Client.Model;

using Microsoft.Extensions.Logging;

using Moq;

using LinkMobilityModel = global::LinkMobility.PSWin.Client.Model;
Expand All @@ -13,6 +16,7 @@ namespace Altinn.Notifications.Sms.Tests.Sms.Integrations
public class SmsClientTests
{
private readonly Mock<IAltinnGatewayClient> _clientMock = new();
private readonly Mock<ILogger<ISmsClient>> _loggerMock = new();

[Fact]
public async Task SendAsync_GatewayReturnsNonSuccess_UnknownError()
Expand All @@ -23,7 +27,7 @@ public async Task SendAsync_GatewayReturnsNonSuccess_UnknownError()
_clientMock.Setup(cm => cm.SendAsync(It.IsAny<LinkMobilityModel.Sms>()))
.ReturnsAsync(gatewayResult);

SmsClient smsClient = new(_clientMock.Object);
SmsClient smsClient = new(_clientMock.Object, _loggerMock.Object);

// Act
var result = await smsClient.SendAsync(new Notifications.Sms.Core.Sending.Sms());
Expand Down Expand Up @@ -52,7 +56,7 @@ public async Task SendAsync_GatewayReturnsNonSuccess_InvalidReceiver()
_clientMock.Setup(cm => cm.SendAsync(It.IsAny<LinkMobilityModel.Sms>()))
.ReturnsAsync(gatewayResult);

SmsClient smsClient = new(_clientMock.Object);
SmsClient smsClient = new(_clientMock.Object, _loggerMock.Object);

// Act
var result = await smsClient.SendAsync(new Notifications.Sms.Core.Sending.Sms());
Expand Down Expand Up @@ -84,7 +88,7 @@ public async Task SendAsync_GatewayReturnsSuccess_GatewayRefReturned()
_clientMock.Setup(cm => cm.SendAsync(It.IsAny<LinkMobilityModel.Sms>()))
.ReturnsAsync(gatewayResult);

SmsClient smsClient = new(_clientMock.Object);
SmsClient smsClient = new(_clientMock.Object, _loggerMock.Object);

// Act
var result = await smsClient.SendAsync(new Notifications.Sms.Core.Sending.Sms());
Expand Down

0 comments on commit 4a7f585

Please sign in to comment.