Skip to content

Commit 62f2e60

Browse files
authored
Merge branch '2.4-develop' into cache-clean-remove
2 parents 76adba3 + 78c411d commit 62f2e60

File tree

27 files changed

+691
-22
lines changed

27 files changed

+691
-22
lines changed

app/code/Magento/AdminAnalytics/Test/Mftf/Test/AdminCheckAnalyticsTrackingTest.xml

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,5 +31,46 @@
3131

3232
<waitForPageLoad stepKey="waitForPageReloaded"/>
3333
<seeInPageSource html="var adminAnalyticsMetadata =" stepKey="seeInPageSource"/>
34+
<grabPageSource stepKey="pageSource"/>
35+
<assertRegExp message="adminAnalyticsMetadata object is invalid" stepKey="validateadminAnalyticsMetadata">
36+
<expectedResult type="string">#var\s+adminAnalyticsMetadata\s+=\s+{\s+("[\w_]+":\s+"[^"]*?",\s+)*?("[\w_]+":\s+"[^"]*?"\s+)};#s</expectedResult>
37+
<actualResult type="variable">$pageSource</actualResult>
38+
</assertRegExp>
39+
<assertRegExp message="adminAnalyticsMetadata object contains incorrect user ID" stepKey="validateUserId">
40+
<expectedResult type="string">#var\s+adminAnalyticsMetadata\s+=\s+{\s+("[\w_]+":\s+"[^"]*?",\s+)*?"user":\s+"[\w\d]{64}"#s</expectedResult>
41+
<actualResult type="variable">$pageSource</actualResult>
42+
</assertRegExp>
43+
<assertRegExp message="adminAnalyticsMetadata object contains incorrect secure base URL" stepKey="validateSecureBaseURL">
44+
<expectedResult type="string">#var\s+adminAnalyticsMetadata\s+=\s+{\s+("[\w_]+":\s+"[^"]*?",\s+)*?"secure_base_url":\s+"http(s)?\\\\u003A\\\\u002F\\\\u002F.+?\\\\u002F"#s</expectedResult>
45+
<actualResult type="variable">$pageSource</actualResult>
46+
</assertRegExp>
47+
<assertRegExp message="adminAnalyticsMetadata object contains incorrect product version" stepKey="validateProductVersion">
48+
<expectedResult type="string">#var\s+adminAnalyticsMetadata\s+=\s+{\s+("[\w_]+":\s+"[^"]*?",\s+)*?"version":\s+"[^\s]+"#s</expectedResult>
49+
<actualResult type="variable">$pageSource</actualResult>
50+
</assertRegExp>
51+
<assertRegExp message="adminAnalyticsMetadata object contains incorrect product edition" stepKey="validateProductEdition">
52+
<expectedResult type="string">#var\s+adminAnalyticsMetadata\s+=\s+{\s+("[\w_]+":\s+"[^"]*?",\s+)*?"product_edition":\s+"(Community|Enterprise|B2B)"#s</expectedResult>
53+
<actualResult type="variable">$pageSource</actualResult>
54+
</assertRegExp>
55+
<assertRegExp message="adminAnalyticsMetadata object contains incorrect application mode" stepKey="validateApplicationMode">
56+
<expectedResult type="string">#var\s+adminAnalyticsMetadata\s+=\s+{\s+("[\w_]+":\s+"[^"]*?",\s+)*?"mode":\s+"default|developer|production"#s</expectedResult>
57+
<actualResult type="variable">$pageSource</actualResult>
58+
</assertRegExp>
59+
<assertRegExp message="adminAnalyticsMetadata object contains incorrect store name" stepKey="validateStoreName">
60+
<expectedResult type="string">#var\s+adminAnalyticsMetadata\s+=\s+{\s+("[\w_]+":\s+"[^"]*?",\s+)*?"store_name_default":\s+".*?"#s</expectedResult>
61+
<actualResult type="variable">$pageSource</actualResult>
62+
</assertRegExp>
63+
<assertRegExp message="adminAnalyticsMetadata object contains incorrect admin user created date" stepKey="validateAdminUserCreatedDate">
64+
<expectedResult type="string">#var\s+adminAnalyticsMetadata\s+=\s+{\s+("[\w_]+":\s+"[^"]*?",\s+)*?"admin_user_created":\s+".+?"#s</expectedResult>
65+
<actualResult type="variable">$pageSource</actualResult>
66+
</assertRegExp>
67+
<assertRegExp message="adminAnalyticsMetadata object contains incorrect admin user log date" stepKey="validateAdminUserLogDate">
68+
<expectedResult type="string">#var\s+adminAnalyticsMetadata\s+=\s+{\s+("[\w_]+":\s+"[^"]*?",\s+)*?"admin_user_logdate":\s+".+?"#s</expectedResult>
69+
<actualResult type="variable">$pageSource</actualResult>
70+
</assertRegExp>
71+
<assertRegExp message="adminAnalyticsMetadata object contains incorrect admin user role name" stepKey="validateAdminUserRoleName">
72+
<expectedResult type="string">#var\s+adminAnalyticsMetadata\s+=\s+{\s+("[\w_]+":\s+"[^"]*?",\s+)*?"admin_user_role_name":\s+".+?"#s</expectedResult>
73+
<actualResult type="variable">$pageSource</actualResult>
74+
</assertRegExp>
3475
</test>
3576
</tests>

app/code/Magento/AdminAnalytics/ViewModel/Metadata.php

Lines changed: 85 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,18 @@
33
* Copyright © Magento, Inc. All rights reserved.
44
* See COPYING.txt for license details.
55
*/
6+
7+
declare(strict_types=1);
8+
69
namespace Magento\AdminAnalytics\ViewModel;
710

11+
use Magento\Config\Model\Config\Backend\Admin\Custom;
12+
use Magento\Framework\App\Config\ScopeConfigInterface;
813
use Magento\Framework\App\ProductMetadataInterface;
914
use Magento\Backend\Model\Auth\Session;
1015
use Magento\Framework\App\State;
1116
use Magento\Framework\View\Element\Block\ArgumentInterface;
17+
use Magento\Store\Model\Information;
1218

1319
/**
1420
* Gets user version and mode
@@ -30,19 +36,27 @@ class Metadata implements ArgumentInterface
3036
*/
3137
private $productMetadata;
3238

39+
/**
40+
* @var ScopeConfigInterface
41+
*/
42+
private $config;
43+
3344
/**
3445
* @param ProductMetadataInterface $productMetadata
3546
* @param Session $authSession
3647
* @param State $appState
48+
* @param ScopeConfigInterface $config
3749
*/
3850
public function __construct(
3951
ProductMetadataInterface $productMetadata,
4052
Session $authSession,
41-
State $appState
53+
State $appState,
54+
ScopeConfigInterface $config
4255
) {
4356
$this->productMetadata = $productMetadata;
4457
$this->authSession = $authSession;
4558
$this->appState = $appState;
59+
$this->config = $config;
4660
}
4761

4862
/**
@@ -55,15 +69,26 @@ public function getMagentoVersion() :string
5569
return $this->productMetadata->getVersion();
5670
}
5771

72+
/**
73+
* Get product edition
74+
*
75+
* @return string
76+
*/
77+
public function getProductEdition(): string
78+
{
79+
return $this->productMetadata->getEdition();
80+
}
81+
5882
/**
5983
* Get current user id (hash generated from email)
6084
*
6185
* @return string
6286
*/
6387
public function getCurrentUser() :string
6488
{
65-
return hash('sha512', 'ADMIN_USER' . $this->authSession->getUser()->getEmail());
89+
return hash('sha256', 'ADMIN_USER' . $this->authSession->getUser()->getEmail());
6690
}
91+
6792
/**
6893
* Get Magento mode that the user is using
6994
*
@@ -73,4 +98,62 @@ public function getMode() :string
7398
{
7499
return $this->appState->getMode();
75100
}
101+
102+
/**
103+
* Get created date for current user
104+
*
105+
* @return string
106+
*/
107+
public function getCurrentUserCreatedDate(): string
108+
{
109+
return $this->authSession->getUser()->getCreated();
110+
}
111+
112+
/**
113+
* Get log date for current user
114+
*
115+
* @return string|null
116+
*/
117+
public function getCurrentUserLogDate(): ?string
118+
{
119+
return $this->authSession->getUser()->getLogdate();
120+
}
121+
122+
/**
123+
* Get secure base URL
124+
*
125+
* @param string $scope
126+
* @param string|null $scopeCode
127+
* @return string|null
128+
*/
129+
public function getSecureBaseUrlForScope(
130+
string $scope = ScopeConfigInterface::SCOPE_TYPE_DEFAULT,
131+
?string $scopeCode = null
132+
): ?string {
133+
return $this->config->getValue(Custom::XML_PATH_SECURE_BASE_URL, $scope, $scopeCode);
134+
}
135+
136+
/**
137+
* Get store name
138+
*
139+
* @param string $scope
140+
* @param string|null $scopeCode
141+
* @return string|null
142+
*/
143+
public function getStoreNameForScope(
144+
string $scope = ScopeConfigInterface::SCOPE_TYPE_DEFAULT,
145+
?string $scopeCode = null
146+
): ?string {
147+
return $this->config->getValue(Information::XML_PATH_STORE_INFO_NAME, $scope, $scopeCode);
148+
}
149+
150+
/**
151+
* Get current user role name
152+
*
153+
* @return string
154+
*/
155+
public function getCurrentUserRoleName(): string
156+
{
157+
return $this->authSession->getUser()->getRole()->getRoleName();
158+
}
76159
}

app/code/Magento/AdminAnalytics/composer.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
"magento/framework": "*",
1010
"magento/module-backend": "*",
1111
"magento/module-config": "*",
12+
"magento/module-store": "*",
1213
"magento/module-ui": "*",
1314
"magento/module-release-notification": "*"
1415
},
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
/**
4+
* Copyright © Magento, Inc. All rights reserved.
5+
* See COPYING.txt for license details.
6+
*/
7+
-->
8+
<csp_whitelist xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
9+
xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Csp:etc/csp_whitelist.xsd">
10+
<policies>
11+
<policy id="script-src">
12+
<values>
13+
<value id="aptrinsic" type="host">*.aptrinsic.com</value>
14+
</values>
15+
</policy>
16+
<policy id="style-src">
17+
<values>
18+
<value id="aptrinsic" type="host">*.aptrinsic.com</value>
19+
<value id="fonts_googleapis" type="host">fonts.googleapis.com</value>
20+
</values>
21+
</policy>
22+
<policy id="img-src">
23+
<values>
24+
<value id="aptrinsic" type="host">*.aptrinsic.com</value>
25+
<value id="storage_googleapis" type="host">storage.googleapis.com</value>
26+
</values>
27+
</policy>
28+
<policy id="connect-src">
29+
<values>
30+
<value id="aptrinsic" type="host">*.aptrinsic.com</value>
31+
</values>
32+
</policy>
33+
<policy id="font-src">
34+
<values>
35+
<value id="fonts_gstatic" type="host">fonts.gstatic.com</value>
36+
</values>
37+
</policy>
38+
</policies>
39+
</csp_whitelist>

app/code/Magento/AdminAnalytics/view/adminhtml/layout/default.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
<referenceContainer name="header">
1111
<block name="tracking" as="tracking" template="Magento_AdminAnalytics::tracking.phtml" ifconfig="admin/usage/enabled">
1212
<arguments>
13-
<argument name="tracking_url" xsi:type="string">//assets.adobedtm.com/launch-EN30eb7ffa064444f1b8b0368ef38fd3a9.min.js</argument>
13+
<argument name="tracking_url" xsi:type="string">//assets.adobedtm.com/a7d65461e54e/37baabec1b6e/launch-177bc126c8e6.min.js</argument>
1414
<argument name="metadata" xsi:type="object">Magento\AdminAnalytics\ViewModel\Metadata</argument>
1515
</arguments>
1616
</block>

app/code/Magento/AdminAnalytics/view/adminhtml/templates/tracking.phtml

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,20 @@
1919
false
2020
) ?>
2121

22-
<?php $scriptString = '
22+
<?php
23+
/** @var \Magento\AdminAnalytics\ViewModel\Metadata $metadata */
24+
$metadata = $block->getMetadata();
25+
$scriptString = '
2326
var adminAnalyticsMetadata = {
24-
"version": "' . $block->escapeJs($block->getMetadata()->getMagentoVersion()) . '",
25-
"user": "' . $block->escapeJs($block->getMetadata()->getCurrentUser()) . '",
26-
"mode": "' . $block->escapeJs($block->getMetadata()->getMode()) . '"
27+
"secure_base_url": "' . $block->escapeJs($metadata->getSecureBaseUrlForScope()) . '",
28+
"version": "' . $block->escapeJs($metadata->getMagentoVersion()) . '",
29+
"product_edition": "' . $block->escapeJs($metadata->getProductEdition()) . '",
30+
"user": "' . $block->escapeJs($metadata->getCurrentUser()) . '",
31+
"mode": "' . $block->escapeJs($metadata->getMode()) . '",
32+
"store_name_default": "' . $block->escapeJs($metadata->getStoreNameForScope()) . '",
33+
"admin_user_created": "' . $block->escapeJs($metadata->getCurrentUserCreatedDate()) . '",
34+
"admin_user_logdate": "' . $block->escapeJs($metadata->getCurrentUserLogDate()) . '",
35+
"admin_user_role_name": "' . $block->escapeJs($metadata->getCurrentUserRoleName()) . '"
2736
};
2837
';
2938
?>

app/code/Magento/Csp/Model/Collector/CspWhitelistXml/Converter.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,12 @@ public function convert($source)
3636
/** @var \DOMElement $value */
3737
foreach ($policy->getElementsByTagName('value') as $value) {
3838
if ($value->attributes->getNamedItem('type')->nodeValue === 'host') {
39-
$policyConfig[$id]['hosts'][] = $value->nodeValue;
39+
$policyConfig[$id]['hosts'][$value->attributes->getNamedItem('id')->nodeValue] = $value->nodeValue;
4040
} else {
4141
$policyConfig[$id]['hashes'][$value->nodeValue]
4242
= $value->attributes->getNamedItem('algorithm')->nodeValue;
4343
}
4444
}
45-
$policyConfig[$id]['hosts'] = array_unique($policyConfig[$id]['hosts']);
4645
}
4746

4847
return $policyConfig;

app/code/Magento/Csp/Model/Collector/FetchPolicyMerger.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,12 @@ public function merge(PolicyInterface $policy1, PolicyInterface $policy2): Polic
2525
return new FetchPolicy(
2626
$policy1->getId(),
2727
$policy1->isNoneAllowed() || $policy2->isNoneAllowed(),
28-
array_unique(array_merge($policy1->getHostSources(), $policy2->getHostSources())),
29-
array_unique(array_merge($policy1->getSchemeSources(), $policy2->getSchemeSources())),
28+
array_merge($policy1->getHostSources(), $policy2->getHostSources()),
29+
array_merge($policy1->getSchemeSources(), $policy2->getSchemeSources()),
3030
$policy1->isSelfAllowed() || $policy2->isSelfAllowed(),
3131
$policy1->isInlineAllowed() || $policy2->isInlineAllowed(),
3232
$policy1->isEvalAllowed() || $policy2->isEvalAllowed(),
33-
array_unique(array_merge($policy1->getNonceValues(), $policy2->getNonceValues())),
33+
array_merge($policy1->getNonceValues(), $policy2->getNonceValues()),
3434
array_merge($policy1->getHashes(), $policy2->getHashes()),
3535
$policy1->isDynamicAllowed() || $policy2->isDynamicAllowed(),
3636
$policy1->areEventHandlersAllowed() || $policy2->areEventHandlersAllowed()

app/code/Magento/Csp/Model/Collector/PluginTypesPolicyMerger.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public function merge(PolicyInterface $policy1, PolicyInterface $policy2): Polic
2222
{
2323
/** @var PluginTypesPolicy $policy1 */
2424
/** @var PluginTypesPolicy $policy2 */
25-
return new PluginTypesPolicy(array_unique(array_merge($policy1->getTypes(), $policy2->getTypes())));
25+
return new PluginTypesPolicy(array_merge($policy1->getTypes(), $policy2->getTypes()));
2626
}
2727

2828
/**

app/code/Magento/Csp/Model/Policy/FetchPolicy.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -116,12 +116,12 @@ public function __construct(
116116
) {
117117
$this->id = $id;
118118
$this->noneAllowed = $noneAllowed;
119-
$this->hostSources = array_unique($hostSources);
120-
$this->schemeSources = array_unique($schemeSources);
119+
$this->hostSources = array_values(array_unique($hostSources));
120+
$this->schemeSources = array_values(array_unique($schemeSources));
121121
$this->selfAllowed = $selfAllowed;
122122
$this->inlineAllowed = $inlineAllowed;
123123
$this->evalAllowed = $evalAllowed;
124-
$this->nonceValues = array_unique($nonceValues);
124+
$this->nonceValues = array_values(array_unique($nonceValues));
125125
$this->hashes = $hashValues;
126126
$this->dynamicAllowed = $dynamicAllowed;
127127
$this->eventHandlersAllowed = $eventHandlersAllowed;

app/code/Magento/Csp/Model/Policy/PluginTypesPolicy.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public function __construct(array $types)
2525
if (!$types) {
2626
throw new \RuntimeException('PluginTypePolicy must be given at least 1 type.');
2727
}
28-
$this->types = array_unique($types);
28+
$this->types = array_values(array_unique($types));
2929
}
3030

3131
/**
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?xml version="1.0"?>
2+
<!--
3+
/**
4+
* Copyright © Magento, Inc. All rights reserved.
5+
* See COPYING.txt for license details.
6+
*/
7+
-->
8+
<csp_whitelist xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Csp/etc/csp_whitelist.xsd">
9+
<policies>
10+
<policy id="object-src">
11+
<values>
12+
<value id="example-base" type="host">example.magento.com</value>
13+
<value id="mage-base" type="host">https://admin.magento.com</value>
14+
</values>
15+
</policy>
16+
<policy id="media-src">
17+
<values>
18+
<value id="example-base" type="host">example.magento.com</value>
19+
<value id="mage-base" type="host">https://admin.magento.com</value>
20+
</values>
21+
</policy>
22+
</policies>
23+
</csp_whitelist>

0 commit comments

Comments
 (0)