mirror of
https://github.com/LBPUnion/ProjectLighthouse.git
synced 2025-07-28 07:58:40 +00:00
Fix digest tests and update controllers with new digest attribute
This commit is contained in:
parent
fd210b3125
commit
d458eb90ad
29 changed files with 178 additions and 267 deletions
|
@ -1,9 +1,9 @@
|
|||
#nullable enable
|
||||
using LBPUnion.ProjectLighthouse.Configuration;
|
||||
using LBPUnion.ProjectLighthouse.Database;
|
||||
using LBPUnion.ProjectLighthouse.Extensions;
|
||||
using LBPUnion.ProjectLighthouse.Helpers;
|
||||
using LBPUnion.ProjectLighthouse.Logging;
|
||||
using LBPUnion.ProjectLighthouse.Servers.GameServer.Types;
|
||||
using LBPUnion.ProjectLighthouse.Types.Entities.Profile;
|
||||
using LBPUnion.ProjectLighthouse.Types.Entities.Token;
|
||||
using LBPUnion.ProjectLighthouse.Types.Filter;
|
||||
|
@ -11,17 +11,12 @@ using LBPUnion.ProjectLighthouse.Types.Levels;
|
|||
using LBPUnion.ProjectLighthouse.Types.Logging;
|
||||
using LBPUnion.ProjectLighthouse.Types.Serialization;
|
||||
using LBPUnion.ProjectLighthouse.Types.Users;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace LBPUnion.ProjectLighthouse.Servers.GameServer.Controllers;
|
||||
|
||||
[ApiController]
|
||||
[Authorize]
|
||||
[Route("LITTLEBIGPLANETPS3_XML/")]
|
||||
[Produces("text/xml")]
|
||||
public class CommentController : ControllerBase
|
||||
public class CommentController : GameController
|
||||
{
|
||||
private readonly DatabaseContext database;
|
||||
public CommentController(DatabaseContext database)
|
||||
|
|
|
@ -1,14 +1,10 @@
|
|||
using LBPUnion.ProjectLighthouse.Types.Serialization;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using LBPUnion.ProjectLighthouse.Servers.GameServer.Types;
|
||||
using LBPUnion.ProjectLighthouse.Types.Serialization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
namespace LBPUnion.ProjectLighthouse.Servers.GameServer.Controllers;
|
||||
|
||||
[ApiController]
|
||||
[Authorize]
|
||||
[Route("LITTLEBIGPLANETPS3_XML/")]
|
||||
[Produces("text/xml")]
|
||||
public class DeveloperController : Controller
|
||||
public class DeveloperController : GameController
|
||||
{
|
||||
[HttpGet("developer_videos")]
|
||||
public IActionResult DeveloperVideos() => this.Ok(new GameDeveloperVideos());
|
||||
|
|
|
@ -1,23 +1,18 @@
|
|||
#nullable enable
|
||||
using LBPUnion.ProjectLighthouse.Database;
|
||||
using LBPUnion.ProjectLighthouse.Extensions;
|
||||
using LBPUnion.ProjectLighthouse.Servers.GameServer.Types;
|
||||
using LBPUnion.ProjectLighthouse.Servers.GameServer.Types.Users;
|
||||
using LBPUnion.ProjectLighthouse.StorableLists.Stores;
|
||||
using LBPUnion.ProjectLighthouse.Types.Entities.Profile;
|
||||
using LBPUnion.ProjectLighthouse.Types.Entities.Token;
|
||||
using LBPUnion.ProjectLighthouse.Types.Serialization;
|
||||
using LBPUnion.ProjectLighthouse.Types.Users;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace LBPUnion.ProjectLighthouse.Servers.GameServer.Controllers;
|
||||
|
||||
[ApiController]
|
||||
[Authorize]
|
||||
[Route("LITTLEBIGPLANETPS3_XML/")]
|
||||
[Produces("text/xml")]
|
||||
public class FriendsController : ControllerBase
|
||||
public class FriendsController : GameController
|
||||
{
|
||||
private readonly DatabaseContext database;
|
||||
|
||||
|
|
|
@ -1,22 +1,18 @@
|
|||
#nullable enable
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using LBPUnion.ProjectLighthouse.Configuration;
|
||||
using LBPUnion.ProjectLighthouse.Database;
|
||||
using LBPUnion.ProjectLighthouse.Extensions;
|
||||
using LBPUnion.ProjectLighthouse.Servers.GameServer.Types;
|
||||
using LBPUnion.ProjectLighthouse.Servers.GameServer.Types.Users;
|
||||
using LBPUnion.ProjectLighthouse.Types.Entities.Profile;
|
||||
using LBPUnion.ProjectLighthouse.Types.Serialization;
|
||||
using LBPUnion.ProjectLighthouse.Types.Users;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
namespace LBPUnion.ProjectLighthouse.Servers.GameServer.Controllers.Login;
|
||||
|
||||
[ApiController]
|
||||
[Authorize]
|
||||
[Route("LITTLEBIGPLANETPS3_XML/")]
|
||||
[Produces("text/plain")]
|
||||
public class ClientConfigurationController : ControllerBase
|
||||
public class ClientConfigurationController : GameController
|
||||
{
|
||||
private readonly DatabaseContext database;
|
||||
|
||||
|
@ -26,6 +22,7 @@ public class ClientConfigurationController : ControllerBase
|
|||
}
|
||||
|
||||
[HttpGet("network_settings.nws")]
|
||||
[UseDigest(EnforceDigest = false)]
|
||||
[SuppressMessage("ReSharper", "StringLiteralTypo")]
|
||||
public IActionResult NetworkSettings()
|
||||
{
|
||||
|
@ -41,15 +38,18 @@ public class ClientConfigurationController : ControllerBase
|
|||
|
||||
[HttpGet("t_conf")]
|
||||
[Produces("text/xml")]
|
||||
[UseDigest(EnforceDigest = false)]
|
||||
public IActionResult Conf() => this.Ok(new TelemetryConfigResponse());
|
||||
|
||||
// The challenge config here is currently based on the official server's config.
|
||||
// We should probably make this configurable in the future.
|
||||
[HttpGet("ChallengeConfig.xml")]
|
||||
[Produces("text/xml")]
|
||||
[UseDigest(EnforceDigest = false)]
|
||||
public IActionResult Challenges() => this.Ok(GameChallengeResponse.ServerChallenges());
|
||||
|
||||
[HttpGet("farc_hashes")]
|
||||
[UseDigest(EnforceDigest = false)]
|
||||
public IActionResult FarcHashes() => this.Ok();
|
||||
|
||||
[HttpGet("privacySettings")]
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
#nullable enable
|
||||
using System.Net;
|
||||
using LBPUnion.ProjectLighthouse.Configuration;
|
||||
using LBPUnion.ProjectLighthouse.Database;
|
||||
|
|
|
@ -1,20 +1,15 @@
|
|||
using LBPUnion.ProjectLighthouse.Database;
|
||||
using LBPUnion.ProjectLighthouse.Extensions;
|
||||
using LBPUnion.ProjectLighthouse.Helpers;
|
||||
using LBPUnion.ProjectLighthouse.Servers.GameServer.Types;
|
||||
using LBPUnion.ProjectLighthouse.Types.Entities.Profile;
|
||||
using LBPUnion.ProjectLighthouse.Types.Entities.Token;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
namespace LBPUnion.ProjectLighthouse.Servers.GameServer.Controllers.Login;
|
||||
|
||||
[ApiController]
|
||||
[Authorize]
|
||||
[Route("LITTLEBIGPLANETPS3_XML/goodbye")]
|
||||
[Produces("text/xml")]
|
||||
public class LogoutController : ControllerBase
|
||||
public class LogoutController : GameController
|
||||
{
|
||||
|
||||
private readonly DatabaseContext database;
|
||||
|
||||
public LogoutController(DatabaseContext database)
|
||||
|
@ -22,8 +17,8 @@ public class LogoutController : ControllerBase
|
|||
this.database = database;
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public async Task<IActionResult> OnPost()
|
||||
[HttpPost("goodbye")]
|
||||
public async Task<IActionResult> OnLogout()
|
||||
{
|
||||
GameTokenEntity token = this.GetToken();
|
||||
|
||||
|
@ -37,6 +32,4 @@ public class LogoutController : ControllerBase
|
|||
|
||||
return this.Ok();
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -1,22 +1,17 @@
|
|||
#nullable enable
|
||||
using LBPUnion.ProjectLighthouse.Database;
|
||||
using LBPUnion.ProjectLighthouse.Extensions;
|
||||
using LBPUnion.ProjectLighthouse.Helpers;
|
||||
using LBPUnion.ProjectLighthouse.Servers.GameServer.Types;
|
||||
using LBPUnion.ProjectLighthouse.Types.Entities.Interaction;
|
||||
using LBPUnion.ProjectLighthouse.Types.Entities.Level;
|
||||
using LBPUnion.ProjectLighthouse.Types.Entities.Token;
|
||||
using LBPUnion.ProjectLighthouse.Types.Users;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace LBPUnion.ProjectLighthouse.Servers.GameServer.Controllers.Matching;
|
||||
|
||||
[ApiController]
|
||||
[Authorize]
|
||||
[Route("LITTLEBIGPLANETPS3_XML/")]
|
||||
[Produces("text/xml")]
|
||||
public class EnterLevelController : ControllerBase
|
||||
public class EnterLevelController : GameController
|
||||
{
|
||||
private readonly DatabaseContext database;
|
||||
|
||||
|
|
|
@ -1,26 +1,21 @@
|
|||
#nullable enable
|
||||
using System.Text.Json;
|
||||
using LBPUnion.ProjectLighthouse.Database;
|
||||
using LBPUnion.ProjectLighthouse.Extensions;
|
||||
using LBPUnion.ProjectLighthouse.Helpers;
|
||||
using LBPUnion.ProjectLighthouse.Logging;
|
||||
using LBPUnion.ProjectLighthouse.Servers.GameServer.Types;
|
||||
using LBPUnion.ProjectLighthouse.Types.Entities.Profile;
|
||||
using LBPUnion.ProjectLighthouse.Types.Entities.Token;
|
||||
using LBPUnion.ProjectLighthouse.Types.Logging;
|
||||
using LBPUnion.ProjectLighthouse.Types.Matchmaking;
|
||||
using LBPUnion.ProjectLighthouse.Types.Matchmaking.MatchCommands;
|
||||
using LBPUnion.ProjectLighthouse.Types.Matchmaking.Rooms;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace LBPUnion.ProjectLighthouse.Servers.GameServer.Controllers.Matching;
|
||||
|
||||
[ApiController]
|
||||
[Authorize]
|
||||
[Route("LITTLEBIGPLANETPS3_XML/")]
|
||||
[Produces("text/xml")]
|
||||
public class MatchController : ControllerBase
|
||||
public class MatchController : GameController
|
||||
{
|
||||
private readonly DatabaseContext database;
|
||||
|
||||
|
|
|
@ -5,23 +5,20 @@ using LBPUnion.ProjectLighthouse.Extensions;
|
|||
using LBPUnion.ProjectLighthouse.Helpers;
|
||||
using LBPUnion.ProjectLighthouse.Logging;
|
||||
using LBPUnion.ProjectLighthouse.Serialization;
|
||||
using LBPUnion.ProjectLighthouse.Servers.GameServer.Types;
|
||||
using LBPUnion.ProjectLighthouse.Types.Entities.Notifications;
|
||||
using LBPUnion.ProjectLighthouse.Types.Entities.Profile;
|
||||
using LBPUnion.ProjectLighthouse.Types.Entities.Token;
|
||||
using LBPUnion.ProjectLighthouse.Types.Logging;
|
||||
using LBPUnion.ProjectLighthouse.Types.Mail;
|
||||
using LBPUnion.ProjectLighthouse.Types.Serialization;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace LBPUnion.ProjectLighthouse.Servers.GameServer.Controllers;
|
||||
|
||||
[ApiController]
|
||||
[Authorize]
|
||||
[Route("LITTLEBIGPLANETPS3_XML/")]
|
||||
[Produces("text/plain")]
|
||||
public class MessageController : ControllerBase
|
||||
public class MessageController : GameController
|
||||
{
|
||||
private readonly DatabaseContext database;
|
||||
|
||||
|
@ -45,9 +42,11 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.";
|
|||
}
|
||||
|
||||
[HttpGet("eula")]
|
||||
[UseDigest(EnforceDigest = false)]
|
||||
public IActionResult Eula() => this.Ok($"{license}\n{ServerConfiguration.Instance.EulaText}");
|
||||
|
||||
[HttpGet("announce")]
|
||||
[UseDigest(EnforceDigest = false)]
|
||||
public async Task<IActionResult> Announce()
|
||||
{
|
||||
GameTokenEntity token = this.GetToken();
|
||||
|
|
|
@ -1,24 +1,19 @@
|
|||
#nullable enable
|
||||
using System.Text.Json;
|
||||
using System.Text.Json;
|
||||
using LBPUnion.ProjectLighthouse.Configuration;
|
||||
using LBPUnion.ProjectLighthouse.Database;
|
||||
using LBPUnion.ProjectLighthouse.Extensions;
|
||||
using LBPUnion.ProjectLighthouse.Files;
|
||||
using LBPUnion.ProjectLighthouse.Helpers;
|
||||
using LBPUnion.ProjectLighthouse.Servers.GameServer.Types;
|
||||
using LBPUnion.ProjectLighthouse.Types.Entities.Moderation;
|
||||
using LBPUnion.ProjectLighthouse.Types.Entities.Token;
|
||||
using LBPUnion.ProjectLighthouse.Types.Moderation.Reports;
|
||||
using LBPUnion.ProjectLighthouse.Types.Serialization;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
namespace LBPUnion.ProjectLighthouse.Servers.GameServer.Controllers;
|
||||
|
||||
[ApiController]
|
||||
[Authorize]
|
||||
[Route("LITTLEBIGPLANETPS3_XML/")]
|
||||
[Produces("text/xml")]
|
||||
public class ReportController : ControllerBase
|
||||
public class ReportController : GameController
|
||||
{
|
||||
private readonly DatabaseContext database;
|
||||
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
#nullable enable
|
||||
using Discord;
|
||||
using LBPUnion.ProjectLighthouse.Configuration;
|
||||
using LBPUnion.ProjectLighthouse.Database;
|
||||
|
@ -6,6 +5,7 @@ using LBPUnion.ProjectLighthouse.Extensions;
|
|||
using LBPUnion.ProjectLighthouse.Files;
|
||||
using LBPUnion.ProjectLighthouse.Helpers;
|
||||
using LBPUnion.ProjectLighthouse.Logging;
|
||||
using LBPUnion.ProjectLighthouse.Servers.GameServer.Types;
|
||||
using LBPUnion.ProjectLighthouse.Types.Entities.Level;
|
||||
using LBPUnion.ProjectLighthouse.Types.Entities.Profile;
|
||||
using LBPUnion.ProjectLighthouse.Types.Entities.Token;
|
||||
|
@ -13,17 +13,12 @@ using LBPUnion.ProjectLighthouse.Types.Filter;
|
|||
using LBPUnion.ProjectLighthouse.Types.Levels;
|
||||
using LBPUnion.ProjectLighthouse.Types.Logging;
|
||||
using LBPUnion.ProjectLighthouse.Types.Serialization;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace LBPUnion.ProjectLighthouse.Servers.GameServer.Controllers.Resources;
|
||||
|
||||
[ApiController]
|
||||
[Authorize]
|
||||
[Route("LITTLEBIGPLANETPS3_XML/")]
|
||||
[Produces("text/xml")]
|
||||
public class PhotosController : ControllerBase
|
||||
public class PhotosController : GameController
|
||||
{
|
||||
private readonly DatabaseContext database;
|
||||
|
||||
|
|
|
@ -1,22 +1,17 @@
|
|||
#nullable enable
|
||||
using System.Text;
|
||||
using LBPUnion.ProjectLighthouse.Extensions;
|
||||
using LBPUnion.ProjectLighthouse.Files;
|
||||
using LBPUnion.ProjectLighthouse.Logging;
|
||||
using LBPUnion.ProjectLighthouse.Servers.GameServer.Types;
|
||||
using LBPUnion.ProjectLighthouse.Servers.GameServer.Types.Misc;
|
||||
using LBPUnion.ProjectLighthouse.Types.Logging;
|
||||
using LBPUnion.ProjectLighthouse.Types.Resources;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using IOFile = System.IO.File;
|
||||
|
||||
namespace LBPUnion.ProjectLighthouse.Servers.GameServer.Controllers.Resources;
|
||||
|
||||
[ApiController]
|
||||
[Authorize]
|
||||
[Produces("text/xml")]
|
||||
[Route("LITTLEBIGPLANETPS3_XML")]
|
||||
public class ResourcesController : ControllerBase
|
||||
public class ResourcesController : GameController
|
||||
{
|
||||
|
||||
[HttpPost("showModerated")]
|
||||
|
@ -51,6 +46,7 @@ public class ResourcesController : ControllerBase
|
|||
|
||||
[HttpPost("upload/{hash}/unattributed")]
|
||||
[HttpPost("upload/{hash}")]
|
||||
[UseDigest(DigestHeaderName = "X-Digest-B", ExcludeBodyFromDigest = true)]
|
||||
public async Task<IActionResult> UploadResource(string hash)
|
||||
{
|
||||
string assetsDirectory = FileHelper.ResourcePath;
|
||||
|
|
|
@ -4,6 +4,7 @@ using LBPUnion.ProjectLighthouse.Filter;
|
|||
using LBPUnion.ProjectLighthouse.Filter.Sorts;
|
||||
using LBPUnion.ProjectLighthouse.Logging;
|
||||
using LBPUnion.ProjectLighthouse.Servers.GameServer.Extensions;
|
||||
using LBPUnion.ProjectLighthouse.Servers.GameServer.Types;
|
||||
using LBPUnion.ProjectLighthouse.Servers.GameServer.Types.Categories;
|
||||
using LBPUnion.ProjectLighthouse.Types.Entities.Level;
|
||||
using LBPUnion.ProjectLighthouse.Types.Entities.Profile;
|
||||
|
@ -13,17 +14,12 @@ using LBPUnion.ProjectLighthouse.Types.Levels;
|
|||
using LBPUnion.ProjectLighthouse.Types.Logging;
|
||||
using LBPUnion.ProjectLighthouse.Types.Misc;
|
||||
using LBPUnion.ProjectLighthouse.Types.Serialization;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace LBPUnion.ProjectLighthouse.Servers.GameServer.Controllers.Slots;
|
||||
|
||||
[ApiController]
|
||||
[Authorize]
|
||||
[Route("LITTLEBIGPLANETPS3_XML/")]
|
||||
[Produces("text/xml")]
|
||||
public class CategoryController : ControllerBase
|
||||
public class CategoryController : GameController
|
||||
{
|
||||
private readonly DatabaseContext database;
|
||||
|
||||
|
|
|
@ -1,22 +1,18 @@
|
|||
using LBPUnion.ProjectLighthouse.Database;
|
||||
using LBPUnion.ProjectLighthouse.Extensions;
|
||||
using LBPUnion.ProjectLighthouse.Helpers;
|
||||
using LBPUnion.ProjectLighthouse.Servers.GameServer.Types;
|
||||
using LBPUnion.ProjectLighthouse.Types.Entities.Interaction;
|
||||
using LBPUnion.ProjectLighthouse.Types.Entities.Level;
|
||||
using LBPUnion.ProjectLighthouse.Types.Entities.Token;
|
||||
using LBPUnion.ProjectLighthouse.Types.Levels;
|
||||
using LBPUnion.ProjectLighthouse.Types.Users;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace LBPUnion.ProjectLighthouse.Servers.GameServer.Controllers.Slots;
|
||||
|
||||
[ApiController]
|
||||
[Authorize]
|
||||
[Route("LITTLEBIGPLANETPS3_XML")]
|
||||
[Produces("text/plain")]
|
||||
public class LevelTagsController : ControllerBase
|
||||
public class LevelTagsController : GameController
|
||||
{
|
||||
private readonly DatabaseContext database;
|
||||
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
#nullable enable
|
||||
using LBPUnion.ProjectLighthouse.Database;
|
||||
using LBPUnion.ProjectLighthouse.Extensions;
|
||||
using LBPUnion.ProjectLighthouse.Filter;
|
||||
using LBPUnion.ProjectLighthouse.Helpers;
|
||||
using LBPUnion.ProjectLighthouse.Servers.GameServer.Extensions;
|
||||
using LBPUnion.ProjectLighthouse.Servers.GameServer.Types;
|
||||
using LBPUnion.ProjectLighthouse.Types.Entities.Level;
|
||||
using LBPUnion.ProjectLighthouse.Types.Entities.Profile;
|
||||
using LBPUnion.ProjectLighthouse.Types.Entities.Token;
|
||||
|
@ -11,17 +11,12 @@ using LBPUnion.ProjectLighthouse.Types.Filter;
|
|||
using LBPUnion.ProjectLighthouse.Types.Levels;
|
||||
using LBPUnion.ProjectLighthouse.Types.Serialization;
|
||||
using LBPUnion.ProjectLighthouse.Types.Users;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace LBPUnion.ProjectLighthouse.Servers.GameServer.Controllers.Slots;
|
||||
|
||||
[ApiController]
|
||||
[Authorize]
|
||||
[Route("LITTLEBIGPLANETPS3_XML/")]
|
||||
[Produces("text/xml")]
|
||||
public class ListController : ControllerBase
|
||||
public class ListController : GameController
|
||||
{
|
||||
private readonly DatabaseContext database;
|
||||
|
||||
|
|
|
@ -1,21 +1,16 @@
|
|||
#nullable enable
|
||||
using LBPUnion.ProjectLighthouse.Configuration;
|
||||
using LBPUnion.ProjectLighthouse.Database;
|
||||
using LBPUnion.ProjectLighthouse.Extensions;
|
||||
using LBPUnion.ProjectLighthouse.Servers.GameServer.Types;
|
||||
using LBPUnion.ProjectLighthouse.Types.Entities.Level;
|
||||
using LBPUnion.ProjectLighthouse.Types.Entities.Token;
|
||||
using LBPUnion.ProjectLighthouse.Types.Serialization;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace LBPUnion.ProjectLighthouse.Servers.GameServer.Controllers.Slots;
|
||||
|
||||
[ApiController]
|
||||
[Authorize]
|
||||
[Route("LITTLEBIGPLANETPS3_XML/")]
|
||||
[Produces("text/xml")]
|
||||
public class PlaylistController : ControllerBase
|
||||
public class PlaylistController : GameController
|
||||
{
|
||||
private readonly DatabaseContext database;
|
||||
|
||||
|
|
|
@ -6,6 +6,7 @@ using LBPUnion.ProjectLighthouse.Files;
|
|||
using LBPUnion.ProjectLighthouse.Helpers;
|
||||
using LBPUnion.ProjectLighthouse.Logging;
|
||||
using LBPUnion.ProjectLighthouse.Servers.GameServer.Helpers;
|
||||
using LBPUnion.ProjectLighthouse.Servers.GameServer.Types;
|
||||
using LBPUnion.ProjectLighthouse.Types.Entities.Level;
|
||||
using LBPUnion.ProjectLighthouse.Types.Entities.Profile;
|
||||
using LBPUnion.ProjectLighthouse.Types.Entities.Token;
|
||||
|
@ -23,7 +24,7 @@ namespace LBPUnion.ProjectLighthouse.Servers.GameServer.Controllers.Slots;
|
|||
[Authorize]
|
||||
[Route("LITTLEBIGPLANETPS3_XML/")]
|
||||
[Produces("text/xml")]
|
||||
public class PublishController : ControllerBase
|
||||
public class PublishController : GameController
|
||||
{
|
||||
private readonly DatabaseContext database;
|
||||
|
||||
|
|
|
@ -1,23 +1,18 @@
|
|||
#nullable enable
|
||||
using LBPUnion.ProjectLighthouse.Database;
|
||||
using LBPUnion.ProjectLighthouse.Extensions;
|
||||
using LBPUnion.ProjectLighthouse.Helpers;
|
||||
using LBPUnion.ProjectLighthouse.Servers.GameServer.Types;
|
||||
using LBPUnion.ProjectLighthouse.Types.Entities.Interaction;
|
||||
using LBPUnion.ProjectLighthouse.Types.Entities.Level;
|
||||
using LBPUnion.ProjectLighthouse.Types.Entities.Token;
|
||||
using LBPUnion.ProjectLighthouse.Types.Filter;
|
||||
using LBPUnion.ProjectLighthouse.Types.Serialization;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace LBPUnion.ProjectLighthouse.Servers.GameServer.Controllers.Slots;
|
||||
|
||||
[ApiController]
|
||||
[Authorize]
|
||||
[Route("LITTLEBIGPLANETPS3_XML/")]
|
||||
[Produces("text/xml")]
|
||||
public class ReviewController : ControllerBase
|
||||
public class ReviewController : GameController
|
||||
{
|
||||
private readonly DatabaseContext database;
|
||||
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
#nullable enable
|
||||
using LBPUnion.ProjectLighthouse.Database;
|
||||
using LBPUnion.ProjectLighthouse.Extensions;
|
||||
using LBPUnion.ProjectLighthouse.Helpers;
|
||||
using LBPUnion.ProjectLighthouse.Logging;
|
||||
using LBPUnion.ProjectLighthouse.Servers.GameServer.Types;
|
||||
using LBPUnion.ProjectLighthouse.StorableLists.Stores;
|
||||
using LBPUnion.ProjectLighthouse.Types.Entities.Level;
|
||||
using LBPUnion.ProjectLighthouse.Types.Entities.Token;
|
||||
|
@ -10,17 +10,12 @@ using LBPUnion.ProjectLighthouse.Types.Levels;
|
|||
using LBPUnion.ProjectLighthouse.Types.Logging;
|
||||
using LBPUnion.ProjectLighthouse.Types.Serialization;
|
||||
using LBPUnion.ProjectLighthouse.Types.Users;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace LBPUnion.ProjectLighthouse.Servers.GameServer.Controllers.Slots;
|
||||
|
||||
[ApiController]
|
||||
[Authorize]
|
||||
[Route("LITTLEBIGPLANETPS3_XML/")]
|
||||
[Produces("text/xml")]
|
||||
public class ScoreController : ControllerBase
|
||||
public class ScoreController : GameController
|
||||
{
|
||||
private readonly DatabaseContext database;
|
||||
|
||||
|
|
|
@ -1,25 +1,20 @@
|
|||
#nullable enable
|
||||
using LBPUnion.ProjectLighthouse.Database;
|
||||
using LBPUnion.ProjectLighthouse.Extensions;
|
||||
using LBPUnion.ProjectLighthouse.Filter;
|
||||
using LBPUnion.ProjectLighthouse.Filter.Filters;
|
||||
using LBPUnion.ProjectLighthouse.Filter.Sorts;
|
||||
using LBPUnion.ProjectLighthouse.Servers.GameServer.Extensions;
|
||||
using LBPUnion.ProjectLighthouse.Servers.GameServer.Types;
|
||||
using LBPUnion.ProjectLighthouse.Types.Entities.Level;
|
||||
using LBPUnion.ProjectLighthouse.Types.Entities.Token;
|
||||
using LBPUnion.ProjectLighthouse.Types.Filter;
|
||||
using LBPUnion.ProjectLighthouse.Types.Serialization;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace LBPUnion.ProjectLighthouse.Servers.GameServer.Controllers.Slots;
|
||||
|
||||
[ApiController]
|
||||
[Authorize]
|
||||
[Route("LITTLEBIGPLANETPS3_XML/slots")]
|
||||
[Produces("text/xml")]
|
||||
public class SearchController : ControllerBase
|
||||
public class SearchController : GameController
|
||||
{
|
||||
private readonly DatabaseContext database;
|
||||
public SearchController(DatabaseContext database)
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
#nullable enable
|
||||
using System.Linq.Expressions;
|
||||
using LBPUnion.ProjectLighthouse.Database;
|
||||
using LBPUnion.ProjectLighthouse.Extensions;
|
||||
|
@ -8,6 +7,7 @@ using LBPUnion.ProjectLighthouse.Filter.Sorts;
|
|||
using LBPUnion.ProjectLighthouse.Filter.Sorts.Metadata;
|
||||
using LBPUnion.ProjectLighthouse.Helpers;
|
||||
using LBPUnion.ProjectLighthouse.Servers.GameServer.Extensions;
|
||||
using LBPUnion.ProjectLighthouse.Servers.GameServer.Types;
|
||||
using LBPUnion.ProjectLighthouse.Types.Entities.Level;
|
||||
using LBPUnion.ProjectLighthouse.Types.Entities.Token;
|
||||
using LBPUnion.ProjectLighthouse.Types.Filter;
|
||||
|
@ -15,17 +15,12 @@ using LBPUnion.ProjectLighthouse.Types.Levels;
|
|||
using LBPUnion.ProjectLighthouse.Types.Misc;
|
||||
using LBPUnion.ProjectLighthouse.Types.Serialization;
|
||||
using LBPUnion.ProjectLighthouse.Types.Users;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace LBPUnion.ProjectLighthouse.Servers.GameServer.Controllers.Slots;
|
||||
|
||||
[ApiController]
|
||||
[Authorize]
|
||||
[Route("LITTLEBIGPLANETPS3_XML/")]
|
||||
[Produces("text/xml")]
|
||||
public class SlotsController : ControllerBase
|
||||
public class SlotsController : GameController
|
||||
{
|
||||
private readonly DatabaseContext database;
|
||||
|
||||
|
|
|
@ -1,20 +1,17 @@
|
|||
using LBPUnion.ProjectLighthouse.Database;
|
||||
using LBPUnion.ProjectLighthouse.Helpers;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using LBPUnion.ProjectLighthouse.Extensions;
|
||||
using LBPUnion.ProjectLighthouse.Filter;
|
||||
using LBPUnion.ProjectLighthouse.Filter.Filters;
|
||||
using LBPUnion.ProjectLighthouse.Servers.GameServer.Extensions;
|
||||
using LBPUnion.ProjectLighthouse.Servers.GameServer.Types;
|
||||
using LBPUnion.ProjectLighthouse.Types.Serialization;
|
||||
|
||||
namespace LBPUnion.ProjectLighthouse.Servers.GameServer.Controllers;
|
||||
|
||||
[ApiController]
|
||||
[Authorize]
|
||||
[Route("LITTLEBIGPLANETPS3_XML/")]
|
||||
[Produces("text/plain")]
|
||||
public class StatisticsController : ControllerBase
|
||||
public class StatisticsController : GameController
|
||||
{
|
||||
private readonly DatabaseContext database;
|
||||
|
||||
|
|
|
@ -1,13 +1,9 @@
|
|||
using Microsoft.AspNetCore.Authorization;
|
||||
using LBPUnion.ProjectLighthouse.Servers.GameServer.Types;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
namespace LBPUnion.ProjectLighthouse.Servers.GameServer.Controllers;
|
||||
|
||||
[ApiController]
|
||||
[Authorize]
|
||||
[Route("LITTLEBIGPLANETPS3_XML/")]
|
||||
[Produces("text/xml")]
|
||||
public class StoreController : Controller
|
||||
public class StoreController : GameController
|
||||
{
|
||||
[HttpGet("promotions")]
|
||||
public IActionResult Promotions() => this.Ok();
|
||||
|
|
|
@ -4,6 +4,7 @@ using LBPUnion.ProjectLighthouse.Extensions;
|
|||
using LBPUnion.ProjectLighthouse.Files;
|
||||
using LBPUnion.ProjectLighthouse.Logging;
|
||||
using LBPUnion.ProjectLighthouse.Servers.GameServer.Helpers;
|
||||
using LBPUnion.ProjectLighthouse.Servers.GameServer.Types;
|
||||
using LBPUnion.ProjectLighthouse.Servers.GameServer.Types.Users;
|
||||
using LBPUnion.ProjectLighthouse.Types.Entities.Level;
|
||||
using LBPUnion.ProjectLighthouse.Types.Entities.Profile;
|
||||
|
@ -12,17 +13,12 @@ using LBPUnion.ProjectLighthouse.Types.Levels;
|
|||
using LBPUnion.ProjectLighthouse.Types.Logging;
|
||||
using LBPUnion.ProjectLighthouse.Types.Serialization;
|
||||
using LBPUnion.ProjectLighthouse.Types.Users;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace LBPUnion.ProjectLighthouse.Servers.GameServer.Controllers;
|
||||
|
||||
[ApiController]
|
||||
[Authorize]
|
||||
[Route("LITTLEBIGPLANETPS3_XML/")]
|
||||
[Produces("text/xml")]
|
||||
public class UserController : ControllerBase
|
||||
public class UserController : GameController
|
||||
{
|
||||
private readonly DatabaseContext database;
|
||||
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
using LBPUnion.ProjectLighthouse.Configuration;
|
||||
using LBPUnion.ProjectLighthouse.Extensions;
|
||||
using LBPUnion.ProjectLighthouse.Helpers;
|
||||
using LBPUnion.ProjectLighthouse.Middlewares;
|
||||
|
@ -10,13 +9,6 @@ namespace LBPUnion.ProjectLighthouse.Servers.GameServer.Middlewares;
|
|||
|
||||
public class DigestMiddleware : Middleware
|
||||
{
|
||||
private readonly bool computeDigests;
|
||||
|
||||
public DigestMiddleware(RequestDelegate next, bool computeDigests) : base(next)
|
||||
{
|
||||
this.computeDigests = computeDigests;
|
||||
}
|
||||
|
||||
private readonly List<string> digestKeys;
|
||||
|
||||
public DigestMiddleware(RequestDelegate next, List<string> digestKeys) : base(next)
|
||||
|
@ -54,61 +46,59 @@ public class DigestMiddleware : Middleware
|
|||
|
||||
public override async Task InvokeAsync(HttpContext context)
|
||||
{
|
||||
UseDigestAttribute? digestAttribute = context.GetEndpoint()?.Metadata.OfType<UseDigestAttribute>().FirstOrDefault();
|
||||
// If no digest keys are supplied, then we can't do anything
|
||||
if (this.digestKeys.Count == 0)
|
||||
{
|
||||
await this.next(context);
|
||||
return;
|
||||
}
|
||||
|
||||
UseDigestAttribute? digestAttribute = context.GetEndpoint()?.Metadata.GetMetadata<UseDigestAttribute>();
|
||||
if (digestAttribute == null)
|
||||
{
|
||||
await this.next(context);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!context.Request.Cookies.TryGetValue("MM_AUTH", out string? authCookie))
|
||||
{
|
||||
context.Response.StatusCode = 403;
|
||||
return;
|
||||
}
|
||||
if (!context.Request.Cookies.TryGetValue("MM_AUTH", out string? authCookie)) authCookie = string.Empty;
|
||||
|
||||
string digestPath = context.Request.Path;
|
||||
|
||||
byte[] bodyBytes = await context.Request.BodyReader.ReadAllAsync();
|
||||
|
||||
if (!context.Request.Headers.TryGetValue(digestAttribute.DigestHeaderName, out StringValues digestHeaders) ||
|
||||
digestHeaders.Count != 1 && digestAttribute.EnforceDigest)
|
||||
if ((!context.Request.Headers.TryGetValue(digestAttribute.DigestHeaderName, out StringValues digestHeaders) ||
|
||||
digestHeaders.Count != 1) && digestAttribute.EnforceDigest)
|
||||
{
|
||||
context.Response.StatusCode = 403;
|
||||
return;
|
||||
}
|
||||
|
||||
string? clientDigest = digestHeaders[0];
|
||||
string? clientDigest = digestHeaders.FirstOrDefault() ?? null;
|
||||
|
||||
string? matchingDigestKey = null;
|
||||
string? calculatedRequestDigest = null;
|
||||
|
||||
if (clientDigest != null)
|
||||
{
|
||||
foreach (string digestKey in this.digestKeys)
|
||||
{
|
||||
string calculatedDigest = CryptoHelper.ComputeDigest(digestPath,
|
||||
authCookie,
|
||||
bodyBytes,
|
||||
digestKey,
|
||||
digestAttribute.ExcludeBodyFromDigest);
|
||||
string calculatedDigest = CalculateDigest(digestKey, bodyBytes);
|
||||
if (calculatedDigest != clientDigest) continue;
|
||||
|
||||
matchingDigestKey = digestKey;
|
||||
calculatedRequestDigest = calculatedDigest;
|
||||
}
|
||||
}
|
||||
|
||||
matchingDigestKey ??= this.digestKeys.First();
|
||||
|
||||
switch (matchingDigestKey)
|
||||
switch (calculatedRequestDigest)
|
||||
{
|
||||
case null when digestAttribute.EnforceDigest:
|
||||
context.Response.StatusCode = 403;
|
||||
return;
|
||||
case null:
|
||||
calculatedRequestDigest = CryptoHelper.ComputeDigest(digestPath,
|
||||
authCookie,
|
||||
bodyBytes,
|
||||
matchingDigestKey,
|
||||
digestAttribute.ExcludeBodyFromDigest);
|
||||
calculatedRequestDigest = CalculateDigest(matchingDigestKey, bodyBytes);
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -124,17 +114,21 @@ public class DigestMiddleware : Middleware
|
|||
|
||||
await HandleResponseCompression(context, responseBuffer);
|
||||
|
||||
string responseDigest = CryptoHelper.ComputeDigest(digestPath,
|
||||
authCookie,
|
||||
responseBuffer.ToArray(),
|
||||
matchingDigestKey,
|
||||
digestAttribute.ExcludeBodyFromDigest);
|
||||
string responseDigest = CalculateDigest(matchingDigestKey, responseBuffer.ToArray());
|
||||
|
||||
context.Response.Headers.Append("X-Digest-A", responseDigest);
|
||||
|
||||
responseBuffer.Position = 0;
|
||||
await responseBuffer.CopyToAsync(originalBody);
|
||||
context.Response.Body = originalBody;
|
||||
return;
|
||||
|
||||
string CalculateDigest(string digestKey, byte[] data) =>
|
||||
CryptoHelper.ComputeDigest(digestPath,
|
||||
authCookie,
|
||||
data,
|
||||
digestKey,
|
||||
digestAttribute.ExcludeBodyFromDigest);
|
||||
}
|
||||
|
||||
}
|
|
@ -84,8 +84,6 @@ public class GameServerStartup
|
|||
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
|
||||
public virtual void Configure(IApplicationBuilder app, IWebHostEnvironment env)
|
||||
{
|
||||
bool computeDigests = true;
|
||||
|
||||
if (string.IsNullOrEmpty(ServerConfiguration.Instance.DigestKey.PrimaryDigestKey))
|
||||
{
|
||||
Logger.Warn
|
||||
|
@ -94,7 +92,6 @@ public class GameServerStartup
|
|||
"To increase security, it is recommended that you find and set this variable.",
|
||||
LogArea.Startup
|
||||
);
|
||||
computeDigests = false;
|
||||
}
|
||||
|
||||
#if DEBUG
|
||||
|
@ -105,11 +102,17 @@ public class GameServerStartup
|
|||
|
||||
app.UseMiddleware<RequestLogMiddleware>();
|
||||
app.UseMiddleware<RateLimitMiddleware>();
|
||||
app.UseMiddleware<DigestMiddleware>(computeDigests);
|
||||
app.UseMiddleware<SetLastContactMiddleware>();
|
||||
|
||||
app.UseRouting();
|
||||
|
||||
List<string> digestKeys =
|
||||
[
|
||||
ServerConfiguration.Instance.DigestKey.PrimaryDigestKey,
|
||||
ServerConfiguration.Instance.DigestKey.AlternateDigestKey,
|
||||
];
|
||||
app.UseMiddleware<DigestMiddleware>(digestKeys);
|
||||
|
||||
app.UseAuthorization();
|
||||
|
||||
app.UseEndpoints(endpoints => endpoints.MapControllers());
|
||||
|
|
11
ProjectLighthouse.Servers.GameServer/Types/GameController.cs
Normal file
11
ProjectLighthouse.Servers.GameServer/Types/GameController.cs
Normal file
|
@ -0,0 +1,11 @@
|
|||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
namespace LBPUnion.ProjectLighthouse.Servers.GameServer.Types;
|
||||
|
||||
[ApiController]
|
||||
[Authorize]
|
||||
[UseDigest]
|
||||
[Route("LITTLEBIGPLANETPS3_XML/")]
|
||||
[Produces("text/xml")]
|
||||
public class GameController : ControllerBase;
|
|
@ -7,5 +7,5 @@ public class UseDigestAttribute : Attribute
|
|||
|
||||
public string DigestHeaderName { get; set; } = "X-Digest-A";
|
||||
|
||||
public bool ExcludeBodyFromDigest { get; set; } = false;
|
||||
public bool ExcludeBodyFromDigest { get; set; }
|
||||
}
|
|
@ -14,9 +14,8 @@ namespace ProjectLighthouse.Tests.GameApiTests.Unit.Middlewares;
|
|||
[Trait("Category", "Unit")]
|
||||
public class DigestMiddlewareTests
|
||||
{
|
||||
//TODO: fix remaining unit tests
|
||||
private static DefaultHttpContext GetHttpContext
|
||||
(Stream body, string path, string cookie, Dictionary<string, StringValues>? extraHeaders = null)
|
||||
(Stream body, string path, string cookie, Dictionary<string, StringValues>? extraHeaders = null, UseDigestAttribute? digestAttribute = null)
|
||||
{
|
||||
|
||||
DefaultHttpContext context = new()
|
||||
|
@ -28,15 +27,21 @@ public class DigestMiddlewareTests
|
|||
Headers =
|
||||
{
|
||||
KeyValuePair.Create<string, StringValues>("Cookie", cookie),
|
||||
}
|
||||
},
|
||||
},
|
||||
};
|
||||
if (extraHeaders == null) return context;
|
||||
|
||||
if (extraHeaders != null)
|
||||
{
|
||||
foreach ((string key, StringValues value) in extraHeaders)
|
||||
{
|
||||
context.Request.Headers.Append(key, value);
|
||||
}
|
||||
}
|
||||
|
||||
if (digestAttribute != null)
|
||||
{
|
||||
context.SetEndpoint(new Endpoint(null, new EndpointMetadataCollection(digestAttribute), null));
|
||||
}
|
||||
|
||||
return context;
|
||||
}
|
||||
|
@ -45,7 +50,6 @@ public class DigestMiddlewareTests
|
|||
public async Task DigestMiddleware_ShouldNotComputeDigests_WithoutDigestAttribute()
|
||||
{
|
||||
DefaultHttpContext context = GetHttpContext(new MemoryStream(), "/LITTLEBIGPLANETPS3_XML/notification", "MM_AUTH=unittest");
|
||||
context.SetEndpoint(new Endpoint(null, new EndpointMetadataCollection(), null));
|
||||
DigestMiddleware middleware = new(httpContext =>
|
||||
{
|
||||
httpContext.Response.StatusCode = 200;
|
||||
|
@ -65,8 +69,11 @@ public class DigestMiddlewareTests
|
|||
[Fact]
|
||||
public async Task DigestMiddleware_ShouldReject_WhenDigestHeaderIsMissing()
|
||||
{
|
||||
DefaultHttpContext context = GetHttpContext(new MemoryStream(), "/LITTLEBIGPLANETPS3_XML/notification", "MM_AUTH=unittest");
|
||||
context.SetEndpoint(new Endpoint(null, new EndpointMetadataCollection(new UseDigestAttribute()), null));
|
||||
DefaultHttpContext context = GetHttpContext(new MemoryStream(),
|
||||
"/LITTLEBIGPLANETPS3_XML/notification",
|
||||
"MM_AUTH=unittest",
|
||||
null,
|
||||
new UseDigestAttribute());
|
||||
DigestMiddleware middleware = new(httpContext =>
|
||||
{
|
||||
httpContext.Response.StatusCode = 200;
|
||||
|
@ -79,8 +86,7 @@ public class DigestMiddlewareTests
|
|||
|
||||
const int expectedCode = 403;
|
||||
|
||||
Assert.True(expectedCode == context.Response.StatusCode,
|
||||
"The digest middleware accepted the request when it shouldn't have (are you running this test in Debug mode?)");
|
||||
Assert.Equal(expectedCode, context.Response.StatusCode);
|
||||
Assert.False(context.Response.Headers.TryGetValue("X-Digest-A", out _));
|
||||
Assert.False(context.Response.Headers.TryGetValue("X-Digest-B", out _));
|
||||
}
|
||||
|
@ -96,8 +102,8 @@ public class DigestMiddlewareTests
|
|||
{
|
||||
"X-Digest-A", "invalid_digest"
|
||||
},
|
||||
});
|
||||
context.SetEndpoint(new Endpoint(null, new EndpointMetadataCollection(new UseDigestAttribute()), null));
|
||||
},
|
||||
new UseDigestAttribute());
|
||||
DigestMiddleware middleware = new(httpContext =>
|
||||
{
|
||||
httpContext.Response.StatusCode = 200;
|
||||
|
@ -126,7 +132,8 @@ public class DigestMiddlewareTests
|
|||
{
|
||||
"X-Digest-A", "df619790a2579a077eae4a6b6864966ff4768723"
|
||||
},
|
||||
});
|
||||
},
|
||||
new UseDigestAttribute());
|
||||
|
||||
DigestMiddleware middleware = new(httpContext =>
|
||||
{
|
||||
|
@ -134,7 +141,7 @@ public class DigestMiddlewareTests
|
|||
httpContext.Response.WriteAsync("");
|
||||
return Task.CompletedTask;
|
||||
},
|
||||
["test, bruh",]);
|
||||
["test", "bruh",]);
|
||||
|
||||
await middleware.InvokeAsync(context);
|
||||
|
||||
|
@ -150,20 +157,16 @@ public class DigestMiddlewareTests
|
|||
}
|
||||
|
||||
[Fact]
|
||||
public async Task DigestMiddleware_ShouldNotReject_WhenRequestingAnnounce()
|
||||
public async Task DigestMiddleware_ShouldNotReject_WhenNotEnforcingDigest()
|
||||
{
|
||||
DefaultHttpContext context = new()
|
||||
DefaultHttpContext context = GetHttpContext(new MemoryStream(),
|
||||
"/LITTLEBIGPLANETPS3_XML/announce",
|
||||
"MM_AUTH=unittest",
|
||||
new Dictionary<string, StringValues>(),
|
||||
new UseDigestAttribute
|
||||
{
|
||||
Request =
|
||||
{
|
||||
Body = new MemoryStream(),
|
||||
Path = "/LITTLEBIGPLANETPS3_XML/announce",
|
||||
Headers =
|
||||
{
|
||||
KeyValuePair.Create<string, StringValues>("Cookie", "MM_AUTH=unittest"),
|
||||
},
|
||||
},
|
||||
};
|
||||
EnforceDigest = false,
|
||||
});
|
||||
|
||||
DigestMiddleware middleware = new(httpContext =>
|
||||
{
|
||||
|
@ -189,18 +192,16 @@ public class DigestMiddlewareTests
|
|||
[Fact]
|
||||
public async Task DigestMiddleware_ShouldCalculate_WhenAuthCookieEmpty()
|
||||
{
|
||||
DefaultHttpContext context = new()
|
||||
DefaultHttpContext context = GetHttpContext(new MemoryStream(),
|
||||
"/LITTLEBIGPLANETPS3_XML/notification",
|
||||
"",
|
||||
new Dictionary<string, StringValues>
|
||||
{
|
||||
Request =
|
||||
{
|
||||
Body = new MemoryStream(),
|
||||
Path = "/LITTLEBIGPLANETPS3_XML/notification",
|
||||
Headers =
|
||||
{
|
||||
KeyValuePair.Create<string, StringValues>("X-Digest-A", "0a06d25662c2d3bab2a767c0c504898df2385e62"),
|
||||
"X-Digest-A", "0a06d25662c2d3bab2a767c0c504898df2385e62"
|
||||
},
|
||||
},
|
||||
};
|
||||
new UseDigestAttribute());
|
||||
|
||||
DigestMiddleware middleware = new(httpContext =>
|
||||
{
|
||||
|
@ -226,19 +227,16 @@ public class DigestMiddlewareTests
|
|||
[Fact]
|
||||
public async Task DigestMiddleware_ShouldComputeDigestsWithNoBody_WhenDigestsEnabled()
|
||||
{
|
||||
DefaultHttpContext context = new()
|
||||
DefaultHttpContext context = GetHttpContext(new MemoryStream(),
|
||||
"/LITTLEBIGPLANETPS3_XML/notification",
|
||||
"MM_AUTH=unittest",
|
||||
new Dictionary<string, StringValues>
|
||||
{
|
||||
Request =
|
||||
{
|
||||
Body = new MemoryStream(),
|
||||
Path = "/LITTLEBIGPLANETPS3_XML/notification",
|
||||
Headers =
|
||||
{
|
||||
KeyValuePair.Create<string, StringValues>("Cookie", "MM_AUTH=unittest"),
|
||||
KeyValuePair.Create<string, StringValues>("X-Digest-A", "df619790a2579a077eae4a6b6864966ff4768723"),
|
||||
"X-Digest-A", "df619790a2579a077eae4a6b6864966ff4768723"
|
||||
},
|
||||
},
|
||||
};
|
||||
new UseDigestAttribute());
|
||||
|
||||
DigestMiddleware middleware = new(httpContext =>
|
||||
{
|
||||
|
@ -264,19 +262,16 @@ public class DigestMiddlewareTests
|
|||
[Fact]
|
||||
public async Task DigestMiddleware_ShouldComputeDigestsWithBody_WhenDigestsEnabled_AndNoResponseBody()
|
||||
{
|
||||
DefaultHttpContext context = new()
|
||||
DefaultHttpContext context = GetHttpContext(new MemoryStream("digest test"u8.ToArray()),
|
||||
"/LITTLEBIGPLANETPS3_XML/filter",
|
||||
"MM_AUTH=unittest",
|
||||
new Dictionary<string, StringValues>
|
||||
{
|
||||
Request =
|
||||
{
|
||||
Body = new MemoryStream("digest test"u8.ToArray()),
|
||||
Path = "/LITTLEBIGPLANETPS3_XML/filter",
|
||||
Headers =
|
||||
{
|
||||
KeyValuePair.Create<string, StringValues>("Cookie", "MM_AUTH=unittest"),
|
||||
KeyValuePair.Create<string, StringValues>("X-Digest-A", "3105059f9283773f7982a4d79455bcc97c330f10"),
|
||||
"X-Digest-A", "3105059f9283773f7982a4d79455bcc97c330f10"
|
||||
},
|
||||
},
|
||||
};
|
||||
new UseDigestAttribute());
|
||||
|
||||
DigestMiddleware middleware = new(httpContext =>
|
||||
{
|
||||
|
@ -302,19 +297,17 @@ public class DigestMiddlewareTests
|
|||
[Fact]
|
||||
public async Task DigestMiddleware_ShouldComputeDigestsWithBody_WhenDigestsEnabled_AndResponseBody()
|
||||
{
|
||||
DefaultHttpContext context = new()
|
||||
DefaultHttpContext context = GetHttpContext(new MemoryStream("digest test"u8.ToArray()),
|
||||
"/LITTLEBIGPLANETPS3_XML/filter",
|
||||
"MM_AUTH=unittest",
|
||||
new Dictionary<string, StringValues>
|
||||
{
|
||||
Request =
|
||||
{
|
||||
Body = new MemoryStream("digest test"u8.ToArray()),
|
||||
Path = "/LITTLEBIGPLANETPS3_XML/filter",
|
||||
Headers =
|
||||
{
|
||||
KeyValuePair.Create<string, StringValues>("Cookie", "MM_AUTH=unittest"),
|
||||
KeyValuePair.Create<string, StringValues>("X-Digest-A", "3105059f9283773f7982a4d79455bcc97c330f10"),
|
||||
"X-Digest-A", "3105059f9283773f7982a4d79455bcc97c330f10"
|
||||
},
|
||||
},
|
||||
};
|
||||
new UseDigestAttribute());
|
||||
|
||||
DigestMiddleware middleware = new(httpContext =>
|
||||
{
|
||||
httpContext.Response.StatusCode = 200;
|
||||
|
@ -337,21 +330,24 @@ public class DigestMiddlewareTests
|
|||
}
|
||||
|
||||
[Fact]
|
||||
public async Task DigestMiddleware_ShouldComputeDigestsWithBody_WhenUploading()
|
||||
public async Task DigestMiddleware_ShouldExcludeBody_WithAttributeSetting()
|
||||
{
|
||||
DefaultHttpContext context = new()
|
||||
DefaultHttpContext context = GetHttpContext(new MemoryStream("digest test"u8.ToArray()),
|
||||
"/LITTLEBIGPLANETPS3_XML/upload/unittesthash",
|
||||
"MM_AUTH=unittest",
|
||||
new Dictionary<string, StringValues>
|
||||
{
|
||||
Request =
|
||||
{
|
||||
Body = new MemoryStream("digest test"u8.ToArray()),
|
||||
Path = "/LITTLEBIGPLANETPS3_XML/upload/unittesthash",
|
||||
Headers =
|
||||
{
|
||||
KeyValuePair.Create<string, StringValues>("Cookie", "MM_AUTH=unittest"),
|
||||
KeyValuePair.Create<string, StringValues>("X-Digest-B", "2e54cd2bc69ff8c1ff85dd3b4f62e0a0e27d9e23"),
|
||||
"X-Digest-B", "2e54cd2bc69ff8c1ff85dd3b4f62e0a0e27d9e23"
|
||||
},
|
||||
},
|
||||
};
|
||||
new UseDigestAttribute
|
||||
{
|
||||
DigestHeaderName = "X-Digest-B",
|
||||
ExcludeBodyFromDigest = true,
|
||||
});
|
||||
|
||||
|
||||
DigestMiddleware middleware = new(httpContext =>
|
||||
{
|
||||
httpContext.Response.StatusCode = 200;
|
||||
|
@ -394,6 +390,8 @@ public class DigestMiddlewareTests
|
|||
},
|
||||
},
|
||||
};
|
||||
context.SetEndpoint(new Endpoint(null, new EndpointMetadataCollection(new UseDigestAttribute()), null));
|
||||
|
||||
DigestMiddleware middleware = new(httpContext =>
|
||||
{
|
||||
httpContext.Response.StatusCode = 200;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue