Skip to content

Commit

Permalink
rm unused group calculation from nginx_stage (#4012)
Browse files Browse the repository at this point in the history
rm unused group calculation from nginx_stage. Supplemental groups are not used in nginx_stage anymore.
  • Loading branch information
johrstrom authored Dec 16, 2024
1 parent 0a3a9ac commit 27d28c5
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 24 deletions.
24 changes: 2 additions & 22 deletions nginx_stage/lib/nginx_stage/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,6 @@ class User
# @return [String] the shell
delegate [:name, :uid, :gid, :gecos, :dir, :shell] => :@passwd

# List of all groups that user belongs to
# @return [Array<String>] list of groups user is in
attr_reader :groups

# @param user [String] the user name defining this object
# @raise [ArgumentError] if user or primary group doesn't exist on local system
def initialize(user)
Expand Down Expand Up @@ -62,8 +58,8 @@ def initialize(user)
raise StandardError, err_msg
end
end
@group = Etc.getgrgid gid
@groups = get_groups

@group = Etc.getgrgid(gid)
end

# User's primary group name
Expand All @@ -90,21 +86,5 @@ def to_s
def to_str
@passwd.name
end

private
# Use `id` to get list of groups as the /etc/group file can give
# erroneous results
def get_groups
# Group names can contain spaces, prevent "domain users" people from being added to the "users" group
# We retrieve GIDs and convert to names (or GID)
`id -G #{name}`.split(' ').map(&:to_i).map do |gid|
begin
Etc.getgrgid(gid).name
rescue ArgumentError
# Still return the GID as a string if the group doesn't exist
gid.to_s
end
end
end
end
end
1 change: 0 additions & 1 deletion nginx_stage/spec/generators/pun_config_generator_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@

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(Struct.new(*etc_stub.keys).new(*etc_stub.values))
allow_any_instance_of(NginxStage::User).to receive(:get_groups).and_return([test_user])
end

it 'has the correct options' do
Expand Down
1 change: 0 additions & 1 deletion nginx_stage/test/test_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,5 @@ def user(username = 'test')
def stub_user(username = test)
Etc.stubs(:getpwnam).returns(user(username))
Etc.stubs(:getgrgid).returns(nil)
NginxStage::User.any_instance.stubs(:get_groups).returns(['test'])
end
end

0 comments on commit 27d28c5

Please sign in to comment.