fix(core): Fix data decryption on credentials import (#7560)

Due to a change, during the credentials import command, the core's
Credential object is being called through its prototype. This caused the
Credential's cipher variable to not be set, thus no cipher service being
available during import. This fix catches this edge case and provides a
fix.
This commit is contained in:
Michael Auerswald
2023-10-31 13:15:09 +01:00
committed by GitHub
parent 774d521dbd
commit b350568505
4 changed files with 74 additions and 6 deletions

View File

@@ -0,0 +1,47 @@
import * as Config from '@oclif/config';
import { InternalHooks } from '@/InternalHooks';
import { ImportCredentialsCommand } from '@/commands/import/credentials';
import { LoadNodesAndCredentials } from '@/LoadNodesAndCredentials';
import * as testDb from '../shared/testDb';
import { mockInstance } from '../shared/utils';
beforeAll(async () => {
mockInstance(InternalHooks);
mockInstance(LoadNodesAndCredentials);
await testDb.init();
});
beforeEach(async () => {
await testDb.truncate(['Credentials']);
});
afterAll(async () => {
await testDb.terminate();
});
test('import:credentials should import a credential', async () => {
const config: Config.IConfig = new Config.Config({ root: __dirname });
const before = await testDb.getAllCredentials();
expect(before.length).toBe(0);
const importer = new ImportCredentialsCommand(
['--input=./test/integration/commands/importCredentials/credentials.json'],
config,
);
const mockExit = jest.spyOn(process, 'exit').mockImplementation(() => {
throw new Error('process.exit');
});
await importer.init();
try {
await importer.run();
} catch (error) {
expect(error.message).toBe('process.exit');
}
const after = await testDb.getAllCredentials();
expect(after.length).toBe(1);
expect(after[0].name).toBe('cred-aws-test');
expect(after[0].id).toBe('123');
expect(after[0].nodesAccess).toStrictEqual([]);
mockExit.mockRestore();
});

View File

@@ -0,0 +1,15 @@
[
{
"createdAt": "2023-07-10T14:50:49.193Z",
"updatedAt": "2023-10-27T13:34:42.917Z",
"id": "123",
"name": "cred-aws-test",
"data": {
"region": "eu-west-1",
"accessKeyId": "999999999999",
"secretAccessKey": "aaaaaaaaaaaaa"
},
"type": "aws",
"nodesAccess": ""
}
]