mirror of https://github.com/rancher/dashboard.git
Merge pull request #13282 from torchiaf/11239-validate-git-repo-url
Fleet: validate GitRepo Url
This commit is contained in:
commit
29e4b82d8f
|
|
@ -6042,6 +6042,8 @@ validation:
|
|||
flowOutput:
|
||||
both: Requires "Output" or "Cluster Output" to be selected.
|
||||
global: Requires "Cluster Output" to be selected.
|
||||
git:
|
||||
repository: Repository URL must be a HTTP(s) or SSH url with no trailing spaces
|
||||
output:
|
||||
logdna:
|
||||
apiKey: Required an "Api Key" to be set.
|
||||
|
|
|
|||
|
|
@ -153,7 +153,13 @@ export default {
|
|||
stepRepoInfo,
|
||||
stepTargetInfo,
|
||||
displayHelmRepoURLRegex: false,
|
||||
fvFormRuleSets: [{ path: 'spec.repo', rules: ['required'] }]
|
||||
fvFormRuleSets: [{
|
||||
path: 'spec.repo',
|
||||
rules: [
|
||||
'required',
|
||||
'gitRepository'
|
||||
],
|
||||
}]
|
||||
};
|
||||
},
|
||||
|
||||
|
|
|
|||
|
|
@ -87,6 +87,45 @@ describe('formRules', () => {
|
|||
);
|
||||
});
|
||||
|
||||
describe('gitRepository', () => {
|
||||
const message = JSON.stringify({ message: 'validation.git.repository' });
|
||||
const testCases = [
|
||||
// Valid HTTP(s)
|
||||
['https://github.com/rancher/dashboard.git', undefined],
|
||||
['http://github.com/rancher/dashboard.git', undefined],
|
||||
['https://github.com/rancher/dashboard', undefined],
|
||||
['https://github.com/rancher/dashboard/', undefined],
|
||||
|
||||
// Valid SSH
|
||||
['git@github.com:rancher/dashboard.git', undefined],
|
||||
['git@github.com:rancher/dashboard', undefined],
|
||||
['git@github.com:rancher/dashboard/', undefined],
|
||||
|
||||
// Not valid HTTP(s)
|
||||
['https://github.com/rancher/ dashboard.git', message],
|
||||
['http://github.com/rancher/ dashboard.git', message],
|
||||
['https://github.com/rancher/dashboard ', message],
|
||||
['foo://github.com/rancher/dashboard/', message],
|
||||
['github.com/rancher/dashboard/', message],
|
||||
|
||||
// Not valid SSH
|
||||
['git@github.com:rancher/ dashboard.git', message],
|
||||
['git@github.com:rancher/dashboard ', message],
|
||||
['git@github.comrancher/dashboard', message],
|
||||
|
||||
[undefined, undefined]
|
||||
];
|
||||
|
||||
it.each(testCases)(
|
||||
'should return undefined or correct message based on the provided Git url: %p',
|
||||
(url, expected) => {
|
||||
const formRuleResult = formRules.gitRepository(url);
|
||||
|
||||
expect(formRuleResult).toStrictEqual(expected);
|
||||
}
|
||||
);
|
||||
});
|
||||
|
||||
describe('alphanumeric', () => {
|
||||
const message = JSON.stringify({ message: 'validation.alphanumeric', key: 'testDisplayKey' });
|
||||
const testCases = [
|
||||
|
|
|
|||
|
|
@ -157,6 +157,8 @@ export default function(t: Translation, { key = 'Value' }: ValidationOptions): {
|
|||
|
||||
const url: Validator = (val: string) => val && !isUrl(val) ? t('validation.setting.serverUrl.url') : undefined;
|
||||
|
||||
const gitRepository: Validator = (val: string) => val && !/^((http|git|ssh|http(s)|file|\/?)|(git@[\w\.]+))(:(\/\/)?)([\w\.@\:\/\-]+)([\d\/\w.-]+?)(.git){0,1}(\/)?$/gm.test(val) ? t('validation.git.repository') : undefined;
|
||||
|
||||
const alphanumeric: Validator = (val: string) => val && !/^[a-zA-Z0-9]+$/.test(val) ? t('validation.alphanumeric', { key }) : undefined;
|
||||
|
||||
const interval: Validator = (val: string) => !/^\d+[hms]$/.test(val) ? t('validation.monitoring.route.interval', { key }) : undefined;
|
||||
|
|
@ -486,6 +488,7 @@ export default function(t: Translation, { key = 'Value' }: ValidationOptions): {
|
|||
dnsLabelRestricted,
|
||||
externalName,
|
||||
fileRequired,
|
||||
gitRepository,
|
||||
groupsAreValid,
|
||||
hostname,
|
||||
imageUrl,
|
||||
|
|
|
|||
Loading…
Reference in New Issue