@@ -40,6 +40,8 @@ const signedUrl = "https://storage.example/image?X-Amz-Date=20260912T120000Z&X-A
4040
4141function fixture ( input : {
4242 token ?: ( ) => string ;
43+ protocol ?: string ;
44+ apiBaseUrl ?: string ;
4345 fetch : ( ...args : Parameters < typeof globalThis . fetch > ) => ReturnType < typeof globalThis . fetch > ;
4446 commands ?: Array < { command : string ; args : ReadonlyArray < string > } > ;
4547} ) {
@@ -52,10 +54,11 @@ function fixture(input: {
5254 const token = input . token ?.( ) ?? "dummy-token" ;
5355 return {
5456 exitCode : ChildProcessSpawner . ExitCode ( 0 ) ,
55- stdout : command === "gh" ? token : "" ,
57+ stdout :
58+ command === "gh" ? token : args [ 0 ] === "config" ? ( input . protocol ?? "https" ) : "" ,
5659 stderr :
5760 command === "glab" && token
58- ? `git.example\n ✓ REST API Endpoint: https://api.git.example:3443/api/v4/\n ✓ Token found in keyring: ${ token } \n`
61+ ? `git.example\n ✓ REST API Endpoint: ${ input . apiBaseUrl ?? " https://api.git.example:3443/api/v4/" } \n ✓ Token found in keyring: ${ token } \n`
5962 : "" ,
6063 stdoutTruncated : false ,
6164 stderrTruncated : false ,
@@ -221,6 +224,83 @@ describe("source-control image delivery", () => {
221224 ) ,
222225 ) ;
223226
227+ for ( const protocol of [ "http" , "" , "ftp" ] ) {
228+ it . effect ( `rejects ${ protocol || "missing" } API protocol before auth status` , ( ) => {
229+ const commands : Array < { command : string ; args : ReadonlyArray < string > } > = [ ] ;
230+ let requested = false ;
231+ return Effect . gen ( function * ( ) {
232+ const proxy = yield * SourceControlMediaProxy . SourceControlMediaProxy ;
233+ expect ( yield * proxy . resolve ( gitlab ) ) . toBeNull ( ) ;
234+ expect ( commands ) . toEqual ( [
235+ { command : "glab" , args : [ "config" , "get" , "api_protocol" , "--host" , "git.example" ] } ,
236+ ] ) ;
237+ expect ( requested ) . toBe ( false ) ;
238+ } ) . pipe (
239+ Effect . provide (
240+ fixture ( {
241+ protocol,
242+ commands,
243+ fetch : async ( ) => {
244+ requested = true ;
245+ return new Response ( "unexpected" ) ;
246+ } ,
247+ } ) ,
248+ ) ,
249+ ) ;
250+ } ) ;
251+ }
252+
253+ it . effect ( "rejects an HTTP endpoint returned despite HTTPS configuration" , ( ) => {
254+ let requested = false ;
255+ return Effect . gen ( function * ( ) {
256+ const proxy = yield * SourceControlMediaProxy . SourceControlMediaProxy ;
257+ expect ( yield * proxy . resolve ( gitlab ) ) . toBeNull ( ) ;
258+ expect ( requested ) . toBe ( false ) ;
259+ } ) . pipe (
260+ Effect . provide (
261+ fixture ( {
262+ apiBaseUrl : "http://api.git.example/api/v4/" ,
263+ fetch : async ( ) => {
264+ requested = true ;
265+ return new Response ( "unexpected" ) ;
266+ } ,
267+ } ) ,
268+ ) ,
269+ ) ;
270+ } ) ;
271+
272+ for ( const length of [
273+ "0" ,
274+ "8" ,
275+ "9007199254740991" ,
276+ "9007199254740993" ,
277+ "9" . repeat ( 400 ) ,
278+ "-1" ,
279+ "1.5" ,
280+ "nope" ,
281+ ] ) {
282+ it . effect ( `validates upstream content length ${ length . slice ( 0 , 20 ) } ` , ( ) =>
283+ Effect . gen ( function * ( ) {
284+ const proxy = yield * SourceControlMediaProxy . SourceControlMediaProxy ;
285+ const delivery = yield * proxy . resolve ( gitlab ) ;
286+ expect ( delivery ?. kind ) . toBe ( "stream" ) ;
287+ if ( delivery ?. kind !== "stream" ) return ;
288+ expect ( delivery . headers [ "content-length" ] ) . toBe (
289+ [ "0" , "8" , "9007199254740991" ] . includes ( length ) ? length : undefined ,
290+ ) ;
291+ } ) . pipe (
292+ Effect . provide (
293+ fixture ( {
294+ fetch : async ( ) =>
295+ new Response ( null , {
296+ headers : { "content-type" : "image/png" , "content-length" : length } ,
297+ } ) ,
298+ } ) ,
299+ ) ,
300+ ) ,
301+ ) ;
302+ }
303+
224304 it . effect ( "does not attach compressed lengths to a decoded media stream" , ( ) =>
225305 Effect . gen ( function * ( ) {
226306 const proxy = yield * SourceControlMediaProxy . SourceControlMediaProxy ;
@@ -319,6 +399,7 @@ describe("source-control image delivery", () => {
319399 { url : "https://storage.example/image" , token : null , redirect : "manual" } ,
320400 ] ) ;
321401 expect ( commands ) . toEqual ( [
402+ { command : "glab" , args : [ "config" , "get" , "api_protocol" , "--host" , "git.example" ] } ,
322403 {
323404 command : "glab" ,
324405 args : [ "auth" , "status" , "--hostname" , "git.example" , "--show-token" ] ,
@@ -364,7 +445,7 @@ describe("source-control image delivery", () => {
364445 expect ( headers ) . toEqual ( [ null , "token logged-in" , "token logged-in" ] ) ;
365446 yield * proxy . resolve ( gitlab ) ;
366447 yield * proxy . resolve ( gitlab ) ;
367- expect ( commands . filter ( ( command ) => command . command === "glab" ) ) . toHaveLength ( 1 ) ;
448+ expect ( commands . filter ( ( command ) => command . command === "glab" ) ) . toHaveLength ( 2 ) ;
368449 } ) . pipe (
369450 Effect . provide (
370451 fixture ( {
0 commit comments