mirror of https://github.com/ghostfolio/ghostfolio
Browse Source
- Add REDIS_TLS environment variable to enable TLS for Redis - Pass tls options in getRedisConnectionOptions for ioredis (Bull queues & rate limiting) - Derive rediss:// URL in getRedisConnectionUrl for @keyv/redis cache - Add unit tests for redis.helper - Document REDIS_TLS in README.md and .env.example
6 changed files with 99 additions and 3 deletions
@ -0,0 +1,91 @@ |
|||||
|
import { ConfigurationService } from '@ghostfolio/api/services/configuration/configuration.service'; |
||||
|
import type { Environment } from '@ghostfolio/api/services/interfaces/environment.interface'; |
||||
|
|
||||
|
import { |
||||
|
getRedisConnectionOptions, |
||||
|
getRedisConnectionUrl |
||||
|
} from './redis.helper'; |
||||
|
|
||||
|
function createConfigurationService(overrides: Partial<Environment> = {}) { |
||||
|
const configuration: Record<string, unknown> = { |
||||
|
REDIS_DB: 0, |
||||
|
REDIS_HOST: 'localhost', |
||||
|
REDIS_PASSWORD: '***', |
||||
|
REDIS_PORT: 6379, |
||||
|
REDIS_TLS: false, |
||||
|
...overrides |
||||
|
}; |
||||
|
|
||||
|
return { |
||||
|
get: jest.fn((key: string) => configuration[key]) |
||||
|
} as unknown as ConfigurationService; |
||||
|
} |
||||
|
|
||||
|
describe('redis.helper', () => { |
||||
|
describe('getRedisConnectionOptions', () => { |
||||
|
it('should return connection options without TLS when REDIS_TLS is false', () => { |
||||
|
const configurationService = createConfigurationService({ |
||||
|
REDIS_TLS: false |
||||
|
}); |
||||
|
|
||||
|
const options = getRedisConnectionOptions(configurationService); |
||||
|
|
||||
|
expect(options).toEqual({ |
||||
|
db: 0, |
||||
|
host: 'localhost', |
||||
|
password: '***', |
||||
|
port: 6379, |
||||
|
tls: undefined |
||||
|
}); |
||||
|
}); |
||||
|
|
||||
|
it('should return connection options with tls object when REDIS_TLS is true', () => { |
||||
|
const configurationService = createConfigurationService({ |
||||
|
REDIS_TLS: true |
||||
|
}); |
||||
|
|
||||
|
const options = getRedisConnectionOptions(configurationService); |
||||
|
|
||||
|
expect(options).toEqual({ |
||||
|
db: 0, |
||||
|
host: 'localhost', |
||||
|
password: '***', |
||||
|
port: 6379, |
||||
|
tls: {} |
||||
|
}); |
||||
|
}); |
||||
|
}); |
||||
|
|
||||
|
describe('getRedisConnectionUrl', () => { |
||||
|
it('should return standard redis:// URL when REDIS_TLS is false', () => { |
||||
|
const configurationService = createConfigurationService({ |
||||
|
REDIS_TLS: false |
||||
|
}); |
||||
|
|
||||
|
const url = getRedisConnectionUrl(configurationService); |
||||
|
|
||||
|
expect(url).toBe('redis://:***@localhost:6379/0'); |
||||
|
}); |
||||
|
|
||||
|
it('should return rediss:// URL when REDIS_TLS is true', () => { |
||||
|
const configurationService = createConfigurationService({ |
||||
|
REDIS_TLS: true |
||||
|
}); |
||||
|
|
||||
|
const url = getRedisConnectionUrl(configurationService); |
||||
|
|
||||
|
expect(url).toBe('rediss://:***@localhost:6379/0'); |
||||
|
}); |
||||
|
|
||||
|
it('should format URL correctly without password', () => { |
||||
|
const configurationService = createConfigurationService({ |
||||
|
REDIS_PASSWORD: '', |
||||
|
REDIS_TLS: false |
||||
|
}); |
||||
|
|
||||
|
const url = getRedisConnectionUrl(configurationService); |
||||
|
|
||||
|
expect(url).toBe('redis://@localhost:6379/0'); |
||||
|
}); |
||||
|
}); |
||||
|
}); |
||||
Loading…
Reference in new issue