1
+ import * as base64 from 'js-base64' ;
1
2
import { times } from 'lodash' ;
2
3
import * as td from 'testdouble' ;
3
4
@@ -23,12 +24,15 @@ import { MemoryOnlyConfigurationStore } from '../configuration-store/memory.stor
23
24
import { MAX_EVENT_QUEUE_SIZE , DEFAULT_POLL_INTERVAL_MS , POLL_JITTER_PCT } from '../constants' ;
24
25
import { decodePrecomputedFlag } from '../decoding' ;
25
26
import { Flag , ObfuscatedFlag , VariationType } from '../interfaces' ;
26
- import { getMD5Hash , setSaltOverrideForTests } from '../obfuscation' ;
27
+ import { getMD5Hash } from '../obfuscation' ;
27
28
import { AttributeType } from '../types' ;
28
29
29
30
import EppoClient , { FlagConfigurationRequestParameters , checkTypeMatch } from './eppo-client' ;
30
31
import { initConfiguration } from './test-utils' ;
31
32
33
+ // Use a known salt to produce deterministic hashes
34
+ const salt = base64 . fromUint8Array ( new Uint8Array ( [ 7 , 53 , 17 , 78 ] ) ) ;
35
+
32
36
describe ( 'EppoClient E2E test' , ( ) => {
33
37
global . fetch = jest . fn ( ( ) => {
34
38
const ufc = readMockUFCResponse ( MOCK_UFC_RESPONSE_FILE ) ;
@@ -215,12 +219,8 @@ describe('EppoClient E2E test', () => {
215
219
client = new EppoClient ( { flagConfigurationStore : storage } ) ;
216
220
} ) ;
217
221
218
- afterEach ( ( ) => {
219
- setSaltOverrideForTests ( null ) ;
220
- } ) ;
221
-
222
222
it ( 'skips disabled flags' , ( ) => {
223
- const encodedPrecomputedWire = client . getPrecomputedConfiguration ( 'subject' , { } ) ;
223
+ const encodedPrecomputedWire = client . getPrecomputedConfiguration ( 'subject' , { } , { } , salt ) ;
224
224
const { precomputed } = JSON . parse ( encodedPrecomputedWire ) as IConfigurationWire ;
225
225
if ( ! precomputed ) {
226
226
fail ( 'Precomputed data not in Configuration response' ) ;
@@ -231,7 +231,6 @@ describe('EppoClient E2E test', () => {
231
231
232
232
expect ( precomputedResponse ) . toBeTruthy ( ) ;
233
233
const precomputedFlags = precomputedResponse ?. flags ?? { } ;
234
- const salt = precomputedResponse . salt ;
235
234
236
235
expect ( Object . keys ( precomputedFlags ) ) . toHaveLength ( 2 ) ;
237
236
expect ( Object . keys ( precomputedFlags ) ) . toContain ( getMD5Hash ( 'anotherFlag' , salt ) ) ;
@@ -240,15 +239,14 @@ describe('EppoClient E2E test', () => {
240
239
} ) ;
241
240
242
241
it ( 'evaluates and returns assignments' , ( ) => {
243
- const encodedPrecomputedWire = client . getPrecomputedConfiguration ( 'subject' , { } ) ;
242
+ const encodedPrecomputedWire = client . getPrecomputedConfiguration ( 'subject' , { } , { } , salt ) ;
244
243
const { precomputed } = JSON . parse ( encodedPrecomputedWire ) as IConfigurationWire ;
245
244
if ( ! precomputed ) {
246
245
fail ( 'Precomputed data not in Configuration response' ) ;
247
246
}
248
247
const precomputedResponse = JSON . parse (
249
248
precomputed . response ,
250
249
) as IObfuscatedPrecomputedConfigurationResponse ;
251
- const salt = precomputedResponse . salt ;
252
250
253
251
expect ( precomputedResponse ) . toBeTruthy ( ) ;
254
252
const precomputedFlags = precomputedResponse ?. flags ?? { } ;
@@ -259,10 +257,7 @@ describe('EppoClient E2E test', () => {
259
257
} ) ;
260
258
261
259
it ( 'obfuscates assignments' , ( ) => {
262
- // Use a known salt to produce deterministic hashes
263
- setSaltOverrideForTests ( new Uint8Array ( [ 7 , 53 , 17 , 78 ] ) ) ;
264
-
265
- const encodedPrecomputedWire = client . getPrecomputedConfiguration ( 'subject' , { } , { } ) ;
260
+ const encodedPrecomputedWire = client . getPrecomputedConfiguration ( 'subject' , { } , { } , salt ) ;
266
261
const { precomputed } = JSON . parse ( encodedPrecomputedWire ) as IConfigurationWire ;
267
262
if ( ! precomputed ) {
268
263
fail ( 'Precomputed data not in Configuration response' ) ;
0 commit comments