From 542e205f1c46ec0b1c42e32c8f5046a5b7871c90 Mon Sep 17 00:00:00 2001 From: Thorarinn Sigurdsson Date: Thu, 19 Dec 2019 12:00:42 +0000 Subject: [PATCH] fix(core): allow git URLs not ending in .git --- garden-service/package-lock.json | 5 ----- garden-service/package.json | 1 - garden-service/src/config/common.ts | 11 +++-------- garden-service/test/unit/src/config/common.ts | 14 ++++++++++++++ 4 files changed, 17 insertions(+), 14 deletions(-) diff --git a/garden-service/package-lock.json b/garden-service/package-lock.json index 86cad0327d..7b21eab49f 100644 --- a/garden-service/package-lock.json +++ b/garden-service/package-lock.json @@ -7206,11 +7206,6 @@ "resolved": "https://registry.npmjs.org/is-generator-function/-/is-generator-function-1.0.7.tgz", "integrity": "sha512-YZc5EwyO4f2kWCax7oegfuSr9mFz1ZvieNYBEjmukLxgXfBUbxAWGVF7GZf0zidYtoBl3WvC07YK0wT76a+Rtw==" }, - "is-git-url": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/is-git-url/-/is-git-url-1.0.0.tgz", - "integrity": "sha1-U/aEzRQyhbUsMkS05vKCU1J69ms=" - }, "is-glob": { "version": "4.0.1", "resolved": "https://registry.npmjs.org/is-glob/-/is-glob-4.0.1.tgz", diff --git a/garden-service/package.json b/garden-service/package.json index bba5c4d46a..c474fe6b80 100644 --- a/garden-service/package.json +++ b/garden-service/package.json @@ -68,7 +68,6 @@ "indent-string": "^4.0.0", "inquirer": "^7.0.1", "ip": "^1.1.5", - "is-git-url": "^1.0.0", "is-glob": "^4.0.1", "is-url": "^1.2.4", "js-yaml": "^3.13.1", diff --git a/garden-service/src/config/common.ts b/garden-service/src/config/common.ts index ab00c6ccef..2c698d66bc 100644 --- a/garden-service/src/config/common.ts +++ b/garden-service/src/config/common.ts @@ -8,7 +8,6 @@ import Joi from "@hapi/joi" import { splitLast } from "../util/util" -import isGitUrl from "is-git-url" import { deline, dedent } from "../util/string" export type Primitive = string | number | boolean | null @@ -209,16 +208,11 @@ joi = joi.extend({ requireHash: "{{#label}} must specify a branch/tag hash", }, validate(value: string, { error }) { - // Make sure it's a string - const baseSchema = Joi.string() + const baseSchema = joi.string().regex(gitUrlRegex) const result = baseSchema.validate(value) if (result.error) { - return { value, errors: result.error } - } - - if (!isGitUrl(value)) { - return { value, errors: error("gitUrl") } + return { value, errors: error("base") } } return { value } @@ -259,6 +253,7 @@ export const absolutePathRegex = /^\/.*/ // Note: Only checks for the leading sl export const identifierRegex = /^(?![0-9]+$)(?!.*-$)(?!-)[a-z0-9-]{1,63}$/ export const userIdentifierRegex = /^(?!garden)(?=.{1,63}$)[a-z][a-z0-9]*(-[a-z0-9]+)*$/ export const envVarRegex = /^(?!garden)[a-z_][a-z0-9_\.]*$/i +export const gitUrlRegex = /(?:git|ssh|https?|git@[-\w.]+):(\/\/)?(.*?)(\/?|\#[-\d\w._\/]+?)$/ export const joiIdentifierDescription = "valid RFC1035/RFC1123 (DNS) label (may contain lowercase letters, numbers and dashes, must start with a letter, " + diff --git a/garden-service/test/unit/src/config/common.ts b/garden-service/test/unit/src/config/common.ts index 5d06fa2a3e..02d139053d 100644 --- a/garden-service/test/unit/src/config/common.ts +++ b/garden-service/test/unit/src/config/common.ts @@ -269,6 +269,13 @@ describe("joiRepositoryUrl", () => { expect(result.error).to.be.undefined }) + it("should accept a git:// URL not ending in .git", () => { + const url = "git://github.com/garden-io/garden-example-remote-sources-web-services#my-tag" + const schema = joiRepositoryUrl() + const result = schema.validate(url) + expect(result.error).to.be.undefined + }) + it("should accept an HTTPS Git URL", () => { const url = "https://github.com/garden-io/garden-example-remote-sources-web-services.git#my-tag" const schema = joiRepositoryUrl() @@ -318,6 +325,13 @@ describe("joiRepositoryUrl", () => { expect(result.error).to.exist }) + it("should reject values missing a schema", () => { + const url = "garden-io/garden-example-remote-sources-web-services.git#my-tag" + const schema = joiRepositoryUrl() + const result = schema.validate(url) + expect(result.error).to.exist + }) + it("should require a branch/tag name", () => { const url = "https://github.com/garden-io/garden-example-remote-sources-web-services.git" const schema = joiRepositoryUrl()