Skip to content

Commit

Permalink
Merge branch 'main' into bugfix/reject-zero-bytes-files
Browse files Browse the repository at this point in the history
  • Loading branch information
tjololo authored Nov 23, 2023
2 parents fb6c7c5 + be99926 commit d21ebf8
Show file tree
Hide file tree
Showing 86 changed files with 4,030 additions and 178 deletions.
33 changes: 33 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": ".NET Core Launch (web)",
"type": "coreclr",
"request": "launch",
"preLaunchTask": "build",
"program": "${workspaceFolder}/src/bin/Debug/net6.0/LocalTest.dll",
"args": [],
"cwd": "${workspaceFolder}/src",
"stopAtEntry": false,
"serverReadyAction": {
"action": "openExternally",
"pattern": "\\bNow listening on:\\s+(https?://\\S+)"
},
"env": {
"ASPNETCORE_ENVIRONMENT": "Development"
},
"sourceFileMap": {
"/Views": "${workspaceFolder}/Views"
}
},
{
"name": ".NET Core Attach",
"type": "coreclr",
"request": "attach"
}
]
}
41 changes: 41 additions & 0 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
{
"version": "2.0.0",
"tasks": [
{
"label": "build",
"command": "dotnet",
"type": "process",
"args": [
"build",
"${workspaceFolder}/LocalTest.sln",
"/property:GenerateFullPaths=true",
"/consoleloggerparameters:NoSummary"
],
"problemMatcher": "$msCompile"
},
{
"label": "publish",
"command": "dotnet",
"type": "process",
"args": [
"publish",
"${workspaceFolder}/LocalTest.sln",
"/property:GenerateFullPaths=true",
"/consoleloggerparameters:NoSummary"
],
"problemMatcher": "$msCompile"
},
{
"label": "watch",
"command": "dotnet",
"type": "process",
"args": [
"watch",
"run",
"--project",
"${workspaceFolder}/LocalTest.sln"
],
"problemMatcher": "$msCompile"
}
]
}
47 changes: 27 additions & 20 deletions loadbalancer/templates/nginx.conf.conf
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ http {

sendfile on;

upstream localtest {
upstream localtest {
server host.docker.internal:5101;
}

Expand All @@ -58,7 +58,7 @@ http {
}

server {
listen 80 default_server;
listen 80 default_server;
server_name ${TEST_DOMAIN};

proxy_redirect off;
Expand All @@ -68,46 +68,53 @@ http {

error_page 502 /502LocalTest.html;

location = / {
location = / {
proxy_pass http://localtest/Home/;
}
sub_filter '<script src="/_framework/aspnetcore-browser-refresh.js"></script>' '<script src="/Home/_framework/aspnetcore-browser-refresh.js"></script>';
}

location / {
location / {
#Support using Local js, when a cookie value is set
sub_filter_once off;
sub_filter 'https://altinncdn.no/toolkits/altinn-app-frontend/3/' $LOCAL_SUB_FILTER;
proxy_pass http://app/;
error_page 502 /502App.html;
proxy_cookie_domain altinn3local.no local.altinn.cloud;
}
}

location /Home/ {
proxy_pass http://localtest/Home/;
}
location /Home/_framework/ {
proxy_pass http://localtest/_framework/;
}

location /Home/ {
proxy_pass http://localtest/Home/;
sub_filter '<script src="/_framework/aspnetcore-browser-refresh.js"></script>' '<script src="/Home/_framework/aspnetcore-browser-refresh.js"></script>';
}

location /receipt/ {
proxy_pass http://receiptcomp/receipt/;
error_page 502 /502Receipt.html;
}
proxy_pass http://receiptcomp/receipt/;
error_page 502 /502Receipt.html;
}

location /accessmanagement/ {
proxy_pass http://accessmanagementcomp/accessmanagement/;
proxy_pass http://accessmanagementcomp/accessmanagement/;
error_page 502 /502Accessmanagement.html;
}
}

location /storage/ {
proxy_pass http://localtest/storage/;
}
proxy_pass http://localtest/storage/;
}

location /pdfservice/ {
proxy_pass http://pdfservice/;
}

location /localtestresources/ {
proxy_pass http://localtest/localtestresources/;
}
proxy_pass http://localtest/localtestresources/;
}
location /LocalPlatformStorage/ {
proxy_pass http://localtest/LocalPlatformStorage/;
proxy_pass http://localtest/LocalPlatformStorage/;
sub_filter '<script src="/_framework/aspnetcore-browser-refresh.js"></script>' '';
}
location /502LocalTest.html {
root /www;
Expand All @@ -122,5 +129,5 @@ http {
root /www;
}

}
}
}
14 changes: 10 additions & 4 deletions src/Configuration/LocalPlatformSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public class LocalPlatformSettings
string _localTestDataPath = null;

/// <summary>
/// The endpoint for the bridge
/// The path to the local storage folder
/// </summary>
public string LocalTestingStorageBasePath { get; set; }

Expand All @@ -21,12 +21,16 @@ public class LocalPlatformSettings

public string BlobStorageFolder { get; set; } = "blobs/";

public string NotificationsStorageFolder { get; set; } = "notifications/";

/// <summary>
/// Folder where static test data like profile, authorization, and register data is available for local testing.
/// </summary>
public string LocalTestingStaticTestDataPath {
public string LocalTestingStaticTestDataPath
{
get => _localTestDataPath;
set {
set
{
if (!value.EndsWith(Path.DirectorySeparatorChar) &&
!value.EndsWith(Path.AltDirectorySeparatorChar))
{
Expand All @@ -47,7 +51,7 @@ public string LocalTestingStaticTestDataPath {
/// <summary>
public string LocalAppMode { get; set; }

public string DocumentDbFolder { get; set; } = "documentdb/";
public string DocumentDbFolder { get; set; } = "documentdb/";

public string InstanceCollectionFolder { get; set; } = "instances/";

Expand All @@ -68,5 +72,7 @@ public string LocalTestingStaticTestDataPath {
public string RolesFolder { get; set; } = "roles/";

public string ClaimsFolder { get; set; } = "claims/";

public string TenorDataFolder { get; set; } = "tenorUsers";
}
}
65 changes: 65 additions & 0 deletions src/Controllers/DebugUsersController.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
#nullable enable

using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Options;


using LocalTest.Configuration;

using LocalTest.Services.TestData;
using Microsoft.AspNetCore.Authorization;

namespace LocalTest.Controllers;

[Route("Home/[controller]/[action]")]
public class DebugUsersController : Controller
{
private readonly LocalPlatformSettings _localPlatformSettings;
private readonly TenorDataRepository _tenorDataRepository;

public DebugUsersController(
IOptions<LocalPlatformSettings> localPlatformSettings,
TenorDataRepository tenorDataRepository)
{
_localPlatformSettings = localPlatformSettings.Value;
_tenorDataRepository = tenorDataRepository;
}

// Debugging endpoint
[AllowAnonymous]
public async Task<IActionResult> LocalTestUsersRaw()
{
var localData = await TestDataDiskReader.ReadFromDisk(_localPlatformSettings.LocalTestingStaticTestDataPath);

return Json(localData);
}

//Debugging endpoint
[AllowAnonymous]
public async Task<IActionResult> LocalTestUsers()
{
var localData = await TestDataDiskReader.ReadFromDisk(_localPlatformSettings.LocalTestingStaticTestDataPath);
var constructedAppData = AppTestDataModel.FromTestDataModel(localData);

return Json(constructedAppData);
}

// Debugging endpoint
[AllowAnonymous]
public async Task<IActionResult> LocalTestUsersRoundTrip()
{
var localData = await TestDataDiskReader.ReadFromDisk(_localPlatformSettings.LocalTestingStaticTestDataPath);
var constructedAppData = AppTestDataModel.FromTestDataModel(localData);

return Json(constructedAppData.GetTestDataModel());
}

// Debugging endpoint
[AllowAnonymous]
public async Task<IActionResult> ShowTenorUsers()
{
var localData = await _tenorDataRepository.GetAppTestDataModel();

return Json(localData);
}
}
87 changes: 87 additions & 0 deletions src/Controllers/FrontendVersionController.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
#nullable enable
using System.Text.Json;

using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Options;

using LocalTest.Configuration;
using LocalTest.Models;
using LocalTest.Services.LocalApp.Interface;

using LocalTest.Services.TestData;
using Microsoft.AspNetCore.Authentication.Cookies;
using Microsoft.AspNetCore.Mvc.Rendering;

namespace LocalTest.Controllers;

[Route("Home/[controller]/[action]")]
public class FrontendVersionController : Controller
{
/// <summary>
/// See src\development\loadbalancer\nginx.conf
/// </summary>
public static readonly string FRONTEND_URL_COOKIE_NAME = "frontendVersion";

[HttpGet]
public async Task<ActionResult> Index([FromServices] HttpClient client)
{
var versionFromCookie = HttpContext.Request.Cookies[FRONTEND_URL_COOKIE_NAME];

var frontendVersion = new FrontendVersion()
{
Version = versionFromCookie,
Versions = new List<SelectListItem>()
{
new ()
{
Text = "Keep as is",
Value = "",
},
new ()
{
Text = "localhost:8080 (local dev)",
Value = "http://localhost:8080/"
}
}
};
var cdnVersionsString = await client.GetStringAsync("https://altinncdn.no/toolkits/altinn-app-frontend/index.json");
var groupCdnVersions = new SelectListGroup() { Name = "Specific version from cdn" };
var versions = JsonSerializer.Deserialize<List<string>>(cdnVersionsString)!;
versions.Reverse();
versions.ForEach(version =>
{
frontendVersion.Versions.Add(new()
{
Text = version,
Value = $"https://altinncdn.no/toolkits/altinn-app-frontend/{version}/",
Group = groupCdnVersions
});
});

return View(frontendVersion);
}
public ActionResult Index(FrontendVersion frontendVersion)
{
var options = new CookieOptions
{
Expires = DateTime.MaxValue,
HttpOnly = true,
};
ICookieManager cookieManager = new ChunkingCookieManager();
if (string.IsNullOrWhiteSpace(frontendVersion.Version))
{
cookieManager.DeleteCookie(HttpContext, FRONTEND_URL_COOKIE_NAME, options);
}
else
{
cookieManager.AppendResponseCookie(
HttpContext,
FRONTEND_URL_COOKIE_NAME,
frontendVersion.Version,
options
);
}

return RedirectToAction("Index", "Home");
}
}
Loading

0 comments on commit d21ebf8

Please sign in to comment.