Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

backport #1816 #1852

Merged
merged 1 commit into from
Feb 25, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions nginx_stage/lib/nginx_stage/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,18 @@ def initialize(user)
@passwd = Etc.getpwnam user.to_s
@group = Etc.getgrgid gid
@groups = get_groups

if name.to_s != user.to_s
err_msg = <<~HEREDOC
Username '#{user}' is being mapped to '#{name}' in SSSD and they don't match.
Users with domain names cannot be mapped correctly. If '#{name}' still has the
domain in it you'll need to set SSSD's full_name_format to '%1$s'.

See https://github.com/OSC/ondemand/issues/1759 for more details.
HEREDOC

raise StandardError, err_msg
end
end

# User's primary group name
Expand Down
43 changes: 43 additions & 0 deletions nginx_stage/spec/user_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
require 'nginx_stage'
require 'spec_helper'

describe NginxStage::User do

let(:test_user) { "spec" }
let(:test_user_full_name) { "spec@domain.edu" }
let(:test_user_gid) { 1111 }

def stub_etc(username)
etc_stub = {
:gid => test_user_gid,
:name => username
}

allow(Etc).to receive(:getpwnam).with(test_user).and_return(Struct.new(*etc_stub.keys).new(*etc_stub.values))
allow(Etc).to receive(:getgrgid).with(test_user_gid).and_return(nil)
allow_any_instance_of(NginxStage::User).to receive(:get_groups).and_return([test_user])
end

describe 'initialization' do

it 'initializes correctly' do
stub_etc(test_user)

u = described_class.new(test_user)
expect(u.name).to equal(test_user)
end

it 'raises an error when etc is different from username' do
stub_etc(test_user_full_name)

msg = <<~HEREDOC
Username 'spec' is being mapped to 'spec@domain.edu' in SSSD and they don't match.
Users with domain names cannot be mapped correctly. If 'spec@domain.edu' still has the
domain in it you'll need to set SSSD's full_name_format to '%1$s'.

See https://github.com/OSC/ondemand/issues/1759 for more details.
HEREDOC
expect { described_class.new(test_user) }.to raise_error(StandardError, msg)
end
end
end