Skip to content

Commit d016104

Browse files
committed
Cred helpers: change logic to use pass if it works, else secret service
This follows the logic used by oras-go, which is used by helm. We have already tested the currentCredsStore above, so there is no point in trying it again. Signed-off-by: Mark Yen <[email protected]>
1 parent c645d8f commit d016104

File tree

2 files changed

+31
-7
lines changed

2 files changed

+31
-7
lines changed

pkg/rancher-desktop/utils/__tests__/dockerDirManager.spec.ts

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -435,17 +435,40 @@ describe('DockerDirManager', () => {
435435
});
436436

437437
it('should return the right cred helper for the right platform', async() => {
438+
jest.spyOn(subj as any, 'credHelperWorking').mockReturnValue(true);
438439
await expect(subj['getCredsStoreFor'](undefined)).resolves.toEqual(platformDefaultHelper);
439440
});
440441

441442
it('should return the platform helper if the existing one does not work', async() => {
442-
jest.spyOn(subj as any, 'credHelperWorking').mockResolvedValue(false);
443+
jest.spyOn<any, any, (_: string) => Promise<boolean>>(subj, 'credHelperWorking').mockImplementation((helperName) => {
444+
return Promise.resolve(os.platform() === 'linux' && helperName === 'pass');
445+
});
443446
await expect(subj['getCredsStoreFor']('broken-helper')).resolves.toEqual(platformDefaultHelper);
444447
});
445448

446-
itLinux('should return secretservice when that is the current value', async() => {
447-
jest.spyOn(subj as any, 'credHelperWorking').mockResolvedValue(false);
448-
await expect(subj['getCredsStoreFor']('secretservice')).resolves.toEqual('secretservice');
449+
itLinux('should default to pass when it works', async() => {
450+
jest.spyOn<any, any, (_: string) => Promise<boolean>>(subj, 'credHelperWorking').mockImplementation((helperName) => {
451+
expect(helperName).toEqual('pass');
452+
453+
return Promise.resolve(true);
454+
});
455+
await expect(subj['getCredsStoreFor'](undefined)).resolves.toEqual('pass');
456+
});
457+
458+
itLinux('should default to pass when secretservice is broken', async() => {
459+
jest.spyOn<any, any, (_: string) => Promise<boolean>>(subj, 'credHelperWorking').mockImplementation((helperName) => {
460+
return Promise.resolve(helperName === 'pass');
461+
});
462+
await expect(subj['getCredsStoreFor']('secretservice')).resolves.toEqual('pass');
463+
});
464+
465+
itLinux('should default to secretservice when pass does not work', async() => {
466+
jest.spyOn<any, any, (_: string) => Promise<boolean>>(subj, 'credHelperWorking').mockImplementation((helperName) => {
467+
expect(helperName).toEqual('pass');
468+
469+
return Promise.resolve(false);
470+
});
471+
await expect(subj['getCredsStoreFor'](undefined)).resolves.toEqual('secretservice');
449472
});
450473
});
451474
});

pkg/rancher-desktop/utils/dockerDirManager.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -283,11 +283,12 @@ export class DockerDirManager {
283283
} else if (platform === 'darwin') {
284284
return 'osxkeychain';
285285
} else if (platform === 'linux') {
286-
if (currentCredsStore === 'secretservice') {
287-
return 'secretservice';
288-
} else {
286+
// On Linux, we need to match the logic used by oras-go (used by helm):
287+
// If `pass` works, use it; otherwise use secret service.
288+
if (await this.credHelperWorking('pass')) {
289289
return 'pass';
290290
}
291+
return 'secretservice';
291292
} else {
292293
throw new Error(`platform "${ platform }" is not supported`);
293294
}

0 commit comments

Comments
 (0)