-
Notifications
You must be signed in to change notification settings - Fork 6
Add useNetModule to newHttpRequest #49
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
okejminja
wants to merge
4
commits into
launchdarkly:main
Choose a base branch
from
okejminja:feat-use-net-module
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,81 @@ | ||
| import * as LDClient from '../index'; | ||
| import * as packageJson from '../../package.json'; | ||
|
|
||
| import { TestHttpHandlers, TestHttpServer, withCloseable } from 'launchdarkly-js-test-helpers'; | ||
|
|
||
| describe('LDClient', () => { | ||
| const envName = 'UNKNOWN_ENVIRONMENT_ID'; | ||
| const user = { key: 'user' }; | ||
|
|
||
| it('should exist', () => { | ||
| expect(LDClient).toBeDefined(); | ||
| }); | ||
|
|
||
| it('should report correct version', () => { | ||
| expect(LDClient.version).toEqual(packageJson.version); | ||
| }); | ||
|
|
||
| describe('initialization', () => { | ||
| it('should initialize successfully', async () => { | ||
| await withCloseable(TestHttpServer.start, async server => { | ||
| const data = { flag: { value: 3 } }; | ||
| server.byDefault(TestHttpHandlers.respondJson(data)); | ||
|
|
||
| const client = LDClient.initializeInMain(envName, user, { | ||
| baseUrl: server.url, | ||
| sendEvents: false, | ||
| useNetModule: true, | ||
| }); | ||
| await withCloseable(client, async () => { | ||
| await client.waitForInitialization(); | ||
|
|
||
| expect(client.variation('flag')).toEqual(3); | ||
| }); | ||
| }); | ||
| }); | ||
|
|
||
| it('sends correct User-Agent in request', async () => { | ||
| await withCloseable(TestHttpServer.start, async server => { | ||
| const data = { flag: { value: 3 } }; | ||
| server.byDefault(TestHttpHandlers.respondJson(data)); | ||
|
|
||
| const client = LDClient.initializeInMain(envName, user, { | ||
| baseUrl: server.url, | ||
| sendEvents: false, | ||
| useNetModule: true, | ||
| }); | ||
| await withCloseable(client, async () => { | ||
| await client.waitForInitialization(); | ||
|
|
||
| expect(server.requests.length()).toEqual(1); | ||
| const req = await server.nextRequest(); | ||
| expect(req.headers['x-launchdarkly-user-agent']).toMatch(/^ElectronClient\/1\./); | ||
| }); | ||
| }); | ||
| }); | ||
| }); | ||
|
|
||
| describe('track()', () => { | ||
| it('should not warn when tracking an arbitrary custom event', async () => { | ||
| const logger = { | ||
| debug: jest.fn(), | ||
| info: jest.fn(), | ||
| warn: jest.fn(), | ||
| error: jest.fn(), | ||
| }; | ||
| const client = LDClient.initializeInMain(envName, user, { | ||
| bootstrap: {}, | ||
| sendEvents: false, | ||
| logger: logger, | ||
| useNetModule: true, | ||
| }); | ||
| await withCloseable(client, async () => { | ||
| await client.waitForInitialization(); | ||
|
|
||
| client.track('whatever'); | ||
| expect(logger.warn).not.toHaveBeenCalled(); | ||
| expect(logger.error).not.toHaveBeenCalled(); | ||
| }); | ||
| }); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,10 +5,11 @@ | |
| "lib": [ | ||
| "es6", | ||
| "dom" | ||
| ] | ||
| ], | ||
| "types": [] | ||
| }, | ||
| "files": [ | ||
| "typings.d.ts", | ||
| "test-types.ts" | ||
| ] | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -60,6 +60,7 @@ declare module 'launchdarkly-electron-client-sdk' { | |
| * Initialization options for the LaunchDarkly Electron SDK. | ||
| */ | ||
| export interface LDOptions extends LDOptionsBase { | ||
| useNetModule?: boolean; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. See above, I think we need to document the caveats as well as what exactly this option does. |
||
| } | ||
|
|
||
| /** | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TLS parameters silently ignored when using net module
Medium Severity
When
useNetModuleistrue, thetlsParamsargument is accepted but never applied — theelectronNet.request()call doesn't incorporate any TLS configuration. A user who sets bothuseNetModule: trueandtlsParams(e.g. a customcafor self-signed certificates, as shown inLDClient-tls-test.js) will have their TLS configuration silently dropped, potentially causing connection failures or unintended security behavior with no indication of what went wrong.Additional Locations (1)
src/electronPlatform.js#L11-L13Reviewed by Cursor Bugbot for commit de42f02. Configure here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think if we introduce this toggle, then we also need to add to the docs that using native
netwill delegate tls concerns to chromium (I think). This may not work for everyone.I would also like to have a warning logged if there is a custom
tlsParamdefined and we are trying to usenet.