-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
189 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
# ------------------------------------------------------------------------------ | ||
# Copyright (c) 2021 SUSE LLC, All Rights Reserved. | ||
# | ||
# This program is free software; you can redistribute it and/or modify it under | ||
# the terms of version 2 of the GNU General Public License as published by the | ||
# Free Software Foundation. | ||
# | ||
# This program is distributed in the hope that it will be useful, but WITHOUT | ||
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS | ||
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. | ||
# | ||
# ------------------------------------------------------------------------------ | ||
|
||
require "yast" | ||
|
||
require "cwm" | ||
require "installation/console/menu_plugin" | ||
require "y2storage/storage_env" | ||
|
||
module Installation | ||
module Console | ||
module Plugins | ||
# define a checkbox for enabling the experimental LUKS2 support in the installer | ||
class LUKS2CheckBox < CWM::CheckBox | ||
include Yast::Logger | ||
|
||
def initialize | ||
textdomain "storage" | ||
end | ||
|
||
# set the initial status | ||
def init | ||
check if Y2Storage::StorageEnv.instance.luks2_available? | ||
end | ||
|
||
def label | ||
# TRANSLATORS: check box label | ||
_("Enable Experimental LUKS2 Encryption Support") | ||
end | ||
|
||
def store | ||
# the evaluated env variables are cached, we need to drop the cache | ||
# when doing any change | ||
Y2Storage::StorageEnv.instance.reset_cache | ||
|
||
if checked? | ||
ENV["YAST_LUKS2_AVAILABLE"] = "1" | ||
else | ||
ENV.delete("YAST_LUKS2_AVAILABLE") | ||
end | ||
end | ||
|
||
def help | ||
# TRANSLATORS: help text for the checkbox enabling LUKS2 support | ||
_("<p>You can enable experimental LUKS2 encryption support in "\ | ||
"the YaST partitioner. It is not supported and is designed as a " \ | ||
"technology preview only.</p>") | ||
end | ||
end | ||
|
||
# define the plugin | ||
class LUKS2CheckBoxPlugin < MenuPlugin | ||
def widget | ||
LUKS2CheckBox.new | ||
end | ||
|
||
# at the end | ||
def order | ||
2000 | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
107 changes: 107 additions & 0 deletions
107
test/installation/console/plugins/luks2_checkbox_test.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
# Copyright (c) [2021] SUSE LLC | ||
# | ||
# All Rights Reserved. | ||
# | ||
# This program is free software; you can redistribute it and/or modify it | ||
# under the terms of version 2 of the GNU General Public License as published | ||
# by the Free Software Foundation. | ||
# | ||
# This program is distributed in the hope that it will be useful, but WITHOUT | ||
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for | ||
# more details. | ||
# | ||
# You should have received a copy of the GNU General Public License along | ||
# with this program; if not, contact SUSE LLC. | ||
# | ||
# To contact SUSE LLC about this file by physical or electronic mail, you may | ||
# find current contact information at www.suse.com. | ||
|
||
require_relative "../../../spec_helper" | ||
|
||
# mock the "installation/console/menu_plugin" content (from yast2-installation) | ||
module Installation | ||
module Console | ||
class MenuPlugin | ||
end | ||
end | ||
end | ||
|
||
require "installation/console/plugins/luks2_checkbox" | ||
require "cwm/rspec" | ||
|
||
describe Installation::Console::Plugins::LUKS2CheckBox do | ||
subject(:widget) { described_class.new } | ||
|
||
include_examples "CWM::CheckBox" | ||
|
||
describe "#init" do | ||
before do | ||
expect(Y2Storage::StorageEnv.instance).to receive(:luks2_available?) | ||
.and_return(luks2_available) | ||
end | ||
|
||
context "LUKS2 available" do | ||
let(:luks2_available) { true } | ||
|
||
it "sets the initial state to checked" do | ||
expect(widget).to receive(:check) | ||
widget.init | ||
end | ||
end | ||
|
||
context "LUKS2 not available" do | ||
let(:luks2_available) { false } | ||
|
||
it "sets the initial state to unchecked" do | ||
expect(widget).to_not receive(:check) | ||
widget.init | ||
end | ||
end | ||
end | ||
|
||
describe "#store" do | ||
before do | ||
allow(Y2Storage::StorageEnv.instance).to receive(:reset_cache) | ||
allow(ENV).to receive(:delete) | ||
allow(ENV).to receive(:[]=) | ||
|
||
allow(widget).to receive(:checked?).and_return(checked) | ||
end | ||
|
||
context "the checkbox is checked" do | ||
let(:checked) { true } | ||
|
||
it "sets the YAST_LUKS2_AVAILABLE env variable to 1" do | ||
expect(Y2Storage::StorageEnv.instance).to receive(:reset_cache) | ||
expect(ENV).to receive(:[]=).with("YAST_LUKS2_AVAILABLE", "1") | ||
widget.store | ||
end | ||
end | ||
|
||
context "the checkbox is not checked" do | ||
let(:checked) { false } | ||
|
||
it "deletes the YAST_LUKS2_AVAILABLE env variable" do | ||
expect(Y2Storage::StorageEnv.instance).to receive(:reset_cache) | ||
expect(ENV).to receive(:delete).with("YAST_LUKS2_AVAILABLE") | ||
widget.store | ||
end | ||
end | ||
end | ||
end | ||
|
||
describe Installation::Console::Plugins::LUKS2CheckBoxPlugin do | ||
describe "#order" do | ||
it "returns a positive number" do | ||
expect(subject.order).to be_a(Numeric) | ||
expect(subject.order).to be > 0 | ||
end | ||
end | ||
|
||
describe "#widget" do | ||
it "returns a CWM widget" do | ||
expect(subject.widget).to be_a(CWM::AbstractWidget) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters