Activity protection
Some checks failed
Dotnet build and test / log-the-inputs (push) Has been cancelled
Dotnet build and test / build (push) Has been cancelled

This commit is contained in:
Paul Schneider 2026-08-10 18:12:59 +01:00
commit 44b391d496
No known key found for this signature in database
GPG key ID: 1E66C65EE2B46F1B
6 changed files with 42 additions and 7 deletions

View file

@ -11,5 +11,6 @@
from without conflicting names. from without conflicting names.
--> -->
<UseProjectNamespaceForGitVersionInformation>true</UseProjectNamespaceForGitVersionInformation> <UseProjectNamespaceForGitVersionInformation>true</UseProjectNamespaceForGitVersionInformation>
<NoWarn>NU1701, NU1901, NU1902</NoWarn>
</PropertyGroup> </PropertyGroup>
</Project> </Project>

View file

@ -15,7 +15,6 @@ namespace Yavsc.Controllers
{ {
[Produces("application/json")] [Produces("application/json")]
[Route("api/activity")] [Route("api/activity")]
[AllowAnonymous]
public class ActivityApiController : Controller public class ActivityApiController : Controller
{ {
private ApplicationDbContext _context; private ApplicationDbContext _context;
@ -88,7 +87,7 @@ namespace Yavsc.Controllers
} }
// POST: api/ActivityApi // POST: api/ActivityApi
[HttpPost,Authorize("AdministratorOnly")] [HttpPost, Authorize("AdministratorOnly")]
public async Task<IActionResult> PostActivity([FromBody] Activity activity) public async Task<IActionResult> PostActivity([FromBody] Activity activity)
{ {
if (!ModelState.IsValid) if (!ModelState.IsValid)

View file

@ -1,15 +1,15 @@
 
using System;
using System.Linq;
using System.Security.Claims; using System.Security.Claims;
using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;
using Yavsc.Helpers;
using Yavsc.Models; using Yavsc.Models;
using Yavsc.Models.Identity; using Yavsc.Models.Identity;
using Yavsc.Server.Helpers; using Yavsc.Server.Helpers;
#nullable enable
[Authorize, Route("~/api/gcm")] [Authorize, Route("~/api/gcm")]
public class NativeConfidentialController : Controller public class NativeConfidentialController : Controller
{ {

View file

@ -148,6 +148,38 @@ public sealed class BlogApiTests : IClassFixture<BlogsWebServerFixture>
Assert.Equal(created.Id, doc.RootElement[0].GetProperty("id").GetInt64()); Assert.Equal(created.Id, doc.RootElement[0].GetProperty("id").GetInt64());
} }
[Fact]
public async Task PostBlog_sets_AuthorId_on_created_post_and_list_entry()
{
ResetDatabase();
using var http = NewClient(subject: "tester");
var draft = new BlogPost
{
Id = 0,
Title = "Billet avec auteur",
AuthorId = "payload-attacker",
Article = "Contenu de test.",
DateCreated = DateTime.UtcNow,
DateModified = DateTime.UtcNow
};
var postResponse = await http.PostAsJsonAsync("/api/v1/blog", draft);
Assert.Equal(HttpStatusCode.Created, postResponse.StatusCode);
var created = await postResponse.Content.ReadFromJsonAsync<BlogPost>();
Assert.NotNull(created);
Assert.Equal("tester", created!.AuthorId);
var listResponse = await http.GetAsync("/api/v1/blog");
Assert.Equal(HttpStatusCode.OK, listResponse.StatusCode);
using var doc = JsonDocument.Parse(await listResponse.Content.ReadAsStringAsync());
Assert.Equal(JsonValueKind.Array, doc.RootElement.ValueKind);
Assert.Equal(1, doc.RootElement.GetArrayLength());
Assert.Equal("tester", doc.RootElement[0].GetProperty("authorId").GetString());
}
[Fact] [Fact]
public async Task GetBlog_returns_401_when_no_token_is_provided() public async Task GetBlog_returns_401_when_no_token_is_provided()
{ {

View file

@ -1189,6 +1189,8 @@ ADD COLUMN IF NOT EXISTS ""Moderated"" boolean NOT NULL DEFAULT FALSE;");
} }
} }
#nullable enable
static void LoadGoogleConfig(IConfigurationRoot configuration) static void LoadGoogleConfig(IConfigurationRoot configuration)
{ {
string? googleClientFile = configuration["Authentication:Google:GoogleWebClientJson"]; string? googleClientFile = configuration["Authentication:Google:GoogleWebClientJson"];
@ -1204,6 +1206,7 @@ ADD COLUMN IF NOT EXISTS ""Moderated"" boolean NOT NULL DEFAULT FALSE;");
Config.GServiceAccount = JsonConvert.DeserializeObject<GoogleServiceAccount>(safile.OpenText().ReadToEnd()); Config.GServiceAccount = JsonConvert.DeserializeObject<GoogleServiceAccount>(safile.OpenText().ReadToEnd());
} }
} }
#nullable disable
public static IApplicationBuilder ConfigureFileServerApp(this IApplicationBuilder app, public static IApplicationBuilder ConfigureFileServerApp(this IApplicationBuilder app,
bool enableDirectoryBrowsing = false) bool enableDirectoryBrowsing = false)

View file

@ -197,7 +197,7 @@ namespace Yavsc.Services
if (credential.IsCreateScopedRequired) if (credential.IsCreateScopedRequired)
{ {
credential = credential.CreateScoped(scopesCalendar); credential = credential.CreateScoped(scopesCalendar);
}/* }/*
var credential = await GoogleHelpers.GetCredentialForApi(new string [] { scopeCalendar }); var credential = await GoogleHelpers.GetCredentialForApi(new string [] { scopeCalendar });
if (credential.IsCreateScopedRequired) if (credential.IsCreateScopedRequired)
{ {