1+ import * as core from "@actions/core" ;
12import * as toolcache from "@actions/tool-cache" ;
23import test from "ava" ;
34import sinon from "sinon" ;
@@ -8,6 +9,7 @@ import { KnownLanguage } from "./languages";
89import { getRunnerLogger } from "./logging" ;
910import * as startProxyExports from "./start-proxy" ;
1011import { parseLanguage } from "./start-proxy" ;
12+ import * as statusReport from "./status-report" ;
1113import {
1214 checkExpectedLogMessages ,
1315 getRecordingLogger ,
@@ -17,6 +19,51 @@ import {
1719
1820setupTests ( test ) ;
1921
22+ test ( "sendFailedStatusReport - does not report arbitrary error messages" , async ( t ) => {
23+ const loggedMessages = [ ] ;
24+ const logger = getRecordingLogger ( loggedMessages ) ;
25+ const error = new Error ( startProxyExports . StartProxyErrorType . DownloadFailed ) ;
26+ const now = new Date ( ) ;
27+
28+ // Override core.setFailed to avoid it setting the program's exit code
29+ sinon . stub ( core , "setFailed" ) . returns ( ) ;
30+
31+ const createStatusReportBase = sinon . stub (
32+ statusReport ,
33+ "createStatusReportBase" ,
34+ ) ;
35+ createStatusReportBase . resolves ( undefined ) ;
36+
37+ await startProxyExports . sendFailedStatusReport ( logger , now , undefined , error ) ;
38+
39+ // Check that the stub has been called exactly once, with the expected arguments,
40+ // but not with the message from the error.
41+ t . assert ( createStatusReportBase . calledOnce ) ;
42+ t . assert (
43+ createStatusReportBase . calledWith (
44+ statusReport . ActionName . StartProxy ,
45+ "failure" ,
46+ now ,
47+ sinon . match . any ,
48+ sinon . match . any ,
49+ sinon . match . any ,
50+ ) ,
51+ "createStatusReportBase wasn't called with the expected arguments" ,
52+ ) ;
53+ t . false (
54+ createStatusReportBase . calledWith (
55+ statusReport . ActionName . StartProxy ,
56+ "failure" ,
57+ now ,
58+ sinon . match . any ,
59+ sinon . match . any ,
60+ sinon . match . any ,
61+ sinon . match ( ( msg : string ) => msg . includes ( error . message ) ) ,
62+ ) ,
63+ "createStatusReportBase was called with the error message" ,
64+ ) ;
65+ } ) ;
66+
2067const toEncodedJSON = ( data : any ) =>
2168 Buffer . from ( JSON . stringify ( data ) ) . toString ( "base64" ) ;
2269
0 commit comments