feat: add possibility of a user provided glpat
Signed-off-by: ElaineDeMattosSilvaB <elaine.de-mattos-silva-bezerra@deutschebahn.com>
This commit is contained in:
@@ -189,15 +189,30 @@ describe('gitlab core', () => {
|
||||
|
||||
describe('getGitLabRequestOptions', () => {
|
||||
it('should return Authorization header when oauthToken is provided', () => {
|
||||
const oauthToken = 'mock-oauth-token';
|
||||
const token =
|
||||
'de6780bc506a0446309bd9362820ba8aed28aa506c71eedbe1c5c4f9dd350e54';
|
||||
const result = getGitLabRequestOptions(
|
||||
configSelfHosteWithRelativePath,
|
||||
oauthToken,
|
||||
token,
|
||||
);
|
||||
|
||||
expect(result).toEqual({
|
||||
headers: {
|
||||
Authorization: `Bearer ${oauthToken}`,
|
||||
Authorization: `Bearer ${token}`,
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
it('should return private-token header when gl-token is provided', () => {
|
||||
const token = 'glpat-1234566';
|
||||
const result = getGitLabRequestOptions(
|
||||
configSelfHosteWithRelativePath,
|
||||
token,
|
||||
);
|
||||
|
||||
expect(result).toEqual({
|
||||
headers: {
|
||||
'PRIVATE-TOKEN': token,
|
||||
},
|
||||
});
|
||||
});
|
||||
@@ -208,7 +223,6 @@ describe('gitlab core', () => {
|
||||
configSelfHosteWithRelativePath,
|
||||
oauthToken,
|
||||
);
|
||||
|
||||
expect(result).toEqual({
|
||||
headers: {
|
||||
'PRIVATE-TOKEN': configSelfHosteWithRelativePath.token,
|
||||
|
||||
@@ -53,21 +53,21 @@ export async function getGitLabFileFetchUrl(
|
||||
*/
|
||||
export function getGitLabRequestOptions(
|
||||
config: GitLabIntegrationConfig,
|
||||
oauthToken?: string,
|
||||
token?: string,
|
||||
): { headers: Record<string, string> } {
|
||||
if (oauthToken) {
|
||||
if (token) {
|
||||
// If token comes from the user and starts with "gl", it's a private token (see https://docs.gitlab.com/ee/security/token_overview.html#token-prefixes)
|
||||
return {
|
||||
headers: {
|
||||
Authorization: `Bearer ${oauthToken}`,
|
||||
},
|
||||
headers: token.startsWith('gl')
|
||||
? { 'PRIVATE-TOKEN': token }
|
||||
: { Authorization: `Bearer ${token}` }, // Otherwise, it's a bearer token
|
||||
};
|
||||
}
|
||||
|
||||
const { token = '' } = config;
|
||||
// If token not provided, fetch the integration token
|
||||
const { token: configToken = '' } = config;
|
||||
return {
|
||||
headers: {
|
||||
'PRIVATE-TOKEN': token,
|
||||
},
|
||||
headers: { 'PRIVATE-TOKEN': configToken },
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user