Merge branch 'psgi' into WebGUI8
This commit is contained in:
commit
89d4f46a18
94 changed files with 2002 additions and 2269 deletions
|
|
@ -1,52 +0,0 @@
|
|||
#-------------------------------------------------------------------
|
||||
# WebGUI is Copyright 2001-2009 Plain Black Corporation.
|
||||
#-------------------------------------------------------------------
|
||||
# Please read the legal notices (docs/legal.txt) and the license
|
||||
# (docs/license.txt) that came with this distribution before using
|
||||
# this software.
|
||||
#-------------------------------------------------------------------
|
||||
# http://www.plainblack.com info@plainblack.com
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
use FindBin;
|
||||
use strict;
|
||||
use lib "$FindBin::Bin/../lib";
|
||||
|
||||
use WebGUI::Test;
|
||||
use WebGUI::Session;
|
||||
use WebGUI::Session::Os;
|
||||
|
||||
my @testSets = (
|
||||
{
|
||||
os => 'Win',
|
||||
type => 'Windowsish',
|
||||
},
|
||||
{
|
||||
os => 'win32',
|
||||
type => 'Windowsish',
|
||||
},
|
||||
{
|
||||
os => 'MSWin32',
|
||||
type => 'Windowsish',
|
||||
},
|
||||
{
|
||||
os => 'Amiga OS',
|
||||
type => 'Linuxish',
|
||||
},
|
||||
);
|
||||
|
||||
use Test::More;
|
||||
|
||||
my $numTests = 2 * scalar @testSets;
|
||||
|
||||
plan tests => $numTests;
|
||||
|
||||
my $session = WebGUI::Test->session;
|
||||
|
||||
foreach my $test (@testSets) {
|
||||
local $^O = $test->{os};
|
||||
my $os = WebGUI::Session::Os->new($session);
|
||||
is($os->get('name'), $test->{os}, "$test->{os}: name set");
|
||||
is($os->get('type'), $test->{type}, "$test->{os}: type set");
|
||||
}
|
||||
|
||||
|
|
@ -13,7 +13,6 @@ use strict;
|
|||
use lib "$FindBin::Bin/../lib";
|
||||
|
||||
use WebGUI::Test;
|
||||
use WebGUI::PseudoRequest;
|
||||
use WebGUI::Session;
|
||||
use WebGUI::Asset;
|
||||
|
||||
|
|
@ -51,13 +50,10 @@ my @getRefererUrlTests = (
|
|||
);
|
||||
|
||||
use Test::More;
|
||||
use Test::MockObject::Extends;
|
||||
plan tests => 81 + scalar(@getRefererUrlTests);
|
||||
plan tests => 79 + scalar(@getRefererUrlTests);
|
||||
|
||||
my $session = WebGUI::Test->session;
|
||||
|
||||
my $pseudoRequest = WebGUI::PseudoRequest->new();
|
||||
$session->{_request} = $pseudoRequest;
|
||||
my $request = $session->request;
|
||||
|
||||
#disable caching
|
||||
my $preventProxyCache = $session->setting->get('preventProxyCache');
|
||||
|
|
@ -140,17 +136,14 @@ $session->url->setSiteURL('http://webgui.org');
|
|||
is( $session->url->getSiteURL, 'http://webgui.org', 'override config setting with setSiteURL');
|
||||
|
||||
##Create a fake environment hash so we can muck with it.
|
||||
my %mockEnv = %ENV;
|
||||
my $env = $session->env;
|
||||
$env = Test::MockObject::Extends->new($env);
|
||||
$env->mock('get', sub { return $mockEnv{$_[1]} } );
|
||||
my $env = $session->request->env;
|
||||
|
||||
$mockEnv{HTTPS} = "on";
|
||||
$env->{'psgi.url_scheme'} = "https";
|
||||
$session->url->setSiteURL(undef);
|
||||
is( $session->url->getSiteURL, 'https://'.$sitename, 'getSiteURL from config as http_host with SSL');
|
||||
|
||||
$mockEnv{HTTPS} = "";
|
||||
$mockEnv{HTTP_HOST} = "devsite.com";
|
||||
$env->{'psgi.url_scheme'} = "http";
|
||||
$env->{HTTP_HOST} = "devsite.com";
|
||||
$session->url->setSiteURL(undef);
|
||||
is( $session->url->getSiteURL, 'http://'.$sitename, 'getSiteURL where requested host is not a configured site');
|
||||
|
||||
|
|
@ -194,26 +187,29 @@ is( $session->url->makeCompliant($url), $url2, 'language specific URL compliance
|
|||
#
|
||||
#######################################
|
||||
|
||||
my $originalRequest = $session->request; ##Save the original request object
|
||||
my $setUri = sub {
|
||||
$request->env->{PATH_INFO} = $_[0];
|
||||
};
|
||||
$session->{_request} = undef;
|
||||
|
||||
is($session->url->getRequestedUrl, undef, 'getRequestedUrl returns undef unless it has a request object');
|
||||
$session->{_request} = $originalRequest;
|
||||
|
||||
$pseudoRequest->uri('empty');
|
||||
is($session->request->uri, 'empty', 'Validate Mock Object operation');
|
||||
$session->{_request} = $request;
|
||||
|
||||
$pseudoRequest->uri('full');
|
||||
is($session->request->uri, 'full', 'Validate Mock Object operation #2');
|
||||
$setUri->('empty');
|
||||
is($session->request->uri, 'http://devsite.com/empty', 'Validate Mock Object operation');
|
||||
|
||||
$pseudoRequest->uri('/path1/file1');
|
||||
$setUri->('full');
|
||||
is($session->request->uri, 'http://devsite.com/full', 'Validate Mock Object operation #2');
|
||||
|
||||
$setUri->('/path1/file1');
|
||||
is($session->url->getRequestedUrl, 'path1/file1', 'getRequestedUrl, fetch');
|
||||
|
||||
$pseudoRequest->uri('/path2/file2');
|
||||
$setUri->('/path2/file2');
|
||||
is($session->url->getRequestedUrl, 'path1/file1', 'getRequestedUrl, check cache of previous result');
|
||||
|
||||
$session->url->{_requestedUrl} = undef; ##Manually clear cached value
|
||||
$pseudoRequest->uri('/path2/file2?param1=one;param2=two');
|
||||
$setUri->('/path2/file2?param1=one;param2=two');
|
||||
is($session->url->getRequestedUrl, 'path2/file2', 'getRequestedUrl, does not return params');
|
||||
|
||||
#######################################
|
||||
|
|
@ -226,7 +222,7 @@ my $sessionAsset = $session->asset;
|
|||
$session->asset(undef);
|
||||
|
||||
$session->url->{_requestedUrl} = undef; ##Manually clear cached value
|
||||
$pseudoRequest->uri('/path1/">file1');
|
||||
$setUri->('/path1/">file1');
|
||||
is($session->url->page, '/path1/%22%3Efile1', 'page with no args returns getRequestedUrl through gateway, escaping the requested URL for safety');
|
||||
|
||||
is($session->url->page('op=viewHelpTOC;topic=Article'), '/path1/%22%3Efile1?op=viewHelpTOC;topic=Article', 'page: pairs are appended');
|
||||
|
|
@ -256,12 +252,12 @@ $session->asset($sessionAsset);
|
|||
#
|
||||
#######################################
|
||||
|
||||
$mockEnv{'HTTP_REFERER'} = 'test';
|
||||
$env->{'HTTP_REFERER'} = 'test';
|
||||
|
||||
is($session->env->get('HTTP_REFERER'), 'test', 'testing overridden ENV');
|
||||
|
||||
foreach my $test (@getRefererUrlTests) {
|
||||
$mockEnv{HTTP_REFERER} = $test->{input};
|
||||
$env->{HTTP_REFERER} = $test->{input};
|
||||
is($session->url->getRefererUrl, $test->{output}, $test->{comment});
|
||||
}
|
||||
|
||||
|
|
@ -321,14 +317,10 @@ is($session->url->extras('/dir1/foo.html'), join('', $cdnCfg->{extrasCdn}, 'dir1
|
|||
is($session->url->extras('tinymce'), join('', $extras, 'tinymce'),
|
||||
'extras exclusion from CDN');
|
||||
# Note: env is already mocked above.
|
||||
$mockEnv{HTTPS} = 'on';
|
||||
$env->{'psgi.url_scheme'} = "https";
|
||||
is($session->url->extras('/dir1/foo.html'), join('', $cdnCfg->{extrasSsl}, 'dir1/foo.html'),
|
||||
'extras using extrasSsl with HTTPS');
|
||||
$mockEnv{HTTPS} = undef;
|
||||
$mockEnv{SSLPROXY} = 1;
|
||||
is($session->url->extras('/dir1/foo.html'), join('', $cdnCfg->{extrasSsl}, 'dir1/foo.html'),
|
||||
'extras using extrasSsl with SSLPROXY');
|
||||
delete $mockEnv{SSLPROXY};
|
||||
$env->{'psgi.url_scheme'} = "http";
|
||||
|
||||
$session->config->set('extrasURL', $origExtras);
|
||||
|
||||
|
|
@ -376,7 +368,7 @@ is($session->url->urlize('home/././here'), 'home/here', '... removes
|
|||
$sessionAsset = $session->asset;
|
||||
$session->{_asset} = undef;
|
||||
$session->url->{_requestedUrl} = undef; ##Manually clear cached value
|
||||
$pseudoRequest->uri('/goBackToTheSite');
|
||||
$setUri->('/goBackToTheSite');
|
||||
|
||||
is($session->url->getBackToSiteURL, '/goBackToTheSite', 'getBackToSiteURL: when session asset is undefined, the method falls back to using page');
|
||||
|
||||
|
|
@ -449,19 +441,12 @@ my $origSSLEnabled = $session->config->get('sslEnabled');
|
|||
##Test all the false cases, first
|
||||
|
||||
$session->config->set('sslEnabled', 0);
|
||||
$mockEnv{HTTPS} = 'not on';
|
||||
$mockEnv{SSLPROXY} = 0;
|
||||
$env->{'psgi.url_scheme'} = "http";
|
||||
ok( ! $session->url->forceSecureConnection(), 'sslEnabled must be 1 to force SSL');
|
||||
|
||||
$session->config->set('sslEnabled', 1);
|
||||
$mockEnv{HTTPS} = 'on';
|
||||
$mockEnv{SSLPROXY} = 0;
|
||||
$env->{'psgi.url_scheme'} = "https";
|
||||
ok( ! $session->url->forceSecureConnection(), 'HTTPS must not be "on" to force SSL');
|
||||
|
||||
$session->config->set('sslEnabled', 1);
|
||||
$mockEnv{HTTPS} = 'not on';
|
||||
$mockEnv{SSLPROXY} = 1;
|
||||
ok( ! $session->url->forceSecureConnection(), 'SSLPROXY must not be true to force SSL');
|
||||
ok( ! $session->url->forceSecureConnection('/test/url'), 'all conditions must be met, even if a URL is directly passed in');
|
||||
|
||||
##Validate the HTTP object state before we start
|
||||
|
|
@ -469,8 +454,7 @@ $session->http->setStatus('200', 'OK');
|
|||
is($session->http->getStatus, 200, 'http status is okay, 200');
|
||||
is($session->http->getRedirectLocation, undef, 'redirect location is empty');
|
||||
|
||||
$mockEnv{HTTPS} = 'not on';
|
||||
$mockEnv{SSLPROXY} = 0;
|
||||
$env->{'psgi.url_scheme'} = "http";
|
||||
|
||||
my $secureUrl = $session->url->getSiteURL . '/foo/bar/baz/buz';
|
||||
$secureUrl =~ s/http:/https:/;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue