* IdentityProvider that returns a sequence of tokens with a fixed delay simulating network latency. * Used for testing token refresh scenarios.
| 53 | * Used for testing token refresh scenarios. |
| 54 | */ |
| 55 | class ControlledIdentityProvider implements IdentityProvider<string> { |
| 56 | private tokenIndex = 0; |
| 57 | private readonly delayMs: number; |
| 58 | private readonly ttlMs: number; |
| 59 | |
| 60 | constructor( |
| 61 | private readonly tokens: string[], |
| 62 | delayMs: number = 0, |
| 63 | tokenTTlMs: number = 100 |
| 64 | ) { |
| 65 | this.delayMs = delayMs; |
| 66 | this.ttlMs = tokenTTlMs; |
| 67 | } |
| 68 | |
| 69 | async requestToken(): Promise<TokenResponse<string>> { |
| 70 | |
| 71 | if (this.tokenIndex >= this.tokens.length) { |
| 72 | throw new Error('No more test tokens available'); |
| 73 | } |
| 74 | |
| 75 | if (this.delayMs > 0) { |
| 76 | await setTimeout(this.delayMs); |
| 77 | } |
| 78 | |
| 79 | return { token: this.tokens[this.tokenIndex++], ttlMs: this.ttlMs }; |
| 80 | } |
| 81 | |
| 82 | } |
| 83 | |
| 84 | /** |
| 85 | * IdentityProvider that simulates various error scenarios with configurable behavior |
nothing calls this directly
no outgoing calls
no test coverage detected