Skip to content

Commit 78c1f3c

Browse files
[CAE-342] Move password to serverArguments
1 parent 0aa00b8 commit 78c1f3c

File tree

4 files changed

+23
-17
lines changed

4 files changed

+23
-17
lines changed

packages/client/lib/sentinel/index.spec.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,13 @@ import { exec } from 'node:child_process';
1111
const execAsync = promisify(exec);
1212

1313
[GLOBAL.SENTINEL.OPEN, GLOBAL.SENTINEL.PASSWORD].forEach(testOptions => {
14-
describe(`test with password - ${testOptions.password}`, () => {
14+
const passIndex = testOptions.serverArguments.indexOf('--requirepass')+1;
15+
let password: string | undefined = undefined;
16+
if (passIndex != 0) {
17+
password = testOptions.serverArguments[passIndex];
18+
}
19+
20+
describe(`test with password - ${password}`, () => {
1521
testUtils.testWithClientSentinel('client should be authenticated', async sentinel => {
1622
await assert.doesNotReject(sentinel.set('x', 1));
1723
}, testOptions);

packages/client/lib/test-utils.ts

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -130,45 +130,37 @@ export const GLOBAL = {
130130
SENTINEL: {
131131
OPEN: {
132132
serverArguments: [...DEBUG_MODE_ARGS],
133-
password: undefined,
134133
},
135134
PASSWORD: {
136-
serverArguments: [...DEBUG_MODE_ARGS],
137-
password: 'test_password',
135+
serverArguments: ['--requirepass', 'test_password', ...DEBUG_MODE_ARGS],
138136
},
139137
WITH_SCRIPT: {
140138
serverArguments: [...DEBUG_MODE_ARGS],
141-
password: undefined,
142139
scripts: {
143140
square: SQUARE_SCRIPT,
144141
},
145142
},
146143
WITH_FUNCTION: {
147144
serverArguments: [...DEBUG_MODE_ARGS],
148-
password: undefined,
149145
functions: {
150146
math: MATH_FUNCTION.library,
151147
},
152148
},
153149
WITH_MODULE: {
154150
serverArguments: [...DEBUG_MODE_ARGS],
155-
password: undefined,
156151
modules: RedisBloomModules,
157152
},
158153
WITH_REPLICA_POOL_SIZE_1: {
159154
serverArguments: [...DEBUG_MODE_ARGS],
160-
password: undefined,
161155
replicaPoolSize: 1,
162156
},
163157
WITH_RESERVE_CLIENT_MASTER_POOL_SIZE_2: {
164158
serverArguments: [...DEBUG_MODE_ARGS],
165-
password: undefined,
166159
masterPoolSize: 2,
167160
reserveClient: true,
168161
},
169162
WITH_MASTER_POOL_SIZE_2: {
170163
serverArguments: [...DEBUG_MODE_ARGS],
171-
password: undefined,
172164
masterPoolSize: 2,
173165
}
174166
}

packages/test-utils/lib/dockers.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,6 @@ const RUNNING_SENTINELS = new Map<Array<string>, Array<RedisServerDocker>>();
333333
export async function spawnRedisSentinel(
334334
dockerConfigs: RedisServerDockerOptions,
335335
serverArguments: Array<string>,
336-
password?: string,
337336
): Promise<Array<RedisServerDocker>> {
338337
const runningNodes = RUNNING_SENTINELS.get(serverArguments);
339338
if (runningNodes) {
@@ -344,9 +343,14 @@ export async function spawnRedisSentinel(
344343
dockerConfigs.env = new Map();
345344
}
346345

346+
const passIndex = serverArguments.indexOf('--requirepass')+1;
347+
let password: string | undefined = undefined;
348+
if (passIndex != 0) {
349+
password = serverArguments[passIndex];
350+
}
351+
347352
if (password !== undefined) {
348353
dockerConfigs.env.set("REDIS_PASSWORD", password);
349-
serverArguments.push("--requirepass", password)
350354
}
351355

352356
const master = await spawnRedisServerDocker(dockerConfigs, serverArguments);

packages/test-utils/lib/index.ts

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,6 @@ interface SentinelTestOptions<
8484
scripts?: S;
8585
functions?: F;
8686
modules?: M;
87-
password?: string;
8887
disableClientSetup?: boolean;
8988
replicaPoolSize?: number;
9089
masterPoolSize?: number;
@@ -310,12 +309,17 @@ export default class TestUtils {
310309
): void {
311310
let dockerPromises: ReturnType<typeof spawnRedisSentinel>;
312311

312+
const passIndex = options.serverArguments.indexOf('--requirepass')+1;
313+
let password: string | undefined = undefined;
314+
if (passIndex != 0) {
315+
password = options.serverArguments[passIndex];
316+
}
317+
313318
if (this.isVersionGreaterThan(options.minimumDockerVersion)) {
314319
const dockerImage = this.#DOCKER_IMAGE;
315320
before(function () {
316321
this.timeout(30000);
317-
318-
dockerPromises = spawnRedisSentinel(dockerImage, options.serverArguments, options?.password);
322+
dockerPromises = spawnRedisSentinel(dockerImage, options.serverArguments);
319323
return dockerPromises;
320324
});
321325
}
@@ -336,10 +340,10 @@ export default class TestUtils {
336340
name: 'mymaster',
337341
sentinelRootNodes: rootNodes,
338342
nodeClientOptions: {
339-
password: options?.password || undefined,
343+
password: password || undefined,
340344
},
341345
sentinelClientOptions: {
342-
password: options?.password || undefined,
346+
password: password || undefined,
343347
},
344348
replicaPoolSize: options?.replicaPoolSize || 0,
345349
scripts: options?.scripts || {},

0 commit comments

Comments
 (0)