Skip to content

Commit fab213c

Browse files
authored
Merge pull request #1778 from hannahyeates/fix-make-token-revocation-idempotent
fix: ensure that token revocation is idempotent
2 parents 89b05fb + 060f493 commit fab213c

File tree

3 files changed

+16
-0
lines changed

3 files changed

+16
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ User-visible changes worth mentioning.
99

1010
Add your entry here.
1111
- [#1775] Fix Applications Secret Not Null Constraint generator
12+
- [#1778] Ensure that token revocation is idempotent by checking that that token has not already been revoked before revoking.
1213

1314
## 5.8.2
1415

lib/doorkeeper/models/concerns/revocable.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ module Revocable
99
# @param clock [Time] time object
1010
#
1111
def revoke(clock = Time)
12+
return if revoked?
1213
update_attribute(:revoked_at, clock.now.utc)
1314
end
1415

spec/lib/models/revocable_spec.rb

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,26 @@
1010
end
1111

1212
describe "#revoke" do
13+
let(:revoked_at) { nil }
14+
15+
before do
16+
allow(fake_object).to receive(:revoked_at).and_return(revoked_at)
17+
end
18+
1319
it "updates :revoked_at attribute with current time" do
1420
utc = double utc: double
1521
clock = double now: utc
1622
expect(fake_object).to receive(:update_attribute).with(:revoked_at, clock.now.utc)
1723
fake_object.revoke(clock)
1824
end
25+
26+
context "when the object is already revoked" do
27+
let(:revoked_at) { Time.now.utc - 1000 }
28+
29+
it "does not update :revoked_at attribute" do
30+
expect(fake_object).not_to receive(:update_attribute)
31+
end
32+
end
1933
end
2034

2135
describe "#revoked?" do

0 commit comments

Comments
 (0)