Skip to content

Commit

Permalink
More details
Browse files Browse the repository at this point in the history
  • Loading branch information
lslezak committed Feb 27, 2019
1 parent 5faf83f commit 294d411
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 11 deletions.
6 changes: 3 additions & 3 deletions src/lib/registration/connect_helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ def self.handle_ssl_error(error, certificate_imported)
# in non-AutoYast mode ask the user to import the certificate
if !Yast::Mode.autoinst && cert && SslErrorCodes::IMPORT_ERROR_CODES.include?(error_code)
# retry after successfull import
return true if ask_import_ssl_certificate(cert)
return true if ask_import_ssl_certificate(cert, error_code)
# in AutoYast mode check whether the certificate fingerprint match
# the configured value (if present)
elsif Yast::Mode.autoinst && cert && expected_cert_type && !expected_cert_type.empty?
Expand All @@ -216,9 +216,9 @@ def self.handle_ssl_error(error, certificate_imported)
false
end

def self.ask_import_ssl_certificate(cert)
def self.ask_import_ssl_certificate(cert, error_code)
# run the import dialog, check the user selection
if UI::ImportCertificateDialog.run(cert) != :import
if UI::ImportCertificateDialog.run(cert, error_code) != :import
log.info "Certificate import rejected"
return false
end
Expand Down
24 changes: 17 additions & 7 deletions src/lib/registration/ui/import_certificate_dialog.rb
Original file line number Diff line number Diff line change
@@ -1,36 +1,41 @@

require "erb"
require "yast"

require "registration/fingerprint"
require "registration/ssl_certificate_details"
require "registration/ssl_error_codes"
require "registration/url_helpers"

module Registration
module UI
# this class displays and runs the dialog for importing a SSL certificate
class ImportCertificateDialog
include ERB::Util
include Yast::Logger
include Yast::I18n
extend Yast::I18n
include Yast::UIShortcuts

attr_accessor :certificate
attr_accessor :certificate, :error_code

Yast.import "UI"
Yast.import "Label"

# create a new dialog for importing a SSL certificate and run it
# @param cert [Registration::SslCertitificate] certificate to display
# @return [Symbol] user input (:import, :cancel)
def self.run(cert)
dialog = ImportCertificateDialog.new(cert)
def self.run(cert, error_code)
dialog = ImportCertificateDialog.new(cert, error_code)
dialog.run
end

# the constructor
# @param cert [Registration::SslCertitificate] certificate to display
def initialize(cert)
def initialize(cert, error_code)
textdomain "registration"
@certificate = cert
@error_code = error_code
end

# display the dialog and wait for a button click
Expand Down Expand Up @@ -77,7 +82,7 @@ def import_dialog_content
hide_help = displayinfo["TextMode"] && displayinfo["Width"] < 105

window_height = displayinfo["Height"]
window_height = 25 if window_height > 25
window_height = 26 if window_height > 26

HBox(
VSpacing(window_height),
Expand All @@ -99,9 +104,14 @@ def handle_dialog

# render Richtext description with the certificate details
def certificate_description
msg = _(SslErrorCodes::OPENSSL_ERROR_MESSAGES[error_code])
url = UrlHelpers.registration_url || SUSE::Connect::YaST::DEFAULT_URL
details = SslCertificateDetails.new(certificate)
"<h2>#{_("Secure Connection Error")}</h2>\n" +
details.richtext_summary

"<h2>#{_("Secure Connection Error")}</h2>\n" \
"<p>#{_("Details:")} #{h(url)}: #{h(msg)}</p>\n" \
"<h3>#{_("Failed Certificate Details")}</h3>\n" +
details.richtext_summary
end

# inline help text displayed in the import dialog
Expand Down
5 changes: 4 additions & 1 deletion test/import_certificate_dialog_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
describe Registration::UI::ImportCertificateDialog do
describe ".run" do
it "displays the certificate details and returns the user input" do
allow(Registration::UrlHelpers).to receive(:registration_url)
# generic UI mocks
expect(Yast::UI).to receive(:CloseDialog)
# "Cancel" button must be the default
Expand All @@ -25,7 +26,9 @@
end

cert = Registration::SslCertificate.load_file(fixtures_file("test.pem"))
expect(Registration::UI::ImportCertificateDialog.run(cert)).to eq(:import)
expect(Registration::UI::ImportCertificateDialog.run(
cert, Registration::SslErrorCodes::SELF_SIGNED_CERT
)).to eq(:import)
end
end
end

0 comments on commit 294d411

Please sign in to comment.