stop_it 0.1.0 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -1 +1,53 @@
1
- # StopIt
1
+ # Stop It
2
+
3
+ Stop It is a middleware for blocking requests to rake apps.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'stop_it'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install stop_it
18
+
19
+ ## Usage
20
+
21
+ Let's see how to use Stop It with Ruby on Rails apps. To insert Stop It into the stack of middlewares of your app open config.ru file and add line
22
+
23
+ use StopIt
24
+
25
+ right after line
26
+
27
+ require ::File.expand_path('../config/environment', __FILE__)
28
+
29
+ so that the file contains code similar to this:
30
+
31
+ # This file is used by Rack-based servers to start the application.
32
+
33
+ require ::File.expand_path('../config/environment', __FILE__)
34
+ use StopIt
35
+ run MyRailsApp::Application # Here should be your application class name
36
+
37
+ To configure which requests should be stopped add config/initializers/stop_it.rb file to your Ruby on Rails app with the following content:
38
+
39
+ StopIt.stop do |path_info, remote_addr, query_string, request_method, user_agent|
40
+
41
+ end
42
+
43
+ If the block in stop method returns true then the request will be blocked. If it returns false then the request will be passed to the next middleware. In the following example all requests to /forbidden will be blocked.
44
+
45
+ StopIt.stop do |path_info, remote_addr, query_string, request_method, user_agent|
46
+ path_info == "/forbidden"
47
+ end
48
+
49
+ Requests can be blocked by request path, remote address, query string, HTTP method, and user agent.
50
+
51
+ ## Contributing
52
+
53
+ Your contribution is welcome.
data/lib/stop_it.rb CHANGED
@@ -15,10 +15,14 @@ class StopIt
15
15
  end
16
16
 
17
17
  def call(env)
18
- if stop?(env)
19
- return [200, { 'Content-Type' => 'text/html', 'Content-Length' => '0' }, []]
20
- else
18
+ response = stop?(env)
19
+
20
+ if response == true
21
+ [200, { 'Content-Type' => 'text/html', 'Content-Length' => '0' }, []]
22
+ elsif response == false
21
23
  @app.call(env)
24
+ else
25
+ response
22
26
  end
23
27
  end
24
28
 
data/spec/stop_it_spec.rb CHANGED
@@ -19,14 +19,22 @@ describe StopIt do
19
19
  end
20
20
  end
21
21
 
22
- describe "does not stop request if stop block returns false" do
23
- before { StopIt.stop { |path_info, remote_addr, query_string, request_method, user_agent| false } }
24
- it_should_behave_like "non-blocker", {}
25
- end
22
+ describe "middleware response" do
23
+ context "stop block returns false" do
24
+ before { StopIt.stop { |path_info, remote_addr, query_string, request_method, user_agent| false } }
25
+ it_should_behave_like "non-blocker", {}
26
+ end
26
27
 
27
- describe "stops request if stop block returns true" do
28
- before { StopIt.stop { |path_info, remote_addr, query_string, request_method, user_agent| true } }
29
- it_should_behave_like "blocker", {}
28
+ context "stop block returns true" do
29
+ before { StopIt.stop { |path_info, remote_addr, query_string, request_method, user_agent| true } }
30
+ it_should_behave_like "blocker", {}
31
+ end
32
+
33
+ context "stop block returns rake status" do
34
+ let(:response) { [403, { 'Content-Type' => 'text/html', 'Content-Length' => '0' }, []] }
35
+ before { StopIt.stop { |path_info, remote_addr, query_string, request_method, user_agent| response } }
36
+ specify { middleware.call({}).should == response }
37
+ end
30
38
  end
31
39
 
32
40
  describe "filter requests by PATH_INFO env variable" do
data/stop_it.gemspec CHANGED
@@ -11,7 +11,7 @@ Gem::Specification.new do |gem|
11
11
  gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
12
12
  gem.name = "stop_it"
13
13
  gem.require_paths = ["lib"]
14
- gem.version = "0.1.0"
14
+ gem.version = "1.0.0"
15
15
 
16
16
  gem.add_development_dependency 'rspec'
17
17
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: stop_it
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 1.0.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-09-29 00:00:00.000000000 Z
12
+ date: 2013-10-01 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec
16
- requirement: &70181456105600 !ruby/object:Gem::Requirement
16
+ requirement: &70316692893900 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,7 +21,7 @@ dependencies:
21
21
  version: '0'
22
22
  type: :development
23
23
  prerelease: false
24
- version_requirements: *70181456105600
24
+ version_requirements: *70316692893900
25
25
  description: ''
26
26
  email:
27
27
  - andrew.gridnev@gmail.com