mirror of
https://github.com/samsonjs/rack-attack.git
synced 2026-04-25 14:47:43 +00:00
Initial commit
This commit is contained in:
commit
140ea86b7c
7 changed files with 89 additions and 0 deletions
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
Gemfile.lock
|
||||||
2
Gemfile
Normal file
2
Gemfile
Normal file
|
|
@ -0,0 +1,2 @@
|
||||||
|
source :rubygems
|
||||||
|
gemspec
|
||||||
27
lib/rack/attack.rb
Normal file
27
lib/rack/attack.rb
Normal file
|
|
@ -0,0 +1,27 @@
|
||||||
|
require 'rack'
|
||||||
|
module Rack
|
||||||
|
class Attack
|
||||||
|
class << self
|
||||||
|
|
||||||
|
def block
|
||||||
|
end
|
||||||
|
|
||||||
|
def throttle
|
||||||
|
end
|
||||||
|
|
||||||
|
def whitelist
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
def initialize(app)
|
||||||
|
@app = app
|
||||||
|
end
|
||||||
|
|
||||||
|
def call(env)
|
||||||
|
puts 'Rack attack!'
|
||||||
|
@app.call(env)
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
end
|
||||||
5
lib/rack/attack/version.rb
Normal file
5
lib/rack/attack/version.rb
Normal file
|
|
@ -0,0 +1,5 @@
|
||||||
|
module Rack
|
||||||
|
class Attack
|
||||||
|
VERSION = '0.0.1'
|
||||||
|
end
|
||||||
|
end
|
||||||
29
rack-attack.gemspec
Normal file
29
rack-attack.gemspec
Normal file
|
|
@ -0,0 +1,29 @@
|
||||||
|
# -*- encoding: utf-8 -*-
|
||||||
|
lib = File.expand_path('../lib/', __FILE__)
|
||||||
|
$:.unshift lib unless $:.include?(lib)
|
||||||
|
|
||||||
|
require 'rack/attack/version'
|
||||||
|
|
||||||
|
Gem::Specification.new do |s|
|
||||||
|
s.name = 'rack-attack'
|
||||||
|
s.version = Rack::Attack::VERSION
|
||||||
|
|
||||||
|
s.authors = ["Aaron Suggs"]
|
||||||
|
s.description = "A flexible rack middleware for throttling and blocking requests"
|
||||||
|
s.email = "aaron@ktheory.com"
|
||||||
|
|
||||||
|
s.files = Dir.glob("{bin,lib}/**/*") + %w(LICENSE README.rdoc Rakefile)
|
||||||
|
s.homepage = 'http://github.com/kickstarter/rack-attack'
|
||||||
|
s.rdoc_options = ["--charset=UTF-8"]
|
||||||
|
s.require_paths = ["lib"]
|
||||||
|
s.summary = %q{Block & throttle abusive requests}
|
||||||
|
s.test_files = Dir.glob("spec/**/*")
|
||||||
|
|
||||||
|
s.required_ruby_version = '>= 1.9.3' # Maybe less?
|
||||||
|
|
||||||
|
s.add_dependency 'rack'
|
||||||
|
s.add_development_dependency 'minitest'
|
||||||
|
s.add_development_dependency 'rack-test'
|
||||||
|
s.add_development_dependency 'debugger', '~> 1.1.3'
|
||||||
|
end
|
||||||
|
|
||||||
18
spec/rack_attack_spec.rb
Normal file
18
spec/rack_attack_spec.rb
Normal file
|
|
@ -0,0 +1,18 @@
|
||||||
|
require_relative 'spec_helper'
|
||||||
|
|
||||||
|
describe 'Rack::Attack' do
|
||||||
|
include Rack::Test::Methods
|
||||||
|
|
||||||
|
def app
|
||||||
|
Rack::Builder.new {
|
||||||
|
use Rack::Attack
|
||||||
|
run lambda {|env| [200, {}, ['Hello World']]}
|
||||||
|
}.to_app
|
||||||
|
end
|
||||||
|
|
||||||
|
it "says hello" do
|
||||||
|
get '/'
|
||||||
|
last_response.status.must_equal 200
|
||||||
|
last_response.body.must_equal 'Hello World'
|
||||||
|
end
|
||||||
|
end
|
||||||
7
spec/spec_helper.rb
Normal file
7
spec/spec_helper.rb
Normal file
|
|
@ -0,0 +1,7 @@
|
||||||
|
require "rubygems"
|
||||||
|
require "bundler/setup"
|
||||||
|
|
||||||
|
require "minitest/autorun"
|
||||||
|
require "rack"
|
||||||
|
require "rack/test"
|
||||||
|
require "rack/attack"
|
||||||
Loading…
Reference in a new issue