@@ -53,7 +53,7 @@ function expectNoMediaDownload(result: Awaited<ReturnType<typeof downloadSlackFi
5353 expect ( resolveSlackMedia ) . not . toHaveBeenCalled ( ) ;
5454}
5555
56- function expectResolveSlackMediaCalledWithDefaults ( ) {
56+ function expectResolveSlackMediaCalledWithDefaults ( client : ReturnType < typeof createClient > ) {
5757 expect ( resolveSlackMedia ) . toHaveBeenCalledWith ( {
5858 files : [
5959 {
@@ -64,6 +64,7 @@ function expectResolveSlackMediaCalledWithDefaults() {
6464 url_private_download : "https://files.slack.com/files-pri/T1-F123/image.png" ,
6565 } ,
6666 ] ,
67+ client,
6768 token : "xoxb-test" ,
6869 maxBytes : 1024 ,
6970 } ) ;
@@ -116,10 +117,28 @@ describe("downloadSlackFile", () => {
116117 } ) ;
117118
118119 expect ( client . files . info ) . toHaveBeenCalledWith ( { file : "F123" } ) ;
119- expectResolveSlackMediaCalledWithDefaults ( ) ;
120+ expectResolveSlackMediaCalledWithDefaults ( client ) ;
120121 expect ( result ) . toEqual ( makeResolvedSlackMedia ( ) ) ;
121122 } ) ;
122123
124+ it ( "passes the prepared GovSlack client to the media trust boundary" , async ( ) => {
125+ const client = Object . assign ( createClient ( ) , { slackApiUrl : "https://slack-gov.com/api/" } ) ;
126+ client . files . info . mockResolvedValueOnce ( {
127+ file : makeSlackFileInfo ( {
128+ url_private_download : "https://files.slack-gov.com/files-pri/T1-F123/image.png" ,
129+ } ) ,
130+ } ) ;
131+ resolveSlackMedia . mockResolvedValueOnce ( [ makeResolvedSlackMedia ( ) ] ) ;
132+
133+ await downloadSlackFile ( "F123" , {
134+ client,
135+ token : "xoxb-test" ,
136+ maxBytes : 1024 ,
137+ } ) ;
138+
139+ expect ( resolveSlackMedia ) . toHaveBeenCalledWith ( expect . objectContaining ( { client } ) ) ;
140+ } ) ;
141+
123142 it ( "preserves non-image download metadata" , async ( ) => {
124143 const client = createClient ( ) ;
125144 client . files . info . mockResolvedValueOnce ( {
@@ -153,6 +172,7 @@ describe("downloadSlackFile", () => {
153172 url_private_download : "https://files.slack.com/files-pri/T1-F123/report.pdf" ,
154173 } ,
155174 ] ,
175+ client,
156176 token : "xoxb-test" ,
157177 maxBytes : 1024 ,
158178 } ) ;
@@ -218,7 +238,7 @@ describe("downloadSlackFile", () => {
218238
219239 expect ( result ) . toEqual ( makeResolvedSlackMedia ( ) ) ;
220240 expect ( resolveSlackMedia ) . toHaveBeenCalledTimes ( 1 ) ;
221- expectResolveSlackMediaCalledWithDefaults ( ) ;
241+ expectResolveSlackMediaCalledWithDefaults ( client ) ;
222242 } ) ;
223243
224244 it ( "resolves the bot token from cfg when no explicit token or client is provided" , async ( ) => {
@@ -258,6 +278,7 @@ describe("downloadSlackFile", () => {
258278 url_private_download : "https://files.slack.com/files-pri/T1-F123/image.png" ,
259279 } ,
260280 ] ,
281+ client,
261282 token : "xoxb-from-cfg" ,
262283 maxBytes : 1024 ,
263284 } ) ;
0 commit comments