-
-
Notifications
You must be signed in to change notification settings - Fork 600
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
Issue #191: Allow leeway to handle clock skew #248
Merged
Merged
Changes from all commits
Commits
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
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
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 |
---|---|---|
|
@@ -26,6 +26,19 @@ public function constructorShouldConfigureTheItems() | |
$this->assertAttributeSame($expected, 'items', $data); | ||
} | ||
|
||
/** | ||
* @test | ||
* | ||
* @covers Lcobucci\JWT\ValidationData::__construct | ||
*/ | ||
public function constructorWithLeewayShouldConfigureTheItems() | ||
{ | ||
$expected = $this->createExpectedData(null, null, null, null, 111, 111, 89); | ||
$data = new ValidationData(100, 11); | ||
|
||
$this->assertAttributeSame($expected, 'items', $data); | ||
} | ||
|
||
/** | ||
* @test | ||
* | ||
|
@@ -114,6 +127,22 @@ public function setCurrentTimeShouldChangeTheTimeBasedValues() | |
$this->assertAttributeSame($expected, 'items', $data); | ||
} | ||
|
||
/** | ||
* @test | ||
* | ||
* @uses Lcobucci\JWT\ValidationData::__construct | ||
* | ||
* @covers Lcobucci\JWT\ValidationData::setCurrentTime | ||
*/ | ||
public function setCurrentTimeShouldChangeTheTimeBasedValuesUsingLeeway() | ||
{ | ||
$expected = $this->createExpectedData(null, null, null, null, 30, 30, 10); | ||
$data = new ValidationData(15, 10); | ||
$data->setCurrentTime(20); | ||
|
||
$this->assertAttributeSame($expected, 'items', $data); | ||
} | ||
|
||
/** | ||
* @test | ||
* | ||
|
@@ -196,11 +225,13 @@ public function claimValues() | |
} | ||
|
||
/** | ||
* @param string $id | ||
* @param string $sub | ||
* @param string $iss | ||
* @param string $aud | ||
* @param int $time | ||
* @param string|null $id | ||
* @param string|null $sub | ||
* @param string|null $iss | ||
* @param string|null $aud | ||
* @param int $iat | ||
* @param int|null $nbf | ||
* @param int|null $exp | ||
* | ||
* @return array | ||
*/ | ||
|
@@ -209,16 +240,18 @@ private function createExpectedData( | |
$sub = null, | ||
$iss = null, | ||
$aud = null, | ||
$time = 1 | ||
$iat = 1, | ||
$nbf = null, | ||
$exp = null | ||
) { | ||
return [ | ||
'jti' => $id !== null ? (string) $id : null, | ||
'iss' => $iss !== null ? (string) $iss : null, | ||
'aud' => $aud !== null ? (string) $aud : null, | ||
'sub' => $sub !== null ? (string) $sub : null, | ||
'iat' => $time, | ||
'nbf' => $time, | ||
'exp' => $time | ||
'iat' => $iat, | ||
'nbf' => $nbf !== null ? $nbf: $iat, | ||
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. It's sad that we can't use |
||
'exp' => $exp !== null ? $exp: $iat | ||
]; | ||
} | ||
} |
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.
I was wondering if it makes sense to have this as a property... I mean, it's only used for configuring the current time, maybe it would be better to simply pass it to
ValidationData#setCurrentTime()
... @Ocramius any thoughts?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.
I'm completely fine with doing it either way. Leaving it as it is makes sense if it's fairly common to use the
setCurrentTime()
method 1 or more times after initial construction of the object while keeping the same leeway. However, if users would want to keep changing the leeway without constructing a new object, or if they rarely usesetCurrentTime()
directly at all, then passing leeway as a parameter tosetCurrentTime()
makes more sense.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.
@m777z I'm have no clue on how users are using this object, and since it will be deprecated very soon I don't think we should debate this much. Let's go with your suggested approach and if needed we change it. Thanks!
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.
@lcobucci I am assuming you mean it is okay to just leave things as they are for this part. If so, are there other changes I need to make before this pull request is merged?
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.
@m777z that's correct. There're some small CS changes (which I'll handle ASAP), I just didn't manage to work on this. Plan to work on it tomorrow