fix(editor): Allow $secrets to resolve on credentials (#10093)

This commit is contained in:
Iván Ovejero 2024-07-19 12:00:07 +02:00 committed by GitHub
parent dd54390b0a
commit bf57f38d1c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 43 additions and 3 deletions

View file

@ -7,7 +7,7 @@
[$style.highlight]: highlight,
}"
>
<span v-html="simplyText"></span>
<span data-test-id="parameter-input-hint" v-html="simplyText"></span>
</div>
<div
v-else

View file

@ -0,0 +1,39 @@
import { renderComponent } from '@/__tests__/render';
import { createTestingPinia } from '@pinia/testing';
import ParameterInputWrapper from './ParameterInputWrapper.vue';
describe('ParameterInputWrapper.vue', () => {
test('should resolve expression', async () => {
const { getByTestId } = renderComponent(ParameterInputWrapper, {
pinia: createTestingPinia({
initialState: {
ndv: {
activeNodeName: 'testNode',
input: { nodeName: 'inputNode' },
},
},
}),
props: {
parameter: {
name: 'test',
type: 'string',
},
path: 'params.test',
modelValue: '={{ $secrets.infisical.password }}',
isForCredential: true,
},
global: {
mocks: {
$workflowHelpers: {
resolveExpression: vi.fn(() => 'topSecret'),
},
$ndvStore: {
activeNode: vi.fn(() => ({ test: 'test' })),
},
},
},
});
expect(getByTestId('parameter-input-hint')).toHaveTextContent('[ERROR: ]');
});
});

View file

@ -177,6 +177,8 @@ const evaluatedExpression = computed<Result<unknown, Error>>(() => {
};
}
if (props.isForCredential) opts.additionalKeys = resolvedAdditionalExpressionData.value;
return { ok: true, result: workflowHelpers.resolveExpression(value, undefined, opts) };
} catch (error) {
return { ok: false, error };

View file

@ -293,14 +293,13 @@ export const useExpressionEditor = ({
// e.g. credential modal
result.resolved = Expression.resolveWithoutWorkflow(resolvable, toValue(additionalData));
} else {
let opts;
let opts: Record<string, unknown> = { additionalKeys: toValue(additionalData) };
if (ndvStore.isInputParentOfActiveNode) {
opts = {
targetItem: target ?? undefined,
inputNodeName: ndvStore.ndvInputNodeName,
inputRunIndex: ndvStore.ndvInputRunIndex,
inputBranchIndex: ndvStore.ndvInputBranchIndex,
additionalKeys: toValue(additionalData),
};
}
result.resolved = workflowHelpers.resolveExpression('=' + resolvable, undefined, opts);