-
Notifications
You must be signed in to change notification settings - Fork 184
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
NONE: small fixes of connect screen (#1600)
* NONE: fixing timeout and status code messages * NONE: improve URL validator * NONE: add more debug info for GHE connect page backend * NONE: refactor GHE connect page backend validation * NONE: frontend fixes * NONE: add error handling to jira-server-url; use hostname for checks * NONE: PR comments
- Loading branch information
Showing
9 changed files
with
235 additions
and
127 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import { validateUrl } from "utils/validate-url"; | ||
|
||
describe("validateUrl", () => { | ||
it("should return VALID for valid URLs", async () => { | ||
expect(validateUrl("http://myvalidurl.com").isValidUrl).toBeTruthy(); | ||
expect(validateUrl("https://myvalidurl.net").isValidUrl).toBeTruthy(); | ||
expect(validateUrl("https://192.213.23.12/branch/mypage").isValidUrl).toBeTruthy(); | ||
expect(validateUrl("https://192.213.23.12:8080/branch/mypage").isValidUrl).toBeTruthy(); | ||
}); | ||
|
||
it("should return INVALID for unsupported protocol", async () => { | ||
expect(validateUrl("accd://thatsnotavalidprotocol")).toEqual({ | ||
isValidUrl: false, | ||
reason: "unsupported protocol, only HTTP and HTTPS are allowed" | ||
}); | ||
}); | ||
|
||
it("should return INVALID for corrupted URL", () => { | ||
expect(validateUrl("thisaintaurlatall")).toEqual({ | ||
isValidUrl: false | ||
}); | ||
expect(validateUrl("www.wheresmyprotocol.com")).toEqual({ | ||
isValidUrl: false | ||
}); | ||
}); | ||
|
||
it("should return INVALID invalid port", () => { | ||
expect(validateUrl("http://foo.com:12345")).toEqual({ | ||
isValidUrl: false, | ||
reason: "only the following ports are allowed: 80, 8080, 443, 6017, 8443, 8444, 7990, 8090, 8085, 8060, 8900, 9900" | ||
}); | ||
}); | ||
|
||
it("should return INVALID if url has query parameters", async () => { | ||
expect(validateUrl("https://192.213.23.12/branch/mypage/?foo=bar")).toEqual({ | ||
isValidUrl: false, | ||
reason: "query parameters are not allowed" | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
interface UrlValidationResult { | ||
isValidUrl: boolean, | ||
reason?: string | ||
} | ||
|
||
// See https://stash.atlassian.com/projects/EDGE/repos/edge-proxies/browse/sceptre/data/squid_outbound-proxy.conf.jinja2#43 | ||
const ALLOWED_PORTS = [80, 8080, 443, 6017, 8443, 8444, 7990, 8090, 8085, 8060, 8900, 9900]; | ||
|
||
export const validateUrl = (url: string): UrlValidationResult => { | ||
try { | ||
const { protocol, port } = new URL(url); | ||
if (port && !ALLOWED_PORTS.includes(parseInt(port))) { | ||
return { | ||
isValidUrl: false, | ||
reason: "only the following ports are allowed: " + ALLOWED_PORTS.join(", ") | ||
}; | ||
} | ||
if (!(/^https?:$/.test(protocol))) { | ||
return { | ||
isValidUrl: false, | ||
reason: "unsupported protocol, only HTTP and HTTPS are allowed" | ||
}; | ||
} | ||
if (url.includes("?")) { | ||
return { | ||
isValidUrl: false, | ||
reason: "query parameters are not allowed" | ||
}; | ||
} | ||
} catch (err) { | ||
return { | ||
isValidUrl: false | ||
}; | ||
} | ||
return { | ||
isValidUrl: true | ||
}; | ||
}; |
Oops, something went wrong.