@@ -1631,7 +1631,7 @@ describe('OAuthProvider', () => {
1631
1631
1632
1632
// Verify that the TTL is from the callback, not the default
1633
1633
expect ( newTokens . expires_in ) . toBe ( 7200 ) ;
1634
-
1634
+
1635
1635
// Verify the token contains our custom property
1636
1636
const apiRequest = createMockRequest (
1637
1637
'https://example.com/api/test' ,
@@ -1723,7 +1723,7 @@ describe('OAuthProvider', () => {
1723
1723
// The props should be the original ones (no change)
1724
1724
expect ( apiData . user ) . toEqual ( { userId : "test-user-123" , username : "TestUser" } ) ;
1725
1725
} ) ;
1726
-
1726
+
1727
1727
it ( 'should correctly handle the previous refresh token when callback updates grant props' , async ( ) => {
1728
1728
// This test verifies fixes for two bugs:
1729
1729
// 1. previousRefreshTokenWrappedKey not being re-wrapped when grant props change
@@ -1736,7 +1736,7 @@ describe('OAuthProvider', () => {
1736
1736
...options . props ,
1737
1737
updatedCount : ( options . props . updatedCount || 0 ) + 1
1738
1738
} ;
1739
-
1739
+
1740
1740
// Only return newProps to test that accessTokenProps will inherit from it
1741
1741
return {
1742
1742
// Return new props to trigger the re-encryption with a new key
@@ -1809,7 +1809,7 @@ describe('OAuthProvider', () => {
1809
1809
1810
1810
// Reset the callback invocations before refresh
1811
1811
callCount = 0 ;
1812
-
1812
+
1813
1813
// First refresh - this will update the grant props and re-encrypt them with a new key
1814
1814
const refreshParams = new URLSearchParams ( ) ;
1815
1815
refreshParams . append ( 'grant_type' , 'refresh_token' ) ;
@@ -1826,13 +1826,13 @@ describe('OAuthProvider', () => {
1826
1826
1827
1827
const refreshResponse = await testProvider . fetch ( refreshRequest , mockEnv , mockCtx ) ;
1828
1828
expect ( refreshResponse . status ) . toBe ( 200 ) ;
1829
-
1829
+
1830
1830
// The callback should have been called once for the refresh
1831
1831
expect ( callCount ) . toBe ( 1 ) ;
1832
-
1832
+
1833
1833
// Get the new tokens from the first refresh
1834
1834
const newTokens = await refreshResponse . json ( ) ;
1835
-
1835
+
1836
1836
// Get the refresh token's corresponding token data to verify it has the updated props
1837
1837
const apiRequest1 = createMockRequest (
1838
1838
'https://example.com/api/test' ,
@@ -1842,16 +1842,16 @@ describe('OAuthProvider', () => {
1842
1842
1843
1843
const apiResponse1 = await testProvider . fetch ( apiRequest1 , mockEnv , mockCtx ) ;
1844
1844
const apiData1 = await apiResponse1 . json ( ) ;
1845
-
1845
+
1846
1846
// Print the actual API response to debug
1847
1847
console . log ( "First API response:" , JSON . stringify ( apiData1 ) ) ;
1848
-
1848
+
1849
1849
// Verify that the token has the updated props (updatedCount should be 1)
1850
1850
expect ( apiData1 . user . updatedCount ) . toBe ( 1 ) ;
1851
-
1851
+
1852
1852
// Reset callCount before the second refresh
1853
1853
callCount = 0 ;
1854
-
1854
+
1855
1855
// Now try to use the SAME refresh token again (which should work once due to token rotation)
1856
1856
// With the bug, this would fail because previousRefreshTokenWrappedKey wasn't re-wrapped with the new key
1857
1857
const secondRefreshRequest = createMockRequest (
@@ -1862,17 +1862,17 @@ describe('OAuthProvider', () => {
1862
1862
) ;
1863
1863
1864
1864
const secondRefreshResponse = await testProvider . fetch ( secondRefreshRequest , mockEnv , mockCtx ) ;
1865
-
1866
- // With the bug, this would fail with an error.
1865
+
1866
+ // With the bug, this would fail with an error.
1867
1867
// When fixed, it should succeed because the previous refresh token is still valid once.
1868
1868
expect ( secondRefreshResponse . status ) . toBe ( 200 ) ;
1869
-
1869
+
1870
1870
const secondTokens = await secondRefreshResponse . json ( ) ;
1871
1871
expect ( secondTokens . access_token ) . toBeDefined ( ) ;
1872
-
1872
+
1873
1873
// The callback should have been called again
1874
1874
expect ( callCount ) . toBe ( 1 ) ;
1875
-
1875
+
1876
1876
// Use the token to access API and verify it has the updated props
1877
1877
const apiRequest2 = createMockRequest (
1878
1878
'https://example.com/api/test' ,
@@ -1882,7 +1882,7 @@ describe('OAuthProvider', () => {
1882
1882
1883
1883
const apiResponse2 = await testProvider . fetch ( apiRequest2 , mockEnv , mockCtx ) ;
1884
1884
const apiData2 = await apiResponse2 . json ( ) ;
1885
-
1885
+
1886
1886
// The updatedCount should be 2 now (incremented again during the second refresh)
1887
1887
expect ( apiData2 . user . updatedCount ) . toBe ( 2 ) ;
1888
1888
} ) ;
0 commit comments