Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions service/lib/dinstaller/dbus/clients/question.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ def initialize(object_path)

@dbus_object = service[object_path]
@dbus_iface = @dbus_object["org.opensuse.DInstaller.Question1"]
# one D-Bus client for all kinds of questions
@luks_iface = @dbus_object["org.opensuse.DInstaller.Question.LuksActivation1"]
end

# @return [String]
Expand All @@ -46,11 +48,21 @@ def service_name

# TODO: what other methods are useful?

# @return [String] Question text
def text
@dbus_iface["Text"].to_s
end

# @return [Symbol] no answer yet = :""
def answer
@dbus_iface["Answer"].to_sym
end

# @return [String]
def password
@luks_iface["Password"]
end

# Whether the question is already answered
#
# @return [Boolean]
Expand Down
28 changes: 23 additions & 5 deletions service/lib/dinstaller/dbus/clients/questions_manager.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,18 @@ def service_name
# @param question [DInstaller::Question]
# @return [DBus::Clients::Question]
def add(question)
q_path = @dbus_object.New(
question.text,
question.options.map(&:to_s),
Array(question.default_option&.to_s)
)
q_path = add_dbus_question(question)
DBus::Clients::Question.new(q_path)
end

def add_dbus_question(question)
if question.is_a?(DInstaller::LuksActivationQuestion)
add_luks_activation_question(question)
else
add_generic_question(question)
end
end

# Deletes the given question
#
# @param question [DBus::Clients::Question]
Expand Down Expand Up @@ -85,6 +89,20 @@ def wait(questions)

# @return [::DBus::Object]
attr_reader :dbus_object

def add_generic_question(question)
@dbus_object.New(
question.text,
question.options.map(&:to_s),
Array(question.default_option&.to_s)
)
end

def add_luks_activation_question(question)
@dbus_object.NewLuksActivation(
question.device, question.label, question.size
)
end
end
end
end
Expand Down
8 changes: 1 addition & 7 deletions service/lib/dinstaller/dbus/manager_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
require "dinstaller/manager"
require "dinstaller/cockpit_manager"
require "dinstaller/dbus/manager"
require "dinstaller/dbus/language"
require "dinstaller/dbus/storage/proposal"

module DInstaller
Expand Down Expand Up @@ -102,18 +101,13 @@ def service
# @return [Array<::DBus::Object>]
def dbus_objects
@dbus_objects ||= [
manager_dbus,
language_dbus
manager_dbus
]
end

def manager_dbus
@manager_dbus ||= DInstaller::DBus::Manager.new(manager, logger)
end

def language_dbus
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch!

@language_dbus ||= DInstaller::DBus::Language.new(manager.language, logger)
end
end
end
end
8 changes: 8 additions & 0 deletions service/lib/dinstaller/dbus/questions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,14 @@ def managed_objects
path_for(backend_q)
end

dbus_method :NewLuksActivation, "in device:s, in label:s, in size:s, out q:o" do
|device, label, size|

backend_q = DInstaller::LuksActivationQuestion.new(device, label: label, size: size)
backend.add(backend_q)
path_for(backend_q)
end

dbus_method :Delete, "in question:o" do |question_path|
dbus_q = @service.get_node(question_path)&.object
raise ArgumentError, "Object path #{question_path} not found" unless dbus_q
Expand Down
18 changes: 9 additions & 9 deletions service/lib/dinstaller/luks_activation_question.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,15 @@ module DInstaller
#
# question.answer = :decrypt # in case you want to decrypt with the given password
class LuksActivationQuestion < Question
# @return [String]
attr_reader :device

# @return [String, nil]
attr_reader :label

# @return [String, nil]
attr_reader :size

# Current attempt to decrypt the device
#
# @return [Integer]
Expand All @@ -62,15 +71,6 @@ def initialize(device, label: nil, size: nil, attempt: 1)

private

# @return [String]
attr_reader :device

# @return [String, nil]
attr_reader :label

# @return [String, nil]
attr_reader :size

# Generate the text for the question
#
# @return [String]
Expand Down
17 changes: 17 additions & 0 deletions service/test/dinstaller/dbus/clients/question_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,15 @@
.and_return(dbus_object)
allow(dbus_object).to receive(:[]).with("org.opensuse.DInstaller.Question1")
.and_return(question_iface)
allow(dbus_object).to receive(:[]).with("org.opensuse.DInstaller.Question.LuksActivation1")
.and_return(luks_iface)
end

let(:bus) { instance_double(::DBus::SystemBus) }
let(:service) { instance_double(::DBus::Service) }
let(:dbus_object) { instance_double(::DBus::ProxyObject) }
let(:question_iface) { instance_double(::DBus::ProxyObjectInterface) }
let(:luks_iface) { instance_double(::DBus::ProxyObjectInterface) }

subject { described_class.new("/org/opensuse/DInstaller/Questions1/23") }

Expand All @@ -46,4 +49,18 @@
expect(subject.answered?).to eq false
end
end

describe "#text" do
it "returns the appropriate property" do
expect(question_iface).to receive(:[]).with("Text").and_return("the text")
expect(subject.text).to eq "the text"
end
end

describe "#password" do
it "returns the appropriate property of the luks interface" do
expect(luks_iface).to receive(:[]).with("Password").and_return("the password")
expect(subject.password).to eq "the password"
end
end
end
14 changes: 5 additions & 9 deletions service/test/dinstaller/dbus/manager_service_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,17 +37,13 @@
let(:software_client) do
instance_double(DInstaller::DBus::Clients::Software, on_product_selected: nil)
end
let(:language_client) do
instance_double(DInstaller::DBus::Clients::Language, on_language_selected: nil)
end

before do
allow(::DBus::SystemBus).to receive(:instance).and_return(bus)
allow(bus).to receive(:request_service).and_return(bus_service)
allow(DInstaller::Manager).to receive(:new).with(config, logger).and_return(manager)
allow(DInstaller::CockpitManager).to receive(:new).and_return(cockpit)
allow(manager).to receive(:software).and_return(software_client)
allow(manager).to receive(:language).and_return(language_client)
end

describe "#start" do
Expand All @@ -58,12 +54,12 @@
end

describe "#export" do
it "exports the language manager object" do
language_obj = instance_double(DInstaller::DBus::Language, path: nil)
allow(DInstaller::DBus::Language).to receive(:new)
.with(manager.language, logger).and_return(language_obj)
it "exports the manager object" do
manager_obj = instance_double(DInstaller::DBus::Manager, path: nil)
allow(DInstaller::DBus::Manager).to receive(:new)
.with(manager, logger).and_return(manager_obj)

expect(bus_service).to receive(:export).with(language_obj)
expect(bus_service).to receive(:export).with(manager_obj)
service.export
end
end
Expand Down
40 changes: 40 additions & 0 deletions service/test/dinstaller/dbus/questions_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -132,4 +132,44 @@
.to contain_exactly("Attempt", "Password")
end
end

describe "Questions interface" do
let(:interface) { "org.opensuse.DInstaller.Questions1" }
let(:full_method_name) { described_class.make_method_name(interface, method_name) }

describe "#New" do
let(:method_name) { "New" }

it "adds a question and returns its path" do
expect(backend).to receive(:add)
expect(subject.public_send(full_method_name, "How you doin?", ["fine", "great"], []))
.to start_with "/org/opensuse/DInstaller/Questions1/"
end
end

describe "#NewLuksActivation" do
let(:method_name) { "NewLuksActivation" }

it "adds a question and returns its path" do
expect(backend).to receive(:add)
expect(subject.public_send(full_method_name, "/dev/tape1", "New games", "90 minutes"))
.to start_with "/org/opensuse/DInstaller/Questions1/"
end
end

describe "#Delete" do
let(:method_name) { "Delete" }

it "deletes the question" do
q = DInstaller::Question.new("Huh?", options: [])
path = "/org/opensuse/DInstaller/Questions1/666"
dbus_q = DInstaller::DBus::Question.new(path, q, logger)
node = instance_double(DBus::Node, object: dbus_q)

expect(service).to receive(:get_node).with(path).and_return(node)
expect(backend).to receive(:delete).with(q)
expect { subject.public_send(full_method_name, path) }.to_not raise_error
end
end
end
end
6 changes: 3 additions & 3 deletions service/test/dinstaller/questions_manager_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
let(:callback) { proc {} }

let(:question1) { DInstaller::Question.new("test1", options: [:yes, :no]) }
let(:question2) { DInstaller::Question.new("test2", options: [:yes, :no]) }
let(:question2) { DInstaller::LuksActivationQuestion.new("sda1") }

describe "#add" do
before do
Expand All @@ -51,7 +51,7 @@
subject.add(question1)
end

it "returns trthy value" do
it "returns truthy value" do
expect(subject.add(question1)).to be_truthy
end
end
Expand Down Expand Up @@ -137,7 +137,7 @@
proc do
times += 1
question1.answer = :yes if times == 2
question2.answer = :no if times == 3
question2.answer = :skip if times == 3
end
end

Expand Down