1313use Lcobucci \JWT \Token \DataSet ;
1414use Lcobucci \JWT \UnencryptedToken ;
1515use OxidEsales \Eshop \Application \Model \User ;
16- use OxidEsales \EshopCommunity \Internal \Framework \Database \ConnectionProviderInterface ;
1716use OxidEsales \EshopCommunity \Tests \Integration \IntegrationTestCase ;
1817use OxidEsales \EshopCommunity \Tests \TestContainerFactory ;
1918use OxidEsales \GraphQL \Base \DataType \Token as TokenDataType ;
2019use OxidEsales \GraphQL \Base \DataType \User as UserDataType ;
2120use OxidEsales \GraphQL \Base \Infrastructure \Model \Token as TokenModel ;
2221use OxidEsales \GraphQL \Base \Infrastructure \Token as TokenInfrastructure ;
22+ use OxidEsales \GraphQL \Base \Service \Token ;
2323use OxidEsales \GraphQL \Base \Service \Token as TokenService ;
2424
2525class TokenTest extends IntegrationTestCase
@@ -31,17 +31,13 @@ class TokenTest extends IntegrationTestCase
3131 /** @var TokenInfrastructure */
3232 private $ tokenInfrastructure ;
3333
34- /** @var ConnectionProviderInterface */
35- private $ connection ;
36-
3734 public function setUp (): void
3835 {
3936 parent ::setUp ();
4037 $ containerFactory = new TestContainerFactory ();
4138 $ container = $ containerFactory ->create ();
4239 $ container ->compile ();
4340 $ this ->tokenInfrastructure = $ container ->get (TokenInfrastructure::class);
44- $ this ->connection = $ container ->get (ConnectionProviderInterface::class)->get ();
4541 }
4642
4743 public function testRegisterToken (): void
@@ -74,6 +70,28 @@ public function testIsTokenRegisteredNo(): void
7470 $ this ->assertFalse ($ this ->tokenInfrastructure ->isTokenRegistered ('not_registered_token ' ));
7571 }
7672
73+ public function testIsTokenExpired (): void
74+ {
75+ $ this ->tokenInfrastructure ->registerToken (
76+ $ this ->getTokenMock ('valid_token ' ),
77+ new DateTimeImmutable ('now ' ),
78+ new DateTimeImmutable ('+8 hours ' )
79+ );
80+
81+ $ this ->assertFalse ($ this ->tokenInfrastructure ->isTokenExpired ('valid_token ' ));
82+ }
83+
84+ public function testIsTokenExpiredNo (): void
85+ {
86+ $ this ->tokenInfrastructure ->registerToken (
87+ $ this ->getTokenMock ('expired_token ' ),
88+ new DateTimeImmutable ('now ' ),
89+ new DateTimeImmutable ('-8 hours ' )
90+ );
91+
92+ $ this ->assertTrue ($ this ->tokenInfrastructure ->isTokenExpired ('expired_token ' ));
93+ }
94+
7795 public function testRemoveExpiredTokens (): void
7896 {
7997 $ this ->tokenInfrastructure ->registerToken (
@@ -323,13 +341,7 @@ public function testInvalidateAccessTokens(): void
323341 );
324342
325343 $ this ->tokenInfrastructure ->invalidateUserTokens ($ userId );
326- $ result = $ this ->connection ->executeQuery (
327- "select expires_at from `oegraphqltoken` where oxid=:tokenId " ,
328- ['tokenId ' => $ token ]
329- );
330- $ expiresAtAfterChange = $ result ->fetchOne ();
331-
332- $ this ->assertTrue (new DateTimeImmutable ($ expiresAtAfterChange ) <= new DateTimeImmutable ('now ' ));
344+ $ this ->assertTrue ($ this ->tokenInfrastructure ->isTokenExpired ($ token ));
333345 }
334346
335347 public function testInvalidateAccessTokensWrongUserId (): void
@@ -344,13 +356,7 @@ public function testInvalidateAccessTokensWrongUserId(): void
344356 );
345357
346358 $ this ->tokenInfrastructure ->invalidateUserTokens ('wrong_user_id ' );
347- $ result = $ this ->connection ->executeQuery (
348- "select expires_at from `oegraphqltoken` where oxid=:tokenId " ,
349- ['tokenId ' => $ token ]
350- );
351- $ expiresAtAfterChange = $ result ->fetchOne ();
352-
353- $ this ->assertFalse (new DateTimeImmutable ($ expiresAtAfterChange ) <= new DateTimeImmutable ('now ' ));
359+ $ this ->assertFalse ($ this ->tokenInfrastructure ->isTokenExpired ($ token ));
354360 }
355361
356362 private function getTokenMock (
0 commit comments