@@ -8,7 +8,14 @@ import * as actionsUtil from "./actions-util";
88import * as api from "./api-client" ;
99import { DO_NOT_RETRY_STATUSES } from "./api-client" ;
1010import { ActionsEnvVars , RegistryProxyVars } from "./environment" ;
11- import { callee , getTestEnv , setupTests } from "./testing-utils" ;
11+ import { GITHUB_DOTCOM_API_URL , GITHUB_DOTCOM_URL } from "./github" ;
12+ import {
13+ callee ,
14+ getTestEnv ,
15+ RecordingLogger ,
16+ SAMPLE_DOTCOM_API_DETAILS ,
17+ setupTests ,
18+ } from "./testing-utils" ;
1219import * as util from "./util" ;
1320
1421setupTests ( test ) ;
@@ -284,3 +291,74 @@ test("makeProxyRequestOptions - returns fetch with custom proxy", async (t) => {
284291 githubUtils . defaults . request ,
285292 ) ;
286293} ) ;
294+
295+ test ( "getAuthorizationHeaderFor - returns undefined if there's no token" , ( t ) => {
296+ const logger = new RecordingLogger ( ) ;
297+
298+ t . is (
299+ api . getAuthorizationHeaderFor (
300+ logger ,
301+ { ...SAMPLE_DOTCOM_API_DETAILS , auth : undefined } ,
302+ `${ GITHUB_DOTCOM_URL } /github` ,
303+ ) ,
304+ undefined ,
305+ ) ;
306+ t . is (
307+ api . getAuthorizationHeaderFor (
308+ logger ,
309+ { ...SAMPLE_DOTCOM_API_DETAILS , auth : "" } ,
310+ `${ GITHUB_DOTCOM_URL } /github` ,
311+ ) ,
312+ undefined ,
313+ ) ;
314+ t . is (
315+ api . getAuthorizationHeaderFor (
316+ logger ,
317+ { ...SAMPLE_DOTCOM_API_DETAILS , auth : " " } ,
318+ `${ GITHUB_DOTCOM_URL } /github` ,
319+ ) ,
320+ undefined ,
321+ ) ;
322+ } ) ;
323+
324+ test ( "getAuthorizationHeaderFor - returns header value with token if url is allowed" , ( t ) => {
325+ const logger = new RecordingLogger ( ) ;
326+
327+ t . is (
328+ api . getAuthorizationHeaderFor (
329+ logger ,
330+ SAMPLE_DOTCOM_API_DETAILS ,
331+ `${ GITHUB_DOTCOM_URL } /github` ,
332+ ) ,
333+ `token ${ SAMPLE_DOTCOM_API_DETAILS . auth } ` ,
334+ ) ;
335+ t . is (
336+ api . getAuthorizationHeaderFor (
337+ logger ,
338+ SAMPLE_DOTCOM_API_DETAILS ,
339+ `${ GITHUB_DOTCOM_API_URL } /github` ,
340+ ) ,
341+ `token ${ SAMPLE_DOTCOM_API_DETAILS . auth } ` ,
342+ ) ;
343+ } ) ;
344+
345+ test ( "getAuthorizationHeaderFor - returns undefined if url is not allowed" , ( t ) => {
346+ const logger = new RecordingLogger ( ) ;
347+
348+ t . is (
349+ api . getAuthorizationHeaderFor (
350+ logger ,
351+ SAMPLE_DOTCOM_API_DETAILS ,
352+ `https://localhost/github` ,
353+ ) ,
354+ undefined ,
355+ ) ;
356+ t . is (
357+ api . getAuthorizationHeaderFor (
358+ logger ,
359+ SAMPLE_DOTCOM_API_DETAILS ,
360+ `https://api.localhost/github` ,
361+ ) ,
362+ undefined ,
363+ ) ;
364+ } ) ;
0 commit comments