weak_headers 0.0.4 → 0.0.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rspec +2 -0
- data/.travis.yml +17 -0
- data/CHANGELOG.md +3 -0
- data/README.md +4 -6
- data/lib/weak_headers/controller.rb +3 -3
- data/lib/weak_headers/version.rb +1 -1
- data/lib/weak_headers.rb +5 -3
- data/spec/spec_helper.rb +11 -11
- data/spec/weak_headers_spec.rb +55 -0
- data/weak_headers.gemspec +2 -2
- metadata +6 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3d041f4923d87ab6cfc1b8383a6e96327a673afc
|
4
|
+
data.tar.gz: 2529efe4295e89663808d43862aafc5a7a680543
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ebb0291307e827cc6f1a0ad1e8709b202a45fb2abc3fb30f05d3c7ab1f9e6c81a6ce8e14758354b47eb64792b5bb6d3d4108864c723ae9ca6ade4d0de90cb72c
|
7
|
+
data.tar.gz: aa5921f4d92dd19bce8b8d693bd867e6847b223619363949ad9412ef92e1f9974e08ec5691e6627e3b7ce8535551f998757fbc1aa0df63747adc5e6902466077
|
data/.rspec
ADDED
data/.travis.yml
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
language: ruby
|
2
|
+
bundler_args: --without development --path vendor/bundle --jobs=3 --retry=3
|
3
|
+
cache:
|
4
|
+
directories:
|
5
|
+
- vendor/bundle
|
6
|
+
before_install:
|
7
|
+
- gem update --system
|
8
|
+
install:
|
9
|
+
- gem install bundler
|
10
|
+
- bundle install
|
11
|
+
script: bundle exec rspec
|
12
|
+
|
13
|
+
rvm:
|
14
|
+
- 1.9.3
|
15
|
+
- 2.0.0
|
16
|
+
- 2.1
|
17
|
+
- 2.2
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -1,13 +1,11 @@
|
|
1
|
-
|
2
|
-
Validates `request.headers` in your controller.
|
1
|
+
![Build Status](https://api.travis-ci.org/kenchan0130/weak_headers.png)
|
3
2
|
|
4
|
-
|
5
|
-
|
6
|
-
I'll add test as soon as possible.
|
3
|
+
# WeakHeaders
|
4
|
+
Validates `request.headers` in your rails controller.
|
7
5
|
|
8
6
|
## Installation
|
9
7
|
```ruby
|
10
|
-
gem
|
8
|
+
gem 'weak_headers'
|
11
9
|
```
|
12
10
|
|
13
11
|
## Usage
|
@@ -1,10 +1,10 @@
|
|
1
1
|
module WeakHeaders
|
2
2
|
module Controller
|
3
3
|
def validates_headers(action_name = nil, &block)
|
4
|
-
|
5
|
-
|
4
|
+
filter_options = {}
|
5
|
+
filter_options.merge!(only: action_name) unless action_name.nil?
|
6
6
|
|
7
|
-
before_filter
|
7
|
+
before_filter filter_options do
|
8
8
|
validator = WeakHeaders::Validator.new(self, &block)
|
9
9
|
WeakHeaders.stats[params[:controller]][params[:action]] = validator
|
10
10
|
WeakHeaders.stats[params[:controller]][params[:action]].validate
|
data/lib/weak_headers/version.rb
CHANGED
data/lib/weak_headers.rb
CHANGED
@@ -14,13 +14,15 @@ require 'weak_headers/version'
|
|
14
14
|
# Examples
|
15
15
|
#
|
16
16
|
# class AuthController < ApplicationController
|
17
|
-
# rescue_from WeakHeaders::ValidationError do |
|
18
|
-
# render text:
|
17
|
+
# rescue_from WeakHeaders::ValidationError do |e|
|
18
|
+
# render text: e.message, status: 400
|
19
19
|
# end
|
20
20
|
#
|
21
21
|
# validates_headers :create do
|
22
22
|
# requires 'X-Test-Token'
|
23
|
-
# optional 'X-Test-Id'
|
23
|
+
# optional 'X-Test-Id' do |value|
|
24
|
+
# value =~ /\A\d+\z/
|
25
|
+
# end
|
24
26
|
# end
|
25
27
|
#
|
26
28
|
# def create
|
data/spec/spec_helper.rb
CHANGED
@@ -1,19 +1,19 @@
|
|
1
|
+
ENV['RAILS_ENV'] ||= 'test'
|
2
|
+
|
1
3
|
require 'bundler/setup'
|
2
|
-
require '
|
4
|
+
require 'action_controller/railtie'
|
3
5
|
require 'rspec/rails'
|
4
6
|
|
7
|
+
Bundler.require(:default, ENV['RAILS_ENV'])
|
8
|
+
|
5
9
|
require 'weak_headers'
|
6
10
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
# instead of true.
|
11
|
-
config.use_transactional_fixtures = true
|
11
|
+
class DummyApplication < Rails::Application
|
12
|
+
config.secret_key_base = 'test'
|
13
|
+
end
|
12
14
|
|
13
|
-
|
14
|
-
# automatically. This will be the default behavior in future versions of
|
15
|
-
# rspec-rails.
|
16
|
-
config.infer_base_class_for_anonymous_controllers = false
|
15
|
+
Rails.application = DummyApplication
|
17
16
|
|
18
|
-
|
17
|
+
RSpec.configure do |config|
|
18
|
+
config.infer_base_class_for_anonymous_controllers = false
|
19
19
|
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
require_relative 'spec_helper'
|
2
|
+
|
3
|
+
RSpec.describe 'Anything', type: :controller do
|
4
|
+
controller do
|
5
|
+
extend WeakHeaders::Controller
|
6
|
+
include Rails.application.routes.url_helpers
|
7
|
+
|
8
|
+
def index
|
9
|
+
render text: 'dummy'
|
10
|
+
end
|
11
|
+
|
12
|
+
rescue_from WeakHeaders::ValidationError do |e|
|
13
|
+
render text: e.message, status: 400
|
14
|
+
end
|
15
|
+
|
16
|
+
validates_headers :index do
|
17
|
+
requires 'X-Test-Token'
|
18
|
+
optional 'X-Test-Id' do |value|
|
19
|
+
value =~ /\A\d+\z/
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
context 'with incorrect headers' do
|
25
|
+
it 'should return 400' do
|
26
|
+
get :index
|
27
|
+
|
28
|
+
expect(response).to have_http_status(400)
|
29
|
+
end
|
30
|
+
|
31
|
+
context 'with block' do
|
32
|
+
before do
|
33
|
+
request.headers['X-Test-Id'] = 'test'
|
34
|
+
end
|
35
|
+
|
36
|
+
it 'should return 400' do
|
37
|
+
get :index
|
38
|
+
|
39
|
+
expect(response).to have_http_status(400)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
context 'with correct headers' do
|
45
|
+
before do
|
46
|
+
request.headers['X-Test-Token'] = 'token'
|
47
|
+
end
|
48
|
+
|
49
|
+
it 'should return 200' do
|
50
|
+
get :index
|
51
|
+
|
52
|
+
expect(response).to have_http_status(200)
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
data/weak_headers.gemspec
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
$:.push File.expand_path(
|
1
|
+
$:.push File.expand_path('../lib', __FILE__)
|
2
2
|
|
3
3
|
require 'weak_headers/version'
|
4
4
|
|
@@ -7,7 +7,7 @@ Gem::Specification.new do |spec|
|
|
7
7
|
spec.version = WeakHeaders::VERSION
|
8
8
|
spec.authors = ['Tadayuki Onishi']
|
9
9
|
spec.email = ['tt.tanishi100@gmail.com']
|
10
|
-
spec.summary = 'Add a validation headers filter to your controller.'
|
10
|
+
spec.summary = 'Add a validation headers filter to your rails controller.'
|
11
11
|
spec.homepage = 'https://github.com/kenchan0130/weak_headers'
|
12
12
|
spec.license = 'MIT'
|
13
13
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: weak_headers
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tadayuki Onishi
|
@@ -60,6 +60,8 @@ extensions: []
|
|
60
60
|
extra_rdoc_files: []
|
61
61
|
files:
|
62
62
|
- ".gitignore"
|
63
|
+
- ".rspec"
|
64
|
+
- ".travis.yml"
|
63
65
|
- CHANGELOG.md
|
64
66
|
- Gemfile
|
65
67
|
- LICENSE.txt
|
@@ -74,6 +76,7 @@ files:
|
|
74
76
|
- lib/weak_headers/validator.rb
|
75
77
|
- lib/weak_headers/version.rb
|
76
78
|
- spec/spec_helper.rb
|
79
|
+
- spec/weak_headers_spec.rb
|
77
80
|
- weak_headers.gemspec
|
78
81
|
homepage: https://github.com/kenchan0130/weak_headers
|
79
82
|
licenses:
|
@@ -98,6 +101,7 @@ rubyforge_project:
|
|
98
101
|
rubygems_version: 2.4.8
|
99
102
|
signing_key:
|
100
103
|
specification_version: 4
|
101
|
-
summary: Add a validation headers filter to your controller.
|
104
|
+
summary: Add a validation headers filter to your rails controller.
|
102
105
|
test_files:
|
103
106
|
- spec/spec_helper.rb
|
107
|
+
- spec/weak_headers_spec.rb
|