-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(git): move git autentification via environment variables to git …
…auth (#22821) Co-authored-by: Michael Kriese <[email protected]>
- Loading branch information
Showing
3 changed files
with
223 additions
and
93 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,8 @@ | ||
import { getGitAuthenticatedEnvironmentVariables } from './auth'; | ||
import { add, clear } from '../host-rules'; | ||
import { | ||
getGitAuthenticatedEnvironmentVariables, | ||
getGitEnvironmentVariables, | ||
} from './auth'; | ||
|
||
describe('util/git/auth', () => { | ||
afterEach(() => { | ||
|
@@ -307,4 +311,132 @@ describe('util/git/auth', () => { | |
}); | ||
}); | ||
}); | ||
|
||
describe('getGitEnvironmentVariables()', () => { | ||
beforeEach(() => { | ||
clear(); | ||
}); | ||
|
||
it('returns empty object if no environment variables exist', () => { | ||
expect(getGitEnvironmentVariables()).toStrictEqual({}); | ||
}); | ||
|
||
it('returns environment variables with token if hostRule for api.github.com exists', () => { | ||
add({ | ||
hostType: 'github', | ||
matchHost: 'api.github.com', | ||
token: 'token123', | ||
}); | ||
expect(getGitEnvironmentVariables()).toStrictEqual({ | ||
GIT_CONFIG_COUNT: '3', | ||
GIT_CONFIG_KEY_0: 'url.https://ssh:[email protected]/.insteadOf', | ||
GIT_CONFIG_KEY_1: 'url.https://git:[email protected]/.insteadOf', | ||
GIT_CONFIG_KEY_2: 'url.https://[email protected]/.insteadOf', | ||
GIT_CONFIG_VALUE_0: 'ssh://[email protected]/', | ||
GIT_CONFIG_VALUE_1: '[email protected]:', | ||
GIT_CONFIG_VALUE_2: 'https://github.com/', | ||
}); | ||
}); | ||
|
||
it('returns environment variables with token if hostRule for multiple hostsRules', () => { | ||
add({ | ||
hostType: 'github', | ||
matchHost: 'api.github.com', | ||
token: 'token123', | ||
}); | ||
add({ | ||
hostType: 'gitlab', | ||
matchHost: 'https://gitlab.example.com', | ||
token: 'token234', | ||
}); | ||
add({ | ||
hostType: 'github', | ||
matchHost: 'https://github.example.com', | ||
token: 'token345', | ||
}); | ||
expect(getGitEnvironmentVariables()).toStrictEqual({ | ||
GIT_CONFIG_COUNT: '9', | ||
GIT_CONFIG_KEY_0: 'url.https://ssh:[email protected]/.insteadOf', | ||
GIT_CONFIG_KEY_1: 'url.https://git:[email protected]/.insteadOf', | ||
GIT_CONFIG_KEY_2: 'url.https://[email protected]/.insteadOf', | ||
GIT_CONFIG_KEY_3: | ||
'url.https://gitlab-ci-token:[email protected]/.insteadOf', | ||
GIT_CONFIG_KEY_4: | ||
'url.https://gitlab-ci-token:[email protected]/.insteadOf', | ||
GIT_CONFIG_KEY_5: | ||
'url.https://gitlab-ci-token:[email protected]/.insteadOf', | ||
GIT_CONFIG_KEY_6: | ||
'url.https://ssh:[email protected]/.insteadOf', | ||
GIT_CONFIG_KEY_7: | ||
'url.https://git:[email protected]/.insteadOf', | ||
GIT_CONFIG_KEY_8: 'url.https://[email protected]/.insteadOf', | ||
GIT_CONFIG_VALUE_0: 'ssh://[email protected]/', | ||
GIT_CONFIG_VALUE_1: '[email protected]:', | ||
GIT_CONFIG_VALUE_2: 'https://github.com/', | ||
GIT_CONFIG_VALUE_3: 'ssh://[email protected]/', | ||
GIT_CONFIG_VALUE_4: '[email protected]:', | ||
GIT_CONFIG_VALUE_5: 'https://gitlab.example.com/', | ||
GIT_CONFIG_VALUE_6: 'ssh://[email protected]/', | ||
GIT_CONFIG_VALUE_7: '[email protected]:', | ||
GIT_CONFIG_VALUE_8: 'https://github.example.com/', | ||
}); | ||
}); | ||
|
||
it('returns environment variables with token if hostRule is for Gitlab', () => { | ||
add({ | ||
hostType: 'gitlab', | ||
matchHost: 'https://gitlab.example.com', | ||
token: 'token123', | ||
}); | ||
expect(getGitEnvironmentVariables()).toStrictEqual({ | ||
GIT_CONFIG_COUNT: '3', | ||
GIT_CONFIG_KEY_0: | ||
'url.https://gitlab-ci-token:[email protected]/.insteadOf', | ||
GIT_CONFIG_KEY_1: | ||
'url.https://gitlab-ci-token:[email protected]/.insteadOf', | ||
GIT_CONFIG_KEY_2: | ||
'url.https://gitlab-ci-token:[email protected]/.insteadOf', | ||
GIT_CONFIG_VALUE_0: 'ssh://[email protected]/', | ||
GIT_CONFIG_VALUE_1: '[email protected]:', | ||
GIT_CONFIG_VALUE_2: 'https://gitlab.example.com/', | ||
}); | ||
}); | ||
|
||
it('returns no environment variables when hostType is not supported', () => { | ||
add({ | ||
hostType: 'custom', | ||
matchHost: 'https://custom.example.com', | ||
token: 'token123', | ||
}); | ||
expect(getGitEnvironmentVariables()).toStrictEqual({}); | ||
}); | ||
|
||
it('returns environment variables when hostType is explicitly set', () => { | ||
add({ | ||
hostType: 'custom', | ||
matchHost: 'https://custom.example.com', | ||
token: 'token123', | ||
}); | ||
expect(getGitEnvironmentVariables(['custom'])).toStrictEqual({ | ||
GIT_CONFIG_COUNT: '3', | ||
GIT_CONFIG_KEY_0: | ||
'url.https://ssh:[email protected]/.insteadOf', | ||
GIT_CONFIG_KEY_1: | ||
'url.https://git:[email protected]/.insteadOf', | ||
GIT_CONFIG_KEY_2: 'url.https://[email protected]/.insteadOf', | ||
GIT_CONFIG_VALUE_0: 'ssh://[email protected]/', | ||
GIT_CONFIG_VALUE_1: '[email protected]:', | ||
GIT_CONFIG_VALUE_2: 'https://custom.example.com/', | ||
}); | ||
}); | ||
|
||
it('returns empty environment variables when matchHost contains invalid protocol', () => { | ||
add({ | ||
hostType: 'github', | ||
matchHost: 'invalid://*.github.example.com', | ||
token: 'token123', | ||
}); | ||
expect(getGitEnvironmentVariables(['custom'])).toStrictEqual({}); | ||
}); | ||
}); | ||
}); |
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