• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

cameri / nostream / 25165731547

30 Apr 2026 12:37PM UTC coverage: 64.452% (+0.01%) from 64.44%
25165731547

push

github

web-flow
fix: skip Redis auth when credentials are unset with unit test (#541) (#545)

1736 of 3039 branches covered (57.12%)

Branch coverage included in aggregate %.

16 of 20 new or added lines in 1 file covered. (80.0%)

4055 of 5946 relevant lines covered (68.2%)

21.63 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

80.36
/src/cache/client.ts
1
import { createClient, RedisClientOptions } from 'redis'
2✔
2
import { CacheClient } from '../@types/cache'
3
import { createLogger } from '../factories/logger-factory'
2✔
4

5
const logger = createLogger('cache-client')
2✔
6

7
const redactRedisUrlCredentials = (url: string): string => {
2✔
8
  try {
1✔
9
    const parsedUrl = new URL(url)
1✔
10

11
    if (!parsedUrl.username && !parsedUrl.password) {
1!
12
      return url
1✔
13
    }
14

NEW
15
    parsedUrl.username = parsedUrl.username ? '***' : ''
×
NEW
16
    parsedUrl.password = parsedUrl.password ? '***' : ''
×
17

NEW
18
    return parsedUrl.toString()
×
19
  } catch {
NEW
20
    return url
×
21
  }
22
}
23

24
export const getCacheConfig = (): RedisClientOptions => {
2✔
25
  const password = process.env.REDIS_PASSWORD
6✔
26

27
  if (process.env.REDIS_URI) {
6✔
28
    return {
1✔
29
      url: process.env.REDIS_URI,
30
      ...(password ? { password } : {}),
1!
31
    }
32
  }
33

34
  const host = process.env.REDIS_HOST
5✔
35
  const port = process.env.REDIS_PORT
5✔
36

37
  if (password) {
5✔
38
    const username = process.env.REDIS_USER ?? 'default'
4✔
39

40
    return {
4✔
41
      url: `redis://${host}:${port}`,
42
      username,
43
      password,
44
    }
45
  }
46

47
  return {
1✔
48
    url: `redis://${host}:${port}`,
49
  }
50
}
51

52
let instance: CacheClient | undefined = undefined
2✔
53

54
export const getCacheClient = (): CacheClient => {
2✔
55
  if (!instance) {
2✔
56
    const config = getCacheConfig()
1✔
57
    // eslint-disable-next-line @typescript-eslint/no-unused-vars
58
    const { password: _, ...loggableConfig } = config
1✔
59
    logger('config: %o', {
1✔
60
      ...loggableConfig,
61
      ...(loggableConfig.url ? { url: redactRedisUrlCredentials(loggableConfig.url) } : {}),
1!
62
    })
63
    instance = createClient(config)
1✔
64
  }
65

66
  return instance
2✔
67
}
68

69
export const closeCacheClient = async (): Promise<void> => {
2✔
70
  if (instance?.isOpen) {
2✔
71
    await instance.disconnect()
1✔
72
    instance = undefined
1✔
73
  }
74
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc