Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
80 changes: 71 additions & 9 deletions src/Adapter/DynamoDB/DynamoDBRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,24 @@

public function createShop(ShopInterface $shop): void
{
$item = [
'id' => ['S' => $shop->getShopId()],
'active' => ['BOOL' => $shop->isShopActive() ? '1' : '0'],
'confirmed' => ['BOOL' => $shop->isRegistrationConfirmed() ? '1' : '0'],
'url' => ['S' => $shop->getShopUrl()],
'secret' => ['S' => $shop->getShopSecret()],
'clientId' => ['S' => (string) $shop->getShopClientId()],
'clientSecret' => ['S' => (string) $shop->getShopClientSecret()],
'pendingShopSecret' => ['S' => (string) $shop->getPendingShopSecret()],
'pendingShopUrl' => ['S' => (string) $shop->getPendingShopUrl()],
'previousShopSecret' => ['S' => (string) $shop->getPreviousShopSecret()],
'secretsRotatedAt' => ['S' => (string) ($shop->getSecretsRotatedAt()?->getTimestamp() ?? '')],

Check warning on line 42 in src/Adapter/DynamoDB/DynamoDBRepository.php

View workflow job for this annotation

GitHub Actions / unit

Escaped Mutant for Mutator "CastString": @@ @@ } public function createShop(ShopInterface $shop): void { - $item = ['id' => ['S' => $shop->getShopId()], 'active' => ['BOOL' => $shop->isShopActive() ? '1' : '0'], 'confirmed' => ['BOOL' => $shop->isRegistrationConfirmed() ? '1' : '0'], 'url' => ['S' => $shop->getShopUrl()], 'secret' => ['S' => $shop->getShopSecret()], 'clientId' => ['S' => (string) $shop->getShopClientId()], 'clientSecret' => ['S' => (string) $shop->getShopClientSecret()], 'pendingShopSecret' => ['S' => (string) $shop->getPendingShopSecret()], 'pendingShopUrl' => ['S' => (string) $shop->getPendingShopUrl()], 'previousShopSecret' => ['S' => (string) $shop->getPreviousShopSecret()], 'secretsRotatedAt' => ['S' => (string) ($shop->getSecretsRotatedAt()?->getTimestamp() ?? '')], 'hasVerifiedWithDoubleSignature' => ['BOOL' => $shop->hasVerifiedWithDoubleSignature() ? '1' : '0']]; + $item = ['id' => ['S' => $shop->getShopId()], 'active' => ['BOOL' => $shop->isShopActive() ? '1' : '0'], 'confirmed' => ['BOOL' => $shop->isRegistrationConfirmed() ? '1' : '0'], 'url' => ['S' => $shop->getShopUrl()], 'secret' => ['S' => $shop->getShopSecret()], 'clientId' => ['S' => (string) $shop->getShopClientId()], 'clientSecret' => ['S' => (string) $shop->getShopClientSecret()], 'pendingShopSecret' => ['S' => (string) $shop->getPendingShopSecret()], 'pendingShopUrl' => ['S' => (string) $shop->getPendingShopUrl()], 'previousShopSecret' => ['S' => (string) $shop->getPreviousShopSecret()], 'secretsRotatedAt' => ['S' => $shop->getSecretsRotatedAt()?->getTimestamp() ?? ''], 'hasVerifiedWithDoubleSignature' => ['BOOL' => $shop->hasVerifiedWithDoubleSignature() ? '1' : '0']]; $this->client->putItem(new PutItemInput(['TableName' => $this->tableName, 'Item' => $item])); } public function getShopFromId(string $shopId): ShopInterface|null
'hasVerifiedWithDoubleSignature' => ['BOOL' => $shop->hasVerifiedWithDoubleSignature() ? '1' : '0'],
];

$this->client->putItem(new PutItemInput([
'TableName' => $this->tableName,
'Item' => [
'id' => ['S' => $shop->getShopId()],
'active' => ['BOOL' => $shop->isShopActive() ? '1' : '0'],
'url' => ['S' => $shop->getShopUrl()],
'secret' => ['S' => $shop->getShopSecret()],
'clientId' => ['S' => (string) $shop->getShopClientId()],
'clientSecret' => ['S' => (string) $shop->getShopClientSecret()],
],
'Item' => $item,
]));
}

Expand Down Expand Up @@ -67,17 +75,65 @@

$active = $item['active']->getBool();

if ($active === null) {

Check warning on line 78 in src/Adapter/DynamoDB/DynamoDBRepository.php

View workflow job for this annotation

GitHub Actions / unit

Escaped Mutant for Mutator "Identical": @@ @@ $shopClientId = null; } $active = $item['active']->getBool(); - if ($active === null) { + if ($active !== null) { $active = false; } $confirmed = true;
$active = false;
}

$confirmed = true;
if (isset($item['confirmed'])) {
$confirmed = $item['confirmed']->getBool();
if ($confirmed === null) {

Check warning on line 85 in src/Adapter/DynamoDB/DynamoDBRepository.php

View workflow job for this annotation

GitHub Actions / unit

Escaped Mutant for Mutator "Identical": @@ @@ $confirmed = true; if (isset($item['confirmed'])) { $confirmed = $item['confirmed']->getBool(); - if ($confirmed === null) { + if ($confirmed !== null) { $confirmed = false; } }
$confirmed = false;
}
}

$pendingShopSecret = isset($item['pendingShopSecret']) ? $item['pendingShopSecret']->getS() : null;
$pendingShopUrl = isset($item['pendingShopUrl']) ? $item['pendingShopUrl']->getS() : null;
$previousShopSecret = isset($item['previousShopSecret']) ? $item['previousShopSecret']->getS() : null;

if ($pendingShopSecret === '') {
$pendingShopSecret = null;
}

if ($pendingShopUrl === '') {
$pendingShopUrl = null;
}

if ($previousShopSecret === '') {
$previousShopSecret = null;
}

$secretsRotatedAt = null;

if (isset($item['secretsRotatedAt'])) {
$timestamp = $item['secretsRotatedAt']->getS();
if ($timestamp !== null && $timestamp !== '') {
$secretsRotatedAt = (new \DateTimeImmutable())->setTimestamp((int) $timestamp);
}
}

$hasVerifiedWithDoubleSignature = false;
if (isset($item['hasVerifiedWithDoubleSignature'])) {
$hasVerifiedWithDoubleSignature = $item['hasVerifiedWithDoubleSignature']->getBool();

if ($hasVerifiedWithDoubleSignature === null) {
$hasVerifiedWithDoubleSignature = false;
}
}

return new DynamoDBShop(
$item['id']->getS() ?? '',
$item['url']->getS() ?? '',
$item['secret']->getS() ?? '',
$shopClientId,
$shopClientSecret,
$active,
$pendingShopSecret,
$pendingShopUrl,
$previousShopSecret,
$secretsRotatedAt,
$hasVerifiedWithDoubleSignature,
$confirmed,
);
}

Expand All @@ -88,16 +144,22 @@
'Key' => [
'id' => ['S' => $shop->getShopId()],
],
'UpdateExpression' => 'SET active = :active, #u = :url, secret = :secret, clientId = :clientId, clientSecret = :clientSecret',
'UpdateExpression' => 'SET active = :active, confirmed = :confirmed, #u = :url, secret = :secret, clientId = :clientId, clientSecret = :clientSecret, pendingShopSecret = :pendingShopSecret, pendingShopUrl = :pendingShopUrl, previousShopSecret = :previousShopSecret, secretsRotatedAt = :secretsRotatedAt, hasVerifiedWithDoubleSignature = :hasVerifiedWithDoubleSignature',
'ExpressionAttributeNames' => [
'#u' => 'url',
],
'ExpressionAttributeValues' => [
':active' => ['BOOL' => $shop->isShopActive() ? '1' : '0'],
':confirmed' => ['BOOL' => $shop->isRegistrationConfirmed() ? '1' : '0'],
':url' => ['S' => $shop->getShopUrl()],
':secret' => ['S' => $shop->getShopSecret()],
':clientId' => ['S' => (string) $shop->getShopClientId()],
':clientSecret' => ['S' => (string) $shop->getShopClientSecret()],
':pendingShopSecret' => ['S' => (string) $shop->getPendingShopSecret()],
':pendingShopUrl' => ['S' => (string) $shop->getPendingShopUrl()],
':previousShopSecret' => ['S' => (string) $shop->getPreviousShopSecret()],
':secretsRotatedAt' => ['S' => (string) ($shop->getSecretsRotatedAt()?->getTimestamp() ?? '')],

Check warning on line 161 in src/Adapter/DynamoDB/DynamoDBRepository.php

View workflow job for this annotation

GitHub Actions / unit

Escaped Mutant for Mutator "CastString": @@ @@ } public function updateShop(ShopInterface $shop): void { - $this->client->updateItem(new UpdateItemInput(['TableName' => $this->tableName, 'Key' => ['id' => ['S' => $shop->getShopId()]], 'UpdateExpression' => 'SET active = :active, confirmed = :confirmed, #u = :url, secret = :secret, clientId = :clientId, clientSecret = :clientSecret, pendingShopSecret = :pendingShopSecret, pendingShopUrl = :pendingShopUrl, previousShopSecret = :previousShopSecret, secretsRotatedAt = :secretsRotatedAt, hasVerifiedWithDoubleSignature = :hasVerifiedWithDoubleSignature', 'ExpressionAttributeNames' => ['#u' => 'url'], 'ExpressionAttributeValues' => [':active' => ['BOOL' => $shop->isShopActive() ? '1' : '0'], ':confirmed' => ['BOOL' => $shop->isRegistrationConfirmed() ? '1' : '0'], ':url' => ['S' => $shop->getShopUrl()], ':secret' => ['S' => $shop->getShopSecret()], ':clientId' => ['S' => (string) $shop->getShopClientId()], ':clientSecret' => ['S' => (string) $shop->getShopClientSecret()], ':pendingShopSecret' => ['S' => (string) $shop->getPendingShopSecret()], ':pendingShopUrl' => ['S' => (string) $shop->getPendingShopUrl()], ':previousShopSecret' => ['S' => (string) $shop->getPreviousShopSecret()], ':secretsRotatedAt' => ['S' => (string) ($shop->getSecretsRotatedAt()?->getTimestamp() ?? '')], ':hasVerifiedWithDoubleSignature' => ['BOOL' => $shop->hasVerifiedWithDoubleSignature() ? '1' : '0']]])); + $this->client->updateItem(new UpdateItemInput(['TableName' => $this->tableName, 'Key' => ['id' => ['S' => $shop->getShopId()]], 'UpdateExpression' => 'SET active = :active, confirmed = :confirmed, #u = :url, secret = :secret, clientId = :clientId, clientSecret = :clientSecret, pendingShopSecret = :pendingShopSecret, pendingShopUrl = :pendingShopUrl, previousShopSecret = :previousShopSecret, secretsRotatedAt = :secretsRotatedAt, hasVerifiedWithDoubleSignature = :hasVerifiedWithDoubleSignature', 'ExpressionAttributeNames' => ['#u' => 'url'], 'ExpressionAttributeValues' => [':active' => ['BOOL' => $shop->isShopActive() ? '1' : '0'], ':confirmed' => ['BOOL' => $shop->isRegistrationConfirmed() ? '1' : '0'], ':url' => ['S' => $shop->getShopUrl()], ':secret' => ['S' => $shop->getShopSecret()], ':clientId' => ['S' => (string) $shop->getShopClientId()], ':clientSecret' => ['S' => (string) $shop->getShopClientSecret()], ':pendingShopSecret' => ['S' => (string) $shop->getPendingShopSecret()], ':pendingShopUrl' => ['S' => (string) $shop->getPendingShopUrl()], ':previousShopSecret' => ['S' => (string) $shop->getPreviousShopSecret()], ':secretsRotatedAt' => ['S' => $shop->getSecretsRotatedAt()?->getTimestamp() ?? ''], ':hasVerifiedWithDoubleSignature' => ['BOOL' => $shop->hasVerifiedWithDoubleSignature() ? '1' : '0']]])); } public function deleteShop(string $shopId): void {
':hasVerifiedWithDoubleSignature' => ['BOOL' => $shop->hasVerifiedWithDoubleSignature() ? '1' : '0'],
],
]));
}
Expand Down
104 changes: 102 additions & 2 deletions src/Adapter/DynamoDB/DynamoDBShop.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,23 @@

class DynamoDBShop implements ShopInterface
{
public function __construct(public string $shopId, public string $shopUrl, public string $shopSecret, public ?string $shopClientId = null, public ?string $shopClientSecret = null, public bool $active = false)
{
public function __construct(
public string $shopId,
public string $shopUrl,
public string $shopSecret,
public ?string $shopClientId = null,
public ?string $shopClientSecret = null,
public bool $active = false,
public ?string $pendingShopSecret = null,
public ?string $pendingShopUrl = null,
public ?string $previousShopSecret = null,
public ?\DateTimeImmutable $secretsRotatedAt = null,
/**
* @deprecated tag:v6.0.0 - Will be removed. Double signature verification will always be enforced.
*/
public bool $hasVerifiedWithDoubleSignature = false,

Check warning on line 25 in src/Adapter/DynamoDB/DynamoDBShop.php

View workflow job for this annotation

GitHub Actions / unit

Escaped Mutant for Mutator "FalseValue": @@ @@ /** * @deprecated tag:v6.0.0 - Will be removed. Double signature verification will always be enforced. */ - public bool $hasVerifiedWithDoubleSignature = false, + public bool $hasVerifiedWithDoubleSignature = true, public bool $registrationConfirmed = false ) {
public bool $registrationConfirmed = false,
) {
}

public function isShopActive(): bool
Expand All @@ -32,6 +47,16 @@
return $this->shopSecret;
}

public function getPreviousShopSecret(): ?string
{
return $this->previousShopSecret;
}

public function getPendingShopSecret(): ?string
{
return $this->pendingShopSecret;
}

public function getShopClientId(): ?string
{
return $this->shopClientId;
Expand All @@ -42,6 +67,16 @@
return $this->shopClientSecret;
}

public function getPendingShopUrl(): ?string
{
return $this->pendingShopUrl;
}

public function getSecretsRotatedAt(): ?\DateTimeImmutable
{
return $this->secretsRotatedAt;
}

public function setShopApiCredentials(string $clientId, string $clientSecret): ShopInterface
{
$this->shopClientId = $clientId;
Expand All @@ -50,6 +85,13 @@
return $this;
}

public function setShopSecret(string $secret): ShopInterface
{
$this->shopSecret = $secret;

return $this;
}

public function setShopUrl(string $url): ShopInterface
{
$this->shopUrl = $url;
Expand All @@ -63,4 +105,62 @@

return $this;
}

public function setPendingShopSecret(?string $secret): ShopInterface
{
$this->pendingShopSecret = $secret;

return $this;
}

public function setPendingShopUrl(?string $shopUrl): ShopInterface
{
$this->pendingShopUrl = $shopUrl;

return $this;
}

public function setPreviousShopSecret(string $secret): ShopInterface
{
$this->previousShopSecret = $secret;

return $this;
}

public function setSecretsRotatedAt(\DateTimeImmutable $updatedAt): ShopInterface
{
$this->secretsRotatedAt = $updatedAt;

return $this;
}

public function isRegistrationConfirmed(): bool
{
return $this->registrationConfirmed;
}

public function setRegistrationConfirmed(): ShopInterface
{
$this->registrationConfirmed = true;

return $this;
}

/**
* @deprecated tag:v6.0.0 - Will be removed. Double signature verification will always be enforced.
*/
public function setVerifiedWithDoubleSignature(): ShopInterface
{
$this->hasVerifiedWithDoubleSignature = true;

return $this;
}

/**
* @deprecated tag:v6.0.0 - Will be removed. Double signature verification will always be enforced.
*/
public function hasVerifiedWithDoubleSignature(): bool
{
return $this->hasVerifiedWithDoubleSignature;
}
}
11 changes: 10 additions & 1 deletion src/AppConfiguration.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ class AppConfiguration
public function __construct(
private readonly string $appName,
private readonly string $appSecret,
private readonly string $registrationConfirmationUrl
private readonly string $registrationConfirmationUrl,
private readonly bool $enforceDoubleSignature = false
) {
}

Expand All @@ -27,4 +28,12 @@ public function getRegistrationConfirmUrl(): string
{
return $this->registrationConfirmationUrl;
}

/**
* @deprecated tag:v6.0.0 - Will be removed. Double signature verification will always be enforced.
*/
public function enforceDoubleSignature(): bool
{
return $this->enforceDoubleSignature;
}
}
Loading
Loading