diff --git a/.github/workflows/ecotag-ci.yml b/.github/workflows/ecotag-ci.yml index f2868b49..a81ad781 100644 --- a/.github/workflows/ecotag-ci.yml +++ b/.github/workflows/ecotag-ci.yml @@ -5,28 +5,70 @@ on: branches: [ master ] pull_request: branches: [ master ] - - # Allows you to run this workflow manually from the Actions tab - workflow_dispatch: + types: [opened, synchronize, reopened] jobs: - - build-windows: + + sonarcloud: + name: SonarCloud environment: ml-cli runs-on: windows-latest steps: - - uses: actions/checkout@v2 + - name: Set up JDK 17 + uses: actions/setup-java@v3 + with: + java-version: 17 + distribution: 'zulu' # Alternative distribution options are available. + - uses: actions/checkout@v3 + with: + fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis + - name: Cache SonarCloud packages + uses: actions/cache@v3 + with: + path: ~\sonar\cache + key: ${{ runner.os }}-sonar + restore-keys: ${{ runner.os }}-sonar + - name: Cache SonarCloud scanner + id: cache-sonar-scanner + uses: actions/cache@v3 + with: + path: .\.sonar\scanner + key: ${{ runner.os }}-sonar-scanner + restore-keys: ${{ runner.os }}-sonar-scanner + - uses: actions/setup-dotnet@v3 with: - fetch-depth: 0 + global-json-file: global.json + - name: Install SonarCloud scanner + if: steps.cache-sonar-scanner.outputs.cache-hit != 'true' + shell: powershell + run: | + New-Item -Path .\.sonar\scanner -ItemType Directory + dotnet tool update dotnet-sonarscanner --tool-path .\.sonar\scanner + - uses: actions/setup-node@v2 + with: + node-version: '18' + - name: npm install + run: npm install + working-directory: src/Ecotag/ClientApp + - name: npm test + run: npm test -- --runInBand --coverage --watchAll=false + working-directory: src/Ecotag/ClientApp + - name: Build and analyze + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Needed to get PR information, if any + SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} + shell: powershell + run: | + .\.sonar\scanner\dotnet-sonarscanner begin /k:"AxaGuilDEv_ml-cli" /o:"axaguildev" /d:sonar.token="${{ secrets.SONAR_TOKEN }}" /d:sonar.host.url="https://sonarcloud.io" /d:sonar.cs.vscoveragexml.reportsPaths=coverage.xml /d:sonar.exclusions="**/*.spec.js,**/*.stories.js,**/ClientApp/src/Toolkit/**,**/ClientApp/coverage/**,Scripts/**,**/*.scss,**/__snapshots__/**,**/*Sould.cs,**/*[Tt]ests.cs,**/node_modules/**,**/ClientApp/build-local/**,**/ClientApp/build-server/**,**/ClientApp/.storybook/**,**/ClientApp/storybook-static/**,**/obj/**,**/__mocks__/**,**/ClientApp/src/serviceWorker.ts,**/ClientApp/public/**" /d:sonar.javascript.lcov.reportPaths="**/ClientApp/coverage/lcov.info" + dotnet tool install --global dotnet-coverage + dotnet-coverage collect "dotnet test" -f xml -o "coverage.xml" + .\.sonar\scanner\dotnet-sonarscanner end /d:sonar.token="${{ secrets.SONAR_TOKEN }}" - - uses: actions/setup-dotnet@v3 - - run: dotnet test - build-linux: environment: ml-cli runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 with: fetch-depth: 0 - uses: actions/setup-node@v2 diff --git a/Dockerfile b/Dockerfile index 2b2a736a..aa87727d 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -FROM mcr.microsoft.com/dotnet/sdk:7.0 AS build +FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build ENV NODE_VERSION 18.2.0 ENV NODE_DOWNLOAD_SHA 73d3f98e96e098587c2154dcaa82a6469a510e89a4881663dc4c86985acf245e @@ -21,11 +21,9 @@ COPY ./src/Ecotag/ClientApp/public/environment.docker.json ./src/Ecotag/ClientAp COPY ./src/Ecotag/ClientApp/public/OidcTrustedDomains.docker.js ./src/Ecotag/ClientApp/public/OidcTrustedDomains.js RUN dotnet publish "./src/Ecotag/Ecotag.csproj" -c Release -r linux-x64 --self-contained=true /p:PublishSingleFile=true /p:PublishTrimmed=true /p:PublishReadyToRun=true -o /publish -FROM mcr.microsoft.com/dotnet/runtime-deps:7.0 AS final - -RUN apt update \ - && apt-get install -y libreoffice +FROM mcr.microsoft.com/dotnet/runtime-deps:8.0 AS final +RUN apt update && apt-get install -y libreoffice RUN libreoffice --version RUN sed -i 's/UserInstallation/#UserInstallation/' /usr/lib/libreoffice/program/bootstraprc diff --git a/docker-compose.yml b/docker-compose.yml index 19690803..0eb139fb 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -18,7 +18,7 @@ services: image: "axaguildev/ecotag:latest" #build: # context: . - # dockerfile: ./Dockerfile + # dockerfile: ./Dockerfile environment: ASPNETCORE_ENVIRONMENT: Docker ports: diff --git a/global.json b/global.json index 30e2afca..67723072 100644 --- a/global.json +++ b/global.json @@ -1,6 +1,6 @@ { "sdk": { - "version": "7.0.100", + "version": "8.0.101", "rollForward": "latestMajor", "allowPrerelease": false } diff --git a/src/Ecotag/ClientApp/package-lock.json b/src/Ecotag/ClientApp/package-lock.json index 2acc59c1..0c3ffeb9 100644 --- a/src/Ecotag/ClientApp/package-lock.json +++ b/src/Ecotag/ClientApp/package-lock.json @@ -9,7 +9,7 @@ "version": "1.0.0", "hasInstallScript": true, "dependencies": { - "@axa-fr/react-oidc": "7.3.4", + "@axa-fr/react-oidc": "7.9.3", "@axa-fr/react-toolkit-all": "1.4.1", "@microsoft/applicationinsights-web": "2.8.6", "@monaco-editor/react": "4.2.1", @@ -101,27 +101,27 @@ } }, "node_modules/@axa-fr/oidc-client": { - "version": "7.3.4", - "resolved": "https://registry.npmjs.org/@axa-fr/oidc-client/-/oidc-client-7.3.4.tgz", - "integrity": "sha512-U04IqMtDhmD/1E4RlCPh3r6HdQRmIMSbr1RmOuW7Ol0sJMaS+Ta2+wgr7QeosdZMB/72pk9CwOfbgBkm9oAaBw==", + "version": "7.9.3", + "resolved": "https://registry.npmjs.org/@axa-fr/oidc-client/-/oidc-client-7.9.3.tgz", + "integrity": "sha512-9H86/di81xPhApTUWn8wlryW5nVvAAqs+U7BpcA1ktQrfztCUpXSNhdcm3x7FaKtqqwG+nb61rrVf531zzsxrg==", "hasInstallScript": true, "dependencies": { - "@axa-fr/oidc-client-service-worker": "7.3.4" + "@axa-fr/oidc-client-service-worker": "7.9.3" } }, "node_modules/@axa-fr/oidc-client-service-worker": { - "version": "7.3.4", - "resolved": "https://registry.npmjs.org/@axa-fr/oidc-client-service-worker/-/oidc-client-service-worker-7.3.4.tgz", - "integrity": "sha512-t0FjYEl4LFj40KDhtchz/O2jYXw1nhdP8WZHPfjy+iS/O1bGzZ0AgMY3vUs1yCgOpzi1gdqwIGl9zJ0AyMw6MA==" + "version": "7.9.3", + "resolved": "https://registry.npmjs.org/@axa-fr/oidc-client-service-worker/-/oidc-client-service-worker-7.9.3.tgz", + "integrity": "sha512-6GMkkrDX+hCPjffSC2Ytp0RbkD0UFRZMqrcXKxQ+A6ad+qzcAmfV4Npl71iXAO4lsSqXPrRw0AMpWM5NWcI9hg==" }, "node_modules/@axa-fr/react-oidc": { - "version": "7.3.4", - "resolved": "https://registry.npmjs.org/@axa-fr/react-oidc/-/react-oidc-7.3.4.tgz", - "integrity": "sha512-HXfgTf4IaDqX/+czQTK77Ky0vw8xcZun4Y25k+uRpnTr0E+o7z05owm1JflLc2hLNQtDywp2LW920VNFf1g1zA==", + "version": "7.9.3", + "resolved": "https://registry.npmjs.org/@axa-fr/react-oidc/-/react-oidc-7.9.3.tgz", + "integrity": "sha512-SXvMZ13j8Ey74IR252ZuyCE78TR4mTOXIejgV6ImJdgrISmZEcBbDorXMNaTeUWyJ/Xsrssw5XF170I52b8ZPw==", "hasInstallScript": true, "dependencies": { - "@axa-fr/oidc-client": "7.3.4", - "@axa-fr/oidc-client-service-worker": "7.3.4", + "@axa-fr/oidc-client": "7.9.3", + "@axa-fr/oidc-client-service-worker": "7.9.3", "base64-js": "1.5.1" }, "peerDependencies": { diff --git a/src/Ecotag/ClientApp/package.json b/src/Ecotag/ClientApp/package.json index 113cc01b..1973b51a 100644 --- a/src/Ecotag/ClientApp/package.json +++ b/src/Ecotag/ClientApp/package.json @@ -3,7 +3,7 @@ "version": "1.0.0", "private": true, "dependencies": { - "@axa-fr/react-oidc": "7.3.4", + "@axa-fr/react-oidc": "7.9.3", "@axa-fr/react-toolkit-all": "1.4.1", "@microsoft/applicationinsights-web": "2.8.6", "@monaco-editor/react": "4.2.1", diff --git a/src/Ecotag/Ecotag.csproj b/src/Ecotag/Ecotag.csproj index dbeb43d8..03aaa2e6 100644 --- a/src/Ecotag/Ecotag.csproj +++ b/src/Ecotag/Ecotag.csproj @@ -1,33 +1,29 @@ - net7.0 + net8.0 1.0.0 - linux-x64;rhel-x64;osx-x64;win10-x64 true Latest false ClientApp\ $(DefaultItemExcludes);$(SpaRoot)node_modules\** AxaGuilDEv.Ecotag + true - - - - - - + + + + + + - - - - - - - - + + + + diff --git a/src/Ecotag/Program.cs b/src/Ecotag/Program.cs index 7dd6c0a9..67e1c56a 100644 --- a/src/Ecotag/Program.cs +++ b/src/Ecotag/Program.cs @@ -13,7 +13,6 @@ using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting; -using Serilog; namespace AxaGuilDEv.Ecotag; @@ -121,7 +120,6 @@ private static IHostBuilder CreateHostBuilderServer(string[] args) var keyVaultConfig = keyVaultConfigBuilder.Build(); config.AddConfiguration(keyVaultConfig); }) - .UseSerilog((context, logger) => { logger.ReadFrom.Configuration(context.Configuration); }) .ConfigureWebHostDefaults(webBuilder => { webBuilder.UseContentRoot(Directory.GetCurrentDirectory()); diff --git a/src/Ecotag/Server/Audits/Queue.cs b/src/Ecotag/Server/Audits/Queue.cs index c71d2422..de510033 100644 --- a/src/Ecotag/Server/Audits/Queue.cs +++ b/src/Ecotag/Server/Audits/Queue.cs @@ -13,12 +13,12 @@ public class Subscriber public class Queue : IQueue { - private readonly IList subscribers = new List(); + private readonly IList _subscribers = new List(); public async Task PublishAsync(string type, object message) { var messageJson = JsonSerializer.Serialize(message); - foreach (var subscriber in subscribers) + foreach (var subscriber in _subscribers) if (subscriber.Type == type) await subscriber.CallbackAsync(type, messageJson); } @@ -30,6 +30,6 @@ public void Subscribe(string type, Func> func) Type = type, CallbackAsync = func }; - subscribers.Add(subscriber); + _subscribers.Add(subscriber); } } \ No newline at end of file diff --git a/src/Ecotag/Server/Datasets/Database/Annotations/AnnotationsRepository.cs b/src/Ecotag/Server/Datasets/Database/Annotations/AnnotationsRepository.cs index a926a3e7..cb1029c6 100644 --- a/src/Ecotag/Server/Datasets/Database/Annotations/AnnotationsRepository.cs +++ b/src/Ecotag/Server/Datasets/Database/Annotations/AnnotationsRepository.cs @@ -227,7 +227,7 @@ await _datasetsContext.Annotations.FirstOrDefaultAsync(a => } public async Task> GetAnnotationsByProjectIdAndDatasetIdAsync(string projectId, - string datasetId) + string datasetId, JsonSerializerOptions? options = null) { var result = new List(); var fileDataModels = await _datasetsContext.Files.AsNoTracking() @@ -242,7 +242,7 @@ public async Task> GetAnnotationsByProjectIdAndDatasetIdA FileName = fileDataModel.Name, NameIdentifier = annotation.CreatorNameIdentifier, CreateDate = annotation.TimeStamp, - Annotation = JsonSerializer.Deserialize(annotation.ExpectedOutput) + Annotation = JsonSerializer.Deserialize(annotation.ExpectedOutput, options) }); result.AddRange(fileAnnotations); } diff --git a/src/Ecotag/Server/ErrorLoggingMiddleware.cs b/src/Ecotag/Server/ErrorLoggingMiddleware.cs index 4de43bfb..70f802e8 100644 --- a/src/Ecotag/Server/ErrorLoggingMiddleware.cs +++ b/src/Ecotag/Server/ErrorLoggingMiddleware.cs @@ -28,7 +28,7 @@ public async Task Invoke(HttpContext context, ILogger lo } catch (Exception e) { - logger.LogError(e, $"The following error happened: {e.Message}"); + logger.LogError(e, "The following error happened: {EMessage}", e.Message); if (!context.Response.HasStarted) { context.Response.StatusCode = 500; diff --git a/src/Ecotag/Server/Groups/Cmd/UpdateGroupCmd.cs b/src/Ecotag/Server/Groups/Cmd/UpdateGroupCmd.cs index c1b22a00..20c255ba 100644 --- a/src/Ecotag/Server/Groups/Cmd/UpdateGroupCmd.cs +++ b/src/Ecotag/Server/Groups/Cmd/UpdateGroupCmd.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using System.ComponentModel.DataAnnotations; using System.Text.Json; +using System.Text.Json.Serialization; using System.Threading.Tasks; using AxaGuilDEv.Ecotag.Server.Audits; using AxaGuilDEv.Ecotag.Server.Groups.Database.Group; @@ -72,7 +73,7 @@ public async Task> ExecuteAsync(UpdateGroup Id = updateGroupInput.Id, UpdateDate = updateDate, UserIds = updateGroupInput.UserIds - }) + }, GroupUpdateAuditSerializerContext.Default.GroupUpdateAudit) }); return commandResult; @@ -84,4 +85,8 @@ public record GroupUpdateAudit public string Id { get; set; } public List UserIds { get; set; } public long UpdateDate { get; set; } -} \ No newline at end of file +} + +[JsonSerializable(typeof(GroupUpdateAudit))] +[JsonSourceGenerationOptions(WriteIndented = false, DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull)] +public partial class GroupUpdateAuditSerializerContext : JsonSerializerContext; \ No newline at end of file diff --git a/src/Ecotag/Server/Groups/Oidc/OidcConfiguration.cs b/src/Ecotag/Server/Groups/Oidc/OidcConfiguration.cs index cf562980..ed3596a8 100644 --- a/src/Ecotag/Server/Groups/Oidc/OidcConfiguration.cs +++ b/src/Ecotag/Server/Groups/Oidc/OidcConfiguration.cs @@ -3,9 +3,9 @@ namespace AxaGuilDEv.Ecotag.Server.Groups.Oidc; -[ExcludeFromCodeCoverage] -public class OidcConfiguration -{ - [JsonPropertyName("userinfo_endpoint")] - public string UserinfoEndpoint { get; set; } -} \ No newline at end of file +[method: JsonConstructorAttribute] +public record OidcConfiguration(string userinfo_endpoint); + +[JsonSerializable(typeof(OidcConfiguration))] +[JsonSourceGenerationOptions(WriteIndented = false, DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull)] +public partial class OidcConfigurationSerializerContext : JsonSerializerContext; \ No newline at end of file diff --git a/src/Ecotag/Server/Groups/Oidc/OidcUserInfo.cs b/src/Ecotag/Server/Groups/Oidc/OidcUserInfo.cs index 9f53863e..6a51ad75 100644 --- a/src/Ecotag/Server/Groups/Oidc/OidcUserInfo.cs +++ b/src/Ecotag/Server/Groups/Oidc/OidcUserInfo.cs @@ -1,9 +1,11 @@ using System.Diagnostics.CodeAnalysis; +using System.Text.Json.Serialization; namespace AxaGuilDEv.Ecotag.Server.Groups.Oidc; [ExcludeFromCodeCoverage] -public class OidcUserInfo -{ - public string Email { get; set; } -} \ No newline at end of file +public record OidcUserInfo(string Email); + +[JsonSerializable(typeof(OidcUserInfo))] +[JsonSourceGenerationOptions(WriteIndented = false, DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull, PropertyNameCaseInsensitive = true)] +public partial class OidcUserInfoSerializerContext : JsonSerializerContext; diff --git a/src/Ecotag/Server/Groups/Oidc/OidcUserInfoService.cs b/src/Ecotag/Server/Groups/Oidc/OidcUserInfoService.cs index 8f8aaaf6..7d860a39 100644 --- a/src/Ecotag/Server/Groups/Oidc/OidcUserInfoService.cs +++ b/src/Ecotag/Server/Groups/Oidc/OidcUserInfoService.cs @@ -26,18 +26,12 @@ public async Task GetUserEmailAsync(string accessToken) { var oidcConfiguration = await GetOidcConfigurationAsync(); var request = new HttpRequestMessage(HttpMethod.Get, - oidcConfiguration.UserinfoEndpoint); + oidcConfiguration.userinfo_endpoint); request.Headers.Add("authorization", $"Bearer {accessToken}"); var client = _clientFactory.CreateClient(NamedHttpClients.ProxiedClient); var response = await client.SendAsync(request); await using var responseStream = await response.Content.ReadAsStreamAsync(); - var serializeOptions = new JsonSerializerOptions - { - PropertyNamingPolicy = JsonNamingPolicy.CamelCase, - WriteIndented = true - }; - var userInfo = await JsonSerializer.DeserializeAsync - (responseStream, serializeOptions); + var userInfo = await JsonSerializer.DeserializeAsync(responseStream, OidcUserInfoSerializerContext.Default.OidcUserInfo); return userInfo; } @@ -48,8 +42,7 @@ private async Task GetOidcConfigurationAsync() var client = _clientFactory.CreateClient(NamedHttpClients.ProxiedClient); var response = await client.SendAsync(request); await using var responseStream = await response.Content.ReadAsStreamAsync(); - var userInfo = await JsonSerializer.DeserializeAsync - (responseStream); + var userInfo = await JsonSerializer.DeserializeAsync(responseStream, OidcConfigurationSerializerContext.Default.OidcConfiguration); return userInfo; } } \ No newline at end of file diff --git a/src/Ecotag/Server/Projects/Cmd/Annotations/ExportCmd.cs b/src/Ecotag/Server/Projects/Cmd/Annotations/ExportCmd.cs index ca07c1b2..851d8d56 100644 --- a/src/Ecotag/Server/Projects/Cmd/Annotations/ExportCmd.cs +++ b/src/Ecotag/Server/Projects/Cmd/Annotations/ExportCmd.cs @@ -1,4 +1,5 @@ using System.Collections.Generic; +using System.Text.Json.Serialization; using System.Threading.Tasks; using AxaGuilDEv.Ecotag.Server.Datasets.Database; using AxaGuilDEv.Ecotag.Server.Datasets.Database.Annotations; diff --git a/src/Ecotag/Server/Projects/Database/Converter.cs b/src/Ecotag/Server/Projects/Database/Converter.cs index 9f7f5cfc..7b794938 100644 --- a/src/Ecotag/Server/Projects/Database/Converter.cs +++ b/src/Ecotag/Server/Projects/Database/Converter.cs @@ -29,7 +29,7 @@ public static AnnotationTypeEnumeration ToAnnotationType(this string type) private static List ToListLabelDataModel(this string labelsJson) { - return JsonSerializer.Deserialize>(labelsJson, - new JsonSerializerOptions { PropertyNameCaseInsensitive = true }); + return JsonSerializer.Deserialize(labelsJson, ListLabelDataModelSerializerContext.Default.ListLabelDataModel); } + } \ No newline at end of file diff --git a/src/Ecotag/Server/Projects/Database/LabelDataModel.cs b/src/Ecotag/Server/Projects/Database/LabelDataModel.cs index 649ed6d9..933610ec 100644 --- a/src/Ecotag/Server/Projects/Database/LabelDataModel.cs +++ b/src/Ecotag/Server/Projects/Database/LabelDataModel.cs @@ -1,8 +1,17 @@ -namespace AxaGuilDEv.Ecotag.Server.Projects.Database; +using System.Collections.Generic; +using System.Text.Json.Serialization; -public class LabelDataModel +namespace AxaGuilDEv.Ecotag.Server.Projects.Database; + +public record LabelDataModel { public string Name { get; set; } public string Color { get; set; } public string Id { get; set; } -} \ No newline at end of file +} + +public class ListLabelDataModel : List; + +[JsonSerializable(typeof(ListLabelDataModel))] +[JsonSourceGenerationOptions(WriteIndented = false, DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull)] +public partial class ListLabelDataModelSerializerContext : JsonSerializerContext; diff --git a/src/Ecotag/Server/StartupServer.cs b/src/Ecotag/Server/StartupServer.cs index bff2b139..17ec5f0d 100644 --- a/src/Ecotag/Server/StartupServer.cs +++ b/src/Ecotag/Server/StartupServer.cs @@ -15,7 +15,6 @@ using AxaGuilDEv.Ecotag.Server.Datasets.Database; using AxaGuilDEv.Ecotag.Server.Groups; using AxaGuilDEv.Ecotag.Server.Groups.Database; -using AxaGuilDEv.Ecotag.Server.Groups.Database.Users; using AxaGuilDEv.Ecotag.Server.Groups.Oidc; using AxaGuilDEv.Ecotag.Server.Oidc; using AxaGuilDEv.Ecotag.Server.Projects; @@ -31,7 +30,6 @@ using Microsoft.Extensions.Hosting; using Microsoft.IdentityModel.Tokens; using Microsoft.OpenApi.Models; -using Serilog; using AnnotationsController = AxaGuilDEv.Ecotag.Local.AnnotationsController; using DatasetsController = AxaGuilDEv.Ecotag.Local.DatasetsController; @@ -148,9 +146,9 @@ public void ConfigureServices(IServiceCollection services) } else { - var usersRepository = - context.HttpContext.RequestServices.GetRequiredService(); - var nameIdentifier = context.Principal.Identity.GetNameIdentifier(); + //var usersRepository = + // context.HttpContext.RequestServices.GetRequiredService(); + //var nameIdentifier = context.Principal.Identity.GetNameIdentifier(); //var userTask = usersRepository.GetUserByNameIdentifierAsync(nameIdentifier); //userTask.Wait(); var role = ""; //userTask.Result.Role; @@ -246,11 +244,9 @@ private CorsSettings GetCorsSettings() public void Configure(IApplicationBuilder app, IWebHostEnvironment env, IServiceProvider serviceProvider) { - app.UseSerilogRequestLogging(); app.UseErrorLogging(); AuditsService.ConfigureAudits(serviceProvider); - - + var databaseSettings = Configuration.GetSection(DatabaseSettings.Database).Get(); if (databaseSettings.Mode == DatabaseMode.Sqlite) { @@ -268,9 +264,9 @@ public void Configure(IApplicationBuilder app, IWebHostEnvironment env, IService app.Use(async (context, next) => { - context.Response.Headers.Add("X-Frame-Options", "sameorigin"); - context.Response.Headers.Add("X-Xss-Protection", "1; mode=block"); - context.Response.Headers.Add("X-Content-Type-Options", "nosniff"); + context.Response.Headers.Append("X-Frame-Options", "sameorigin"); + context.Response.Headers.Append("X-Xss-Protection", "1; mode=block"); + context.Response.Headers.Append("X-Content-Type-Options", "nosniff"); await next(); }); if (!env.IsDevelopment()) diff --git a/src/Ecotag/appsettings-server.Azure.json b/src/Ecotag/appsettings-server.Azure.json index 56eaa180..8dd07987 100644 --- a/src/Ecotag/appsettings-server.Azure.json +++ b/src/Ecotag/appsettings-server.Azure.json @@ -1,12 +1,4 @@ { - "Serilog": { - "MinimumLevel": { - "Default": "Warning", - "Override": { - "Microsoft": "Warning" - } - } - }, "AllowedHosts": "", "Cors": { "Origins": "https://axaguildev-ecotag.azurewebsites.net" diff --git a/src/Ecotag/appsettings-server.DesktopWinx64.json b/src/Ecotag/appsettings-server.DesktopWinx64.json index 821bdee8..d246fec0 100644 --- a/src/Ecotag/appsettings-server.DesktopWinx64.json +++ b/src/Ecotag/appsettings-server.DesktopWinx64.json @@ -1,12 +1,4 @@ { - "Serilog": { - "MinimumLevel": { - "Default": "Warning", - "Override": { - "Microsoft": "Warning" - } - } - }, "AllowedHosts": "*", "Cors": { "Origins": "" diff --git a/src/Ecotag/appsettings-server.Production.json b/src/Ecotag/appsettings-server.Production.json index f7c6ac1f..53a34757 100644 --- a/src/Ecotag/appsettings-server.Production.json +++ b/src/Ecotag/appsettings-server.Production.json @@ -1,34 +1,4 @@ { - "Serilog": { - "Using": [ - "Serilog.Sinks.Console", - "Serilog.Sinks.Async", - "Serilog.Sinks.ApplicationInsights" - ], - "MinimumLevel": { - "Default": "Warning", - "Override": { - "Microsoft": "Warning" - } - }, - "WriteTo": [ - { - "Name": "ApplicationInsights", - "Args": { - "restrictedToMinimumLevel": "Warning", - "telemetryConverter": "Serilog.Sinks.ApplicationInsights.Sinks.ApplicationInsights.TelemetryConverters.TraceTelemetryConverter, Serilog.Sinks.ApplicationInsights" - } - } - ], - "Enrich": [ - "FromLogContext", - "WithMachineName", - "WithThreadId" - ], - "Properties": { - "Application": "Ecotag api" - } - }, "AllowedHosts": "", "Cors": { "Origins": "#{Api:CorsOrigins}#" diff --git a/src/Ecotag/appsettings-server.json b/src/Ecotag/appsettings-server.json index 01e63efa..cc6f965a 100644 --- a/src/Ecotag/appsettings-server.json +++ b/src/Ecotag/appsettings-server.json @@ -1,49 +1,4 @@ { - "Serilog": { - "Using": [ - "Serilog.Sinks.Console", - "Serilog.Sinks.Async", - "Serilog.Sinks.ApplicationInsights" - ], - "MinimumLevel": { - "Default": "Information", - "Override": { - "Microsoft": "Information" - } - }, - "WriteTo": [ - { - "Name": "Console" - }, - { - "Name": "Debug" - }, - { - "Name": "Async", - "Args": { - "configure": [ - { - "Name": "File", - "Args": { - "path": "./Logs/log.txt", - "rollingInterval": "Day", - "retainedFileCountLimit": 7, - "buffered": true - } - } - ] - } - } - ], - "Enrich": [ - "FromLogContext", - "WithMachineName", - "WithThreadId" - ], - "Properties": { - "Application": "Advalorem api" - } - }, "AllowedHosts": "*", "Cors": { "Origins": "" diff --git a/src/MlCli.DemoApi/MlCli.DemoApi.csproj b/src/MlCli.DemoApi/MlCli.DemoApi.csproj index 51c3e686..18f6f2f7 100644 --- a/src/MlCli.DemoApi/MlCli.DemoApi.csproj +++ b/src/MlCli.DemoApi/MlCli.DemoApi.csproj @@ -1,7 +1,7 @@ - net7.0 + net8.0 AxaGuilDEv.MlCli.DemoApi @@ -78,7 +78,7 @@ - + diff --git a/src/MlCli/JobApiCall/Initializer.cs b/src/MlCli/JobApiCall/Initializer.cs index 12948d86..f6a19033 100644 --- a/src/MlCli/JobApiCall/Initializer.cs +++ b/src/MlCli/JobApiCall/Initializer.cs @@ -77,31 +77,39 @@ public static Callapi CreateTask(JObject jObject, string type, bool tokenEnabled ? (int)jObject.Property("waitTimeMsBetweenRequest") : 0; - if (!jObject.ContainsKey("Authorization")) + try { - services.AddHttpClient(taskId).ConfigurePrimaryHttpMessageHandler(() => new HttpClientHandler + if (!jObject.ContainsKey("Authorization")) { - ClientCertificateOptions = ClientCertificateOption.Manual, - ServerCertificateCustomValidationCallback = - (httpRequestMessage, cert, cetChain, policyErrors) => true, - DefaultProxyCredentials = CredentialCache.DefaultCredentials - }); - } - else - { - var Authorization = jObject.Property("Authorization").Value; - var oAuth2ClientCredentialsOptions = - JsonConvert.DeserializeObject(Authorization.ToString()); - services.AddHttpClient(taskId) - .AddOAuth2ClientCredentialsMessageHandler(oAuth2ClientCredentialsOptions) - .ConfigurePrimaryHttpMessageHandler(() => new HttpClientHandler + services.AddHttpClient(taskId).ConfigurePrimaryHttpMessageHandler(() => new HttpClientHandler { ClientCertificateOptions = ClientCertificateOption.Manual, ServerCertificateCustomValidationCallback = (httpRequestMessage, cert, cetChain, policyErrors) => true, DefaultProxyCredentials = CredentialCache.DefaultCredentials }); + } + else + { + var Authorization = jObject.Property("Authorization").Value; + var oAuth2ClientCredentialsOptions = + JsonConvert.DeserializeObject(Authorization.ToString()); + services.AddHttpClient(taskId) + .AddOAuth2ClientCredentialsMessageHandler(oAuth2ClientCredentialsOptions) + .ConfigurePrimaryHttpMessageHandler(() => new HttpClientHandler + { + ClientCertificateOptions = ClientCertificateOption.Manual, + ServerCertificateCustomValidationCallback = + (httpRequestMessage, cert, cetChain, policyErrors) => true, + DefaultProxyCredentials = CredentialCache.DefaultCredentials + }); + } + } + catch (Exception e) + { + Console.WriteLine(e); } + return new Callapi( type, diff --git a/src/MlCli/MlCli.csproj b/src/MlCli/MlCli.csproj index cd6a43f1..bb3cf420 100644 --- a/src/MlCli/MlCli.csproj +++ b/src/MlCli/MlCli.csproj @@ -2,29 +2,29 @@ Exe - net7.0 - linux-x64;rhel-x64;osx-x64;win10-x64 + net8.0 AxaGuilDEv.MlCli MlCli + true - - + + - - - - - + + + + + - - - - - + + + + + diff --git a/tests/Ecotag.Tests/Ecotag.Tests.csproj b/tests/Ecotag.Tests/Ecotag.Tests.csproj index 66db82b8..4becde94 100644 --- a/tests/Ecotag.Tests/Ecotag.Tests.csproj +++ b/tests/Ecotag.Tests/Ecotag.Tests.csproj @@ -1,29 +1,22 @@ - net7.0 + net8.0 AxaGuilDEv.Ecotag.Tests false - - runtime; build; native; contentfiles; analyzers; buildtransitive - all - - - - + + + - - all - runtime; build; native; contentfiles; analyzers; buildtransitive - - + all runtime; build; native; contentfiles; analyzers; buildtransitive + diff --git a/tests/Ecotag.Tests/Server/Groups/CreateUserMiddlewareShould.cs b/tests/Ecotag.Tests/Server/Groups/CreateUserMiddlewareShould.cs index d657e981..03ca6e05 100644 --- a/tests/Ecotag.Tests/Server/Groups/CreateUserMiddlewareShould.cs +++ b/tests/Ecotag.Tests/Server/Groups/CreateUserMiddlewareShould.cs @@ -75,7 +75,7 @@ public async Task CreateUser(string path, string subject, string usersInDatabase var createUserMidleware = new CreateUserMiddleware(nextMiddleware); var httpContext = DefaultHttpContext(path, subject, authorization); var oidcUserInfoServiceMock = new Mock(); - var oidcUserInfo = new OidcUserInfo() { Email = "guillaume.chervet@toto.fr" }; + var oidcUserInfo = new OidcUserInfo("guillaume.chervet@toto.fr"); oidcUserInfoServiceMock.Setup(it => it.GetUserEmailAsync(It.IsAny())).ReturnsAsync(oidcUserInfo); var memoryCache = new MemoryCache(Options.Create(new MemoryCacheOptions())); diff --git a/tests/Ecotag.Tests/Server/Groups/Oidc/OidcUserInfoServiceSould.cs b/tests/Ecotag.Tests/Server/Groups/Oidc/OidcUserInfoServiceSould.cs index 4b7c44d4..33b457c6 100644 --- a/tests/Ecotag.Tests/Server/Groups/Oidc/OidcUserInfoServiceSould.cs +++ b/tests/Ecotag.Tests/Server/Groups/Oidc/OidcUserInfoServiceSould.cs @@ -21,10 +21,10 @@ public async Task RetrunOidcUserInfo() var httpMessageHandler = new Mock(); var httpsDemoIdentityserverIoApiUserInfo = "https://demo.identityserver.io/api/user_info"; - var resultConfiguration = new OidcConfiguration { UserinfoEndpoint = httpsDemoIdentityserverIoApiUserInfo }; + var resultConfiguration = new OidcConfiguration(httpsDemoIdentityserverIoApiUserInfo); var responseConfiguration = new HttpResponseMessage(HttpStatusCode.OK) { - Content = new StringContent(JsonSerializer.Serialize(resultConfiguration)) + Content = new StringContent(JsonSerializer.Serialize(resultConfiguration, OidcConfigurationSerializerContext.Default.OidcConfiguration)) }; httpMessageHandler.Protected() .Setup>("SendAsync", @@ -34,16 +34,11 @@ public async Task RetrunOidcUserInfo() "https://demo.identityserver.io/.well-known/openid-configuration")), ItExpr.IsAny()) .ReturnsAsync(responseConfiguration); - - var resultObject = new OidcUserInfo { Email = "toto@gmail.fr" }; - var serializeOptions = new JsonSerializerOptions - { - PropertyNamingPolicy = JsonNamingPolicy.CamelCase, - WriteIndented = true - }; + var resultObject = new OidcUserInfo( "toto@gmail.fr"); + var response = new HttpResponseMessage(HttpStatusCode.OK) { - Content = new StringContent(JsonSerializer.Serialize(resultObject, serializeOptions)) + Content = new StringContent(JsonSerializer.Serialize(resultObject, OidcUserInfoSerializerContext.Default.OidcUserInfo)) }; httpMessageHandler.Protected() .Setup>("SendAsync", @@ -61,6 +56,7 @@ public async Task RetrunOidcUserInfo() var someOptions = Options.Create(new OidcSettings { Authority = "https://demo.identityserver.io" }); var service = new OidcUserInfoService(mockFactory.Object, someOptions); + var result = await service.GetUserEmailAsync("access_token"); Assert.Equal(resultObject.Email, result.Email); diff --git a/tests/MlCli.Tests/JobsTests/ApiCallUnitTest.cs b/tests/MlCli.Tests/JobsTests/ApiCallUnitTest.cs index be9e1d72..b9c6968a 100644 --- a/tests/MlCli.Tests/JobsTests/ApiCallUnitTest.cs +++ b/tests/MlCli.Tests/JobsTests/ApiCallUnitTest.cs @@ -247,8 +247,7 @@ public void ApiCallShouldInitialize() var serviceCollection = new Mock(); var pathValidatorHelper = new Mock(); - var callapiResult = Initializer.CreateTask(jObject, "callapi", false, true, "baseDirectory", "1", - serviceCollection.Object, pathValidatorHelper.Object); + var callapiResult = Initializer.CreateTask(jObject, "callapi", false, true, "baseDirectory", "1", serviceCollection.Object, pathValidatorHelper.Object); var expectedCallapiResult = new Callapi( "callapi", "1", @@ -267,6 +266,8 @@ public void ApiCallShouldInitialize() true, 1, 1); + + Assert.Equal(JsonConvert.SerializeObject(expectedCallapiResult), JsonConvert.SerializeObject(callapiResult)); } diff --git a/tests/MlCli.Tests/MlCli.Tests.csproj b/tests/MlCli.Tests/MlCli.Tests.csproj index 2e28b8df..76b6fe83 100644 --- a/tests/MlCli.Tests/MlCli.Tests.csproj +++ b/tests/MlCli.Tests/MlCli.Tests.csproj @@ -1,26 +1,19 @@ - net7.0 + net8.0 AxaGuilDEv.MlCli.Tests false - - runtime; build; native; contentfiles; analyzers; buildtransitive - all - - - + + + - - - all - runtime; build; native; contentfiles; analyzers; buildtransitive - - + + all runtime; build; native; contentfiles; analyzers; buildtransitive