omniauth-pam 1.3.0 → 2.0.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
  SHA256:
3
- metadata.gz: 3ad17e332ef7ec8d88db799e55709bd4a37c0f066c7dbf009ff9fd89aa4f3055
4
- data.tar.gz: f2b8dc59720e592fc6e60171bc61b28e4d506475fd26be7269c2730ee49f57ae
3
+ metadata.gz: 42f231c42e7642db6d111c52d4eafce71b8e68e973da9de38ac34ca1a9334cf5
4
+ data.tar.gz: ecaef201a88402649d3328dd15cfd9f4cc2415387f540802d9dcd5464eaff1c0
5
5
  SHA512:
6
- metadata.gz: 5459da25741c89ec011f234cc4e634ccfffcf025ce94ee739eedcd86116a551e14810b7ddaa065ad55ef432c7fef8df9f5a85b31ccdac0c8895311dc9a123aa4
7
- data.tar.gz: 911e2c60b64f08c52405b29991fcefc81555f2a0a9965b395ffe8ffa8dedd50d5b7e0ea9df446fe82ea583bb0e1304103939a274eb8c40f1fa4865bdcdc6ee57
6
+ metadata.gz: cb5789493f26df5653c0b6a60ac707919230ea5b3a430145f07c504e3624d97dc8e4970294f6a2ed678a61f414c4732e443d4a78daa3e4ff60e005dd27ca44f2
7
+ data.tar.gz: 05d8e2414f63dd6689c759e745a1dcb197964d91c9321c599feb23fda6392f92ea395110e375ae1c5c05642cd862a6058024a4d76d7b10515b189c6779e4495a
@@ -1,5 +1,11 @@
1
1
  # CHANGELOG
2
2
 
3
+ ## 2.0.0 (2018-07-13)
4
+
5
+ * Switch to using `rpam2` ([9][])
6
+
7
+ [9]: https://github.com/nickcharlton/omniauth-pam/pull/9
8
+
3
9
  ## 1.3.0 (2018-05-19)
4
10
 
5
11
  * Update the README.
@@ -1,5 +1,5 @@
1
1
  module OmniAuth
2
2
  module PAM
3
- VERSION = "1.3.0".freeze
3
+ VERSION = "2.0.0".freeze
4
4
  end
5
5
  end
@@ -1,6 +1,5 @@
1
1
  require "omniauth"
2
- require "rpam"
3
- require "etc"
2
+ require "rpam2"
4
3
 
5
4
  module OmniAuth
6
5
  module Strategies
@@ -6,16 +6,17 @@ module OmniAuth
6
6
  option :name, 'pam'
7
7
  option :fields, [:username]
8
8
  option :uid_field, :username
9
-
10
- # this map is used to return gecos in info
11
- option :gecos_map, [:name, :location, :phone, :home_phone, :description]
12
- # option :email_domain - if defined, info.email is build using uid@email_domain if not found from gecos
13
- # option :service - pam service name passed to rpam (/etc/pam.d/service_name), if not given rpam uses 'rpam'
9
+ # if provided, info.email is build using uid@email_domain
10
+ # this is used if :email is not found in pam environment
11
+ option :email_domain, nil
12
+ # pam service name passed to rpam2 (/etc/pam.d/service_name)
13
+ # if not provided rpam2 uses 'rpam'
14
+ option :service, nil
14
15
 
15
16
  def request_phase
16
17
  OmniAuth::Form.build(
17
- :title => (options[:title] || "Authenticate"),
18
- :url => callback_path
18
+ title: (options[:title] || "Authenticate"),
19
+ url: callback_path,
19
20
  ) do |field|
20
21
  field.text_field 'Username', 'username'
21
22
  field.password_field 'Password', 'password'
@@ -23,13 +24,9 @@ module OmniAuth
23
24
  end
24
25
 
25
26
  def callback_phase
26
- rpam_opts = Hash.new
27
- rpam_opts[:service] = options[:service] unless options[:service].nil?
28
-
29
- unless Rpam.auth(request['username'], request['password'], rpam_opts)
27
+ unless Rpam2.auth(options[:service], uid, request["password"])
30
28
  return fail!(:invalid_credentials)
31
29
  end
32
-
33
30
  super
34
31
  end
35
32
 
@@ -38,21 +35,17 @@ module OmniAuth
38
35
  end
39
36
 
40
37
  info do
41
- info = { :nickname => uid, :name => uid }
42
- info[:email] = "#{uid}@#{options[:email_domain]}" if options.has_key?(:email_domain)
43
- info.merge!(parse_gecos || {})
44
- end
45
-
46
- private
47
-
48
- def parse_gecos
49
- if options[:gecos_map].kind_of?(Array)
50
- begin
51
- gecos = Etc.getpwnam(uid).gecos.split(',')
52
- Hash[options[:gecos_map].zip(gecos)].delete_if { |k, v| v.nil? || v.empty? }
53
- rescue
54
- end
38
+ info = { nickname: uid, name: uid }
39
+ rpam_env = Rpam2.listenv(options[:service], uid, request["password"])
40
+ # if authentication fails fall back to empty dictionary
41
+ info.merge!(rpam_env || {})
42
+ # info should contain now email if email in pam environment
43
+ # and authentication successful
44
+ # fallback if email is not in listenv
45
+ if info[:email].nil? && !options[:email_domain].nil?
46
+ info[:email] = "#{uid}@#{options[:email_domain]}"
55
47
  end
48
+ info
56
49
  end
57
50
  end
58
51
  end
@@ -18,9 +18,8 @@ Gem::Specification.new do |s|
18
18
  s.test_files = s.files.grep(/^(test|spec|features)/)
19
19
  s.require_paths = ["lib"]
20
20
 
21
- s.add_runtime_dependency "omniauth", "~> 1.5"
22
- s.add_runtime_dependency 'rpam-ruby19', '~> 1.2.1'
23
- s.add_runtime_dependency 'etc'
21
+ s.add_runtime_dependency 'omniauth', '~> 1.5'
22
+ s.add_runtime_dependency 'rpam2', '~> 4.0'
24
23
 
25
24
  s.add_development_dependency "pry"
26
25
  s.add_development_dependency "rack-test"
@@ -1,6 +1,20 @@
1
1
  require "spec_helper"
2
2
 
3
3
  describe OmniAuth::Strategies::PAM do
4
+ before(:all) do
5
+ Rpam2.fake_data =
6
+ {
7
+ usernames: Set["authur"],
8
+ servicenames: Set["rpam", nil],
9
+ password: "a_password",
10
+ env:
11
+ {
12
+ email: "me@example.com",
13
+ name: "Authur Dent",
14
+ },
15
+ }
16
+ end
17
+
4
18
  describe "#request_phase" do
5
19
  it "displays a form" do
6
20
  get "/auth/pam"
@@ -12,21 +26,17 @@ describe OmniAuth::Strategies::PAM do
12
26
  describe "#callback_phase" do
13
27
  context "with valid credentials" do
14
28
  it "populates the auth hash" do
15
- mock_rpam(valid_credentials.merge(opts: {})).and_return(true)
16
- mock_etc
17
29
 
18
30
  post "/auth/pam/callback", valid_credentials
19
31
 
20
32
  expect(auth_hash["provider"]).to eq("pam")
21
33
  expect(auth_hash["uid"]).to eq("authur")
22
34
  expect(auth_hash["info"]["name"]).to eq("Authur Dent")
23
- expect_rpam_to_be_called(valid_credentials.merge(opts: {}))
24
35
  end
25
36
  end
26
37
 
27
38
  context "with invalid credentials" do
28
39
  it "redirects to /auth/failure" do
29
- mock_rpam(invalid_credentials.merge(opts: {}))
30
40
 
31
41
  post "/auth/pam/callback", invalid_credentials
32
42
 
@@ -34,7 +44,6 @@ describe OmniAuth::Strategies::PAM do
34
44
  expect(last_response.headers["Location"]).to eq(
35
45
  "/auth/failure?message=invalid_credentials&strategy=pam",
36
46
  )
37
- expect_rpam_to_be_called(invalid_credentials.merge(opts: {}))
38
47
  end
39
48
  end
40
49
  end
@@ -62,18 +71,4 @@ describe OmniAuth::Strategies::PAM do
62
71
  { username: "not_a_valid_user", password: "not_a_valid_password" }
63
72
  end
64
73
 
65
- def mock_rpam(username:, password:, opts:)
66
- allow(Rpam).to receive(:auth).with(username, password, opts)
67
- end
68
-
69
- def expect_rpam_to_be_called(username:, password:, opts: {})
70
- expect(Rpam).to have_received(:auth).with(username, password, opts)
71
- end
72
-
73
- def mock_etc
74
- etc_struct = Etc::Passwd.new
75
- etc_struct.gecos = "Authur Dent,,"
76
-
77
- expect(Etc).to receive(:getpwnam).with("authur").and_return(etc_struct)
78
- end
79
74
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: omniauth-pam
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.0
4
+ version: 2.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nick Charlton
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-05-19 00:00:00.000000000 Z
11
+ date: 2018-07-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: omniauth
@@ -25,33 +25,19 @@ dependencies:
25
25
  - !ruby/object:Gem::Version
26
26
  version: '1.5'
27
27
  - !ruby/object:Gem::Dependency
28
- name: rpam-ruby19
28
+ name: rpam2
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: 1.2.1
33
+ version: '4.0'
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: 1.2.1
41
- - !ruby/object:Gem::Dependency
42
- name: etc
43
- requirement: !ruby/object:Gem::Requirement
44
- requirements:
45
- - - ">="
46
- - !ruby/object:Gem::Version
47
- version: '0'
48
- type: :runtime
49
- prerelease: false
50
- version_requirements: !ruby/object:Gem::Requirement
51
- requirements:
52
- - - ">="
53
- - !ruby/object:Gem::Version
54
- version: '0'
40
+ version: '4.0'
55
41
  - !ruby/object:Gem::Dependency
56
42
  name: pry
57
43
  requirement: !ruby/object:Gem::Requirement