Skip to content

Commit 3fad54f

Browse files
committed
Add unit tests for 'encrypted' and 'trust' config validation
1 parent 533ee31 commit 3fad54f

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

test/internal/channel-config.test.js

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import ChannelConfig from '../../src/v1/internal/channel-config';
2121
import urlUtil from '../../src/v1/internal/url-util';
2222
import {SERVICE_UNAVAILABLE} from '../../src/v1/error';
23+
import {ENCRYPTION_OFF, ENCRYPTION_ON} from '../../src/v1/internal/util';
2324

2425
describe('ChannelConfig', () => {
2526

@@ -127,4 +128,35 @@ describe('ChannelConfig', () => {
127128
expect(config.connectionTimeout).toBeNull();
128129
});
129130

131+
it('should validate value of "encrypted" property', () => {
132+
expect(new ChannelConfig(null, {encrypted: null}, '').encrypted).toBeNull();
133+
expect(new ChannelConfig(null, {encrypted: undefined}, '').encrypted).toBeUndefined();
134+
expect(new ChannelConfig(null, {encrypted: true}, '').encrypted).toBeTruthy();
135+
expect(new ChannelConfig(null, {encrypted: false}, '').encrypted).toBeFalsy();
136+
expect(new ChannelConfig(null, {encrypted: ENCRYPTION_ON}, '').encrypted).toEqual(ENCRYPTION_ON);
137+
expect(new ChannelConfig(null, {encrypted: ENCRYPTION_OFF}, '').encrypted).toEqual(ENCRYPTION_OFF);
138+
139+
expect(() => new ChannelConfig(null, {encrypted: []}, '')).toThrow();
140+
expect(() => new ChannelConfig(null, {encrypted: {}}, '')).toThrow();
141+
expect(() => new ChannelConfig(null, {encrypted: () => 'Hello'}, '')).toThrow();
142+
expect(() => new ChannelConfig(null, {encrypted: 42}, '')).toThrow();
143+
expect(() => new ChannelConfig(null, {encrypted: 'Hello'}, '')).toThrow();
144+
});
145+
146+
it('should validate value of "trust" property', () => {
147+
expect(new ChannelConfig(null, {trust: null}, '').trust).toBeNull();
148+
expect(new ChannelConfig(null, {trust: undefined}, '').trust).toBeUndefined();
149+
expect(new ChannelConfig(null, {trust: 'TRUST_ALL_CERTIFICATES'}, '').trust).toEqual('TRUST_ALL_CERTIFICATES');
150+
expect(new ChannelConfig(null, {trust: 'TRUST_ON_FIRST_USE'}, '').trust).toEqual('TRUST_ON_FIRST_USE');
151+
expect(new ChannelConfig(null, {trust: 'TRUST_SIGNED_CERTIFICATES'}, '').trust).toEqual('TRUST_SIGNED_CERTIFICATES');
152+
expect(new ChannelConfig(null, {trust: 'TRUST_CUSTOM_CA_SIGNED_CERTIFICATES'}, '').trust).toEqual('TRUST_CUSTOM_CA_SIGNED_CERTIFICATES');
153+
expect(new ChannelConfig(null, {trust: 'TRUST_SYSTEM_CA_SIGNED_CERTIFICATES'}, '').trust).toEqual('TRUST_SYSTEM_CA_SIGNED_CERTIFICATES');
154+
155+
expect(() => new ChannelConfig(null, {trust: []}, '')).toThrow();
156+
expect(() => new ChannelConfig(null, {trust: {}}, '')).toThrow();
157+
expect(() => new ChannelConfig(null, {trust: () => 'Trust'}, '')).toThrow();
158+
expect(() => new ChannelConfig(null, {trust: 42}, '')).toThrow();
159+
expect(() => new ChannelConfig(null, {trust: 'SOME_WRONG_TRUST_STRATEGY'}, '')).toThrow();
160+
});
161+
130162
});

0 commit comments

Comments
 (0)