Skip to content

Commit 12a0741

Browse files
Merge branch 'fix_sdk_key_validation' into sdks-7437
2 parents 886a31c + bbad0a4 commit 12a0741

File tree

5 files changed

+77
-14
lines changed

5 files changed

+77
-14
lines changed

CHANGES.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
- Updated the following SDK manager methods to expose flag sets on flag views.
99
- Added `defaultTreatment` property to the `SplitView` object returned by the `split` and `splits` methods of the SDK manager (Related to issue https://github.com/splitio/javascript-commons/issues/225).
1010
- Updated @splitsoftware/splitio-commons package to version 1.11.0 that includes vulnerability fixes, and adds the `defaultTreatment` property to the `SplitView` object.
11+
- Bugfixing - Fixed SDK key validation in NodeJS to ensure the SDK_READY_TIMED_OUT event is emitted when a client-side type SDK key is provided instead of a server-side one (Related to issue https://github.com/splitio/javascript-client/issues/768).
1112

1213
10.23.1 (September 22, 2023)
1314
- Updated @splitsoftware/splitio-commons package to version 1.9.1. This update removes the handler for 'unload' DOM events, that can prevent browsers from being able to put pages in the back/forward cache for faster back and forward loads (Related to issue https://github.com/splitio/javascript-client/issues/759).

package-lock.json

Lines changed: 13 additions & 13 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
"node": ">=6"
4141
},
4242
"dependencies": {
43-
"@splitsoftware/splitio-commons": "1.10.1-rc.3",
43+
"@splitsoftware/splitio-commons": "1.10.1-rc.4",
4444
"@types/google.analytics": "0.0.40",
4545
"@types/ioredis": "^4.28.0",
4646
"bloom-filters": "^3.0.0",
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
import { SplitFactory } from '../../';
2+
3+
import splitChangesMock1 from '../mocks/splitchanges.since.-1.json';
4+
import splitChangesMock2 from '../mocks/splitchanges.since.1457552620999.json';
5+
6+
const readyTimeout = 0.1;
7+
8+
const baseConfig = {
9+
core: {
10+
authorizationKey: '<fake-token>',
11+
},
12+
startup: {
13+
readyTimeout,
14+
},
15+
streamingEnabled: false
16+
};
17+
18+
export default function (fetchMock, assert) {
19+
20+
assert.test(t => { // Timeout test: we provide a client-side SDK key on server-side (403 error)
21+
const testUrls = {
22+
sdk: 'https://sdk.baseurl/readinessSuite1',
23+
events: 'https://events.baseurl/readinessSuite1'
24+
};
25+
26+
fetchMock.getOnce(testUrls.sdk + '/splitChanges?since=-1', { status: 200, body: splitChangesMock1 });
27+
fetchMock.getOnce(testUrls.sdk + '/splitChanges?since=1457552620999', { status: 200, body: splitChangesMock2 });
28+
fetchMock.get(new RegExp(testUrls.sdk + '/segmentChanges/*'), 403);
29+
fetchMock.postOnce(testUrls.events + '/events/bulk', 200);
30+
31+
const splitio = SplitFactory({
32+
...baseConfig, urls: testUrls
33+
});
34+
const client = splitio.client();
35+
36+
t.true(client.track('some_key', 'some_tt', 'some_event_type'), 'since client is not destroyed, client.track returns true');
37+
38+
client.once(client.Event.SDK_READY, () => {
39+
t.fail('### IS READY - NOT TIMED OUT when it should.');
40+
t.end();
41+
});
42+
client.once(client.Event.SDK_READY_TIMED_OUT, async () => {
43+
t.pass('### SDK TIMED OUT - SegmentChanges requests with client-side SDK key should fail with 403. Timed out.');
44+
45+
t.false(client.track('some_key', 'some_tt', 'some_event_type'), 'since client is flagged as destroyed, client.track returns false');
46+
t.equal(client.getTreatment('hierarchical_splits_test'), 'control', 'since client is flagged as destroyed, client.getTreatment returns control');
47+
48+
// ready promise should reject
49+
try {
50+
await client.ready();
51+
} catch (e) {
52+
await client.destroy();
53+
t.end();
54+
}
55+
});
56+
});
57+
58+
}

src/__tests__/online/node.spec.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import expectedTreatmentsSuite from '../nodeSuites/expected-treatments.spec';
1414
import managerSuite from '../nodeSuites/manager.spec';
1515
import ipAddressesSetting from '../nodeSuites/ip-addresses-setting.spec';
1616
import ipAddressesSettingDebug from '../nodeSuites/ip-addresses-setting.debug.spec';
17+
import readinessSuite from '../nodeSuites/readiness.spec';
1718
import readyPromiseSuite from '../nodeSuites/ready-promise.spec';
1819
import { fetchSpecificSplits, fetchSpecificSplitsForFlagSets } from '../nodeSuites/fetch-specific-splits.spec';
1920

@@ -78,6 +79,9 @@ tape('## Node JS - E2E CI Tests ##', async function (assert) {
7879
assert.test('E2E / IP Addresses Setting', ipAddressesSetting.bind(null, fetchMock));
7980
assert.test('E2E / IP Addresses Setting Debug', ipAddressesSettingDebug.bind(null, fetchMock));
8081

82+
/* Validate readiness */
83+
assert.test('E2E / Readiness', readinessSuite.bind(null, fetchMock));
84+
8185
/* Validate readiness with ready promises */
8286
assert.test('E2E / Ready promise', readyPromiseSuite.bind(null, key, fetchMock));
8387

0 commit comments

Comments
 (0)