Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ const isWindowsWildcardPathValid = (path: string): boolean => {
trimmedValue.length !== path.length ||
firstCharacter === '^' ||
lastCharacter === '\\' ||
!hasWildcard({ path, isWindowsPath: true })
!hasWildcardInPath({ path, isWindowsPath: true })
) {
return false;
} else {
Expand All @@ -219,15 +219,15 @@ const isLinuxMacWildcardPathValid = (path: string): boolean => {
lastCharacter === '/' ||
path.length > 1024 === true ||
path.includes('//') === true ||
!hasWildcard({ path, isWindowsPath: false })
!hasWildcardInPath({ path, isWindowsPath: false })
) {
return false;
} else {
return true;
}
};

const hasWildcard = ({
const hasWildcardInPath = ({
path,
isWindowsPath,
}: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -313,29 +313,63 @@ describe('Trusted apps form', () => {
expect(getConditionValue(getCondition()).required).toEqual(true);
});

it('should show path malformed warning', () => {
render();
expect(screen.queryByText(INPUT_ERRORS.pathWarning(0))).toBeNull();
describe('IS operator', () => {
it('should show path malformed warning', () => {
render();
expect(screen.queryByText(INPUT_ERRORS.pathWarning(0))).toBeNull();

const propsItem: Partial<ArtifactFormComponentProps['item']> = {
entries: [createEntry(ConditionEntryField.PATH, 'match', 'malformed-path')],
};
formProps.item = { ...formProps.item, ...propsItem };
render();
expect(screen.getByText(INPUT_ERRORS.pathWarning(0))).not.toBeNull();
});

const propsItem: Partial<ArtifactFormComponentProps['item']> = {
entries: [createEntry(ConditionEntryField.PATH, 'match', 'malformed-path')],
};
formProps.item = { ...formProps.item, ...propsItem };
render();
expect(screen.getByText(INPUT_ERRORS.pathWarning(0))).not.toBeNull();
it('should show path malformed path warning for linux/mac without an executable name', () => {
render();
expect(screen.queryByText(INPUT_ERRORS.pathWarning(0))).toBeNull();
expect(screen.queryByText(INPUT_ERRORS.wildcardPathWarning(0))).toBeNull();

const propsItem: Partial<ArtifactFormComponentProps['item']> = {
os_types: [OperatingSystem.LINUX],
entries: [createEntry(ConditionEntryField.PATH, 'match', '/')],
};
formProps.item = { ...formProps.item, ...propsItem };
render();
expect(screen.getByText(INPUT_ERRORS.pathWarning(0))).not.toBeNull();
expect(screen.queryByText(INPUT_ERRORS.wildcardPathWarning(0))).toBeNull();
});

it('should show path malformed path warning for windows with no executable name', () => {
render();
expect(screen.queryByText(INPUT_ERRORS.pathWarning(0))).toBeNull();
expect(screen.queryByText(INPUT_ERRORS.wildcardPathWarning(0))).toBeNull();

const propsItem: Partial<ArtifactFormComponentProps['item']> = {
os_types: [OperatingSystem.WINDOWS],
entries: [createEntry(ConditionEntryField.PATH, 'match', 'c:\\fold\\')],
};
formProps.item = { ...formProps.item, ...propsItem };
render();
expect(screen.getByText(INPUT_ERRORS.pathWarning(0))).not.toBeNull();
expect(screen.queryByText(INPUT_ERRORS.wildcardPathWarning(0))).toBeNull();
});
});

it('should show wildcard in path warning', () => {
render();
expect(screen.queryByText(INPUT_ERRORS.wildcardPathWarning(0))).toBeNull();
describe('MATCHES operator', () => {
it('should show wildcard in path warning', () => {
render();
expect(screen.queryByText(INPUT_ERRORS.wildcardPathWarning(0))).toBeNull();

const propsItem: Partial<ArtifactFormComponentProps['item']> = {
os_types: [OperatingSystem.LINUX],
entries: [createEntry(ConditionEntryField.PATH, 'wildcard', '/sys/wil*/*.app')],
};
formProps.item = { ...formProps.item, ...propsItem };
render();
expect(screen.getByText(INPUT_ERRORS.wildcardPathWarning(0))).not.toBeNull();
const propsItem: Partial<ArtifactFormComponentProps['item']> = {
os_types: [OperatingSystem.LINUX],
entries: [createEntry(ConditionEntryField.PATH, 'wildcard', '/sys/wil*/*.app')],
};
formProps.item = { ...formProps.item, ...propsItem };
render();
expect(screen.getByText(INPUT_ERRORS.wildcardPathWarning(0))).not.toBeNull();
});
});

it('should display the `AND` button', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -200,12 +200,16 @@ const validateValues = (values: ArtifactFormComponentProps['item']): ValidationR
type: entry.type as EntryTypes,
})
) {
addResultToValidation(
validation,
'entries',
'warnings',
INPUT_ERRORS.wildcardPathWarning(index)
);
if (entry.type === 'wildcard') {
addResultToValidation(
validation,
'entries',
'warnings',
INPUT_ERRORS.wildcardPathWarning(index)
);
} else {
addResultToValidation(validation, 'entries', 'warnings', INPUT_ERRORS.pathWarning(index));
}
}
});
}
Expand Down