mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-19 19:11:13 +00:00
fix(core): Prevent mutation of credential type parents (#16841)
This commit is contained in:
@@ -117,5 +117,26 @@ describe('CredentialTypes', () => {
|
|||||||
|
|
||||||
expect(credentialTypes.getParentTypes('unknownCredential')).toBeEmptyArray();
|
expect(credentialTypes.getParentTypes('unknownCredential')).toBeEmptyArray();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('Should not mutate the original extends array', () => {
|
||||||
|
const knownCredentials = {
|
||||||
|
childType: { extends: ['parentType'] },
|
||||||
|
parentType: { extends: ['grandparentType'] },
|
||||||
|
grandparentType: { extends: [] },
|
||||||
|
};
|
||||||
|
|
||||||
|
const credentialTypes = new CredentialTypes(
|
||||||
|
mock<LoadNodesAndCredentials>({ knownCredentials }),
|
||||||
|
);
|
||||||
|
|
||||||
|
const originalExtends = knownCredentials.childType.extends;
|
||||||
|
const originalLength = originalExtends.length;
|
||||||
|
|
||||||
|
credentialTypes.getParentTypes('childType');
|
||||||
|
credentialTypes.getParentTypes('childType');
|
||||||
|
credentialTypes.getParentTypes('childType');
|
||||||
|
|
||||||
|
expect(originalExtends).toHaveLength(originalLength);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -25,11 +25,15 @@ export class CredentialTypes implements ICredentialTypes {
|
|||||||
*/
|
*/
|
||||||
getParentTypes(typeName: string): string[] {
|
getParentTypes(typeName: string): string[] {
|
||||||
const extendsArr = this.loadNodesAndCredentials.knownCredentials[typeName]?.extends ?? [];
|
const extendsArr = this.loadNodesAndCredentials.knownCredentials[typeName]?.extends ?? [];
|
||||||
if (extendsArr.length) {
|
|
||||||
extendsArr.forEach((type) => {
|
if (extendsArr.length === 0) return [];
|
||||||
extendsArr.push(...this.getParentTypes(type));
|
|
||||||
});
|
const extendsArrCopy = [...extendsArr];
|
||||||
|
|
||||||
|
for (const type of extendsArrCopy) {
|
||||||
|
extendsArrCopy.push(...this.getParentTypes(type));
|
||||||
}
|
}
|
||||||
return extendsArr;
|
|
||||||
|
return extendsArrCopy;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user