55 BundleSelectionOptions ,
66 getPublicRelease ,
77 getRelease ,
8+ parseCodeQLReleaseUrl ,
89 selectBundle ,
910} from "./codeql-release" ;
1011import { ActionsEnvVars } from "./environment" ;
@@ -17,6 +18,7 @@ import {
1718 getTestEnv ,
1819 initAllState ,
1920 LoggedMessage ,
21+ SAMPLE_DOTCOM_API_DETAILS ,
2022} from "./testing-utils" ;
2123import { ConfigurationError , GitHubVariant } from "./util" ;
2224
@@ -198,3 +200,93 @@ test("getPublicRelease constructs download URLs without looking up the release",
198200 ) ;
199201 t . deepEqual ( fixture . requests , [ ] ) ;
200202} ) ;
203+
204+ test ( "parseCodeQLReleaseUrl accepts web and legacy links and decodes tags once" , ( t ) => {
205+ for ( const [ suffix , tagName ] of [
206+ [ `tag/${ TAG } ` , TAG ] ,
207+ [ TAG , TAG ] ,
208+ [ "codeql-bundle-20230120" , "codeql-bundle-20230120" ] ,
209+ [ "codeql-bundle-v2.27.1-rc.1" , "codeql-bundle-v2.27.1-rc.1" ] ,
210+ [ "tag/run-123" , "run-123" ] ,
211+ [ "tag/build/123" , "build/123" ] ,
212+ [ "tag/build%2F123%2Brc%231" , "build/123+rc#1" ] ,
213+ [ "tag/build%252F123" , "build%2F123" ] ,
214+ [ `tag/${ TAG } /?expanded=true#assets` , TAG ] ,
215+ ] ) {
216+ t . deepEqual (
217+ parseCodeQLReleaseUrl (
218+ `https://github.com/octo/tools/releases/${ suffix } ` ,
219+ SAMPLE_DOTCOM_API_DETAILS ,
220+ ) ,
221+ { ...REFERENCE , isCurrentInstance : true , tagName } ,
222+ ) ;
223+ }
224+ t . throws (
225+ ( ) =>
226+ parseCodeQLReleaseUrl (
227+ "https://github.com/octo/tools/releases/tag/%zz" ,
228+ SAMPLE_DOTCOM_API_DETAILS ,
229+ ) ,
230+ { instanceOf : ConfigurationError , message : / I n v a l i d U R L e n c o d i n g / } ,
231+ ) ;
232+ } ) ;
233+
234+ test ( "parseCodeQLReleaseUrl matches the current instance and GitHub.com by origin" , ( t ) => {
235+ for ( const [ url , origin , serverURL ] of [
236+ [ "https://github.example.test" , "https://github.com" , "https://github.com" ] ,
237+ [
238+ "https://github.example.test/" ,
239+ "https://github.example.test" ,
240+ "https://github.example.test" ,
241+ ] ,
242+ [
243+ "https://GitHub.Example.test" ,
244+ "https://github.example.test" ,
245+ "https://github.example.test" ,
246+ ] ,
247+ [
248+ "https://github.example.test:443" ,
249+ "https://GITHUB.example.test:443" ,
250+ "https://github.example.test" ,
251+ ] ,
252+ ] ) {
253+ t . deepEqual (
254+ parseCodeQLReleaseUrl ( `${ origin } /octo/tools/releases/tag/${ TAG } ` , {
255+ auth : "token" ,
256+ url,
257+ apiURL : undefined ,
258+ } ) ,
259+ {
260+ ...REFERENCE ,
261+ serverURL,
262+ isCurrentInstance : serverURL !== "https://github.com" ,
263+ } ,
264+ `${ url } ${ origin } ` ,
265+ ) ;
266+ }
267+ } ) ;
268+
269+ test ( "parseCodeQLReleaseUrl excludes archives, REST references and untrusted URLs" , ( t ) => {
270+ for ( const input of [
271+ "/tmp/codeql-bundle.tar.zst" ,
272+ "nightly" ,
273+ `https://github.com/octo/tools/releases/download/${ TAG } /${ JAVA } ` ,
274+ "https://api.github.com/repos/octo/tools/releases/assets/123" ,
275+ "https://api.github.com/repos/octo/tools/releases/123" ,
276+ `https://api.github.com/repos/octo/tools/releases/tags/${ TAG } ` ,
277+ "https://github.com/octo/tools/releases/latest" ,
278+ "https://github.com/octo/tools/releases/tag/" ,
279+ "https://github.com/octo/tools/releases/run-123" ,
280+ `https://github.com.example.test/octo/tools/releases/tag/${ TAG } ` ,
281+ `https://github.com:8443/octo/tools/releases/tag/${ TAG } ` ,
282+ `https://github.com@example.test/octo/tools/releases/tag/${ TAG } ` ,
283+ `https://user@github.com/octo/tools/releases/tag/${ TAG } ` ,
284+ `http://github.com/octo/tools/releases/tag/${ TAG } ` ,
285+ ] ) {
286+ t . is (
287+ parseCodeQLReleaseUrl ( input , SAMPLE_DOTCOM_API_DETAILS ) ,
288+ undefined ,
289+ input ,
290+ ) ;
291+ }
292+ } ) ;
0 commit comments