Skip to content

Commit

Permalink
Fix incoming status creation date not being restricted to standard IS…
Browse files Browse the repository at this point in the history
…O8601 (mastodon#27655)
  • Loading branch information
ClearlyClaire authored and vmstan committed Dec 14, 2023
1 parent d7bdda3 commit 97a42d2
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 6 deletions.
3 changes: 2 additions & 1 deletion app/lib/activitypub/parser/status_parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ def title
end

def created_at
@object['published']&.to_datetime
datetime = @object['published']&.to_datetime
datetime if datetime.present? && (0..9999).cover?(datetime.year)
rescue ArgumentError
nil
end
Expand Down
48 changes: 43 additions & 5 deletions spec/lib/activitypub/activity/create_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -134,29 +134,67 @@ def activity_for_object(json)
subject.perform
end

context 'when object has been edited' do
context 'when object publication date is below ISO8601 range' do
let(:object_json) do
{
id: [ActivityPub::TagManager.instance.uri_for(sender), '#bar'].join,
type: 'Note',
content: 'Lorem ipsum',
published: '2022-01-22T15:00:00Z',
updated: '2022-01-22T16:00:00Z',
published: '-0977-11-03T08:31:22Z',
}
end

it 'creates status' do
it 'creates status with a valid creation date', :aggregate_failures do
status = sender.statuses.first

expect(status).to_not be_nil
expect(status.text).to eq 'Lorem ipsum'

expect(status.created_at).to be_within(30).of(Time.now.utc)
end
end

context 'when object publication date is above ISO8601 range' do
let(:object_json) do
{
id: [ActivityPub::TagManager.instance.uri_for(sender), '#bar'].join,
type: 'Note',
content: 'Lorem ipsum',
published: '10000-11-03T08:31:22Z',
}
end

it 'creates status with a valid creation date', :aggregate_failures do
status = sender.statuses.first

expect(status).to_not be_nil
expect(status.text).to eq 'Lorem ipsum'

expect(status.created_at).to be_within(30).of(Time.now.utc)
end
end

context 'when object has been edited' do
let(:object_json) do
{
id: [ActivityPub::TagManager.instance.uri_for(sender), '#bar'].join,
type: 'Note',
content: 'Lorem ipsum',
published: '2022-01-22T15:00:00Z',
updated: '2022-01-22T16:00:00Z',
}
end

it 'marks status as edited' do
it 'creates status with appropriate creation and edition dates', :aggregate_failures do
status = sender.statuses.first

expect(status).to_not be_nil
expect(status.text).to eq 'Lorem ipsum'

expect(status.created_at).to eq '2022-01-22T15:00:00Z'.to_datetime

expect(status.edited?).to be true
expect(status.edited_at).to eq '2022-01-22T16:00:00Z'.to_datetime
end
end

Expand Down

0 comments on commit 97a42d2

Please sign in to comment.