Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
91.67% |
11 / 12 |
|
66.67% |
2 / 3 |
CRAP | |
0.00% |
0 / 1 |
| SessionCookieAttributesFactory | |
91.67% |
11 / 12 |
|
66.67% |
2 / 3 |
5.01 | |
0.00% |
0 / 1 |
| __construct | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
1 | |||
| create | |
100.00% |
8 / 8 |
|
100.00% |
1 / 1 |
3 | |||
| createLtiLaunchData | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| 1 | <?php |
| 2 | |
| 3 | /** |
| 4 | * This program is free software; you can redistribute it and/or |
| 5 | * modify it under the terms of the GNU General Public License |
| 6 | * as published by the Free Software Foundation; under version 2 |
| 7 | * of the License (non-upgradable). |
| 8 | * |
| 9 | * This program is distributed in the hope that it will be useful, |
| 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | * GNU General Public License for more details. |
| 13 | * |
| 14 | * You should have received a copy of the GNU General Public License |
| 15 | * along with this program; if not, write to the Free Software |
| 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
| 17 | * |
| 18 | * Copyright (c) 2020 (original work) Open Assessment Technologies SA; |
| 19 | * |
| 20 | * @author Sergei Mikhailov <sergei.mikhailov@taotesting.com> |
| 21 | */ |
| 22 | |
| 23 | declare(strict_types=1); |
| 24 | |
| 25 | namespace oat\ltiDeliveryProvider\model\session\DataAccess\Factory; |
| 26 | |
| 27 | use common_http_Request as Request; |
| 28 | use oat\tao\model\security\Business\Contract\SecuritySettingsRepositoryInterface; |
| 29 | use oat\tao\model\service\InjectionAwareService; |
| 30 | use oat\tao\model\session\Business\Contract\SessionCookieAttributesFactoryInterface; |
| 31 | use oat\tao\model\session\Business\Domain\SessionCookieAttribute; |
| 32 | use oat\tao\model\session\Business\Domain\SessionCookieAttributeCollection; |
| 33 | use oat\taoLti\models\classes\LtiLaunchData; |
| 34 | |
| 35 | class SessionCookieAttributesFactory extends InjectionAwareService implements SessionCookieAttributesFactoryInterface |
| 36 | { |
| 37 | public const SERVICE_ID = 'taoLti/SessionCookieAttributesFactory'; |
| 38 | |
| 39 | /** @var SessionCookieAttributesFactoryInterface */ |
| 40 | private $sessionCookieAttributesFactory; |
| 41 | /** @var SecuritySettingsRepositoryInterface */ |
| 42 | private $securitySettingsRepository; |
| 43 | |
| 44 | public function __construct( |
| 45 | SessionCookieAttributesFactoryInterface $sessionCookieAttributesFactory, |
| 46 | SecuritySettingsRepositoryInterface $securitySettingsRepository |
| 47 | ) { |
| 48 | parent::__construct(); |
| 49 | |
| 50 | $this->sessionCookieAttributesFactory = $sessionCookieAttributesFactory; |
| 51 | $this->securitySettingsRepository = $securitySettingsRepository; |
| 52 | } |
| 53 | |
| 54 | public function create(): SessionCookieAttributeCollection |
| 55 | { |
| 56 | $attributes = $this->sessionCookieAttributesFactory->create(); |
| 57 | |
| 58 | if (!$this->createLtiLaunchData()->hasVariable(LtiLaunchData::LTI_VERSION)) { |
| 59 | return $attributes; |
| 60 | } |
| 61 | |
| 62 | $whitelistedSources = $this->securitySettingsRepository->findAll()->findContentSecurityPolicy()->getValue(); |
| 63 | |
| 64 | if (!in_array($whitelistedSources, ['*', 'list'], true)) { |
| 65 | return $attributes; |
| 66 | } |
| 67 | |
| 68 | return $attributes |
| 69 | ->add(new SessionCookieAttribute('samesite', 'none')); |
| 70 | } |
| 71 | |
| 72 | protected function createLtiLaunchData(): LtiLaunchData |
| 73 | { |
| 74 | return LtiLaunchData::fromRequest(Request::currentRequest()); |
| 75 | } |
| 76 | } |