Skip to content

Commit

Permalink
Reject uploads with invalid LastReviewTime (#1387)
Browse files Browse the repository at this point in the history
  • Loading branch information
karashiiro authored Nov 25, 2024
1 parent 9d56946 commit f7b2aec
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,27 @@ public void Behavior_DoesNotRun_WithInvalidStackSizeSales()
Assert.False(test.Behavior.ShouldExecute(upload));
}

[Theory]
[InlineData(0L)]
[InlineData(-1L)]
[InlineData(null)]
public void Behavior_DoesNotRun_WithInvalidReviewTimeListings(long? lastReviewTimeUnixSeconds)
{
var test = TestResources.Create();

var (listings, _) = SchemaSeedDataGenerator.GetUploadListingsAndSales(74, 5333);
listings[0].LastReviewTimeUnixSeconds = lastReviewTimeUnixSeconds;

var upload = new UploadParameters
{
WorldId = 74,
ItemId = 5333,
UploaderId = "5627384655756342554",
Listings = listings,
};
Assert.False(test.Behavior.ShouldExecute(upload));
}

[Fact]
public void Behavior_DoesNotRun_WithInvalidStackSizeListings()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,10 +97,7 @@ public async Task<IActionResult> Execute(ApiKey source, UploadParameters paramet

if (parameters.Listings != null)
{
if (parameters.Listings.Any(l =>
Util.HasHtmlTags(l.ListingId) || Util.HasHtmlTags(l.RetainerName) ||
Util.HasHtmlTags(l.RetainerId) || Util.HasHtmlTags(l.CreatorName) || Util.HasHtmlTags(l.SellerId) ||
Util.HasHtmlTags(l.CreatorId)))
if (parameters.Listings.Any(IsInvalid))
{
return new BadRequestResult();
}
Expand All @@ -111,6 +108,20 @@ public async Task<IActionResult> Execute(ApiKey source, UploadParameters paramet
return null;
}

private static bool IsInvalid(Universalis.Application.Uploads.Schema.Listing l)
{
// Listings can be up for at most 7 days - checking against 8 to give some buffer
var lastReviewTime = DateTimeOffset.FromUnixTimeSeconds(l.LastReviewTimeUnixSeconds ?? 0).UtcDateTime;
if ((DateTime.UtcNow - lastReviewTime).TotalDays >= 8)
{
return false;
}

return Util.HasHtmlTags(l.ListingId) || Util.HasHtmlTags(l.RetainerName) ||
Util.HasHtmlTags(l.RetainerId) || Util.HasHtmlTags(l.CreatorName) || Util.HasHtmlTags(l.SellerId) ||
Util.HasHtmlTags(l.CreatorId);
}

private async Task HandleListings(IList<Schema.Listing> uploadedListings, int itemId, int worldId,
ApiKey source, CancellationToken cancellationToken = default)
{
Expand Down
2 changes: 1 addition & 1 deletion src/Universalis.Application/Uploads/Schema/Listing.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public string CreatorId
public int? DyeId { get; init; }

[JsonPropertyName("lastReviewTime")]
public long? LastReviewTimeUnixSeconds { get; init; }
public long? LastReviewTimeUnixSeconds { get; set; }

[JsonPropertyName("materia")]
public List<Materia> Materia { get; init; }
Expand Down

0 comments on commit f7b2aec

Please sign in to comment.