Skip to content

Commit

Permalink
Merge pull request #867 from shundhammer/huha-no-local-users
Browse files Browse the repository at this point in the history
Allow system role to default to no local user
  • Loading branch information
shundhammer committed Nov 22, 2018
2 parents d03eb4d + b7d7bfd commit da0dadb
Show file tree
Hide file tree
Showing 4 changed files with 165 additions and 64 deletions.
23 changes: 23 additions & 0 deletions library/control/src/modules/ProductFeatures.rb
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ def main
"vendor_url" => "",
"enable_clone" => false,
"disable_os_prober" => false,
"enable_local_users" => true,
# FATE #304865
"base_product_license_directory" => "/etc/YaST2/licenses/base/",
"full_system_media_name" => "",
Expand Down Expand Up @@ -241,6 +242,27 @@ def GetBooleanFeature(section, feature)
Ops.is_string?(value) && Builtins.tolower(Convert.to_string(value)) == "yes"
end

# Get value of a boolean feature with a fallback value.
#
# @note This is a stable API function
# @param [String] section string section of the feature
# @param [String] feature feature name
# @param [Boolean] fallback
#
# @return [Boolean] the feature value or fallback if not specified
def GetBooleanFeatureWithFallback(section, feature, fallback)
value = GetFeature(section, feature)
return fallback if value.nil?
return value if Ops.is_boolean?(value)

if value.respond_to?(:downcase)
return true if ["yes", "true"].include?(value.downcase)
return false if ["no", "false"].include?(value.downcase)
end

fallback
end

# Get value of a feature
# @note This is a stable API function
# @param [String] section string section of the feature
Expand Down Expand Up @@ -358,6 +380,7 @@ def ClearOverlay
publish function: :InitIfNeeded, type: "void ()"
publish function: :GetFeature, type: "any (string, string)"
publish function: :GetBooleanFeature, type: "boolean (string, string)"
publish function: :GetBooleanFeatureWithFallback, type: "boolean (string, string, boolean)"
publish function: :GetIntegerFeature, type: "integer (string, string)"
publish function: :SetFeature, type: "void (string, string, any)"
publish function: :SetStringFeature, type: "void (string, string, string)"
Expand Down
197 changes: 134 additions & 63 deletions library/control/test/ProductFeatures_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,84 +7,155 @@
describe Yast::ProductFeatures do
subject { Yast::ProductFeatures }

before do
# ensure no overlay is active
subject.ClearOverlay
end
context "With simple features" do

let(:original_features) do
{
"globals" => {
"keyboard " => "Hammond",
"flags" => ["Uruguay", "Bhutan"]
},
"partitioning" => {
"open_space" => false
let(:simple_features) do
{
"globals" => {
"enable_true" => true,
"enable_false" => false,
"enable_yes" => "yes",
"enable_no" => "no",
"enable_xy" => "xy",
"enable_empty" => ""
# "enable_missing" => nil
}
}
}
end
end

let(:overlay_features) do
{
"globals" => {
"flags" => ["Namibia"]
},
"software" => {
"packages" => ["tangut-fonts"]
}
}
end
before do
subject.Import(simple_features)
end

let(:resulting_features) do
{
"globals" => {
"keyboard " => "Hammond",
"flags" => ["Namibia"]
},
"partitioning" => {
"open_space" => false
},
"software" => {
"packages" => ["tangut-fonts"]
}
}
end
describe ".GetBooleanFeature" do
it "gets simple boolean values" do
expect(subject.GetBooleanFeature("globals", "enable_true")).to be true
expect(subject.GetBooleanFeature("globals", "enable_false")).to be false
end

describe ".SetOverlay" do
it "overrides desired values and keeps other values" do
subject.Import(original_features)
subject.SetOverlay(overlay_features)
expect(subject.Export).to eq(resulting_features)
it "understands 'yes'" do
expect(subject.GetBooleanFeature("globals", "enable_yes")).to be true
end

it "falls back to 'false' for arbitrary texts" do
expect(subject.GetBooleanFeature("globals", "enable_xy")).to be false
end

it "falls back to 'false' for empty strings" do
expect(subject.GetBooleanFeature("globals", "enable_empty")).to be false
end

it "falls back to 'false' for missing values" do
expect(subject.GetBooleanFeature("globals", "enable_missing")).to be false
end
end

it "raises RuntimeError if called twice without ClearOverlay meanwhile" do
subject.Import(original_features)
subject.SetOverlay(overlay_features)
expect { subject.SetOverlay(overlay_features) }.to raise_error(RuntimeError)
describe ".GetBooleanFeatureWithFallback" do
it "gets simple boolean values" do
expect(subject.GetBooleanFeatureWithFallback("globals", "enable_true", false)).to be true
expect(subject.GetBooleanFeatureWithFallback("globals", "enable_false", true)).to be false
end

it "understands 'yes' and 'no'" do
expect(subject.GetBooleanFeatureWithFallback("globals", "enable_yes", false)).to be true
expect(subject.GetBooleanFeatureWithFallback("globals", "enable_no", true)).to be false
end

it "uses the fallback for arbitrary texts" do
expect(subject.GetBooleanFeatureWithFallback("globals", "enable_xy", true)).to be true
end

it "uses the fallback for empty strings" do
expect(subject.GetBooleanFeatureWithFallback("globals", "enable_empty", true)).to be true
end

it "uses the fallback for missing values" do
expect(subject.GetBooleanFeatureWithFallback("globals", "enable_missing", true)).to be true
expect(subject.GetBooleanFeatureWithFallback("globals", "enable_missing", false)).to be false
end
end
end

describe ".ClearOverlay" do
it "restores the original state" do
subject.Import(original_features)
subject.SetOverlay(overlay_features)
context "With overlays" do
before do
# ensure no overlay is active
subject.ClearOverlay
expect(subject.Export).to eq(original_features)
end

it "does nothing in second consequent call" do
subject.Import(original_features)
subject.SetOverlay(overlay_features)
subject.ClearOverlay
subject.SetFeature("globals", "keyboard", "test")
subject.ClearOverlay
expect(subject.Export).to_not eq(original_features)
let(:original_features) do
{
"globals" => {
"keyboard " => "Hammond",
"flags" => ["Uruguay", "Bhutan"]
},
"partitioning" => {
"open_space" => false
}
}
end

it "keeps the original state if nothing was overlaid" do
subject.Import(original_features)
subject.ClearOverlay
expect(subject.Export).to eq(original_features)
let(:overlay_features) do
{
"globals" => {
"flags" => ["Namibia"]
},
"software" => {
"packages" => ["tangut-fonts"]
}
}
end

let(:resulting_features) do
{
"globals" => {
"keyboard " => "Hammond",
"flags" => ["Namibia"]
},
"partitioning" => {
"open_space" => false
},
"software" => {
"packages" => ["tangut-fonts"]
}
}
end

describe ".SetOverlay" do
it "overrides desired values and keeps other values" do
subject.Import(original_features)
subject.SetOverlay(overlay_features)
expect(subject.Export).to eq(resulting_features)
end

it "raises RuntimeError if called twice without ClearOverlay meanwhile" do
subject.Import(original_features)
subject.SetOverlay(overlay_features)
expect { subject.SetOverlay(overlay_features) }.to raise_error(RuntimeError)
end
end

describe ".ClearOverlay" do
it "restores the original state" do
subject.Import(original_features)
subject.SetOverlay(overlay_features)
subject.ClearOverlay
expect(subject.Export).to eq(original_features)
end

it "does nothing in second consequent call" do
subject.Import(original_features)
subject.SetOverlay(overlay_features)
subject.ClearOverlay
subject.SetFeature("globals", "keyboard", "test")
subject.ClearOverlay
expect(subject.Export).to_not eq(original_features)
end

it "keeps the original state if nothing was overlaid" do
subject.Import(original_features)
subject.ClearOverlay
expect(subject.Export).to eq(original_features)
end
end
end
end
7 changes: 7 additions & 0 deletions package/yast2.changes
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
-------------------------------------------------------------------
Wed Nov 21 17:23:00 UTC 2018 - Stefan Hundhammer <shundhammer@suse.com>

- Added global parameter enable_local_users (Fate#326447)
- Added ProductFeatures::GetBooleanFeatureWithFallback
- 4.1.35

-------------------------------------------------------------------
Fri Nov 16 14:38:31 CET 2018 - aschnell@suse.com

Expand Down
2 changes: 1 addition & 1 deletion package/yast2.spec
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@


Name: yast2
Version: 4.1.34
Version: 4.1.35
Release: 0
Summary: YaST2 - Main Package
License: GPL-2.0-only
Expand Down

0 comments on commit da0dadb

Please sign in to comment.