Skip to content
This repository has been archived by the owner on Apr 12, 2023. It is now read-only.

Fix/sonarcloud issues #1009

Merged
merged 6 commits into from
May 25, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Covid19Radar.Api.Common/Common/ErrorStrings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace Covid19Radar.Api.Common
{
public class ErrorStrings
public static class ErrorStrings
{

//1000: User error strings
Expand Down
2 changes: 1 addition & 1 deletion src/Covid19Radar.Api.Common/Common/PartitionKeyRotation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public class PartitionKeyRotation
{
private readonly KeyInformation[] Keys;
private readonly int Max;
private int Current = -1;
private int Current;
public PartitionKeyRotation(string[] keys)
{
Keys = keys.Select((_, i) => new KeyInformation(_, i + 1)).ToArray();
Expand Down
2 changes: 1 addition & 1 deletion src/Covid19Radar.Api.Common/Common/QueryCache.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ namespace Covid19Radar.Api.Common
/// <typeparam name="T">Return type</typeparam>
public class QueryCache<T>
{
private readonly int CacheTimeout = Constants.CacheTimeout;
private readonly int CacheTimeout;
private readonly EventWaitHandle Event = new EventWaitHandle(true, EventResetMode.AutoReset);
private T Cache;
private long Timestamp = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,10 @@ public async Task<ulong> GetNextAsync(string key, ulong startNo, int increment =
int ms = (int)(ex.RetryAfter.HasValue ? ex.RetryAfter.Value.TotalMilliseconds : 5);
_logger.LogInformation(ex, $"GetNextAsync Retry {i} RequestCharge:{ex.RequestCharge} RetryAfter:{ms}");
await Task.Delay(ms);
continue;
}
}
_logger.LogWarning("GetNextAsync is over retry count.");
throw new ApplicationException("GetNextAsync is over retry count.");
throw new Exception("GetNextAsync is over retry count.");
}

public async Task<ulong> GetNextAsync(PartitionKeyRotation.KeyInformation key, ulong startNo, int increment = 1)
Expand All @@ -67,11 +66,10 @@ public async Task<ulong> GetNextAsync(PartitionKeyRotation.KeyInformation key, u
int ms = (int)(ex.RetryAfter.HasValue ? ex.RetryAfter.Value.TotalMilliseconds : 5);
_logger.LogInformation(ex, $"GetNextAsync Retry {i} RequestCharge:{ex.RequestCharge} RetryAfter:{ms}");
await Task.Delay(ms);
continue;
}
}
}
_logger.LogWarning("GetNextAsync is over retry count.");
throw new ApplicationException("GetNextAsync is over retry count.");
throw new Exception("GetNextAsync is over retry count.");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public async Task<TemporaryExposureKeyModel[]> GetNextAsync()
var oldest = (int)new DateTimeOffset(DateTime.UtcNow.AddDays(Constants.OutOfDateDays).Date.Ticks, TimeSpan.Zero).ToUnixTimeSeconds() / 600;
var query = _db.TemporaryExposureKey.GetItemLinqQueryable<TemporaryExposureKeyModel>(true)
.Where(tek => tek.RollingStartIntervalNumber > oldest)
.Where(tek => tek.Exported == false)
.Where(tek => !tek.Exported)
.ToFeedIterator();
var e = Enumerable.Empty<TemporaryExposureKeyModel>();
while (query.HasMoreResults)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ public interface IDiagnosisRepository
{

Task<DiagnosisModel[]> GetNotApprovedAsync();
Task<DiagnosisModel> GetAsync(string SubmissionNumber, string UserUuid);
Task<DiagnosisModel> GetAsync(string submissionNumber, string userUuid);

Task<DiagnosisModel> SubmitDiagnosisAsync(string SubmissionNumber, DateTimeOffset timestamp, string UserUuid, TemporaryExposureKeyModel[] Keys);
Task<DiagnosisModel> SubmitDiagnosisAsync(string submissionNumber, DateTimeOffset timestamp, string userUuid, TemporaryExposureKeyModel[] Keys);

Task DeleteAsync(IUser user);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Covid19Radar.Api.Common/DataStore/Cosmos.cs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ private async Task GenerateAsync()
&& dbResult.StatusCode != System.Net.HttpStatusCode.Created)
{
Logger.LogError(dbResult.ToString());
throw new ApplicationException(dbResult.ToString());
throw new Exception(dbResult.ToString());
}

// Container User
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ public class ValidateResult
IsValid = false,
ErrorActionResult = new BadRequestResult()
};
public bool IsValid;
public IActionResult ErrorActionResult;
public bool IsValid { get; set; }
public IActionResult ErrorActionResult { get; set; }
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ public class ValidateResult
IsValid = false,
ErrorActionResult = new BadRequestResult()
};
public bool IsValid;
public IActionResult ErrorActionResult;
public bool IsValid { get; set; }
public IActionResult ErrorActionResult { get; set; }
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ public ValidationInquiryLogService(ILogger<ValidationInquiryLogService> logger,
public IValidationInquiryLogService.ValidateResult Validate(HttpRequest req)
{
Logger.LogInformation($"{nameof(ValidationInquiryLogService)} {nameof(Validate)}");
var test = Config.InquiryLogApiKey();
var test2 = req.Headers["x-api-key"].ToString();
var test3 = req.Headers.ContainsKey("x-api-key");
Config.InquiryLogApiKey();
req.Headers["x-api-key"].ToString();
req.Headers.ContainsKey("x-api-key");
if (!req.Headers.ContainsKey("x-api-key") || Config.InquiryLogApiKey() != req.Headers["x-api-key"].ToString())
{
return IValidationInquiryLogService.ValidateResult.Error;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,20 @@ namespace Covid19Radar.Api.Services
public class ValidationServerService : IValidationServerService
{
private readonly ILogger<ValidationServerService> Logger;
private readonly IConfiguration Config;
private readonly bool AzureFrontDoorRestrictionEnabled;
private readonly string AzureFrontDoorId;


public ValidationServerService(IConfiguration config, ILogger<ValidationServerService> logger)
{
Logger = logger;
Config = config;
AzureFrontDoorRestrictionEnabled = Config.AzureFrontDoorRestrictionEnabled();
AzureFrontDoorId = Config.AzureFrontDoorId();
AzureFrontDoorRestrictionEnabled = config.AzureFrontDoorRestrictionEnabled();
AzureFrontDoorId = config.AzureFrontDoorId();
}

public IValidationServerService.ValidateResult Validate(HttpRequest req)
{
Logger.LogInformation($"{nameof(ValidationServerService)}#{nameof(Validate)}");
if (AzureFrontDoorRestrictionEnabled)
{
if (!req.Headers.ContainsKey("X-Azure-FDID"))
Expand Down
49 changes: 0 additions & 49 deletions src/Covid19Radar.Api.Tests/Background/BackgroundStartupTest.cs

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,6 @@
using Microsoft.Extensions.Configuration;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Moq;
using System;
using System.Collections.Generic;
using System.IO;
using System.Security.Cryptography;
using System.Text;
using System.Threading.Tasks;

namespace Covid19Radar.Api.Tests.Background.Services
{
Expand All @@ -31,6 +25,9 @@ public void CreateMethod()
var logger = new Mock.LoggerMock<TemporaryExposureKeyBlobService>();
// action
var service = new TemporaryExposureKeyBlobService(config.Object, logger);

// assert
Assert.IsNotNull(service);
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,7 @@
using Microsoft.Extensions.Configuration;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Moq;
using System;
using System.Collections.Generic;
using System.IO;
using System.Security.Cryptography;
using System.Text;
using System.Threading.Tasks;

namespace Covid19Radar.Api.Tests.Background.Services
Expand All @@ -35,6 +31,8 @@ public void CreateMethod()
var logger = new Mock.LoggerMock<TemporaryExposureKeySignService>();
// action
var service = new TemporaryExposureKeySignService(config.Object, logger);
// assert
Assert.IsNotNull(service);
}

[TestMethod]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,15 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */

using Covid19Radar.Api;
using Covid19Radar.Api.Common;
using Covid19Radar.Api.DataAccess;
using Covid19Radar.Api.DataStore;
using Covid19Radar.Api.Models;
using Microsoft.AspNetCore.Http;
using Microsoft.Azure.Cosmos;
using Microsoft.Azure.Cosmos.Linq;
using Microsoft.Azure.Documents.SystemFunctions;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Moq;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Reflection;
using System.Reflection.Emit;
using System.Threading;
using System.Threading.Tasks;

Expand All @@ -36,6 +28,9 @@ public void CreateMethod()
var logger = new Mock.LoggerMock<CosmosDiagnosisRepository>();
// action
var instance = new CosmosDiagnosisRepository(cosmos.Object, logger);
// assert
Assert.IsNotNull(instance);

}

[DataTestMethod]
Expand Down
15 changes: 5 additions & 10 deletions src/Covid19Radar.Api.Tests/Common/DataStore/CosmosTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,14 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */

using Castle.Core.Logging;
using Covid19Radar.Api;
using Covid19Radar.Api.Common;
using Covid19Radar.Api.DataStore;
using Covid19Radar.Api.Tests.Mock;
using Microsoft.AspNetCore.Http;
using Microsoft.Azure.Cosmos;
using Microsoft.Azure.Cosmos.Scripts;
using Microsoft.Azure.Documents.Client;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Logging;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Moq;
using System;
using System.Collections.Generic;
using System.Reflection;
using System.Threading;

namespace Covid19Radar.Api.Tests.Common.DataStore
Expand Down Expand Up @@ -50,10 +42,12 @@ public void CreateMethod()
client.Setup(_ => _.CreateDatabaseIfNotExistsAsync
(It.IsAny<string>(), It.IsAny<int?>(), It.IsAny<Microsoft.Azure.Cosmos.RequestOptions>(), It.IsAny<CancellationToken>()))
.ReturnsAsync(databaseResponse.Object);

var logger = new LoggerMock<ICosmos>();
// action
var instance = new Cosmos(config.Object, client.Object, logger);
// assert
Assert.IsNotNull(instance);
}

[TestMethod]
Expand Down Expand Up @@ -84,7 +78,8 @@ public void CreateMethodThrowException()
var logger = new LoggerMock<ICosmos>();
// action
#if DEBUG
Assert.ThrowsException<AggregateException>(() => {
Assert.ThrowsException<AggregateException>(() =>
{
var instance = new Cosmos(config.Object, client.Object, logger);
});
#else
Expand Down
9 changes: 5 additions & 4 deletions src/Covid19Radar.Api.Tests/Common/KeyLockTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */

using Covid19Radar.Api;
using Covid19Radar.Api.Common;
using Microsoft.AspNetCore.Http;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using System.Collections.Generic;
Expand Down Expand Up @@ -36,7 +34,10 @@ public void CreateMethod(string uuid)
var dic = Dictionary;
dic.Clear();
// action
using (var l = new KeyLock(uuid)) { }
using (var l = new KeyLock(uuid))
{
Assert.IsNotNull(l);
}
}

[TestMethod]
Expand Down Expand Up @@ -121,7 +122,7 @@ public void CreateMultipleSame()
// Assert
Assert.AreEqual(255, dic.Count);

foreach(var lockItem in lockItems.ToArray())
foreach (var lockItem in lockItems.ToArray())
{
// dispose
lockItem.Dispose();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */

using System;
using Covid19Radar.Api.Common;
using Covid19Radar.Api.Models;
using Microsoft.VisualStudio.TestTools.UnitTesting;

Expand All @@ -18,6 +16,8 @@ public void CreateMethod()
{
// action
var model = new DiagnosisModel();
// assert
Assert.IsNotNull(model);
}

[TestMethod]
Expand Down
4 changes: 2 additions & 2 deletions src/Covid19Radar.Api.Tests/Common/Models/SequenceModelTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */


using System;
using Covid19Radar.Api.Common;
using Covid19Radar.Api.Models;
using Microsoft.VisualStudio.TestTools.UnitTesting;

Expand All @@ -19,6 +17,8 @@ public void CreateMethod()
{
// action
var model = new SequenceModel();
// assert
Assert.IsNotNull(model);
}

[TestMethod]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ public void CreateMethod()
{
// action
var model = new TemporaryExposureKeyExportModel();
// assert
Assert.IsNotNull(model);
}

[TestMethod]
Expand Down
Loading