Skip to content

Commit

Permalink
feat: add additional git authentication rules (#13477)
Browse files Browse the repository at this point in the history
* feat: add additional git authentication rules

* feat: refactor and add additional test cases

* fix: add git envs to gomod tests

* chore: revert function renaming

* chore: use interface instead of type

* chore: add test for different protocol

* chore: add typed import

* fix: do not use quotes, it breaks the docker sidecar

* chore: use correct quotes

* chore: incorporate feedback

* chore: lint files

Co-authored-by: Michael Kriese <michael.kriese@visualon.de>
Co-authored-by: Rhys Arkins <rhys@arkins.net>
  • Loading branch information
3 people committed Feb 5, 2022
1 parent ead221d commit 2eadd19
Show file tree
Hide file tree
Showing 5 changed files with 345 additions and 69 deletions.
12 changes: 8 additions & 4 deletions lib/manager/gomod/__snapshots__/artifacts.spec.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -279,15 +279,19 @@ Array [
},
},
Object {
"cmd": "docker run --rm --name=renovate_go --label=renovate_child -v \\"/tmp/github/some/repo\\":\\"/tmp/github/some/repo\\" -v \\"/tmp/renovate/cache\\":\\"/tmp/renovate/cache\\" -e GOPROXY -e GOPRIVATE -e GONOPROXY -e GONOSUMDB -e GOFLAGS -e CGO_ENABLED -e GIT_CONFIG_KEY_0 -e GIT_CONFIG_VALUE_0 -e GIT_CONFIG_COUNT -w \\"/tmp/github/some/repo\\" renovate/go:latest bash -l -c \\"go get -d -t ./...\\"",
"cmd": "docker run --rm --name=renovate_go --label=renovate_child -v \\"/tmp/github/some/repo\\":\\"/tmp/github/some/repo\\" -v \\"/tmp/renovate/cache\\":\\"/tmp/renovate/cache\\" -e GOPROXY -e GOPRIVATE -e GONOPROXY -e GONOSUMDB -e GOFLAGS -e CGO_ENABLED -e GIT_CONFIG_KEY_0 -e GIT_CONFIG_VALUE_0 -e GIT_CONFIG_KEY_1 -e GIT_CONFIG_VALUE_1 -e GIT_CONFIG_KEY_2 -e GIT_CONFIG_VALUE_2 -e GIT_CONFIG_COUNT -w \\"/tmp/github/some/repo\\" renovate/go:latest bash -l -c \\"go get -d -t ./...\\"",
"options": Object {
"cwd": "/tmp/github/some/repo",
"encoding": "utf-8",
"env": Object {
"CGO_ENABLED": "1",
"GIT_CONFIG_COUNT": "1",
"GIT_CONFIG_KEY_0": "url.https://some-token@github.com/.insteadOf",
"GIT_CONFIG_VALUE_0": "https://github.com/",
"GIT_CONFIG_COUNT": "3",
"GIT_CONFIG_KEY_0": "url.\\"https://ssh:some-token@github.com/\\".insteadOf",
"GIT_CONFIG_KEY_1": "url.\\"https://git:some-token@github.com/\\".insteadOf",
"GIT_CONFIG_KEY_2": "url.\\"https://some-token@github.com/\\".insteadOf",
"GIT_CONFIG_VALUE_0": "ssh://git@github.com/",
"GIT_CONFIG_VALUE_1": "git@github.com:",
"GIT_CONFIG_VALUE_2": "https://github.com/",
"GOFLAGS": "-modcacherw",
"GONOPROXY": "noproxy.example.com/*",
"GONOSUMDB": "1",
Expand Down
125 changes: 97 additions & 28 deletions lib/manager/gomod/artifacts.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -246,12 +246,25 @@ describe('manager/gomod/artifacts', () => {
expect.objectContaining({
options: expect.objectContaining({
env: expect.objectContaining({
GIT_CONFIG_COUNT: '2',
GIT_CONFIG_KEY_0: 'url.https://some-token@github.com/.insteadOf',
GIT_CONFIG_COUNT: '6',
GIT_CONFIG_KEY_0:
'url."https://ssh:some-token@github.com/".insteadOf',
GIT_CONFIG_KEY_1:
'url.https://some-enterprise-token@github.enterprise.com/.insteadOf',
GIT_CONFIG_VALUE_0: 'https://github.com/',
GIT_CONFIG_VALUE_1: 'https://github.enterprise.com/',
'url."https://git:some-token@github.com/".insteadOf',
GIT_CONFIG_KEY_2:
'url."https://some-token@github.com/".insteadOf',
GIT_CONFIG_KEY_3:
'url."https://ssh:some-enterprise-token@github.enterprise.com/".insteadOf',
GIT_CONFIG_KEY_4:
'url."https://git:some-enterprise-token@github.enterprise.com/".insteadOf',
GIT_CONFIG_KEY_5:
'url."https://some-enterprise-token@github.enterprise.com/".insteadOf',
GIT_CONFIG_VALUE_0: 'ssh://git@github.com/',
GIT_CONFIG_VALUE_1: 'git@github.com:',
GIT_CONFIG_VALUE_2: 'https://github.com/',
GIT_CONFIG_VALUE_3: 'ssh://git@github.enterprise.com/',
GIT_CONFIG_VALUE_4: 'git@github.enterprise.com:',
GIT_CONFIG_VALUE_5: 'https://github.enterprise.com/',
}),
}),
}),
Expand Down Expand Up @@ -288,10 +301,16 @@ describe('manager/gomod/artifacts', () => {
expect.objectContaining({
options: expect.objectContaining({
env: expect.objectContaining({
GIT_CONFIG_COUNT: '1',
GIT_CONFIG_COUNT: '3',
GIT_CONFIG_KEY_0:
'url.https://gitlab-ci-token:some-enterprise-token@gitlab.enterprise.com/.insteadOf',
GIT_CONFIG_VALUE_0: 'https://gitlab.enterprise.com/',
'url."https://gitlab-ci-token:some-enterprise-token@gitlab.enterprise.com/".insteadOf',
GIT_CONFIG_KEY_1:
'url."https://gitlab-ci-token:some-enterprise-token@gitlab.enterprise.com/".insteadOf',
GIT_CONFIG_KEY_2:
'url."https://gitlab-ci-token:some-enterprise-token@gitlab.enterprise.com/".insteadOf',
GIT_CONFIG_VALUE_0: 'ssh://git@gitlab.enterprise.com/',
GIT_CONFIG_VALUE_1: 'git@gitlab.enterprise.com:',
GIT_CONFIG_VALUE_2: 'https://gitlab.enterprise.com/',
}),
}),
}),
Expand Down Expand Up @@ -333,13 +352,25 @@ describe('manager/gomod/artifacts', () => {
expect.objectContaining({
options: expect.objectContaining({
env: expect.objectContaining({
GIT_CONFIG_COUNT: '2',
GIT_CONFIG_COUNT: '6',
GIT_CONFIG_KEY_0:
'url.https://gitlab-ci-token:some-enterprise-token-repo1@gitlab.enterprise.com/repo1.insteadOf',
'url."https://gitlab-ci-token:some-enterprise-token-repo1@gitlab.enterprise.com/repo1".insteadOf',
GIT_CONFIG_KEY_1:
'url.https://gitlab-ci-token:some-enterprise-token-repo2@gitlab.enterprise.com/repo2.insteadOf',
GIT_CONFIG_VALUE_0: 'https://gitlab.enterprise.com/repo1',
GIT_CONFIG_VALUE_1: 'https://gitlab.enterprise.com/repo2',
'url."https://gitlab-ci-token:some-enterprise-token-repo1@gitlab.enterprise.com/repo1".insteadOf',
GIT_CONFIG_KEY_2:
'url."https://gitlab-ci-token:some-enterprise-token-repo1@gitlab.enterprise.com/repo1".insteadOf',
GIT_CONFIG_KEY_3:
'url."https://gitlab-ci-token:some-enterprise-token-repo2@gitlab.enterprise.com/repo2".insteadOf',
GIT_CONFIG_KEY_4:
'url."https://gitlab-ci-token:some-enterprise-token-repo2@gitlab.enterprise.com/repo2".insteadOf',
GIT_CONFIG_KEY_5:
'url."https://gitlab-ci-token:some-enterprise-token-repo2@gitlab.enterprise.com/repo2".insteadOf',
GIT_CONFIG_VALUE_0: 'ssh://git@gitlab.enterprise.com/repo1',
GIT_CONFIG_VALUE_1: 'git@gitlab.enterprise.com:repo1',
GIT_CONFIG_VALUE_2: 'https://gitlab.enterprise.com/repo1',
GIT_CONFIG_VALUE_3: 'ssh://git@gitlab.enterprise.com/repo2',
GIT_CONFIG_VALUE_4: 'git@gitlab.enterprise.com:repo2',
GIT_CONFIG_VALUE_5: 'https://gitlab.enterprise.com/repo2',
}),
}),
}),
Expand Down Expand Up @@ -381,10 +412,16 @@ describe('manager/gomod/artifacts', () => {
expect.objectContaining({
options: expect.objectContaining({
env: expect.objectContaining({
GIT_CONFIG_COUNT: '1',
GIT_CONFIG_COUNT: '3',
GIT_CONFIG_KEY_0:
'url.https://gitlab-ci-token:some-gitlab-token@gitlab.enterprise.com/.insteadOf',
GIT_CONFIG_VALUE_0: 'https://gitlab.enterprise.com/',
'url."https://gitlab-ci-token:some-gitlab-token@gitlab.enterprise.com/".insteadOf',
GIT_CONFIG_KEY_1:
'url."https://gitlab-ci-token:some-gitlab-token@gitlab.enterprise.com/".insteadOf',
GIT_CONFIG_KEY_2:
'url."https://gitlab-ci-token:some-gitlab-token@gitlab.enterprise.com/".insteadOf',
GIT_CONFIG_VALUE_0: 'ssh://git@gitlab.enterprise.com/',
GIT_CONFIG_VALUE_1: 'git@gitlab.enterprise.com:',
GIT_CONFIG_VALUE_2: 'https://gitlab.enterprise.com/',
}),
}),
}),
Expand Down Expand Up @@ -434,18 +471,43 @@ describe('manager/gomod/artifacts', () => {
expect.objectContaining({
options: expect.objectContaining({
env: expect.objectContaining({
GIT_CONFIG_COUNT: '4',
GIT_CONFIG_KEY_0: 'url.https://some-token@github.com/.insteadOf',
GIT_CONFIG_COUNT: '12',
GIT_CONFIG_KEY_0:
'url."https://ssh:some-token@github.com/".insteadOf',
GIT_CONFIG_KEY_1:
'url.https://some-token@api.github.com/.insteadOf',
'url."https://git:some-token@github.com/".insteadOf',
GIT_CONFIG_KEY_2:
'url.https://some-enterprise-token@github.enterprise.com/.insteadOf',
'url."https://some-token@github.com/".insteadOf',
GIT_CONFIG_KEY_3:
'url.https://gitlab-ci-token:some-gitlab-token@gitlab.enterprise.com/.insteadOf',
GIT_CONFIG_VALUE_0: 'https://github.com/',
GIT_CONFIG_VALUE_1: 'https://api.github.com/',
GIT_CONFIG_VALUE_2: 'https://github.enterprise.com/',
GIT_CONFIG_VALUE_3: 'https://gitlab.enterprise.com/',
'url."https://ssh:some-token@api.github.com/".insteadOf',
GIT_CONFIG_KEY_4:
'url."https://git:some-token@api.github.com/".insteadOf',
GIT_CONFIG_KEY_5:
'url."https://some-token@api.github.com/".insteadOf',
GIT_CONFIG_KEY_6:
'url."https://ssh:some-enterprise-token@github.enterprise.com/".insteadOf',
GIT_CONFIG_KEY_7:
'url."https://git:some-enterprise-token@github.enterprise.com/".insteadOf',
GIT_CONFIG_KEY_8:
'url."https://some-enterprise-token@github.enterprise.com/".insteadOf',
GIT_CONFIG_KEY_9:
'url."https://gitlab-ci-token:some-gitlab-token@gitlab.enterprise.com/".insteadOf',
GIT_CONFIG_KEY_10:
'url."https://gitlab-ci-token:some-gitlab-token@gitlab.enterprise.com/".insteadOf',
GIT_CONFIG_KEY_11:
'url."https://gitlab-ci-token:some-gitlab-token@gitlab.enterprise.com/".insteadOf',
GIT_CONFIG_VALUE_0: 'ssh://git@github.com/',
GIT_CONFIG_VALUE_1: 'git@github.com:',
GIT_CONFIG_VALUE_2: 'https://github.com/',
GIT_CONFIG_VALUE_3: 'ssh://git@api.github.com/',
GIT_CONFIG_VALUE_4: 'git@api.github.com:',
GIT_CONFIG_VALUE_5: 'https://api.github.com/',
GIT_CONFIG_VALUE_6: 'ssh://git@github.enterprise.com/',
GIT_CONFIG_VALUE_7: 'git@github.enterprise.com:',
GIT_CONFIG_VALUE_8: 'https://github.enterprise.com/',
GIT_CONFIG_VALUE_9: 'ssh://git@gitlab.enterprise.com/',
GIT_CONFIG_VALUE_10: 'git@gitlab.enterprise.com:',
GIT_CONFIG_VALUE_11: 'https://gitlab.enterprise.com/',
}),
}),
}),
Expand Down Expand Up @@ -485,9 +547,16 @@ describe('manager/gomod/artifacts', () => {
expect.objectContaining({
options: expect.objectContaining({
env: expect.objectContaining({
GIT_CONFIG_COUNT: '1',
GIT_CONFIG_KEY_0: 'url.https://some-token@github.com/.insteadOf',
GIT_CONFIG_VALUE_0: 'https://github.com/',
GIT_CONFIG_COUNT: '3',
GIT_CONFIG_KEY_0:
'url."https://ssh:some-token@github.com/".insteadOf',
GIT_CONFIG_KEY_1:
'url."https://git:some-token@github.com/".insteadOf',
GIT_CONFIG_KEY_2:
'url."https://some-token@github.com/".insteadOf',
GIT_CONFIG_VALUE_0: 'ssh://git@github.com/',
GIT_CONFIG_VALUE_1: 'git@github.com:',
GIT_CONFIG_VALUE_2: 'https://github.com/',
}),
}),
}),
Expand Down
Loading

0 comments on commit 2eadd19

Please sign in to comment.