From 3fb4d0750b55238158b57ddbc47ef72e2a436808 Mon Sep 17 00:00:00 2001 From: alecmerdler Date: Wed, 24 May 2017 15:12:17 -0700 Subject: [PATCH] fixed build_source validation in custom git trigger --- .../manage-trigger.component.spec.ts | 17 +++++++++++++++++ .../manage-trigger/manage-trigger.component.ts | 3 ++- 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/static/js/directives/ui/manage-trigger/manage-trigger.component.spec.ts b/static/js/directives/ui/manage-trigger/manage-trigger.component.spec.ts index 0c7ea80b6..90154357e 100644 --- a/static/js/directives/ui/manage-trigger/manage-trigger.component.spec.ts +++ b/static/js/directives/ui/manage-trigger/manage-trigger.component.spec.ts @@ -47,6 +47,23 @@ describe("ManageTriggerComponent", () => { }); }); + describe("checkBuildSource", () => { + + it("sets selected repository full name if given build source matches regex pattern", () => { + const buildSource: string = "git@somegithost.net:user/repo.git"; + component.checkBuildSource(buildSource); + + expect(component.local.selectedRepository.full_name).toEqual(buildSource); + }); + + it("sets selected repository full name to null if given build source does not match regex pattern", () => { + const buildSource: string = "a_randomstring"; + component.checkBuildSource(buildSource); + + expect(component.local.selectedRepository.full_name).toBe(null); + }); + }); + describe("getTriggerIcon", () => { beforeEach(() => { diff --git a/static/js/directives/ui/manage-trigger/manage-trigger.component.ts b/static/js/directives/ui/manage-trigger/manage-trigger.component.ts index 08ebf93f2..9e7ca9629 100644 --- a/static/js/directives/ui/manage-trigger/manage-trigger.component.ts +++ b/static/js/directives/ui/manage-trigger/manage-trigger.component.ts @@ -70,8 +70,9 @@ export class ManageTriggerComponent implements OnInit { } public checkBuildSource(buildSource: string): void { + const buildSourceRegExp = new RegExp(/(((http|https):\/\/)(.+)|\w+@(.+):(.+))/, 'i'); try { - this.local.selectedRepository.full_name = buildSource.split(':')[1].replace('.git', ''); + this.local.selectedRepository.full_name = buildSourceRegExp.test(buildSource) ? buildSource : null; } catch (error) { this.local.selectedRepository.full_name = null; }