mirror of
https://github.com/caprover/caprover
synced 2025-10-30 10:07:01 +00:00
Enhance SSH_PATH_RE on GitHelper to improve URL parsing
This commit is contained in:
@@ -24,11 +24,19 @@ test('Testing - sanitizeRepoPathSsh', () => {
|
||||
).toBe('ssh://git@github.com:22/username/repository.git')
|
||||
})
|
||||
|
||||
test('Testing - sanitizeRepoPathSsh', () => {
|
||||
expect(
|
||||
GitHelper.sanitizeRepoPathSsh(' git@gitlab.com/test1/test2/test3.git')
|
||||
.repoPath
|
||||
).toBe('ssh://git@gitlab.com:22/test1/test2/test3.git')
|
||||
test('Testing - sanitizeRepoPathSsh - with extra path components', () => {
|
||||
const sanitized = GitHelper.sanitizeRepoPathSsh(
|
||||
' git@gitlab.com/test1/test2/test3.git'
|
||||
);
|
||||
expect(sanitized).toEqual({
|
||||
domain: "gitlab.com",
|
||||
owner: "test1",
|
||||
port: 22,
|
||||
repo: "test2/test3",
|
||||
repoPath: "ssh://git@gitlab.com:22/test1/test2/test3.git",
|
||||
suffix: ".git",
|
||||
user: "git",
|
||||
})
|
||||
})
|
||||
|
||||
test('Testing - sanitizeRepoPathSsh - port', () => {
|
||||
@@ -40,11 +48,18 @@ test('Testing - sanitizeRepoPathSsh - port', () => {
|
||||
})
|
||||
|
||||
test('Testing - sanitizeRepoPathSsh - custom port', () => {
|
||||
expect(
|
||||
GitHelper.sanitizeRepoPathSsh(
|
||||
' git@github.com:1234/username/repository.git/ '
|
||||
).port
|
||||
).toBe(1234)
|
||||
const sanitized = GitHelper.sanitizeRepoPathSsh(
|
||||
' git@github.com:1234/username/repository.git/ '
|
||||
)
|
||||
expect(sanitized).toEqual({
|
||||
user: "git",
|
||||
domain: "github.com",
|
||||
owner: "username",
|
||||
port: 1234,
|
||||
repo: "repository",
|
||||
suffix: ".git",
|
||||
repoPath: "ssh://git@github.com:1234/username/repository.git",
|
||||
})
|
||||
})
|
||||
|
||||
test('Testing - sanitizeRepoPathSsh from HTTPS', () => {
|
||||
@@ -58,7 +73,7 @@ test('Testing - sanitizeRepoPathSsh from HTTPS', () => {
|
||||
test('Testing - sanitizeRepoPathSsh - name with dot', () => {
|
||||
expect(
|
||||
GitHelper.sanitizeRepoPathSsh(' github.com/owner/site.com ').repoPath
|
||||
).toBe('ssh://git@github.com:22/owner/site.com.git')
|
||||
).toBe('ssh://git@github.com:22/owner/site.com')
|
||||
})
|
||||
|
||||
test('Testing - sanitizeRepoPathSsh - name with dot and git suffix', () => {
|
||||
@@ -72,7 +87,7 @@ test('Testing - sanitizeRepoPathSsh - name containing ".git"', () => {
|
||||
expect(
|
||||
GitHelper.sanitizeRepoPathSsh(' github.com/owner/repo.github ')
|
||||
.repoPath
|
||||
).toBe('ssh://git@github.com:22/owner/repo.github.git')
|
||||
).toBe('ssh://git@github.com:22/owner/repo.github')
|
||||
})
|
||||
|
||||
test('Testing - sanitizeRepoPathSsh - name containing ".git" and git suffix', () => {
|
||||
@@ -92,7 +107,7 @@ test('Testing - sanitizeRepoPathSsh - name containing ".git", git suffix and /'
|
||||
test('Testing - sanitizeRepoPathSsh - not git suffix', () => {
|
||||
expect(
|
||||
GitHelper.sanitizeRepoPathSsh(' github.com/owner/repository ').repoPath
|
||||
).toBe('ssh://git@github.com:22/owner/repository.git')
|
||||
).toBe('ssh://git@github.com:22/owner/repository')
|
||||
})
|
||||
|
||||
test('Testing - sanitizeRepoPathSsh - alt domain', () => {
|
||||
@@ -125,6 +140,51 @@ test('Testing - sanitizeRepoPathSsh - no owner', () => {
|
||||
).toBe('ssh://git@github.com:22/repository.git')
|
||||
})
|
||||
|
||||
test('Testing - sanitizeRepoPathSsh - with extra path components separated by column', () => {
|
||||
const sanitized = GitHelper.sanitizeRepoPathSsh(
|
||||
' git@ssh.dev.azure.com:v3/myOrg/My%20Project%20Name/my-repo-name '
|
||||
)
|
||||
expect(sanitized).toEqual({
|
||||
user: 'git',
|
||||
domain: 'ssh.dev.azure.com',
|
||||
port: 22,
|
||||
owner: 'v3',
|
||||
repo: "myOrg/My%20Project%20Name/my-repo-name",
|
||||
repoPath: "ssh://git@ssh.dev.azure.com:22/v3/myOrg/My%20Project%20Name/my-repo-name",
|
||||
suffix: "",
|
||||
})
|
||||
})
|
||||
|
||||
test('Testing - sanitizeRepoPathSsh - with extra path components and port separated by column', () => {
|
||||
const sanitized = GitHelper.sanitizeRepoPathSsh(
|
||||
' git@ssh.dev.azure.com:422:v3/myOrg/My%20Project%20Name/my-repo-name '
|
||||
)
|
||||
expect(sanitized).toEqual({
|
||||
user: "git",
|
||||
domain: 'ssh.dev.azure.com',
|
||||
owner: "v3",
|
||||
port: 422,
|
||||
repo: "myOrg/My%20Project%20Name/my-repo-name",
|
||||
repoPath: "ssh://git@ssh.dev.azure.com:422/v3/myOrg/My%20Project%20Name/my-repo-name",
|
||||
suffix: "",
|
||||
})
|
||||
})
|
||||
|
||||
test('Testing - sanitizeRepoPathSsh - with extra path components and "owner" instead of "git" user', () => {
|
||||
const sanitized = GitHelper.sanitizeRepoPathSsh(
|
||||
' myOrg@vs-ssh.visualstudio.com:v3/myOrg/My%20Project%20Name/my-repo-name '
|
||||
)
|
||||
expect(sanitized).toEqual({
|
||||
user: 'myOrg',
|
||||
domain: 'vs-ssh.visualstudio.com',
|
||||
port: 22,
|
||||
owner: "v3",
|
||||
repo: "myOrg/My%20Project%20Name/my-repo-name",
|
||||
repoPath: "ssh://myOrg@vs-ssh.visualstudio.com:22/v3/myOrg/My%20Project%20Name/my-repo-name",
|
||||
suffix: "",
|
||||
})
|
||||
})
|
||||
|
||||
test('Testing - getDomainFromSanitizedSshRepoPath - pure', () => {
|
||||
expect(
|
||||
GitHelper.getDomainFromSanitizedSshRepoPath(
|
||||
@@ -160,3 +220,23 @@ test('Testing - getDomainFromSanitizedSshRepoPath - alt domain', () => {
|
||||
)
|
||||
).toBe('some.other-domain.com')
|
||||
})
|
||||
|
||||
test('Testing - getDomainFromSanitizedSshRepoPath - with extra path components separated by column', () => {
|
||||
expect(
|
||||
GitHelper.getDomainFromSanitizedSshRepoPath(
|
||||
GitHelper.sanitizeRepoPathSsh(
|
||||
' git@ssh.dev.azure.com:422:v3/myOrg/My%20Project%20Name/my-repo-name '
|
||||
).repoPath
|
||||
)
|
||||
).toBe('ssh.dev.azure.com')
|
||||
})
|
||||
|
||||
test('Testing - getDomainFromSanitizedSshRepoPath - with extra path components separated by column and "owner" instead of "git" user', () => {
|
||||
expect(
|
||||
GitHelper.getDomainFromSanitizedSshRepoPath(
|
||||
GitHelper.sanitizeRepoPathSsh(
|
||||
' myOrg@vs-ssh.visualstudio.com:v3/myOrg/My%20Project%20Name/my-repo-name '
|
||||
).repoPath
|
||||
)
|
||||
).toBe('vs-ssh.visualstudio.com')
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user