-
Notifications
You must be signed in to change notification settings - Fork 53
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
PISHPS-328: added ApplePayDirectDomainAllowList #790
Merged
+572
−25
Merged
Changes from 1 commit
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
36a96c4
PISHPS-328: added ApplePayValidationAllowList, subscriber to list def…
m-muxfeld-diw fc8fcc2
PISHPS-303: applied requested todos
m-muxfeld-diw f792781
PISHPS-328: applied requested todos
m-muxfeld-diw ef4a49c
PISHPS-328: added test case to ApplePayDirectDomainSanitizerTest for …
m-muxfeld-diw File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 12 additions & 0 deletions
12
...onents/ApplePayDirect/Exceptions/ApplePayValidationUrlAllowListCanNotBeEmptyException.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<?php | ||
declare(strict_types=1); | ||
|
||
namespace Kiener\MolliePayments\Components\ApplePayDirect\Exceptions; | ||
|
||
class ApplePayValidationUrlAllowListCanNotBeEmptyException extends \Exception | ||
{ | ||
public function __construct() | ||
{ | ||
parent::__construct('The Apple Pay validation URL allow list can not be empty. Please check the configuration.'); | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
src/Components/ApplePayDirect/Exceptions/ApplePayValidationUrlNotInAllowListException.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<?php | ||
declare(strict_types=1); | ||
|
||
namespace Kiener\MolliePayments\Components\ApplePayDirect\Exceptions; | ||
|
||
class ApplePayValidationUrlNotInAllowListException extends \Exception | ||
{ | ||
public function __construct(string $url) | ||
{ | ||
parent::__construct(sprintf('The given URL %s is not in the Apple Pay validation URL allow list.', $url)); | ||
} | ||
} |
47 changes: 47 additions & 0 deletions
47
src/Components/ApplePayDirect/Gateways/ApplePayValidationUrlAllowListGateway.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
<?php | ||
declare(strict_types=1); | ||
|
||
namespace Kiener\MolliePayments\Components\ApplePayDirect\Gateways; | ||
|
||
use Kiener\MolliePayments\Components\ApplePayDirect\Models\ApplePayValidationUrlAllowListItem; | ||
use Kiener\MolliePayments\Components\ApplePayDirect\Models\Collections\ApplePayValidationUrlAllowList; | ||
use Shopware\Core\System\SystemConfig\SystemConfigService; | ||
|
||
class ApplePayValidationUrlAllowListGateway | ||
{ | ||
/** | ||
* @var SystemConfigService | ||
*/ | ||
private $systemConfigService; | ||
|
||
/** | ||
* ApplePayValidationUrlAllowListItem constructor. | ||
* | ||
* @param SystemConfigService $systemConfigService | ||
*/ | ||
public function __construct(SystemConfigService $systemConfigService) | ||
{ | ||
$this->systemConfigService = $systemConfigService; | ||
} | ||
|
||
/** | ||
* Get the ApplePayValidationUrlAllowList | ||
* | ||
* @return ApplePayValidationUrlAllowList | ||
*/ | ||
public function getAllowList(): ApplePayValidationUrlAllowList | ||
{ | ||
$allowList = $this->systemConfigService->get('MolliePayments.config.ApplePayValidationAllowList'); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. please use our own SettingsService to avoid duplicate hardcoded config strings |
||
|
||
if (is_string($allowList) === false || empty($allowList)) { | ||
return ApplePayValidationUrlAllowList::create(); | ||
} | ||
|
||
$allowList = trim($allowList); | ||
|
||
$items = explode(',', $allowList); | ||
$items = array_map([ApplePayValidationUrlAllowListItem::class, 'create'], $items); | ||
|
||
return ApplePayValidationUrlAllowList::create(...$items); | ||
} | ||
} |
50 changes: 50 additions & 0 deletions
50
src/Components/ApplePayDirect/Models/ApplePayValidationUrlAllowListItem.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
<?php | ||
declare(strict_types=1); | ||
|
||
namespace Kiener\MolliePayments\Components\ApplePayDirect\Models; | ||
|
||
class ApplePayValidationUrlAllowListItem | ||
{ | ||
/** | ||
* @var string | ||
*/ | ||
private $value; | ||
|
||
/** | ||
* ApplePayValidationUrlAllowListItem constructor. | ||
* | ||
* @param string $value | ||
*/ | ||
private function __construct(string $value) | ||
{ | ||
$this->value = $value; | ||
} | ||
|
||
public static function create(string $value): self | ||
{ | ||
if (empty($value)) { | ||
throw new \InvalidArgumentException(sprintf('The value of %s must not be empty', self::class)); | ||
} | ||
|
||
if (strpos($value, 'http') !== 0) { | ||
$value = 'https://' . $value; | ||
} | ||
|
||
if (substr($value, -1) !== '/') { | ||
$value .= '/'; | ||
} | ||
|
||
return new self($value); | ||
} | ||
|
||
/** | ||
* Compare the value with the given value | ||
* | ||
* @param string $value value that will be compared | ||
* @return bool | ||
*/ | ||
public function equals(string $value): bool | ||
{ | ||
return $this->value === $value; | ||
} | ||
} |
69 changes: 69 additions & 0 deletions
69
src/Components/ApplePayDirect/Models/Collections/ApplePayValidationUrlAllowList.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
<?php | ||
declare(strict_types=1); | ||
|
||
namespace Kiener\MolliePayments\Components\ApplePayDirect\Models\Collections; | ||
|
||
use Countable; | ||
use Kiener\MolliePayments\Components\ApplePayDirect\Models\ApplePayValidationUrlAllowListItem; | ||
|
||
class ApplePayValidationUrlAllowList implements Countable | ||
{ | ||
/** | ||
* @var ApplePayValidationUrlAllowListItem[] | ||
*/ | ||
private $allowList; | ||
|
||
/** | ||
* ApplePayValidationUrlAllowList constructor. | ||
* | ||
* @param ApplePayValidationUrlAllowListItem[] $allowList | ||
*/ | ||
private function __construct(array $allowList = []) | ||
{ | ||
$this->allowList = $allowList; | ||
} | ||
|
||
/** | ||
* Create a new ApplePayAllowList | ||
* | ||
* @param ApplePayValidationUrlAllowListItem ...$items | ||
* @return ApplePayValidationUrlAllowList | ||
*/ | ||
public static function create(ApplePayValidationUrlAllowListItem ...$items): self | ||
{ | ||
return new self($items); | ||
} | ||
|
||
/** | ||
* Check if the given value is in the allow list | ||
* | ||
* @param string $value | ||
* @return bool | ||
*/ | ||
public function contains(string $value): bool | ||
{ | ||
foreach ($this->allowList as $item) { | ||
if ($item->equals($value)) { | ||
return true; | ||
} | ||
} | ||
|
||
return false; | ||
} | ||
|
||
/** | ||
* @return bool | ||
*/ | ||
public function isEmpty(): bool | ||
{ | ||
return count($this) === 0; | ||
} | ||
|
||
/** | ||
* @inheritDoc | ||
*/ | ||
public function count(): int | ||
{ | ||
return count($this->allowList); | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
src/Components/ApplePayDirect/Services/ApplePayValidationUrlSanitizer.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<?php | ||
declare(strict_types=1); | ||
|
||
namespace Kiener\MolliePayments\Components\ApplePayDirect\Services; | ||
|
||
/** | ||
* Responsible for sanitizing the validation URL for Apple Pay | ||
*/ | ||
class ApplePayValidationUrlSanitizer | ||
{ | ||
/** | ||
* Sanitize the given validation URL | ||
* | ||
* @param string $url | ||
* @return string | ||
*/ | ||
public function sanitizeValidationUrl(string $url): string | ||
{ | ||
if (strpos($url, 'http') !== 0) { | ||
$url = 'https://' . $url; | ||
} | ||
|
||
if (substr($url, -1) !== '/') { | ||
$url .= '/'; | ||
} | ||
|
||
return $url; | ||
} | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
validate DOMAIN? or?
validation URL is something else, we need to validate the domain
which also means we should rename the whole member variables and probably classes?
(we can talk in zoom if you want)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
also why do we require a string return value? its no "getter" it just validates with exception approach, meaning void is totally fine?
so sanitizing might be better as a second function? function naming and content is a bit different i think?