@@ -8,7 +8,7 @@ import * as FakeTimers from '@sinonjs/fake-timers'
8
8
import * as sinon from 'sinon'
9
9
import { SsoAccessTokenProvider } from '../../../auth/sso/ssoAccessTokenProvider'
10
10
import { installFakeClock } from '../../testUtil'
11
- import { getCache , getTokenCacheFile , isDirSafeToDeleteFrom , getRegistrationCacheFile } from '../../../auth/sso/cache'
11
+ import { getCache } from '../../../auth/sso/cache'
12
12
13
13
import { instance , mock , when , anything , reset } from '../../utilities/mockito'
14
14
import { makeTemporaryToolkitFolder , tryRemoveFolder } from '../../../shared/filesystemUtilities'
@@ -124,74 +124,6 @@ describe('SsoAccessTokenProvider', function () {
124
124
assert . strictEqual ( await cache . token . load ( startUrl ) , undefined )
125
125
} )
126
126
127
- describe ( 'does not return old tokens' , function ( ) {
128
- // A file is old when the creation time is under a certain date
129
- const oldTime : Date = new Date ( 2023 , 3 , 10 ) // April 10, 2023
130
- const nonOldTime : Date = new Date ( 2023 , 3 , 15 ) // April 15, 2023
131
-
132
- function oldBirthtime ( file : fs . PathLike ) : fs . Stats {
133
- return { birthtimeMs : oldTime . getTime ( ) , birthtime : oldTime } as fs . Stats
134
- }
135
-
136
- /** Windows edge case where birthtime does not exist, instead check ctime */
137
- function noBirthtimeOldCTime ( file : fs . PathLike ) : fs . Stats {
138
- return { birthtimeMs : 0 , ctime : oldTime } as fs . Stats
139
- }
140
-
141
- const oldStatsFuncs = [ oldBirthtime , noBirthtimeOldCTime ]
142
-
143
- oldStatsFuncs . forEach ( invalidStatsFunc => {
144
- it ( `deletes old invalid tokens when ${ invalidStatsFunc . name } then returns undefined` , async function ( ) {
145
- await cache . token . save ( startUrl , { region, startUrl, token : createToken ( hourInMs ) } )
146
- const tokenCacheFile = getTokenCacheFile ( tempDir , startUrl )
147
- assert . strictEqual ( fs . existsSync ( tokenCacheFile ) , true )
148
-
149
- // Set the func which returns Stats that are always 'invalid'
150
- cache = getCache ( tempDir , invalidStatsFunc )
151
-
152
- assert . strictEqual ( await cache . token . load ( startUrl ) , undefined )
153
- assert . strictEqual ( fs . existsSync ( tokenCacheFile ) , false )
154
- } )
155
-
156
- it ( `deletes old invalid registrations when ${ invalidStatsFunc . name } then returns undefined` , async function ( ) {
157
- const registrationKey = { region }
158
- await cache . registration . save ( registrationKey , createRegistration ( hourInMs ) )
159
- const registrationCacheFile = getRegistrationCacheFile ( tempDir , registrationKey )
160
- assert . strictEqual ( fs . existsSync ( registrationCacheFile ) , true )
161
-
162
- // Set the func which returns Stats that are always 'invalid'
163
- cache = getCache ( tempDir , invalidStatsFunc )
164
- assert . strictEqual ( await cache . token . load ( startUrl ) , undefined )
165
- assert . strictEqual ( fs . existsSync ( registrationCacheFile ) , false )
166
- } )
167
- } )
168
-
169
- function nonOldBirthtime ( file : fs . PathLike ) : fs . Stats {
170
- return { birthtimeMs : nonOldTime . getTime ( ) } as fs . Stats
171
- }
172
-
173
- it ( `returns token from non-old file` , async function ( ) {
174
- const token = createToken ( hourInMs )
175
- await cache . token . save ( startUrl , { region, startUrl, token } )
176
- const tokenCacheFile = getTokenCacheFile ( tempDir , startUrl )
177
- assert . strictEqual ( fs . existsSync ( tokenCacheFile ) , true )
178
-
179
- cache = getCache ( tempDir , nonOldBirthtime )
180
-
181
- assert . deepStrictEqual ( ( await cache . token . load ( startUrl ) ) ! . token , token )
182
- assert . strictEqual ( fs . existsSync ( tokenCacheFile ) , true )
183
- } )
184
-
185
- it ( 'isDirSafeToDeleteFrom()' , function ( ) {
186
- assert . ok ( ! isDirSafeToDeleteFrom ( '.' ) )
187
- assert . ok ( ! isDirSafeToDeleteFrom ( '/' ) )
188
- assert . ok ( ! isDirSafeToDeleteFrom ( 'not/an/absolute/path' ) )
189
- assert . ok ( ! isDirSafeToDeleteFrom ( '/a/b/c' ) ) // Too shallow
190
-
191
- assert . ok ( isDirSafeToDeleteFrom ( '/a/b/c/d' ) )
192
- } )
193
- } )
194
-
195
127
it ( 'returns `undefined` for expired tokens that cannot be refreshed' , async function ( ) {
196
128
const expiredToken = createToken ( - hourInMs )
197
129
await cache . token . save ( startUrl , { region, startUrl, token : expiredToken } )
0 commit comments