Skip to content

Commit 7edfd0c

Browse files
author
Oleksii Korshenko
committed
Merge pull request #88 from magento-extensibility/pr
[Extensibility] Bug fixes - part 2
2 parents 387242c + c51b1f3 commit 7edfd0c

File tree

22 files changed

+309
-187
lines changed

22 files changed

+309
-187
lines changed

.htaccess

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@
206206

207207
###########################################
208208
## Deny access to root files to hide sensitive application information
209-
RedirectMatch 404 /\.git
209+
RedirectMatch 403 /\.git
210210

211211
<Files composer.json>
212212
order allow,deny
@@ -277,10 +277,14 @@
277277
deny from all
278278
</Files>
279279
<Files magento_umask>
280-
order allow,deny
281-
deny from all
280+
order allow,deny
281+
deny from all
282282
</Files>
283283

284+
# For 404s and 403s that aren't handled by the application, show plain 404 response
285+
ErrorDocument 404 /pub/errors/404.php
286+
ErrorDocument 403 /pub/errors/404.php
287+
284288
################################
285289
## If running in cluster environment, uncomment this
286290
## http://developer.yahoo.com/performance/rules.html#etags

.htaccess.sample

Lines changed: 33 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
############################################
2-
## Optional override of deployment mode. We recommend you use the
3-
## command bin/magento deploy:mode:set to switch modes instead
4-
# SetEnv MAGE_MODE default # or production or developer
2+
## overrides deployment configuration mode value
3+
## use command bin/magento deploy:mode:set to switch modes
4+
5+
# SetEnv MAGE_MODE developer
56

67
############################################
7-
## Uncomment these lines for CGI mode.
8-
## Make sure to specify the correct cgi php binary file name
8+
## uncomment these lines for CGI mode
9+
## make sure to specify the correct cgi php binary file name
910
## it might be /cgi-bin/php-cgi
1011

1112
# Action php5-cgi /cgi-bin/php5-cgi
@@ -16,42 +17,42 @@
1617

1718
# Options -MultiViews
1819

19-
## You might also need to add this line to php.ini
20+
## you might also need to add this line to php.ini
2021
## cgi.fix_pathinfo = 1
21-
## If it still doesn't work, rename php.ini to php5.ini
22+
## if it still doesn't work, rename php.ini to php5.ini
2223

2324
############################################
24-
## This line is specific for 1and1 hosting
25+
## this line is specific for 1and1 hosting
2526

2627
#AddType x-mapp-php5 .php
2728
#AddHandler x-mapp-php5 .php
2829

2930
############################################
30-
## Default index file
31+
## default index file
3132

3233
DirectoryIndex index.php
3334

3435
<IfModule mod_php5.c>
3536

3637
############################################
37-
## Adjust memory limit
38+
## adjust memory limit
3839

3940
php_value memory_limit 768M
4041
php_value max_execution_time 18000
4142

4243
############################################
43-
## Disable automatic session start
44+
## disable automatic session start
4445
## before autoload was initialized
4546

4647
php_flag session.auto_start off
4748

4849
############################################
49-
## Enable resulting html compression
50+
## enable resulting html compression
5051

5152
#php_flag zlib.output_compression on
5253

5354
###########################################
54-
## Disable user agent verification to not break multiple image upload
55+
## disable user agent verification to not break multiple image upload
5556

5657
php_flag suhosin.session.cryptua off
5758

@@ -60,32 +61,32 @@
6061
<IfModule mod_php7.c>
6162

6263
############################################
63-
## Adjust memory limit
64+
## adjust memory limit
6465

6566
php_value memory_limit 768M
6667
php_value max_execution_time 18000
6768

6869
############################################
69-
## Disable automatic session start
70+
## disable automatic session start
7071
## before autoload was initialized
7172

7273
php_flag session.auto_start off
7374

7475
############################################
75-
## Enable resulting html compression
76+
## enable resulting html compression
7677

7778
#php_flag zlib.output_compression on
7879

7980
###########################################
80-
## Disable user agent verification to not break multiple image upload
81+
## disable user agent verification to not break multiple image upload
8182

8283
php_flag suhosin.session.cryptua off
8384

8485
</IfModule>
8586

8687
<IfModule mod_security.c>
8788
###########################################
88-
## Disable POST processing to not break multiple image upload
89+
## disable POST processing to not break multiple image upload
8990

9091
SecFilterEngine Off
9192
SecFilterScanPOST Off
@@ -94,7 +95,7 @@
9495
<IfModule mod_deflate.c>
9596

9697
############################################
97-
## Enable apache served files compression
98+
## enable apache served files compression
9899
## http://developer.yahoo.com/performance/rules.html#gzip
99100

100101
# Insert filter on all content
@@ -122,14 +123,14 @@
122123
<IfModule mod_ssl.c>
123124

124125
############################################
125-
## Make HTTPS env vars available for CGI mode
126+
## make HTTPS env vars available for CGI mode
126127

127128
SSLOptions StdEnvVars
128129

129130
</IfModule>
130131

131132
############################################
132-
## Workaround for Apache 2.4.6 CentOS build when working via ProxyPassMatch with HHVM (or any other)
133+
## workaround for Apache 2.4.6 CentOS build when working via ProxyPassMatch with HHVM (or any other)
133134
## Please, set it on virtual host configuration level
134135

135136
## SetEnvIf Authorization "(.*)" HTTP_AUTHORIZATION=$1
@@ -138,19 +139,19 @@
138139
<IfModule mod_rewrite.c>
139140

140141
############################################
141-
## Enable rewrites
142+
## enable rewrites
142143

143144
Options +FollowSymLinks
144145
RewriteEngine on
145146

146147
############################################
147-
## You can put here your magento root folder
148+
## you can put here your magento root folder
148149
## path relative to web root
149150

150151
#RewriteBase /magento/
151152

152153
############################################
153-
## Workaround for HTTP authorization
154+
## workaround for HTTP authorization
154155
## in CGI environment
155156

156157
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
@@ -162,21 +163,21 @@
162163
RewriteRule .* - [L,R=405]
163164

164165
############################################
165-
## Redirect for mobile user agents
166+
## redirect for mobile user agents
166167

167168
#RewriteCond %{REQUEST_URI} !^/mobiledirectoryhere/.*$
168169
#RewriteCond %{HTTP_USER_AGENT} "android|blackberry|ipad|iphone|ipod|iemobile|opera mobile|palmos|webos|googlebot-mobile" [NC]
169170
#RewriteRule ^(.*)$ /mobiledirectoryhere/ [L,R=302]
170171

171172
############################################
172-
## Never rewrite for existing files, directories and links
173+
## never rewrite for existing files, directories and links
173174

174175
RewriteCond %{REQUEST_FILENAME} !-f
175176
RewriteCond %{REQUEST_FILENAME} !-d
176177
RewriteCond %{REQUEST_FILENAME} !-l
177178

178179
############################################
179-
## Rewrite everything else to index.php
180+
## rewrite everything else to index.php
180181

181182
RewriteRule .* index.php [L]
182183

@@ -205,7 +206,7 @@
205206

206207
###########################################
207208
## Deny access to root files to hide sensitive application information
208-
RedirectMatch 404 /\.git
209+
RedirectMatch 403 /\.git
209210

210211
<Files composer.json>
211212
order allow,deny
@@ -280,6 +281,10 @@
280281
deny from all
281282
</Files>
282283

284+
# For 404s and 403s that aren't handled by the application, show plain 404 response
285+
ErrorDocument 404 /pub/errors/404.php
286+
ErrorDocument 403 /pub/errors/404.php
287+
283288
################################
284289
## If running in cluster environment, uncomment this
285290
## http://developer.yahoo.com/performance/rules.html#etags

app/code/Magento/PageCache/Model/Config.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,13 @@ protected function _getReplacements()
147147
\Magento\Store\Model\ScopeInterface::SCOPE_STORE
148148
),
149149
'/* {{ ips }} */' => $this->_getAccessList(),
150-
'/* {{ design_exceptions_code }} */' => $this->_getDesignExceptions()
150+
'/* {{ design_exceptions_code }} */' => $this->_getDesignExceptions(),
151+
// http headers get transformed by php `X-Forwarded-Proto: https` becomes $SERVER['HTTP_X_FORWARDED_PROTO'] = 'https'
152+
// Apache and Nginx drop all headers with underlines by default.
153+
'/* {{ ssl_offloaded_header }} */' => str_replace('_', '-', $this->_scopeConfig->getValue(
154+
\Magento\Framework\HTTP\PhpEnvironment\Request::XML_PATH_OFFLOADER_HEADER,
155+
\Magento\Store\Model\ScopeInterface::SCOPE_STORE))
156+
151157
];
152158
}
153159

app/code/Magento/PageCache/Observer/ProcessLayoutRenderElement.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,8 @@ protected function _wrapEsi(
5959
'handles' => json_encode($layout->getUpdate()->getHandles())
6060
]
6161
);
62+
// Varnish does not support ESI over HTTPS must change to HTTP
63+
$url = substr($url, 0, 5) === 'https' ? 'http' . substr($url, 5) : $url;
6264
return sprintf('<esi:include src="%s" />', $url);
6365
}
6466

app/code/Magento/PageCache/etc/varnish3.vcl

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import std;
22
# The minimal Varnish version is 3.0.5
3+
# For SSL offloading, pass the following header in your proxy server or load balancer: '/* {{ ssl_offloaded_header }} */: https'
4+
35

46
backend default {
57
.host = "/* {{ host }} */";
@@ -61,6 +63,7 @@ sub vcl_recv {
6163
# static files are always cacheable. remove SSL flag and cookie
6264
if (req.url ~ "^/(pub/)?(media|static)/.*\.(ico|css|js|jpg|jpeg|png|gif|tiff|bmp|gz|tgz|bz2|tbz|mp3|ogg|svg|swf|woff|woff2|eot|ttf|otf)$") {
6365
unset req.http.Https;
66+
unset req.http./* {{ ssl_offloaded_header }} */;
6467
unset req.http.Cookie;
6568
}
6669

@@ -73,6 +76,10 @@ sub vcl_hash {
7376
if (req.http.cookie ~ "X-Magento-Vary=") {
7477
hash_data(regsub(req.http.cookie, "^.*?X-Magento-Vary=([^;]+);*.*$", "\1"));
7578
}
79+
80+
if (req.http./* {{ ssl_offloaded_header }} */) {
81+
hash_data(req.http./* {{ ssl_offloaded_header }} */);
82+
}
7683
/* {{ design_exceptions_code }} */
7784
}
7885

app/code/Magento/PageCache/etc/varnish4.vcl

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ vcl 4.0;
22

33
import std;
44
# The minimal Varnish version is 4.0
5+
# For SSL offloading, pass the following header in your proxy server or load balancer: '/* {{ ssl_offloaded_header }} */: https'
56

67
backend default {
78
.host = "/* {{ host }} */";
@@ -74,6 +75,7 @@ sub vcl_recv {
7475
# static files are always cacheable. remove SSL flag and cookie
7576
if (req.url ~ "^/(pub/)?(media|static)/.*\.(ico|css|js|jpg|jpeg|png|gif|tiff|bmp|mp3|ogg|svg|swf|woff|woff2|eot|ttf|otf)$") {
7677
unset req.http.Https;
78+
unset req.http./* {{ ssl_offloaded_header }} */;
7779
unset req.http.Cookie;
7880
}
7981

@@ -93,8 +95,8 @@ sub vcl_hash {
9395
}
9496

9597
# To make sure http users don't see ssl warning
96-
if (req.http.X-Forwarded-Proto) {
97-
hash_data(req.http.X-Forwarded-Proto);
98+
if (req.http./* {{ ssl_offloaded_header }} */) {
99+
hash_data(req.http./* {{ ssl_offloaded_header }} */);
98100
}
99101
/* {{ design_exceptions_code }} */
100102
}

app/code/Magento/Store/etc/config.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@
7676
<base_link_url>{{secure_base_url}}</base_link_url>
7777
<use_in_frontend>0</use_in_frontend>
7878
<use_in_adminhtml>0</use_in_adminhtml>
79-
<offloader_header>SSL_OFFLOADED</offloader_header>
79+
<offloader_header>X-Forwarded-Proto</offloader_header>
8080
</secure>
8181
<session>
8282
<use_remote_addr>0</use_remote_addr>

app/code/Magento/Webapi/Test/Unit/Controller/SoapTest.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,12 +49,16 @@ class SoapTest extends \PHPUnit_Framework_TestCase
4949
*/
5050
protected $_appStateMock;
5151

52+
53+
protected $_appconfig;
5254
/**
5355
* Set up Controller object.
5456
*/
5557
protected function setUp()
5658
{
5759
parent::setUp();
60+
61+
$objectManagerHelper = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
5862

5963
$this->_soapServerMock = $this->getMockBuilder('Magento\Webapi\Model\Soap\Server')
6064
->disableOriginalConstructor()
@@ -95,6 +99,15 @@ protected function setUp()
9599
->method('getHeaders')
96100
->will($this->returnValue(new \Zend\Http\Headers()));
97101

102+
$appconfig = $this->getMock(\Magento\Framework\App\Config::class, [], [], '' , false);
103+
$objectManagerHelper->setBackwardCompatibleProperty(
104+
$this->_requestMock,
105+
'appConfig',
106+
$appconfig
107+
);
108+
109+
110+
98111
$this->_soapServerMock->expects($this->any())->method('setWSDL')->will($this->returnSelf());
99112
$this->_soapServerMock->expects($this->any())->method('setEncoding')->will($this->returnSelf());
100113
$this->_soapServerMock->expects($this->any())->method('setReturnResponse')->will($this->returnSelf());

dev/tests/integration/testsuite/Magento/Store/Model/StoreTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -372,7 +372,7 @@ public function isUseStoreInUrlDataProvider()
372372
*
373373
* @param bool $expected
374374
* @param array $serverValues
375-
* @magentoConfigFixture current_store web/secure/offloader_header SSL_OFFLOADED
375+
* @magentoConfigFixture current_store web/secure/offloader_header X_FORWARDED_PROTO
376376
* @magentoConfigFixture current_store web/secure/base_url https://example.com:80
377377
*/
378378
public function testIsCurrentlySecure($expected, $serverValues)
@@ -391,8 +391,8 @@ public function isCurrentlySecureDataProvider()
391391
{
392392
return [
393393
[true, ['HTTPS' => 'on']],
394-
[true, ['SSL_OFFLOADED' => 'https']],
395-
[true, ['HTTP_SSL_OFFLOADED' => 'https']],
394+
[true, ['X_FORWARDED_PROTO' => 'https']],
395+
[true, ['HTTP_X_FORWARDED_PROTO' => 'https']],
396396
[true, ['HTTPS' => 'on', 'SERVER_PORT' => 80]],
397397
[false, ['SERVER_PORT' => 80]],
398398
[false, []],

lib/internal/Magento/Framework/App/Bootstrap.php

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -404,15 +404,18 @@ public function getErrorCode()
404404
*/
405405
public function isDeveloperMode()
406406
{
407-
if (isset($this->server[State::PARAM_MODE]) && $this->server[State::PARAM_MODE] == State::MODE_DEVELOPER) {
408-
return true;
409-
}
410-
/** @var \Magento\Framework\App\DeploymentConfig $deploymentConfig */
411-
$deploymentConfig = $this->getObjectManager()->get('Magento\Framework\App\DeploymentConfig');
412-
if ($deploymentConfig->get(State::PARAM_MODE) == State::MODE_DEVELOPER) {
413-
return true;
407+
$mode = 'default';
408+
if (isset($this->server[State::PARAM_MODE])) {
409+
$mode = $this->server[State::PARAM_MODE];
410+
} else {
411+
$deploymentConfig = $this->getObjectManager()->get(DeploymentConfig::class);
412+
$configMode = $deploymentConfig->get(State::PARAM_MODE);
413+
if ($configMode) {
414+
$mode = $configMode;
415+
}
414416
}
415-
return false;
417+
418+
return $mode == State::MODE_DEVELOPER;
416419
}
417420

418421
/**

0 commit comments

Comments
 (0)