Skip to content

Commit

Permalink
Added unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
lslezak committed Feb 25, 2019
1 parent 3ac1cc2 commit f8b3aa0
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 4 deletions.
5 changes: 1 addition & 4 deletions src/lib/registration/ssl_error_codes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ module Registration
# @see https://github.com/openssl/openssl/blob/2c75f03b39de2fa7d006bc0f0d7c58235a54d9bb/include/openssl/x509_vfy.h#L99-L189
class SslErrorCodes
extend Yast::I18n

textdomain "registration"

# "certificate has expired"
Expand Down Expand Up @@ -49,9 +48,7 @@ class SslErrorCodes
# TRANSLATORS: SSL error message
SELF_SIGNED_CERT => N_("Self signed certificate"),
# TRANSLATORS: SSL error message
SELF_SIGNED_CERT_IN_CHAIN => N_(
"Self signed certificate in certificate chain"
),
SELF_SIGNED_CERT_IN_CHAIN => N_("Self signed certificate in certificate chain"),
# TRANSLATORS: SSL error message
NO_LOCAL_ISSUER_CERTIFICATE => N_("Unable to get local issuer certificate")
}.freeze
Expand Down
67 changes: 67 additions & 0 deletions test/registration/ui/failed_certificate_popup_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
#!/usr/bin/env rspec
# ------------------------------------------------------------------------------
# Copyright (c) 2018 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_relative "../../spec_helper"
require "registration/ui/failed_certificate_popup"

describe Registration::UI::FailedCertificatePopup do

let(:ssl_error) do
"SSL_connect returned=1 errno=0 state=error: certificate verify failed " \
"(unable to get local issuer certificate"
end

let(:error_code) { Registration::SslErrorCodes::NO_LOCAL_ISSUER_CERTIFICATE }

let(:ssl_cert) do
Registration::SslCertificate.load_file(fixtures_file("test.pem"))
end

subject do
Registration::UI::FailedCertificatePopup.new(ssl_error, ssl_cert, error_code)
end

before do
allow(Yast::Report).to receive(:LongError)
allow(Yast::Stage).to receive(:initial).and_return(false)
end

# the instance method
describe "#show" do
it "displays the certificate details" do
expect(Yast::Report).to receive(:LongError).with(/Organization \(O\): .*WebYaST/)
subject.show
end

it "displays the certificate import hints" do
expect(Yast::Report).to receive(:LongError)
.with(/Save the server certificate in PEM format to file/)
subject.show
end

it "suggests to call the install_ssl_certificates script in inst-sys" do
expect(Yast::Stage).to receive(:initial).and_return(true)
expect(Yast::Report).to receive(:LongError)
.with(/install_ssl_certificates/)
subject.show
end
end

# the class method
describe ".show" do
it "displays the failed certificate popup" do
expect_any_instance_of(Registration::UI::FailedCertificatePopup).to receive(:show)
Registration::UI::FailedCertificatePopup.show(ssl_error, ssl_cert, error_code)
end
end
end

0 comments on commit f8b3aa0

Please sign in to comment.