Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Increase complexity logarithmicly to slowdown brute force attacks
Complexity is increased for each IP address during the last 24 hours. Thus it allows to decrease the base complexity to less penalize legitimate users. Log2 has been choosen to match to the power of 2 complexity of hashcash.
- Loading branch information
1 parent
4889db3
commit 42a14bc
Showing
3 changed files
with
50 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,41 @@ | ||
require "test_helper" | ||
|
||
class ActiveHashcashTest < ActiveSupport::TestCase | ||
test "it has a version number" do | ||
assert ActiveHashcash::VERSION | ||
|
||
class SampleController < ApplicationController | ||
include ActiveHashcash | ||
|
||
def hashcash_ip_address | ||
"127.0.0.1" | ||
end | ||
end | ||
|
||
def test_hashcash_bits | ||
controller = SampleController.new | ||
assert_equal(ActiveHashcash.bits, controller.hashcash_bits) | ||
|
||
ActiveHashcash::Stamp.parse("1:20:220623:test::MPWRGuN3itbd1NiQ:001").update!(ip_address: "127.0.0.1") | ||
assert_equal(ActiveHashcash.bits, controller.hashcash_bits) | ||
|
||
ActiveHashcash::Stamp.parse("1:20:220623:test::MPWRGuN3itbd1NiQ:002").update!(ip_address: "127.0.0.1") | ||
assert_equal(ActiveHashcash.bits + 1, controller.hashcash_bits) | ||
|
||
ActiveHashcash::Stamp.parse("1:20:220623:test::MPWRGuN3itbd1NiQ:003").update!(ip_address: "127.0.0.1") | ||
assert_equal(ActiveHashcash.bits + 1, controller.hashcash_bits) | ||
|
||
ActiveHashcash::Stamp.parse("1:20:220623:test::MPWRGuN3itbd1NiQ:004").update!(ip_address: "127.0.0.1") | ||
assert_equal(ActiveHashcash.bits + 2, controller.hashcash_bits) | ||
|
||
ActiveHashcash::Stamp.parse("1:20:220623:test::MPWRGuN3itbd1NiQ:005").update!(ip_address: "127.0.0.1") | ||
assert_equal(ActiveHashcash.bits + 2, controller.hashcash_bits) | ||
|
||
ActiveHashcash::Stamp.parse("1:20:220623:test::MPWRGuN3itbd1NiQ:006").update!(ip_address: "127.0.0.1") | ||
assert_equal(ActiveHashcash.bits + 2, controller.hashcash_bits) | ||
|
||
ActiveHashcash::Stamp.parse("1:20:220623:test::MPWRGuN3itbd1NiQ:007").update!(ip_address: "127.0.0.1") | ||
assert_equal(ActiveHashcash.bits + 2, controller.hashcash_bits) | ||
|
||
ActiveHashcash::Stamp.parse("1:20:220623:test::MPWRGuN3itbd1NiQ:008").update!(ip_address: "127.0.0.1") | ||
assert_equal(ActiveHashcash.bits + 3, controller.hashcash_bits) | ||
end | ||
end |