|
| 1 | +import { isGitHubUrl, isGitLabUrl } from "./isAllowedRepositoryHost"; |
| 2 | + |
| 3 | +describe("isGitHubUrl", () => { |
| 4 | + it("returns true for valid GitHub URL", () => { |
| 5 | + expect(isGitHubUrl("https://github.com/owner/repo")).toBe(true); |
| 6 | + }); |
| 7 | + |
| 8 | + it("returns true for GitHub URL with path", () => { |
| 9 | + expect(isGitHubUrl("https://github.com/owner/repo/tree/main")).toBe( |
| 10 | + true, |
| 11 | + ); |
| 12 | + }); |
| 13 | + |
| 14 | + it("returns false for GitLab URL", () => { |
| 15 | + expect(isGitHubUrl("https://gitlab.com/owner/repo")).toBe(false); |
| 16 | + }); |
| 17 | + |
| 18 | + it("rejects subdomain attack: github.com.evil.com", () => { |
| 19 | + expect(isGitHubUrl("https://github.com.evil.com/repo")).toBe(false); |
| 20 | + }); |
| 21 | + |
| 22 | + it("rejects subdomain attack: evil-github.com", () => { |
| 23 | + expect(isGitHubUrl("https://evil-github.com/repo")).toBe(false); |
| 24 | + }); |
| 25 | + |
| 26 | + it("rejects path injection: evil.com/github.com", () => { |
| 27 | + expect(isGitHubUrl("https://evil.com/github.com/repo")).toBe(false); |
| 28 | + }); |
| 29 | + |
| 30 | + it("rejects subdomain: api.github.com", () => { |
| 31 | + expect(isGitHubUrl("https://api.github.com/repo")).toBe(false); |
| 32 | + }); |
| 33 | + |
| 34 | + it("rejects HTTP (non-HTTPS)", () => { |
| 35 | + expect(isGitHubUrl("http://github.com/owner/repo")).toBe(false); |
| 36 | + }); |
| 37 | + |
| 38 | + it("rejects invalid URL", () => { |
| 39 | + expect(isGitHubUrl("not-a-url")).toBe(false); |
| 40 | + }); |
| 41 | +}); |
| 42 | + |
| 43 | +describe("isGitLabUrl", () => { |
| 44 | + it("returns true for valid GitLab URL", () => { |
| 45 | + expect(isGitLabUrl("https://gitlab.com/owner/repo")).toBe(true); |
| 46 | + }); |
| 47 | + |
| 48 | + it("returns true for GitLab URL with path", () => { |
| 49 | + expect(isGitLabUrl("https://gitlab.com/owner/repo/-/tree/main")).toBe( |
| 50 | + true, |
| 51 | + ); |
| 52 | + }); |
| 53 | + |
| 54 | + it("returns false for GitHub URL", () => { |
| 55 | + expect(isGitLabUrl("https://github.com/owner/repo")).toBe(false); |
| 56 | + }); |
| 57 | + |
| 58 | + it("rejects subdomain attack: gitlab.com.evil.com", () => { |
| 59 | + expect(isGitLabUrl("https://gitlab.com.evil.com/repo")).toBe(false); |
| 60 | + }); |
| 61 | + |
| 62 | + it("rejects HTTP (non-HTTPS)", () => { |
| 63 | + expect(isGitLabUrl("http://gitlab.com/owner/repo")).toBe(false); |
| 64 | + }); |
| 65 | + |
| 66 | + it("rejects invalid URL", () => { |
| 67 | + expect(isGitLabUrl("not-a-url")).toBe(false); |
| 68 | + }); |
| 69 | +}); |
0 commit comments