@@ -239,5 +239,57 @@ public void FetchHonorsTheFetchPruneConfigurationEntry()
239239 Assert . Equal ( 4 , clonedRepo . Branches . Count ( b => b . IsRemote ) ) ;
240240 }
241241 }
242+
243+ [ Fact ]
244+ public void CannotFetchWithForbiddenCustomHeaders ( )
245+ {
246+ var scd = BuildSelfCleaningDirectory ( ) ;
247+
248+ const string url = "https://github.com/libgit2/TestGitRepository" ;
249+
250+ string clonedRepoPath = Repository . Clone ( url , scd . DirectoryPath ) ;
251+
252+ const string knownHeader = "User-Agent: mygit-201" ;
253+ var options = new FetchOptions { CustomHeaders = new String [ ] { knownHeader } } ;
254+ using ( var repo = new Repository ( clonedRepoPath ) )
255+ {
256+ Assert . Throws < LibGit2SharpException > ( ( ) => Commands . Fetch ( repo , "origin" , new string [ 0 ] , options , null ) ) ;
257+ }
258+ }
259+
260+ [ Fact ]
261+ public void CanFetchWithCustomHeaders ( )
262+ {
263+ var scd = BuildSelfCleaningDirectory ( ) ;
264+
265+ const string url = "https://github.com/libgit2/TestGitRepository" ;
266+
267+ string clonedRepoPath = Repository . Clone ( url , scd . DirectoryPath ) ;
268+
269+ const string knownHeader = "X-Hello: mygit-201" ;
270+ var options = new FetchOptions { CustomHeaders = new String [ ] { knownHeader } } ;
271+ using ( var repo = new Repository ( clonedRepoPath ) )
272+ {
273+ Commands . Fetch ( repo , "origin" , new string [ 0 ] , options , null ) ;
274+ }
275+ }
276+
277+ [ Fact ]
278+ public void CannotFetchWithMalformedCustomHeaders ( )
279+ {
280+ var scd = BuildSelfCleaningDirectory ( ) ;
281+
282+ const string url = "https://github.com/libgit2/TestGitRepository" ;
283+
284+ string clonedRepoPath = Repository . Clone ( url , scd . DirectoryPath ) ;
285+
286+ const string knownHeader = "Hello world" ;
287+ var options = new FetchOptions { CustomHeaders = new String [ ] { knownHeader } } ;
288+ using ( var repo = new Repository ( clonedRepoPath ) )
289+ {
290+ Assert . Throws < LibGit2SharpException > ( ( ) => Commands . Fetch ( repo , "origin" , new string [ 0 ] , options , null ) ) ;
291+ }
292+ }
293+
242294 }
243295}
0 commit comments