Remove WebSub subscriptions (#11303)
This commit is contained in:
parent
4bd58b7f2d
commit
bd87e66679
14 changed files with 14 additions and 203 deletions
|
@ -1,7 +0,0 @@
|
|||
Fabricator(:subscription) do
|
||||
account
|
||||
callback_url "http://example.com/callback"
|
||||
secret "foobar"
|
||||
expires_at "2016-11-28 11:30:07"
|
||||
confirmed false
|
||||
end
|
|
@ -1,67 +0,0 @@
|
|||
require 'rails_helper'
|
||||
|
||||
RSpec.describe Subscription, type: :model do
|
||||
let(:alice) { Fabricate(:account, username: 'alice') }
|
||||
|
||||
subject { Fabricate(:subscription, account: alice) }
|
||||
|
||||
describe '#expired?' do
|
||||
it 'return true when expires_at is past' do
|
||||
subject.expires_at = 2.days.ago
|
||||
expect(subject.expired?).to be true
|
||||
end
|
||||
|
||||
it 'return false when expires_at is future' do
|
||||
subject.expires_at = 2.days.from_now
|
||||
expect(subject.expired?).to be false
|
||||
end
|
||||
end
|
||||
|
||||
describe 'lease_seconds' do
|
||||
it 'returns the time remaining until expiration' do
|
||||
datetime = 1.day.from_now
|
||||
subscription = Subscription.new(expires_at: datetime)
|
||||
travel_to(datetime - 12.hours) do
|
||||
expect(subscription.lease_seconds).to eq(12.hours)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe 'lease_seconds=' do
|
||||
it 'sets expires_at to min expiration when small value is provided' do
|
||||
subscription = Subscription.new
|
||||
datetime = 1.day.from_now
|
||||
too_low = Subscription::MIN_EXPIRATION - 1000
|
||||
travel_to(datetime) do
|
||||
subscription.lease_seconds = too_low
|
||||
end
|
||||
|
||||
expected = datetime + Subscription::MIN_EXPIRATION.seconds
|
||||
expect(subscription.expires_at).to be_within(1.0).of(expected)
|
||||
end
|
||||
|
||||
it 'sets expires_at to value when valid value is provided' do
|
||||
subscription = Subscription.new
|
||||
datetime = 1.day.from_now
|
||||
valid = Subscription::MIN_EXPIRATION + 1000
|
||||
travel_to(datetime) do
|
||||
subscription.lease_seconds = valid
|
||||
end
|
||||
|
||||
expected = datetime + valid.seconds
|
||||
expect(subscription.expires_at).to be_within(1.0).of(expected)
|
||||
end
|
||||
|
||||
it 'sets expires_at to max expiration when large value is provided' do
|
||||
subscription = Subscription.new
|
||||
datetime = 1.day.from_now
|
||||
too_high = Subscription::MAX_EXPIRATION + 1000
|
||||
travel_to(datetime) do
|
||||
subscription.lease_seconds = too_high
|
||||
end
|
||||
|
||||
expected = datetime + Subscription::MAX_EXPIRATION.seconds
|
||||
expect(subscription.expires_at).to be_within(1.0).of(expected)
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,24 +0,0 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
require 'rails_helper'
|
||||
require 'pundit/rspec'
|
||||
|
||||
RSpec.describe SubscriptionPolicy do
|
||||
let(:subject) { described_class }
|
||||
let(:admin) { Fabricate(:user, admin: true).account }
|
||||
let(:john) { Fabricate(:user).account }
|
||||
|
||||
permissions :index? do
|
||||
context 'admin?' do
|
||||
it 'permits' do
|
||||
expect(subject).to permit(admin, Subscription)
|
||||
end
|
||||
end
|
||||
|
||||
context '!admin?' do
|
||||
it 'denies' do
|
||||
expect(subject).to_not permit(john, Subscription)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -14,11 +14,8 @@ RSpec.describe BatchedRemoveStatusService, type: :service do
|
|||
before do
|
||||
allow(Redis.current).to receive_messages(publish: nil)
|
||||
|
||||
stub_request(:post, 'http://example.com/push').to_return(status: 200, body: '', headers: {})
|
||||
stub_request(:post, 'http://example.com/salmon').to_return(status: 200, body: '', headers: {})
|
||||
stub_request(:post, 'http://example.com/inbox').to_return(status: 200)
|
||||
|
||||
Fabricate(:subscription, account: alice, callback_url: 'http://example.com/push', confirmed: true, expires_at: 30.days.from_now)
|
||||
jeff.user.update(current_sign_in_at: Time.zone.now)
|
||||
jeff.follow!(alice)
|
||||
hank.follow!(alice)
|
||||
|
|
|
@ -10,12 +10,9 @@ RSpec.describe RemoveStatusService, type: :service do
|
|||
let!(:bill) { Fabricate(:account, username: 'bill', protocol: :activitypub, domain: 'example2.com', inbox_url: 'http://example2.com/inbox') }
|
||||
|
||||
before do
|
||||
stub_request(:post, 'http://example.com/push').to_return(status: 200, body: '', headers: {})
|
||||
stub_request(:post, 'http://example.com/salmon').to_return(status: 200, body: '', headers: {})
|
||||
stub_request(:post, 'http://example.com/inbox').to_return(status: 200)
|
||||
stub_request(:post, 'http://example2.com/inbox').to_return(status: 200)
|
||||
|
||||
Fabricate(:subscription, account: alice, callback_url: 'http://example.com/push', confirmed: true, expires_at: 30.days.from_now)
|
||||
jeff.follow!(alice)
|
||||
hank.follow!(alice)
|
||||
|
||||
|
|
|
@ -18,7 +18,6 @@ RSpec.describe SuspendAccountService, type: :service do
|
|||
let!(:favourite) { Fabricate(:favourite, account: account) }
|
||||
let!(:active_relationship) { Fabricate(:follow, account: account) }
|
||||
let!(:passive_relationship) { Fabricate(:follow, target_account: account) }
|
||||
let!(:subscription) { Fabricate(:subscription, account: account) }
|
||||
let!(:remote_alice) { Fabricate(:account, inbox_url: 'https://alice.com/inbox', protocol: :activitypub) }
|
||||
let!(:remote_bob) { Fabricate(:account, inbox_url: 'https://bob.com/inbox', protocol: :activitypub) }
|
||||
|
||||
|
@ -31,9 +30,8 @@ RSpec.describe SuspendAccountService, type: :service do
|
|||
account.favourites,
|
||||
account.active_relationships,
|
||||
account.passive_relationships,
|
||||
account.subscriptions
|
||||
].map(&:count)
|
||||
}.from([1, 1, 1, 1, 1, 1, 1]).to([0, 0, 0, 0, 0, 0, 0])
|
||||
}.from([1, 1, 1, 1, 1, 1]).to([0, 0, 0, 0, 0, 0])
|
||||
end
|
||||
|
||||
it 'sends a delete actor activity to all known inboxes' do
|
||||
|
@ -62,7 +60,6 @@ RSpec.describe SuspendAccountService, type: :service do
|
|||
let!(:favourite) { Fabricate(:favourite, account: remote_bob) }
|
||||
let!(:active_relationship) { Fabricate(:follow, account: remote_bob, target_account: account) }
|
||||
let!(:passive_relationship) { Fabricate(:follow, target_account: remote_bob) }
|
||||
let!(:subscription) { Fabricate(:subscription, account: remote_bob) }
|
||||
|
||||
it 'deletes associated records' do
|
||||
is_expected.to change {
|
||||
|
@ -73,9 +70,8 @@ RSpec.describe SuspendAccountService, type: :service do
|
|||
remote_bob.favourites,
|
||||
remote_bob.active_relationships,
|
||||
remote_bob.passive_relationships,
|
||||
remote_bob.subscriptions
|
||||
].map(&:count)
|
||||
}.from([1, 1, 1, 1, 1, 1, 1]).to([0, 0, 0, 0, 0, 0, 0])
|
||||
}.from([1, 1, 1, 1, 1, 1]).to([0, 0, 0, 0, 0, 0])
|
||||
end
|
||||
|
||||
it 'sends a reject follow to follwer inboxes' do
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue