rack-simple_auth 1.0.6 → 1.0.7

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9735c0a4e90adba0ea36922a39003a8a1046b6c3
4
- data.tar.gz: 3bd7569c566dd989a45415621117291f73ce0eff
3
+ metadata.gz: fb48d5d292933a9a8d9f98e548af7e5488afd409
4
+ data.tar.gz: 63bcacb85def1e0b6eaffe3e38f407b21e01d87f
5
5
  SHA512:
6
- metadata.gz: a2856c77a082eec813d49b8bd34ae0d5bc0abd96deb5adacac2436a59dd932b26d334b4f88d23f39daa5586d070f59abe25ce205f346f8d7f85e2e76fc2d060c
7
- data.tar.gz: 3489c779bfad37d133c35bac3b36b45e07a87e89f486bbeec18a4bae020ecf5fe2deddb0676f75642d782be412834f2ec3c5ce76c67cb9c618b88a11bc16fafe
6
+ metadata.gz: 3efc318094e78e8324a27589e37fb259d6562a0daea0042b99f18fdc6f66b6a3e7072eb39443a2a126788402b7ffb1e535c6dcbb2d4ce0fabbcad904eb4495ed
7
+ data.tar.gz: d824623632cc478f0fe80acefc9f8c49120d3161ebba6f2f5adc68ccb7426476fc339a2015dac81020c1fefd78f3d63f653a1f22082c777ab9c9c1131d6b114a
data/HISTORY ADDED
File without changes
@@ -20,8 +20,8 @@ Or install it yourself as:
20
20
 
21
21
  == Gem Status
22
22
 
23
- {<img src="https://travis-ci.org/Benny1992/rack-simple_auth.svg?branch=v1.0.0rc" alt="Build Status" />}[https://travis-ci.org/Benny1992/rack-simple_auth]
24
- {<img src="https://coveralls.io/repos/Benny1992/rack-simple_auth/badge.png" alt="Code Coverage" />}[https://coveralls.io/r/Benny1992/rack-simple_auth]
23
+ {<img src="https://travis-ci.org/tak1n/rack-simple_auth.svg?branch=master" alt="Build Status" />}[https://travis-ci.org/tak1n/rack-simple_auth]
24
+ {<img src="https://coveralls.io/repos/tak1n/rack-simple_auth/badge.svg?branch=master" alt="Coverage Status" />}[https://coveralls.io/r/tak1n/rack-simple_auth?branch=master]
25
25
  {<img src="https://badge.fury.io/rb/rack-simple_auth.png" alt="Gem Version" />}[http://badge.fury.io/rb/rack-simple_auth]
26
26
  {<img src="https://gemnasium.com/Benny1992/rack-simple_auth.png" alt="Dependency Status" />}[https://gemnasium.com/Benny1992/rack-simple_auth]
27
27
  {<img src="https://www.codeship.io/projects/f2d9d790-b0fe-0131-3fd5-025f180094b5/status" alt="Build Status" />}[https://www.codeship.io/projects/f2d9d790-b0fe-0131-3fd5-025f180094b5/status]
@@ -4,7 +4,6 @@ require 'rack/simple_auth/logger'
4
4
  # HMAC utilities
5
5
  require 'rack/simple_auth/hmac/config'
6
6
  require 'rack/simple_auth/hmac/request'
7
- require 'rack/simple_auth/hmac/response'
8
7
  require 'rack/simple_auth/hmac/middleware'
9
8
 
10
9
  require 'json'
@@ -36,7 +36,7 @@ module Rack
36
36
  # @param [Symbol] name
37
37
  # @param [Array] args
38
38
  #
39
- def method_missing(name, *args)
39
+ def method_missing(name, *_args)
40
40
  fail "Unknown option #{name.to_s.gsub!('=', '')}"
41
41
  end
42
42
 
@@ -34,9 +34,8 @@ module Rack
34
34
  # Constructor for Rack Middleware (passing the rack stack)
35
35
  #
36
36
  # @param [Rack Application] app [next middleware or rack app which gets called]
37
- # @param [Proc] block [the dsl block which will be yielded into the config object]
38
37
  #
39
- def initialize(app, &block)
38
+ def initialize(app)
40
39
  @app, @config = app, Config.new
41
40
 
42
41
  yield @config if block_given?
@@ -48,24 +47,20 @@ module Rack
48
47
  # @param [Hash] env [Rack Env Hash which contains headers etc..]
49
48
  #
50
49
  def call(env)
51
- self.dup.call!(env)
50
+ # self.dup.call!(env)
51
+ dup.call!(env)
52
52
  end
53
53
 
54
54
  ##
55
55
  # call! Method
56
56
  #
57
- # Using ! because this method isn't a pure function
58
- # Creating for example @request & @allowed_messages instance variables
59
- #
60
- # Also this is a threadsafe approach for rack
61
- #
62
57
  # @param [Hash] env [Rack Env Hash which contains headers etc..]
63
58
  #
64
59
  def call!(env)
65
60
  env = env.dup
66
- @request = Request.new(env, @config)
61
+ request = Request.new(env, @config)
67
62
 
68
- if @request.valid?
63
+ if request.valid?
69
64
  @app.call(env)
70
65
  else
71
66
  response = Response.new('Unauthorized', 401, 'Content-Type' => 'text/html')
@@ -2,10 +2,12 @@ module Rack
2
2
  module SimpleAuth
3
3
  module HMAC
4
4
  class Request < Rack::Request
5
+ attr_reader :env, :config, :allowed_messages
6
+
5
7
  def initialize(env, config)
6
8
  @env = env
7
9
  @config = config
8
- @allowed_messages = allowed_messages
10
+ @allowed_messages = build_allowed_messages
9
11
  end
10
12
 
11
13
  ##
@@ -15,26 +17,26 @@ module Rack
15
17
  # @return [FalseClass] if request is not authorized or HTTP_AUTHORIZATION Header is not set
16
18
  #
17
19
  def valid?
18
- log
20
+ # log
19
21
 
20
22
  return false if empty_header? || !authorized?
21
23
 
22
24
  true
23
25
  end
24
26
 
25
- private
27
+ private
26
28
 
27
29
  ##
28
- # Builds Array of allowed message hashs between @tolerance via {#message}
30
+ # Builds Array of allowed message hashs between tolerance via {#message}
29
31
  #
30
32
  # @return [Array]
31
- def allowed_messages
33
+ def build_allowed_messages
32
34
  messages = []
33
35
 
34
36
  # Timestamp with milliseconds as Fixnum
35
37
  date = (Time.now.to_f.freeze * 1000).to_i
36
- (-(@config.tolerance)..0).step(1) do |i|
37
- messages << OpenSSL::HMAC.hexdigest(OpenSSL::Digest.new('sha256'), @config.secret, build_message(date, i))
38
+ (-(config.tolerance)..0).step(1) do |i|
39
+ messages << OpenSSL::HMAC.hexdigest(OpenSSL::Digest.new('sha256'), config.secret, build_message(date, i))
38
40
  end
39
41
 
40
42
  messages
@@ -50,19 +52,19 @@ module Rack
50
52
  def build_message(date, delay = 0)
51
53
  date += delay
52
54
 
53
- { 'method' => self.request_method, 'date' => date, 'data' => data }.to_json
55
+ { 'method' => request_method, 'date' => date, 'data' => data }.to_json
54
56
  end
55
57
 
56
58
  ##
57
- # Get Request Data specified by @config.request_config
59
+ # Get Request Data specified by config.request_config
58
60
  #
59
61
  # @return [String|Hash] data
60
62
  #
61
63
  # Note: REFACTOR this shit..
62
64
  def data
63
- return self.send(@config.request_config[method].to_sym) if valid_message_type?
65
+ return send(config.request_config[request_method].to_sym) if valid_message_type?
64
66
 
65
- fail "Not a valid option #{@config.request_config[method]} - Use either params or path"
67
+ fail "Not a valid option #{config.request_config[request_method]} - Use either params or path"
66
68
  end
67
69
 
68
70
  ##
@@ -72,7 +74,7 @@ module Rack
72
74
  # @return [FalseClass] if header is not set
73
75
  #
74
76
  def empty_header?
75
- self.env['HTTP_AUTHORIZATION'].nil?
77
+ env['HTTP_AUTHORIZATION'].nil?
76
78
  end
77
79
 
78
80
  ##
@@ -83,7 +85,7 @@ module Rack
83
85
  # @return [FalseClass] if request is not authorized
84
86
  #
85
87
  def authorized?
86
- signature.eql?(@config.signature) && @allowed_messages.include?(message)
88
+ signature.eql?(config.signature) && allowed_messages.include?(message)
87
89
  end
88
90
 
89
91
  ##
@@ -92,7 +94,7 @@ module Rack
92
94
  # @return [String] signature of current request
93
95
  #
94
96
  def signature
95
- self.env['HTTP_AUTHORIZATION'].split(':').last
97
+ env['HTTP_AUTHORIZATION'].split(':').last
96
98
  end
97
99
 
98
100
  ##
@@ -101,16 +103,7 @@ module Rack
101
103
  # @return [String] message of current request
102
104
  #
103
105
  def message
104
- self.env['HTTP_AUTHORIZATION'].split(':').first
105
- end
106
-
107
- ##
108
- # Request method for current request
109
- #
110
- # @return [String] Request Method [GET|POST|PUT|DELETE|PATCH]
111
- #
112
- def method
113
- self.request_method
106
+ env['HTTP_AUTHORIZATION'].split(':').first
114
107
  end
115
108
 
116
109
  ##
@@ -120,11 +113,11 @@ module Rack
120
113
  # @return [FalseClass] if message type is invalid
121
114
  #
122
115
  def valid_message_type?
123
- @config.request_config[method] == 'path' || @config.request_config[method] == 'params'
116
+ config.request_config[request_method] == 'path' || config.request_config[request_method] == 'params'
124
117
  end
125
118
 
126
119
  ##
127
- # Log to @config.logpath
120
+ # Log to config.logpath
128
121
  # Contains:
129
122
  # - allowed messages and received message
130
123
  # - time when request was made
@@ -135,20 +128,20 @@ module Rack
135
128
  # (Rack::SimpleAuth::Logger.log has IO action, i think there are some performance issues)
136
129
  #
137
130
  def log
138
- msg = "#{Time.new} - #{self.request_method} #{self.path} - 400 Unauthorized\n"
139
- msg << "HTTP_AUTHORIZATION: #{self.env['HTTP_AUTHORIZATION']}\n"
140
- msg << "Auth Message Config: #{@config.request_config[self.request_method]}\n"
131
+ msg = "#{Time.new} - #{request_method} #{path} - 400 Unauthorized\n"
132
+ msg << "HTTP_AUTHORIZATION: #{env['HTTP_AUTHORIZATION']}\n"
133
+ msg << "Auth Message Config: #{config.request_config[request_method]}\n"
141
134
 
142
- if @allowed_messages
135
+ if allowed_messages
143
136
  msg << "Allowed Encrypted Messages:\n"
144
- @allowed_messages.each do |hash|
137
+ allowed_messages.each do |hash|
145
138
  msg << "#{hash}\n"
146
139
  end
147
140
  end
148
141
 
149
- msg << "Auth Signature: #{@config.signature}"
142
+ msg << "Auth Signature: #{config.signature}"
150
143
 
151
- Rack::SimpleAuth::Logger.log(@config.logpath, @config.verbose, ENV['RACK_ENV'], msg)
144
+ Rack::SimpleAuth::Logger.log(config.logpath, config.verbose, ENV['RACK_ENV'], msg)
152
145
  end
153
146
  end
154
147
  end
@@ -2,6 +2,6 @@ module Rack
2
2
  # Module which Contains different Authorization / Authentication Classes (HMAC, ..)
3
3
  module SimpleAuth
4
4
  # Current Gem Version
5
- VERSION = '1.0.6'
5
+ VERSION = '1.0.7'
6
6
  end
7
7
  end
@@ -6,15 +6,15 @@ require 'rack/simple_auth/version'
6
6
  Gem::Specification.new do |spec|
7
7
  spec.name = "rack-simple_auth"
8
8
  spec.version = Rack::SimpleAuth::VERSION
9
- spec.authors = ["Benny1992"]
10
- spec.email = ["r3qnbenni@gmail.com"]
9
+ spec.authors = ["Benny Klotz"]
10
+ spec.email = ["benny.klotz92@gmail.com"]
11
11
  spec.summary = %q{SimpleAuth HMAC authentication}
12
12
  spec.description = spec.summary
13
- spec.homepage = "https://github.com/Benny1992/rack-simple_auth"
13
+ spec.homepage = "https://github.com/tak1n/rack-simple_auth"
14
14
  spec.license = "MIT"
15
15
 
16
16
  spec.post_install_message = 'Please report any issues at: ' \
17
- 'https://github.com/Benny1992/rack-simple_auth/issues/new'
17
+ 'https://github.com/tak1n/rack-simple_auth/issues/new'
18
18
 
19
19
  spec.files = File.read(File.expand_path('../MANIFEST', __FILE__)).split("\n")
20
20
  spec.require_paths = ["lib"]
@@ -26,8 +26,9 @@ Gem::Specification.new do |spec|
26
26
  spec.add_development_dependency "bundler", "~> 1.6"
27
27
  spec.add_development_dependency "rake", '~> 10.3'
28
28
  spec.add_development_dependency "coveralls", '~> 0.7'
29
- spec.add_development_dependency 'codeclimate-test-reporter'
30
29
  spec.add_development_dependency "rack-test", '~> 0.6'
31
30
  spec.add_development_dependency 'minitest', '~> 5.3'
32
31
  spec.add_development_dependency 'minitest-reporters'
32
+ spec.add_development_dependency 'pry'
33
+ spec.add_development_dependency 'rubocop'
33
34
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rack-simple_auth
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.6
4
+ version: 1.0.7
5
5
  platform: ruby
6
6
  authors:
7
- - Benny1992
7
+ - Benny Klotz
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-07-30 00:00:00.000000000 Z
11
+ date: 2015-03-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rack
@@ -66,20 +66,6 @@ dependencies:
66
66
  - - "~>"
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0.7'
69
- - !ruby/object:Gem::Dependency
70
- name: codeclimate-test-reporter
71
- requirement: !ruby/object:Gem::Requirement
72
- requirements:
73
- - - ">="
74
- - !ruby/object:Gem::Version
75
- version: '0'
76
- type: :development
77
- prerelease: false
78
- version_requirements: !ruby/object:Gem::Requirement
79
- requirements:
80
- - - ">="
81
- - !ruby/object:Gem::Version
82
- version: '0'
83
69
  - !ruby/object:Gem::Dependency
84
70
  name: rack-test
85
71
  requirement: !ruby/object:Gem::Requirement
@@ -122,38 +108,56 @@ dependencies:
122
108
  - - ">="
123
109
  - !ruby/object:Gem::Version
124
110
  version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: pry
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ - !ruby/object:Gem::Dependency
126
+ name: rubocop
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ">="
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
125
139
  description: SimpleAuth HMAC authentication
126
140
  email:
127
- - r3qnbenni@gmail.com
141
+ - benny.klotz92@gmail.com
128
142
  executables: []
129
143
  extensions: []
130
144
  extra_rdoc_files: []
131
145
  files:
146
+ - HISTORY
132
147
  - LICENSE
133
- - MANIFEST
134
148
  - README.rdoc
135
- - checksum/rack-simple_auth-0.0.9.gem.sha512
136
- - checksum/rack-simple_auth-0.1.0.gem.sha512
137
- - checksum/rack-simple_auth-0.1.1.gem.sha512
138
- - checksum/rack-simple_auth-0.1.2.gem.sha512
139
- - checksum/rack-simple_auth-1.0.0.gem.sha512
140
- - checksum/rack-simple_auth-1.0.0rc.gem.sha512
141
- - checksum/rack-simple_auth-1.0.1.gem.sha512
142
- - checksum/rack-simple_auth-1.0.3.gem.sha512
143
- - checksum/rack-simple_auth-1.0.4.gem.sha512
144
149
  - lib/rack/simple_auth.rb
145
150
  - lib/rack/simple_auth/hmac/config.rb
146
151
  - lib/rack/simple_auth/hmac/middleware.rb
147
152
  - lib/rack/simple_auth/hmac/request.rb
148
- - lib/rack/simple_auth/hmac/response.rb
149
153
  - lib/rack/simple_auth/logger.rb
150
154
  - lib/rack/simple_auth/version.rb
151
155
  - rack-simple_auth.gemspec
152
- homepage: https://github.com/Benny1992/rack-simple_auth
156
+ homepage: https://github.com/tak1n/rack-simple_auth
153
157
  licenses:
154
158
  - MIT
155
159
  metadata: {}
156
- post_install_message: 'Please report any issues at: https://github.com/Benny1992/rack-simple_auth/issues/new'
160
+ post_install_message: 'Please report any issues at: https://github.com/tak1n/rack-simple_auth/issues/new'
157
161
  rdoc_options: []
158
162
  require_paths:
159
163
  - lib
@@ -169,7 +173,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
169
173
  version: '0'
170
174
  requirements: []
171
175
  rubyforge_project:
172
- rubygems_version: 2.3.0
176
+ rubygems_version: 2.4.5
173
177
  signing_key:
174
178
  specification_version: 4
175
179
  summary: SimpleAuth HMAC authentication
data/MANIFEST DELETED
@@ -1,20 +0,0 @@
1
- LICENSE
2
- MANIFEST
3
- README.rdoc
4
- checksum/rack-simple_auth-0.0.9.gem.sha512
5
- checksum/rack-simple_auth-0.1.0.gem.sha512
6
- checksum/rack-simple_auth-0.1.1.gem.sha512
7
- checksum/rack-simple_auth-0.1.2.gem.sha512
8
- checksum/rack-simple_auth-1.0.0.gem.sha512
9
- checksum/rack-simple_auth-1.0.0rc.gem.sha512
10
- checksum/rack-simple_auth-1.0.1.gem.sha512
11
- checksum/rack-simple_auth-1.0.3.gem.sha512
12
- checksum/rack-simple_auth-1.0.4.gem.sha512
13
- lib/rack/simple_auth.rb
14
- lib/rack/simple_auth/hmac/config.rb
15
- lib/rack/simple_auth/hmac/middleware.rb
16
- lib/rack/simple_auth/hmac/request.rb
17
- lib/rack/simple_auth/hmac/response.rb
18
- lib/rack/simple_auth/logger.rb
19
- lib/rack/simple_auth/version.rb
20
- rack-simple_auth.gemspec
@@ -1 +0,0 @@
1
- 6cea3b5a2a5e2e6f972df781503a4bf41fd51379b30d126c422708b629cb3f4ca297175a0adb78e29ed44be9726ce81aa619636ea3c874fc1c82176a93f2104f
@@ -1 +0,0 @@
1
- 3f44ad70bd27de3e3f20ff929fd6b60e485a7b466de3248281015edef5e7b562e3bcc4ccafec834b05e2e797c2d90cdb30ff8b6a1bdd3dc33c4a11ecd962c3ca
@@ -1 +0,0 @@
1
- 9b0c40311d24b23a2aeba34dcd217f74539be06e626abfdead5c32447f17513ccb10ec697d4e71f9f374a7daf7fc6edc46373bd89d18a0d0e164ceae9966234f
@@ -1 +0,0 @@
1
- 7d8e86a09ec275f7531af9f17a77fb8e307bd95f0d4593627b94441d59f0deb95d4240757216ecb70b65a2e40a5d4d7cba8bc5bf002b458077ca73ad0f2cac11
@@ -1 +0,0 @@
1
- b88704d60bd82de20893861f9d524a8a0d433c7af1b21501d9e69fc6da5a847455c86e01e83743439a5bd46fc9feb66a4371f9c9560f08f8d9de60fdf649dc2b
@@ -1 +0,0 @@
1
- 4c0a5c5b86c0f88193dc9e343334737e709eb69397b6a2dd5a1e76a18d867a79db76cd7e205ad054d1580cdfd28ccb9a81a3f5a1969f77f988d3449f09ee296f
@@ -1 +0,0 @@
1
- 9c1876dcf613f7dcf680b7613f7442a947e381ceccdd1ec883df598e5d20d4485b5edfca0274a5c4f27569555b91fc49f73fd280c73d2a92b4db6b6a1ed625e7
@@ -1 +0,0 @@
1
- 3c74fc621b80b95b3dcde055142e6900778c67c8e5ed3b550195c4d934c5aff5b7ab427b936dd725afc1aa5c118e7e7646a25e991be9f12f0c45e7621902f537
@@ -1 +0,0 @@
1
- 4dc93569f637e6d1e4e4f564efab90c192cba3f84d4368de83ff80b88d14dd642c8a234e64ee3a1167ab765651963d4a37873e34353cff7701cd5e5eef06bf2d
@@ -1,8 +0,0 @@
1
- module Rack
2
- module SimpleAuth
3
- module HMAC
4
- class Response < Rack::Response
5
- end
6
- end
7
- end
8
- end