Skip to content

Commit

Permalink
Merge pull request #109 from yast/review_160830_checking_user_entries…
Browse files Browse the repository at this point in the history
…_in_autoyast

[Review] Request from 'schubi2' @ 'yast/yast-users/review_160830_checking_user_entries_in_autoyast'
  • Loading branch information
schubi2 committed Aug 30, 2016
2 parents af0c393 + a929768 commit 5861b2c
Show file tree
Hide file tree
Showing 6 changed files with 95 additions and 1 deletion.
7 changes: 7 additions & 0 deletions package/yast2-users.changes
@@ -1,3 +1,10 @@
-------------------------------------------------------------------
Tue Aug 30 10:37:18 CEST 2016 - schubi@suse.de

- AutoYaST: Checking users entries for duplicate username/UIDs.
(bnc#995397)
- 3.1.56

-------------------------------------------------------------------
Fri Aug 12 14:37:40 UTC 2016 - ancor@suse.com

Expand Down
2 changes: 1 addition & 1 deletion package/yast2-users.spec
Expand Up @@ -17,7 +17,7 @@


Name: yast2-users
Version: 3.1.55
Version: 3.1.56
Release: 0

BuildRoot: %{_tmppath}/%{name}-%{version}-build
Expand Down
20 changes: 20 additions & 0 deletions src/clients/users_auto.rb
Expand Up @@ -36,8 +36,12 @@
# This is a client for autoinstallation. It takes its arguments,
# goes through the configuration and return the setting.
# Does not do any changes to the configuration.

Yast.import "Report"

module Yast
class UsersAutoClient < Client

def main
Yast.import "UI"
textdomain "users"
Expand Down Expand Up @@ -89,6 +93,7 @@ def main
# param = $["users": users];

if @func == "Import"
check_users(@param["users"] || [])
@ret = Users.Import(@param)
# create a summary
elsif @func == "Summary"
Expand Down Expand Up @@ -156,6 +161,21 @@ def main

deep_copy(@ret)
end

private

# Checking double user entries
# (double username or UID)
# @param [Array] users to check
def check_users(users)
if users.size > users.uniq { |u| u["username"]}.size
Report.Error(_("Found users in profile with equal <username>."))
end
if users.size > users.uniq { |u| u["uid"]}.size
Report.Error(_("Found users in profile with equal <uid>."))
end
end

end
end

Expand Down
23 changes: 23 additions & 0 deletions test/fixtures/users_error.yml
@@ -0,0 +1,23 @@
users:
- username: root
user_password: yast.password
fullname: Superuser
encrypted: true
- username: yast
user_password: suse
fullname: YaST team user
gid: 100
uid: 1000
shell: /usr/bin/zsh
encrypted: true
- username: saprouter
user_password: suse
fullname: SAP User
gid: 100
uid: 1000
shell: /usr/bin/zsh
encrypted: true
- username: root
user_password: yast.password
fullname: Superuser
encrypted: true
3 changes: 3 additions & 0 deletions test/test_helper.rb
Expand Up @@ -48,6 +48,9 @@
config.mock_with :rspec do |c|
# https://relishapp.com/rspec/rspec-mocks/v/3-0/docs/verifying-doubles/partial-doubles
c.verify_partial_doubles = true

config.extend Yast::I18n # available in context/describe
config.include Yast::I18n # available in it/let/before/...
end
end

Expand Down
41 changes: 41 additions & 0 deletions test/users_auto_test.rb
@@ -0,0 +1,41 @@
#!/usr/bin/env rspec

require_relative "test_helper"
require "yaml"
require_relative "../src/clients/users_auto"

describe Yast::UsersAutoClient do
Yast.import "WFM"
Yast.import "Users"
Yast.import "Users"
Yast.import "Report"

let(:mode) { "autoinstallation" }

before do
allow(Yast::Mode).to receive(:mode).and_return(mode)
end

describe "#AutoYaST" do

context "Import" do
let(:func) { "Import" }

context "when double users have been given in the profile" do
let(:users) { YAML.load_file(FIXTURES_PATH.join("users_error.yml")) }

before do
allow(Yast::WFM).to receive(:Args).with(no_args).and_return([func,users])
allow(Yast::WFM).to receive(:Args).with(0).and_return(func)
allow(Yast::WFM).to receive(:Args).with(1).and_return(users)
end

it "report error" do
expect(Yast::Report).to receive(:Error).with(_("Found users in profile with equal <username>."))
expect(Yast::Report).to receive(:Error).with(_("Found users in profile with equal <uid>."))
expect(subject.main).to eq(true)
end
end
end
end
end

0 comments on commit 5861b2c

Please sign in to comment.