Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 7 additions & 42 deletions src/auth/auth.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import {
decodeToken
} from './auth'
import { DecodedToken } from '../types'
import { Logger, LogLevel } from '../logger'

describe('isAccessTokenExpiring', () => {
it('should return true if the token is expiring in an hour', () => {
Expand Down Expand Up @@ -44,53 +43,19 @@ describe('isAccessTokenExpiring', () => {
).toBeFalsy()
})

it('should route opaque-token debug message through process.logger, not console.debug', () => {
it('should return false for an opaque (non-JWT) token without any output', () => {
const debugSpy = jest.spyOn(console, 'debug').mockImplementation(() => {})
const logger = new Logger(LogLevel.Debug)
const loggerSpy = jest.spyOn(logger, 'debug').mockImplementation(() => {})
const originalLogger = process.logger
Object.defineProperty(process, 'logger', {
value: logger,
configurable: true,
writable: true
})
const errorSpy = jest.spyOn(console, 'error').mockImplementation(() => {})

try {
isAccessTokenExpiring('1f8da55057bd4f50a6577f0bc2b38b1a-r')
expect(loggerSpy).toHaveBeenCalledWith(
'isTokenExpiring: token is not a decodable JWT, treating it as not expiring.'
)
expect(debugSpy).not.toHaveBeenCalled()
} finally {
Object.defineProperty(process, 'logger', {
value: originalLogger,
configurable: true,
writable: true
})
debugSpy.mockRestore()
loggerSpy.mockRestore()
}
})

it('should not call console.debug for an opaque token when no logger is set', () => {
const debugSpy = jest.spyOn(console, 'debug').mockImplementation(() => {})
const originalLogger = process.logger
Object.defineProperty(process, 'logger', {
value: undefined,
configurable: true,
writable: true
})

try {
isAccessTokenExpiring('1f8da55057bd4f50a6577f0bc2b38b1a-r')
expect(
isAccessTokenExpiring('1f8da55057bd4f50a6577f0bc2b38b1a-r')
).toBeFalsy()
expect(debugSpy).not.toHaveBeenCalled()
expect(errorSpy).not.toHaveBeenCalled()
} finally {
Object.defineProperty(process, 'logger', {
value: originalLogger,
configurable: true,
writable: true
})
debugSpy.mockRestore()
errorSpy.mockRestore()
}
})

Expand Down
8 changes: 2 additions & 6 deletions src/auth/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,8 @@ function isTokenExpiring(token: string, timeToLiveSeconds: number) {
if (!(err instanceof InvalidTokenError)) throw err
// Opaque tokens cannot be expiry-checked client-side.
// Assume the token is usable and let the server reject it if expired.
// Route through process.logger so the message respects the configured
// log level and doesn't pollute stdout in CI/test runs. Falls back to a
// no-op when no logger has been installed (e.g. library-only usage).
process.logger?.debug?.(
'isTokenExpiring: token is not a decodable JWT, treating it as not expiring.'
)
// Deliberately silent - this is routine (opaque tokens are the norm for
// SAS Logon Manager) and must never appear in CLI output.
return false
}

Expand Down
5 changes: 0 additions & 5 deletions src/types/system/process.d.ts

This file was deleted.

5 changes: 1 addition & 4 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,5 @@
"sourceMap": true
},
"exclude": ["node_modules", "**/*.spec.ts"],
"include": ["src"],
"ts-node": {
"files": true
}
"include": ["src"]
}
Loading