-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
49 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
require 'rails_helper' | ||
|
||
# We spec that the BotDetect filter is actually applying protection, as well as exempting what | ||
# we want | ||
describe DummyImmediateController, type: :controller do | ||
|
||
# enable functionality, and reset config to fresh after any further changes | ||
around(:each) do |example| | ||
orig_config = BotChallengePage::BotChallengePageController.bot_challenge_config.dup | ||
BotChallengePage::BotChallengePageController.bot_challenge_config.enabled = true | ||
|
||
example.run | ||
|
||
# reset config and rack-attack back to orig config | ||
BotChallengePage::BotChallengePageController.bot_challenge_config = orig_config | ||
BotChallengePage::BotChallengePageController.rack_attack_init | ||
end | ||
|
||
describe "when rack key requests bot challenge on protected controller" do | ||
it "redirects even with no ENV request" do | ||
get :index | ||
|
||
expect(response).to have_http_status(307) | ||
expect(response).to redirect_to(bot_detect_challenge_path(dest: dummy_immediate_path)) | ||
end | ||
|
||
# we configured this to try to exempt fetch/ajax to #facet | ||
it "does not redirect if we have stored a pass in session" do | ||
request.session[BotChallengePage::BotChallengePageController.bot_challenge_config.session_passed_key] = { | ||
BotChallengePage::BotChallengePageController::SESSION_DATETIME_KEY => Time.now.utc.iso8601, | ||
BotChallengePage::BotChallengePageController::SESSION_IP_KEY => request.remote_ip | ||
} | ||
|
||
get :index | ||
|
||
expect(response).to have_http_status(:success) # not a redirect | ||
expect(response.body).to include "rendered action" | ||
end | ||
end | ||
end |
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 |
---|---|---|
@@ -0,0 +1,8 @@ | ||
class DummyImmediateController < ApplicationController | ||
# with immediate:true | ||
before_action { |controller| BotChallengePage::BotChallengePageController.bot_challenge_enforce_filter(controller, immediate: true) } | ||
|
||
def index | ||
render plain: "rendered action dummy" | ||
end | ||
end |
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