Skip to content

Commit

Permalink
feat(backend): fix boolean environment cast
Browse files Browse the repository at this point in the history
  • Loading branch information
myst committed Aug 12, 2024
1 parent fc34841 commit 8a4cda9
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
16 changes: 16 additions & 0 deletions backend/src/core/environment/environment.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,22 @@ describe('Environment', () => {
expect(env.telnetTLS).toBe(true);
});

it('should handle TRUE as boolean values for TLS configuration', async () => {
process.env.TELNET_HOST = 'localhost';

process.env.TELNET_PORT = '3000';

process.env.SOCKET_ROOT = '/socket.io';

process.env.CHARSET = 'utf8';

process.env.TELNET_TLS = 'TRUE';

const env = await getFreshEnvironmentInstance();

expect(env.telnetTLS).toBe(true);
});

it('should handle missing TLS configuration gracefully', async () => {
process.env.TELNET_HOST = 'localhost';

Expand Down
6 changes: 5 additions & 1 deletion backend/src/core/environment/environment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,11 @@ export class Environment implements IEnvironment {
this.telnetPort = Number(getEnvironmentVariable('TELNET_PORT'));

this.telnetTLS =
getEnvironmentVariable('TELNET_TLS', false, 'false') === 'true';
getEnvironmentVariable(
'TELNET_TLS',
false,
'false',
)?.toLocaleLowerCase() === 'true';

this.socketRoot = String(getEnvironmentVariable('SOCKET_ROOT'));

Expand Down

0 comments on commit 8a4cda9

Please sign in to comment.