From 5314530a3c07d2d864f533cd0cba8c147971b558 Mon Sep 17 00:00:00 2001 From: Colin Kuskie Date: Wed, 5 Oct 2011 22:38:09 -0700 Subject: [PATCH] When using encrypted logins, do not add the webServerPort from the config file. Fixes bug #12269. --- docs/changelog/7.x.x.txt | 1 + lib/WebGUI/Auth.pm | 13 ++++++++----- lib/WebGUI/Macro/L_loginBox.pm | 7 +++++-- t/Macro/L_loginBox.t | 8 +++++++- 4 files changed, 21 insertions(+), 8 deletions(-) diff --git a/docs/changelog/7.x.x.txt b/docs/changelog/7.x.x.txt index 9a32d64cc..9a318f0da 100644 --- a/docs/changelog/7.x.x.txt +++ b/docs/changelog/7.x.x.txt @@ -2,6 +2,7 @@ - fixed #12256: Calendar Search doesn't show admin controls - fixed #12268: Point of sale form missing from cart screen. - fixed #12201: AssetReport - no selects. + - fixed #12269: Login / Loginbox with encryptlogin 7.10.23 - fixed #12225: Stock asset, multiple instances on a page diff --git a/lib/WebGUI/Auth.pm b/lib/WebGUI/Auth.pm index 4cd99db95..f87a98083 100644 --- a/lib/WebGUI/Auth.pm +++ b/lib/WebGUI/Auth.pm @@ -590,8 +590,10 @@ sub displayLogin { $vars->{title} = $i18n->get(66); my $action; if ($self->session->setting->get("encryptLogin")) { - $action = $self->session->url->page(undef,1); - $action =~ s/http:/https:/; + my $uri = URI->new($session->url->page(undef,1)); + $uri->scheme('https'); + $uri->host_port($uri->host); + $action = $uri->as_string; } $vars->{'login.form.header'} = WebGUI::Form::formHeader($self->session,{action=>$action}); $vars->{'login.form.hidden'} = WebGUI::Form::hidden($self->session,{"name"=>"op","value"=>"auth"}); @@ -923,9 +925,10 @@ sub login { $self->session->scratch->delete("redirectAfterLogin"); } elsif ($self->session->setting->get('encryptLogin')) { - my $currentUrl = $self->session->url->page(undef,1); - $currentUrl =~ s/^https:/http:/; - $self->session->http->setRedirect($currentUrl); + my $currentUrl = URI->new($self->session->url->page(undef,1)); + $currentUrl->scheme('http'); + $currentUrl->port($self->session->config->get('webServerPort') || 80); + $self->session->http->setRedirect($currentUrl->canonical->as-string); } # Get open version tag. This is needed if we want diff --git a/lib/WebGUI/Macro/L_loginBox.pm b/lib/WebGUI/Macro/L_loginBox.pm index a747b1cae..359941965 100644 --- a/lib/WebGUI/Macro/L_loginBox.pm +++ b/lib/WebGUI/Macro/L_loginBox.pm @@ -14,6 +14,7 @@ use strict; use WebGUI::Form; use WebGUI::International; use WebGUI::Asset::Template; +use URI; =head1 NAME @@ -96,8 +97,10 @@ sub process { my $action; if ($session->setting->get("encryptLogin")) { - $action = $session->url->page(undef,1); - $action =~ s/http:/https:/; + my $uri = URI->new($session->url->page(undef,1)); + $uri->scheme('https'); + $uri->host_port($uri->host); + $action = $uri->canonical->as_string; } $var{'form.header'} = WebGUI::Form::formHeader($session,{action=>$action}) .WebGUI::Form::hidden($session,{ diff --git a/t/Macro/L_loginBox.t b/t/Macro/L_loginBox.t index b7a1e4a27..78c7c6c87 100644 --- a/t/Macro/L_loginBox.t +++ b/t/Macro/L_loginBox.t @@ -38,7 +38,7 @@ $session->{_env}->{_env} = \%newEnvHash; my $i18n = WebGUI::International->new($session,'Macro_L_loginBox'); -plan tests => 30; +plan tests => 31; my $output = WebGUI::Macro::L_loginBox::process($session,'','',$template->getId); my %vars = simpleTextParser($output); @@ -155,6 +155,12 @@ $output = WebGUI::Macro::L_loginBox::process($session,'','',$template->getId); %vars = simpleTextParser($output); like($vars{'form.header'}, qr{https://}, 'form.header action set to use SSL by encryptLogin'); +WebGUI::Test->originalConfig('webServerPort'); +$session->config->set('webServerPort', 8081); +$output = WebGUI::Macro::L_loginBox::process($session,'','',$template->getId); +%vars = simpleTextParser($output); +unlike($vars{'form.header'}, qr{:8081}, '... when setting, remove the port'); + ##Finally, a test that the default Template exists $output = WebGUI::Macro::L_loginBox::process($session,'','','');