mirror of
https://github.com/discourse/discourse.git
synced 2025-05-31 14:48:03 +08:00
SECURITY: Handle concurrent invite accepts
Raise an error on concurrent invite accept attempts.
This commit is contained in:

committed by
David Taylor

parent
bfc3132bb2
commit
62a609ea2d
@ -984,6 +984,27 @@ RSpec.describe InvitesController do
|
||||
Fabricate(:invite, email: nil, emailed_status: Invite.emailed_status_types[:not_required])
|
||||
end
|
||||
|
||||
it "does not create multiple users for a single use invite" do
|
||||
user_count = User.count
|
||||
|
||||
2
|
||||
.times
|
||||
.map do
|
||||
Thread.new do
|
||||
put "/invites/show/#{invite.invite_key}.json",
|
||||
params: {
|
||||
email: "test@example.com",
|
||||
password: "verystrongpassword",
|
||||
}
|
||||
end
|
||||
end
|
||||
.each(&:join)
|
||||
|
||||
expect(invite.reload.max_redemptions_allowed).to eq(1)
|
||||
expect(invite.reload.redemption_count).to eq(1)
|
||||
expect(User.count).to eq(user_count + 1)
|
||||
end
|
||||
|
||||
it "sends an activation email and does not activate the user" do
|
||||
expect {
|
||||
put "/invites/show/#{invite.invite_key}.json",
|
||||
|
Reference in New Issue
Block a user