Skip to content

Commit

Permalink
Merge 66b4102 into 4a549ac
Browse files Browse the repository at this point in the history
  • Loading branch information
lslezak committed Oct 11, 2018
2 parents 4a549ac + 66b4102 commit 5088905
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 4 deletions.
7 changes: 7 additions & 0 deletions package/yast2-registration.changes
@@ -1,3 +1,10 @@
-------------------------------------------------------------------
Thu Oct 11 14:55:15 UTC 2018 - lslezak@suse.cz

- CRLF control characters cannot be included in the registration
code, added validation check (bsc#1111419)
- 3.2.17

-------------------------------------------------------------------
Fri Aug 31 10:12:16 UTC 2018 - lslezak@suse.cz

Expand Down
2 changes: 1 addition & 1 deletion package/yast2-registration.spec
Expand Up @@ -17,7 +17,7 @@


Name: yast2-registration
Version: 3.2.16
Version: 3.2.17
Release: 0

BuildRoot: %{_tmppath}/%{name}-%{version}-build
Expand Down
13 changes: 13 additions & 0 deletions src/lib/registration/ui/base_system_registration_dialog.rb
Expand Up @@ -539,6 +539,19 @@ def validate_register_local
end
end

def validate_register_scc
reg_code = Yast::UI.QueryWidget(:reg_code, :Value)

# no CR or LF control characters, they cannot be used in HTTP header fields
if reg_code.include?("\n") || reg_code.include?("\r")
# TRANSLATORS: error message, the entered registration code is not valid.
Yast::Report.Error(_("Invalid registration code.\nCRLF characters are not allowed."))
false
else
true
end
end

VALID_CUSTOM_URL_SCHEMES = ["http", "https"].freeze

# Determine whether an URL is valid and suitable to be used as local SMT server
Expand Down
22 changes: 19 additions & 3 deletions test/base_system_registration_dialog_test.rb
Expand Up @@ -49,7 +49,7 @@
expect(Yast::UI).to receive(:QueryWidget).with(:email, :Value)
.and_return(email)
expect(Yast::UI).to receive(:QueryWidget).with(:reg_code, :Value)
.and_return(reg_code)
.and_return(reg_code).twice
expect(Yast::UI).to receive(:UserInput).and_return(:next)

options = Registration::Storage::InstallationOptions.instance
Expand All @@ -72,7 +72,7 @@
it "does not register the system" do
expect(Yast::UI).to receive(:QueryWidget).with(:email, :Value)
.and_return(email)
expect(Yast::UI).to receive(:QueryWidget).with(:reg_code, :Value)
allow(Yast::UI).to receive(:QueryWidget).with(:reg_code, :Value)
.and_return(reg_code)
expect(Yast::UI).to receive(:UserInput).and_return(:next, :abort)
expect(Registration::UI::AbortConfirmation).to receive(:run).and_return(true)
Expand All @@ -90,6 +90,22 @@
end
end

context "when user enters an invalid regcode" do
# include CRLF characters which are not allowed
let(:reg_code) { "\nmy-reg-code\r" }
it "displays error popup and does not register the system" do
allow(Yast::UI).to receive(:QueryWidget).with(:reg_code, :Value)
.and_return(reg_code)
allow(Yast::UI).to receive(:UserInput).and_return(:next, :abort)
allow(Registration::UI::AbortConfirmation).to receive(:run).and_return(true)

expect(Yast::Report).to receive(:Error).with(/Invalid registration code/)
expect(registration_ui).to_not receive(:register_system_and_base_product)

subject.run
end
end

context "when user sets a registration URL through regurl= parameter" do
let(:regurl) { "https://example.suse.net" }

Expand All @@ -100,7 +116,7 @@
it "uses the given URL to register the system" do
expect(Yast::UI).to receive(:QueryWidget).with(:email, :Value)
.and_return(email)
expect(Yast::UI).to receive(:QueryWidget).with(:reg_code, :Value)
allow(Yast::UI).to receive(:QueryWidget).with(:reg_code, :Value)
.and_return(reg_code)
expect(Yast::UI).to receive(:UserInput).and_return(:next)

Expand Down

0 comments on commit 5088905

Please sign in to comment.