humble_auth 0.0.3 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/lib/humble_auth/helper.rb +5 -5
- data/lib/humble_auth/railtie.rb +1 -1
- data/lib/humble_auth/version.rb +1 -1
- data/test/helper_test.rb +12 -12
- data/test/humble_auth_test.rb +10 -10
- data/test/test_helper.rb +8 -4
- metadata +45 -38
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: dddd7aec8f7c8671926fcf51e3858a4d26820957
|
4
|
+
data.tar.gz: b72216474691403a7b4302fedd6aae53f371f31c
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 6345d1b435c445f7da41344cf25816536ed96e43125022142e5c692c22d6694c32731df19e9b8c935739252980999ddb55c62dc18a3c79bb7b59b048b5ed97cf
|
7
|
+
data.tar.gz: 9258fde3290b73b617e4ebeb4997d624f3e89b13b5043905725a9eeaae4163fcff1212b7d632298b460852f4de3a32e8b275809e8856042d5bfcd587f93bd1ea
|
data/lib/humble_auth/helper.rb
CHANGED
@@ -5,15 +5,15 @@ module HumbleAuth
|
|
5
5
|
helper_method :authenticated?
|
6
6
|
end
|
7
7
|
end
|
8
|
-
|
8
|
+
|
9
9
|
def authenticated?
|
10
10
|
authentication.check
|
11
11
|
end
|
12
|
-
|
12
|
+
|
13
13
|
def reset_authentication
|
14
14
|
authentication.reset
|
15
15
|
end
|
16
|
-
|
16
|
+
|
17
17
|
protected
|
18
18
|
def require_authentication
|
19
19
|
if !authenticated? && process_authentication
|
@@ -28,11 +28,11 @@ module HumbleAuth
|
|
28
28
|
true
|
29
29
|
end
|
30
30
|
end
|
31
|
-
|
31
|
+
|
32
32
|
def authentication
|
33
33
|
@authentication ||= HumbleAuth::Auth.new(authentication_config, cookies)
|
34
34
|
end
|
35
|
-
|
35
|
+
|
36
36
|
def authentication_config
|
37
37
|
Rails.application.config.auth
|
38
38
|
end
|
data/lib/humble_auth/railtie.rb
CHANGED
@@ -6,7 +6,7 @@ module HumbleAuth
|
|
6
6
|
initializer 'humble_auth.initialize' do
|
7
7
|
config_file = Rails.root.join('config', 'auth.yml').to_s
|
8
8
|
config.auth = HumbleAuth::Auth.make_config(File.exists?(config_file) ? YAML.load_file(config_file)[Rails.env]['auth'] : false)
|
9
|
-
|
9
|
+
|
10
10
|
ActiveSupport.on_load :action_controller do
|
11
11
|
include HumbleAuth::Helper
|
12
12
|
end
|
data/lib/humble_auth/version.rb
CHANGED
data/test/helper_test.rb
CHANGED
@@ -3,14 +3,14 @@ require 'test_helper'
|
|
3
3
|
class HelperTest < ActionController::TestCase
|
4
4
|
Routes = ActionDispatch::Routing::RouteSet.new
|
5
5
|
Routes.draw do
|
6
|
-
|
6
|
+
get ':controller(/:action)'
|
7
7
|
end
|
8
8
|
Routes.finalize!
|
9
|
-
|
9
|
+
|
10
10
|
class DummyController < ActionController::Base
|
11
11
|
include HumbleAuth::Helper
|
12
12
|
before_filter :require_authentication
|
13
|
-
|
13
|
+
|
14
14
|
include Routes.url_helpers
|
15
15
|
|
16
16
|
def authentication_config
|
@@ -21,33 +21,33 @@ class HelperTest < ActionController::TestCase
|
|
21
21
|
head :ok
|
22
22
|
end
|
23
23
|
end
|
24
|
-
|
24
|
+
|
25
25
|
tests DummyController
|
26
|
-
|
26
|
+
|
27
27
|
setup do
|
28
28
|
@routes = Routes
|
29
29
|
end
|
30
|
-
|
30
|
+
|
31
31
|
test "deny access for users, who don't provide credentials" do
|
32
32
|
get :index
|
33
33
|
assert_response :unauthorized
|
34
34
|
assert !@controller.authenticated?
|
35
35
|
end
|
36
|
-
|
36
|
+
|
37
37
|
test "prevent authentication on subsequent requests for users, who don't provide credentials" do
|
38
38
|
get :index
|
39
39
|
get :index
|
40
40
|
assert_response :unauthorized
|
41
41
|
assert !@controller.authenticated?
|
42
42
|
end
|
43
|
-
|
43
|
+
|
44
44
|
test "allow access for users, who provide credentials" do
|
45
45
|
@request.env['HTTP_AUTHORIZATION'] = encode_credentials('YourLogin', 'YoURPAsSwORd')
|
46
46
|
get :index
|
47
47
|
assert_response :success
|
48
48
|
assert @controller.authenticated?
|
49
49
|
end
|
50
|
-
|
50
|
+
|
51
51
|
test "allow access for users, who provide credentials on subsequest requests" do
|
52
52
|
@request.env['HTTP_AUTHORIZATION'] = encode_credentials('YourLogin', 'YoURPAsSwORd')
|
53
53
|
get :index
|
@@ -56,7 +56,7 @@ class HelperTest < ActionController::TestCase
|
|
56
56
|
assert_response :success
|
57
57
|
assert @controller.authenticated?
|
58
58
|
end
|
59
|
-
|
59
|
+
|
60
60
|
test "deny access for users after resetting authenticaton" do
|
61
61
|
@request.env['HTTP_AUTHORIZATION'] = encode_credentials('YourLogin', 'YoURPAsSwORd')
|
62
62
|
get :index
|
@@ -65,9 +65,9 @@ class HelperTest < ActionController::TestCase
|
|
65
65
|
get :index
|
66
66
|
assert_response :unauthorized
|
67
67
|
end
|
68
|
-
|
68
|
+
|
69
69
|
private
|
70
70
|
def encode_credentials(username, password)
|
71
|
-
"Basic #{ActiveSupport::Base64.encode64("#{username}:#{password}")}"
|
71
|
+
"Basic #{(defined?(::Base64) ? ::Base64 : ::ActiveSupport::Base64).encode64("#{username}:#{password}")}"
|
72
72
|
end
|
73
73
|
end
|
data/test/humble_auth_test.rb
CHANGED
@@ -2,25 +2,25 @@ require 'test_helper'
|
|
2
2
|
|
3
3
|
class DisabledAuthTest < ActiveSupport::TestCase
|
4
4
|
setup do
|
5
|
-
@store = ActionDispatch::Cookies::CookieJar.new
|
5
|
+
@store = ActionDispatch::Cookies::CookieJar.new(nil)
|
6
6
|
@config = HumbleAuth::Auth.make_config(false)
|
7
7
|
@auth ||= HumbleAuth::Auth.new(@config, @store)
|
8
8
|
end
|
9
|
-
|
9
|
+
|
10
10
|
test "authentication is not required when config is false" do
|
11
11
|
assert !@auth.required?
|
12
12
|
end
|
13
|
-
|
13
|
+
|
14
14
|
test "validates any login / password pair" do
|
15
15
|
assert @auth.validate('A', 'B')
|
16
16
|
assert @auth.validate('C', 'D')
|
17
17
|
end
|
18
|
-
|
18
|
+
|
19
19
|
test "saves 'true' value to the store with key :authentication_salt on #save" do
|
20
20
|
@auth.save
|
21
21
|
assert_equal @store[:authentication_salt], 'true'
|
22
22
|
end
|
23
|
-
|
23
|
+
|
24
24
|
test "resets :authentication_salt key in store on #reset" do
|
25
25
|
@auth.save
|
26
26
|
@auth.reset
|
@@ -30,27 +30,27 @@ end
|
|
30
30
|
|
31
31
|
class EnabledAuthTest < ActiveSupport::TestCase
|
32
32
|
setup do
|
33
|
-
@store = ActionDispatch::Cookies::CookieJar.new
|
33
|
+
@store = ActionDispatch::Cookies::CookieJar.new(nil)
|
34
34
|
@config = HumbleAuth::Auth.make_config(:login => 'YourLogin', :password => 'YoURPAsSwORd', :salt => 'SOMErandomSTRING')
|
35
35
|
@auth ||= HumbleAuth::Auth.new(@config, @store)
|
36
36
|
end
|
37
|
-
|
37
|
+
|
38
38
|
test "authentication is required when config is a hash" do
|
39
39
|
assert @auth.required?
|
40
40
|
end
|
41
|
-
|
41
|
+
|
42
42
|
test "validates only login / password pair, that was specified in config" do
|
43
43
|
assert @auth.validate('YourLogin', 'YoURPAsSwORd')
|
44
44
|
assert !@auth.validate('YourLogin', 'BADPASSWORD')
|
45
45
|
assert !@auth.validate('BADLOGIN', 'YoURPAsSwORd')
|
46
46
|
assert !@auth.validate('BADLOGIN', 'BADPASSWORD')
|
47
47
|
end
|
48
|
-
|
48
|
+
|
49
49
|
test "saves salt value to the store with key :authentication_salt on #save" do
|
50
50
|
@auth.save
|
51
51
|
assert_equal @store[:authentication_salt], 'SOMErandomSTRING'
|
52
52
|
end
|
53
|
-
|
53
|
+
|
54
54
|
test "resets :authentication_salt key in store on #reset" do
|
55
55
|
@auth.save
|
56
56
|
@auth.reset
|
data/test/test_helper.rb
CHANGED
@@ -1,6 +1,10 @@
|
|
1
1
|
require 'bundler/setup'
|
2
|
-
|
3
|
-
|
4
|
-
require
|
2
|
+
require 'test/unit'
|
3
|
+
begin
|
4
|
+
require 'minitest/autorun'
|
5
|
+
rescue LoadError
|
6
|
+
end
|
7
|
+
|
8
|
+
require 'humble_auth'
|
5
9
|
require 'action_controller'
|
6
|
-
require
|
10
|
+
require 'active_support/core_ext'
|
metadata
CHANGED
@@ -1,49 +1,63 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: humble_auth
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
5
|
-
prerelease:
|
4
|
+
version: 0.1.0
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Pavel Forkert (fxposter)
|
9
8
|
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date:
|
11
|
+
date: 2015-06-17 00:00:00.000000000 Z
|
13
12
|
dependencies:
|
14
13
|
- !ruby/object:Gem::Dependency
|
15
|
-
name:
|
16
|
-
requirement:
|
17
|
-
none: false
|
14
|
+
name: railties
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
18
16
|
requirements:
|
19
|
-
- -
|
17
|
+
- - ">="
|
20
18
|
- !ruby/object:Gem::Version
|
21
19
|
version: '3.0'
|
20
|
+
- - "<"
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: '5.0'
|
22
23
|
type: :runtime
|
23
24
|
prerelease: false
|
24
|
-
version_requirements:
|
25
|
-
- !ruby/object:Gem::Dependency
|
26
|
-
name: activesupport
|
27
|
-
requirement: &70356287250580 !ruby/object:Gem::Requirement
|
28
|
-
none: false
|
25
|
+
version_requirements: !ruby/object:Gem::Requirement
|
29
26
|
requirements:
|
30
|
-
- -
|
27
|
+
- - ">="
|
31
28
|
- !ruby/object:Gem::Version
|
32
29
|
version: '3.0'
|
33
|
-
|
30
|
+
- - "<"
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '5.0'
|
33
|
+
- !ruby/object:Gem::Dependency
|
34
|
+
name: test-unit
|
35
|
+
requirement: !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
37
|
+
- - ">="
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: '0'
|
40
|
+
type: :development
|
34
41
|
prerelease: false
|
35
|
-
version_requirements:
|
42
|
+
version_requirements: !ruby/object:Gem::Requirement
|
43
|
+
requirements:
|
44
|
+
- - ">="
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: '0'
|
36
47
|
- !ruby/object:Gem::Dependency
|
37
|
-
name:
|
38
|
-
requirement:
|
39
|
-
none: false
|
48
|
+
name: appraisal
|
49
|
+
requirement: !ruby/object:Gem::Requirement
|
40
50
|
requirements:
|
41
|
-
- -
|
51
|
+
- - ">="
|
42
52
|
- !ruby/object:Gem::Version
|
43
|
-
version: '
|
44
|
-
type: :
|
53
|
+
version: '0'
|
54
|
+
type: :development
|
45
55
|
prerelease: false
|
46
|
-
version_requirements:
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
requirements:
|
58
|
+
- - ">="
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: '0'
|
47
61
|
description: HTTP Basic authentication solution for Rails 3
|
48
62
|
email:
|
49
63
|
- fxposter@g,ail.com
|
@@ -51,49 +65,42 @@ executables: []
|
|
51
65
|
extensions: []
|
52
66
|
extra_rdoc_files: []
|
53
67
|
files:
|
68
|
+
- MIT-LICENSE
|
69
|
+
- README.md
|
70
|
+
- Rakefile
|
54
71
|
- lib/generators/humble_auth/install_generator.rb
|
55
72
|
- lib/generators/humble_auth/templates/auth.yml
|
73
|
+
- lib/humble_auth.rb
|
56
74
|
- lib/humble_auth/auth.rb
|
57
75
|
- lib/humble_auth/helper.rb
|
58
76
|
- lib/humble_auth/railtie.rb
|
59
77
|
- lib/humble_auth/version.rb
|
60
|
-
- lib/humble_auth.rb
|
61
|
-
- MIT-LICENSE
|
62
|
-
- Rakefile
|
63
|
-
- README.md
|
64
78
|
- test/generators_test.rb
|
65
79
|
- test/helper_test.rb
|
66
80
|
- test/humble_auth_test.rb
|
67
81
|
- test/test_helper.rb
|
68
82
|
homepage: https://github.com/fxposter/humble_auth
|
69
83
|
licenses: []
|
84
|
+
metadata: {}
|
70
85
|
post_install_message:
|
71
86
|
rdoc_options: []
|
72
87
|
require_paths:
|
73
88
|
- lib
|
74
89
|
required_ruby_version: !ruby/object:Gem::Requirement
|
75
|
-
none: false
|
76
90
|
requirements:
|
77
|
-
- -
|
91
|
+
- - ">="
|
78
92
|
- !ruby/object:Gem::Version
|
79
93
|
version: '0'
|
80
|
-
segments:
|
81
|
-
- 0
|
82
|
-
hash: 2808104105763644241
|
83
94
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
84
|
-
none: false
|
85
95
|
requirements:
|
86
|
-
- -
|
96
|
+
- - ">="
|
87
97
|
- !ruby/object:Gem::Version
|
88
98
|
version: '0'
|
89
|
-
segments:
|
90
|
-
- 0
|
91
|
-
hash: 2808104105763644241
|
92
99
|
requirements: []
|
93
100
|
rubyforge_project:
|
94
|
-
rubygems_version:
|
101
|
+
rubygems_version: 2.4.5
|
95
102
|
signing_key:
|
96
|
-
specification_version:
|
103
|
+
specification_version: 4
|
97
104
|
summary: The simplest authentication solution for Rails 3
|
98
105
|
test_files:
|
99
106
|
- test/generators_test.rb
|