gollum-auth 0.5.0 → 0.6.0

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: 5cbd79ba09fbb336544e7ef52c1000a385b748c2
4
- data.tar.gz: d6a259ada4ef14639d287edeaefeb8e9dad93b38
3
+ metadata.gz: 2332f8bd41813aec6b0160d881a45938a7cd09ea
4
+ data.tar.gz: 0c670cedc7983d9408c5aa6d773ba0d88031d7e3
5
5
  SHA512:
6
- metadata.gz: adae779482ba1f8b3e5698591658078086132bf1c28d6c5b71cafe9604256f4b984379285940c19c001ab1be29b0fcb26ecc4dd8cade1470955b59285786ec4f
7
- data.tar.gz: f42ee673c27678a7aadaa42bee5e64ba659dd46f4a02886205cfdeb27c75e15976a6acab34213a7918a208e8b74716a3300b2745a610321ea345c0419e6d8118
6
+ metadata.gz: ffdc89c8f9a2b0164d134b2fd6e9c007e562da21595bec50e58755250809ee90c4d7a7d3f360bf164ed74131004b261bc680dbe41be16db8704d19d08ccf9af1
7
+ data.tar.gz: 20b0807e3131edb0306b1b1f19ee9e34b063a186433aad2306b87228c9edbfea6d44cd08668ed88f5e614e3889bebbbbceb35af10a6e29560a39b4d79501d6b3
data/README.md CHANGED
@@ -47,6 +47,10 @@ require 'gollum/app'
47
47
 
48
48
  # Define list of authorized users.
49
49
  # Each user must have a username, password, name and email.
50
+ #
51
+ # Instead of a password you can also define a password_digest, which is the
52
+ # SHA-256 hash of a password.
53
+ #
50
54
  # Example:
51
55
  users = YAML.load %q{
52
56
  ---
@@ -55,7 +59,7 @@ users = YAML.load %q{
55
59
  name: Rick Sanchez
56
60
  email: rick@example.com
57
61
  - username: morty
58
- password: 12345
62
+ password_digest: 5994471abb01112afcc18159f6cc74b4f511b99806da59b3caf5a9c173cacfc5
59
63
  name: Morty Smith
60
64
  email: morty@example.com
61
65
  }
@@ -1,3 +1,4 @@
1
+ require 'digest'
1
2
  require 'rack'
2
3
  require 'active_model'
3
4
  require 'gollum/auth/version'
@@ -21,15 +22,10 @@ module Gollum
21
22
  request = Request.new(env)
22
23
  if request.needs_authentication?(@opts[:allow_guests])
23
24
  auth = Rack::Auth::Basic::Request.new(env)
24
- if auth.provided? && auth.basic? && valid?(auth.credentials)
25
- user = User.find(auth.credentials.first)
25
+ if auth.provided? && auth.basic? && user = User.find_by_credentials(auth.credentials)
26
26
  request.store_author_in_session(user)
27
27
  else
28
- return [
29
- 401,
30
- { 'Content-Type' => 'text/plain', 'WWW-Authenticate' => 'Basic realm="Gollum Wiki"' },
31
- [ 'Not authorized' ]
32
- ]
28
+ return not_authorized
33
29
  end
34
30
  end
35
31
  @app.call(env)
@@ -37,14 +33,15 @@ module Gollum
37
33
 
38
34
  private
39
35
 
40
- def valid?(credentials)
41
- username, password = credentials
42
- current_user = User.find(username)
43
- current_user && current_user.valid_password?(password)
44
- end
45
-
46
- def users
47
- User.all
36
+ def not_authorized
37
+ [
38
+ 401,
39
+ {
40
+ 'Content-Type' => 'text/plain',
41
+ 'WWW-Authenticate' => 'Basic realm="Gollum Wiki"'
42
+ },
43
+ [ 'Not authorized' ]
44
+ ]
48
45
  end
49
46
  end
50
47
  end
@@ -5,12 +5,19 @@ module Gollum::Auth
5
5
  class User
6
6
  include ActiveModel::Model
7
7
 
8
- attr_accessor :username, :password, :name, :email
8
+ attr_accessor :username, :password_digest, :name, :email
9
9
 
10
- validates_presence_of :username, :password, :name, :email
10
+ validates_presence_of :username, :password_digest, :name, :email
11
11
  validates_format_of :username, with: /\A[\w\.-]+\Z/
12
+ validates_format_of :password_digest, with: /\A[0-9a-f]{64}\Z/
12
13
 
13
14
  class << self
15
+ def find_by_credentials(credentials)
16
+ username, password = credentials
17
+ user = find(username)
18
+ user if user && user.valid_password?(password)
19
+ end
20
+
14
21
  def find(username)
15
22
  all.select { |u| u.username == username }.first
16
23
  end
@@ -18,6 +25,10 @@ module Gollum::Auth
18
25
  def all
19
26
  @all ||= []
20
27
  end
28
+
29
+ def delete_all
30
+ @all = []
31
+ end
21
32
  end
22
33
 
23
34
  def save!
@@ -25,15 +36,23 @@ module Gollum::Auth
25
36
  end
26
37
 
27
38
  def save
28
- (self.class.all << self; self) if valid?
39
+ valid? ? (self.class.all << self; true) : false
29
40
  end
30
41
 
31
- def valid_password?(other)
32
- password == other
42
+ def valid_password?(password)
43
+ password_digest == build_digest(password)
44
+ end
45
+
46
+ def password=(password)
47
+ self.password_digest = build_digest(password) if password
33
48
  end
34
49
 
35
50
  private
36
51
 
52
+ def build_digest(password)
53
+ Digest::SHA256.hexdigest(password)
54
+ end
55
+
37
56
  def error_message
38
57
  errors.full_messages.join(', ')
39
58
  end
@@ -1,5 +1,5 @@
1
1
  module Gollum
2
2
  module Auth
3
- VERSION = '0.5.0'
3
+ VERSION = '0.6.0'
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gollum-auth
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0
4
+ version: 0.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Björn Albers
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-04-19 00:00:00.000000000 Z
11
+ date: 2017-04-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rack
@@ -168,5 +168,5 @@ rubyforge_project:
168
168
  rubygems_version: 2.6.10
169
169
  signing_key:
170
170
  specification_version: 4
171
- summary: gollum-auth-0.5.0
171
+ summary: gollum-auth-0.6.0
172
172
  test_files: []