Skip to content

Commit

Permalink
Merge 8a4bbb5 into 94d6832
Browse files Browse the repository at this point in the history
  • Loading branch information
lslezak committed Dec 22, 2021
2 parents 94d6832 + 8a4bbb5 commit 133bdcd
Show file tree
Hide file tree
Showing 4 changed files with 189 additions and 1 deletion.
74 changes: 74 additions & 0 deletions src/lib/installation/console/plugins/luks2_checkbox.rb
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
7 changes: 7 additions & 0 deletions src/lib/y2storage/storage_env.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,13 @@ class StorageEnv
private_constant :ENV_LIBSTORAGE_IGNORE_PROBE_ERRORS

def initialize
reset_cache
end

# Reset the cached values of the environment variables,
# call this after changing the value of any used environment variable
def reset_cache
log.debug "Resetting ENV values cache"
@active_cache = {}
end

Expand Down
107 changes: 107 additions & 0 deletions test/installation/console/plugins/luks2_checkbox_test.rb
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
2 changes: 1 addition & 1 deletion test/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
# fail fast if a class does not declare textdomain (bsc#1130822)
ENV["Y2STRICTTEXTDOMAIN"] = "1"

LIBS_TO_SKIP = ["y2packager/repository"]
LIBS_TO_SKIP = ["y2packager/repository", "installation/console/menu_plugin"]

# Hack to avoid to require some files
#
Expand Down

0 comments on commit 133bdcd

Please sign in to comment.