This repository has been archived by the owner on Nov 1, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Allow nonce owner to be null. #5
Open
noggan
wants to merge
11
commits into
Roave:master
Choose a base branch
from
noggan:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 3 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
b893820
Nonce owner can now be null.
noggan 55698f6
Added separate functions for unassociated create/consume.
noggan 0e7d3c8
Forgot to remove a '= null' from the implementation of the has reposi…
noggan c4afb80
Updated readme.
noggan 872ff66
Renamed functions.
noggan 3973ba2
Fixed broken tests.
noggan 9ff1796
Bad conditional statement.
noggan 3cde992
Composer.lock should not be in the repo.
noggan 03228ee
Fixed missing whitespace.
noggan 0570ead
Added tests for new stuff.
noggan 13a2bfa
Added some missing docblocks.
noggan 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
build/ | ||
vendor/ | ||
.idea |
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
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
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
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 |
---|---|---|
|
@@ -55,6 +55,16 @@ interface NonceRepositoryInterface | |
*/ | ||
public function get(NonceOwnerInterface $owner, $nonce, $namespace = 'default'); | ||
|
||
/** | ||
* Retrieve a nonce entity without an associated owner by token and namespace | ||
* | ||
* @param $nonce | ||
* @param string $namespace | ||
* | ||
* @return NonceEntity|null | ||
*/ | ||
public function getUnassociated($nonce, $namespace = 'default'); | ||
|
||
/** | ||
* Check if a token exists within the given namespace | ||
* | ||
|
@@ -66,6 +76,16 @@ public function get(NonceOwnerInterface $owner, $nonce, $namespace = 'default'); | |
*/ | ||
public function has(NonceOwnerInterface $owner, $nonce, $namespace = 'default'); | ||
|
||
/** | ||
* Check if a nonce entity without an associated owner exists within the given namespace | ||
* | ||
* @param $nonce | ||
* @param string $namespace | ||
* | ||
* @return bool | ||
*/ | ||
public function hasUnassociated($nonce, $namespace = 'default'); | ||
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. Major bc break |
||
|
||
/** | ||
* Remove all the expired tokens | ||
* | ||
|
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 |
---|---|---|
|
@@ -76,18 +76,20 @@ public function __construct(ObjectManager $objectManager, NonceRepositoryInterfa | |
} | ||
|
||
/** | ||
* {@Inheritdoc} | ||
* Creates and persists a nonce entity | ||
* | ||
* @param $nonce | ||
* @param NonceOwnerInterface|null $owner | ||
* @param DateInterval|null $expiresIn | ||
* @param string $namespace | ||
* @return NonceEntity | ||
*/ | ||
public function createNonce( | ||
NonceOwnerInterface $owner, | ||
$namespace = 'default', | ||
private function _create( | ||
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 don't prefix method names. Also, removing public methods is a bc break too |
||
$nonce, | ||
NonceOwnerInterface $owner = null, | ||
DateInterval $expiresIn = null, | ||
$length = 10 | ||
$namespace = 'default' | ||
) { | ||
do { | ||
$nonce = strtr(Rand::getString($length), '+/', '-_'); | ||
} while ($this->repository->has($owner, $nonce, $namespace)); | ||
|
||
$entity = new NonceEntity(); | ||
$entity->setOwner($owner); | ||
$entity->setNonce($nonce); | ||
|
@@ -107,16 +109,17 @@ public function createNonce( | |
return $entity; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function consume( | ||
NonceOwnerInterface $owner, | ||
private function _consume( | ||
$nonce, | ||
NonceOwnerInterface $owner = null, | ||
$namespace = 'default', | ||
RequestInterface $request = null | ||
) { | ||
$nonce = $this->repository->get($owner, $nonce, $namespace); | ||
if ($owner) { | ||
$nonce = $this->repository->get($owner, $nonce, $namespace); | ||
} else { | ||
$nonce = $this->repository->getUnassociated($nonce, $namespace); | ||
} | ||
|
||
if (! $nonce) { | ||
throw new Exception\NonceNotFoundException; | ||
|
@@ -146,4 +149,52 @@ public function consume( | |
|
||
$this->objectManager->flush(); | ||
} | ||
|
||
/** | ||
* {@Inheritdoc} | ||
*/ | ||
public function createNonce( | ||
NonceOwnerInterface $owner, | ||
$namespace = 'default', | ||
DateInterval $expiresIn = null, | ||
$length = 10 | ||
) { | ||
do { | ||
$nonce = strtr(Rand::getString($length), '+/', '-_'); | ||
} while ($this->repository->has($owner, $nonce, $namespace)); | ||
|
||
return $this->_create($owner, $expiresIn, $namespace); | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function createUnassociatedNonce($namespace = 'default', DateInterval $expiresIn = null, $length = 10) | ||
{ | ||
do { | ||
$nonce = strtr(Rand::getString($length), '+/', '-_'); | ||
} while ($this->repository->hasUnassociated($nonce, $namespace)); | ||
|
||
return $this->_create($nonce, null, $expiresIn, $namespace); | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function consume( | ||
NonceOwnerInterface $owner, | ||
$nonce, | ||
$namespace = 'default', | ||
RequestInterface $request = null | ||
) { | ||
$this->_consume($nonce, $owner, $namespace, $request); | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function consumeUnassociated($nonce, $namespace = 'default', RequestInterface $request = null) | ||
{ | ||
$this->_consume($nonce, null, $namespace, $request); | ||
} | ||
} |
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 |
---|---|---|
|
@@ -64,6 +64,17 @@ public function createNonce( | |
$length = 10 | ||
); | ||
|
||
/** | ||
* Create a new nonce without an associated owner | ||
* | ||
* @param string $namespace | ||
* @param DateInterval|null $expiresIn | ||
* @param int $length | ||
* | ||
* @return NonceEntity | ||
*/ | ||
public function createUnassociatedNonce($namespace = 'default', DateInterval $expiresIn = null, $length = 10); | ||
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. Bc break |
||
|
||
/** | ||
* Consume a nonce | ||
* | ||
|
@@ -84,4 +95,15 @@ public function consume( | |
$namespace = 'default', | ||
RequestInterface $request = null | ||
); | ||
|
||
/** | ||
* Consume a nonce without an associated owner | ||
* | ||
* @param $nonce | ||
* @param string $namespace | ||
* @param RequestInterface|null $request | ||
* | ||
* @return void | ||
*/ | ||
public function consumeUnassociated($nonce ,$namespace = 'default', RequestInterface $request = null); | ||
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. Bc break |
||
} |
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.
Major bc break