@@ -244,19 +244,282 @@ describe('getAvailableVersions', () => {
244244 ) . rejects . toThrow ( 'Early access versions are not supported' ) ;
245245 } ) ;
246246
247- it ( 'with non major version expect to throw not supported error' , async ( ) => {
248- const version = '18.0.1' ;
247+ it . each ( [ '18.0.1' , '17.0.13.11' , '17.0.13.11.1.1' ] ) (
248+ 'rejects partial or malformed release %s' ,
249+ async version => {
250+ const distribution = new CorrettoDistribution ( {
251+ version,
252+ architecture : 'x64' ,
253+ packageType : 'jdk' ,
254+ checkLatest : false
255+ } ) ;
256+ mockPlatform ( distribution , 'linux' ) ;
257+
258+ await expect (
259+ distribution [ 'findPackageForDownload' ] ( version )
260+ ) . rejects . toThrow (
261+ 'Specify a major version or a full Corretto release, such as 25.0.5.0.10'
262+ ) ;
263+ }
264+ ) ;
265+
266+ it . each ( [
267+ [
268+ '25.0.5.0.10' ,
269+ 'linux' ,
270+ 'x64' ,
271+ 'jdk' ,
272+ '25.0.5+0.10' ,
273+ 'https://corretto.aws/downloads/resources/25.0.5.0.10/amazon-corretto-25.0.5.0.10-linux-x64.tar.gz'
274+ ] ,
275+ [
276+ '25.0.5+0.10' ,
277+ 'macos' ,
278+ 'arm64' ,
279+ 'jdk' ,
280+ '25.0.5+0.10' ,
281+ 'https://corretto.aws/downloads/resources/25.0.5.0.10/amazon-corretto-25.0.5.0.10-macosx-aarch64.tar.gz'
282+ ] ,
283+ [
284+ '17.0.2.8.1' ,
285+ 'windows' ,
286+ 'x64' ,
287+ 'jdk' ,
288+ '17.0.2+8.1' ,
289+ 'https://corretto.aws/downloads/resources/17.0.2.8.1/amazon-corretto-17.0.2.8.1-windows-x64-jdk.zip'
290+ ] ,
291+ [
292+ '25.0.5.0.10' ,
293+ 'alpine' ,
294+ 'aarch64' ,
295+ 'jdk' ,
296+ '25.0.5+0.10' ,
297+ 'https://corretto.aws/downloads/resources/25.0.5.0.10/amazon-corretto-25.0.5.0.10-alpine-linux-aarch64.tar.gz'
298+ ] ,
299+ [
300+ '11.0.14.10.1' ,
301+ 'linux' ,
302+ 'armv7' ,
303+ 'jdk' ,
304+ '11.0.14+10.1' ,
305+ 'https://corretto.aws/downloads/resources/11.0.14.10.1/amazon-corretto-11.0.14.10.1-linux-armv7.tar.gz'
306+ ] ,
307+ [
308+ '8.472.8+1' ,
309+ 'linux' ,
310+ 'x64' ,
311+ 'jdk' ,
312+ '8.472.8+1' ,
313+ 'https://corretto.aws/downloads/resources/8.472.08.1/amazon-corretto-8.472.08.1-linux-x64.tar.gz'
314+ ] ,
315+ [
316+ '8.472.08.1' ,
317+ 'linux' ,
318+ 'x64' ,
319+ 'jdk' ,
320+ '8.472.8+1' ,
321+ 'https://corretto.aws/downloads/resources/8.472.08.1/amazon-corretto-8.472.08.1-linux-x64.tar.gz'
322+ ] ,
323+ [
324+ '8.472.08.1' ,
325+ 'windows' ,
326+ 'x86' ,
327+ 'jre' ,
328+ '8.472.8+1' ,
329+ 'https://corretto.aws/downloads/resources/8.472.08.1/amazon-corretto-8.472.08.1-windows-x86-jre.zip'
330+ ]
331+ ] ) (
332+ 'resolves exact release %s on %s/%s (%s)' ,
333+ async (
334+ requestedVersion ,
335+ platform ,
336+ architecture ,
337+ packageType ,
338+ expectedVersion ,
339+ url
340+ ) => {
341+ const checksum = 'a' . repeat ( 64 ) ;
342+ spyHttpClient . mockResolvedValue ( {
343+ statusCode : 200 ,
344+ headers : { } ,
345+ result : {
346+ body : `|JDK|[archive](${ url } )|\`md5\` /<br /> \`${ checksum } \`|`
347+ }
348+ } ) ;
349+ const distribution = new CorrettoDistribution ( {
350+ version : requestedVersion ,
351+ architecture,
352+ packageType,
353+ checkLatest : false
354+ } ) ;
355+ mockPlatform ( distribution , platform ) ;
356+
357+ const release = await distribution [ 'findPackageForDownload' ] (
358+ distribution [ 'version' ]
359+ ) ;
360+ const rawVersion = new URL ( url ) . pathname . split ( '/' ) [ 3 ] ;
361+ const source = `https://api.github.com/repos/corretto/corretto-${ rawVersion . split ( '.' ) [ 0 ] } /releases/tags/${ rawVersion } ` ;
362+ expect ( release ) . toEqual ( {
363+ version : expectedVersion ,
364+ url,
365+ checksum : { algorithm : 'sha256' , value : checksum , source}
366+ } ) ;
367+ expect ( spyHttpClient ) . toHaveBeenCalledTimes ( 1 ) ;
368+ expect ( spyHttpClient ) . toHaveBeenCalledWith (
369+ source ,
370+ expect . objectContaining ( { accept : 'application/vnd.github+json' } )
371+ ) ;
372+ }
373+ ) ;
374+
375+ it ( 'rejects exact releases without an archive for the requested platform' , async ( ) => {
376+ spyHttpClient . mockResolvedValueOnce ( {
377+ statusCode : 200 ,
378+ headers : { } ,
379+ result : {
380+ body :
381+ '|[other archive](https://example.com/archive)|`' +
382+ 'a' . repeat ( 64 ) +
383+ '`|'
384+ }
385+ } ) ;
249386 const distribution = new CorrettoDistribution ( {
250- version,
387+ version : '25.0.5.0.10' ,
251388 architecture : 'x64' ,
252389 packageType : 'jdk' ,
253390 checkLatest : false
254391 } ) ;
255392 mockPlatform ( distribution , 'linux' ) ;
393+ await expect (
394+ distribution [ 'findPackageForDownload' ] ( distribution [ 'version' ] )
395+ ) . rejects . toThrow (
396+ 'No linux/x64 jdk archive is listed for Corretto 25.0.5.0.10'
397+ ) ;
398+ } ) ;
256399
400+ it ( 'rejects historical archives with only an MD5 checksum' , async ( ) => {
401+ spyHttpClient . mockResolvedValueOnce ( {
402+ statusCode : 200 ,
403+ headers : { } ,
404+ result : {
405+ body :
406+ '|[archive](https://corretto.aws/downloads/resources/17.0.1.12.1/amazon-corretto-17.0.1.12.1-linux-x64.tar.gz)|`' +
407+ 'a' . repeat ( 32 ) +
408+ '`|'
409+ }
410+ } ) ;
411+ const distribution = new CorrettoDistribution ( {
412+ version : '17.0.1.12.1' ,
413+ architecture : 'x64' ,
414+ packageType : 'jdk' ,
415+ checkLatest : false
416+ } ) ;
417+ mockPlatform ( distribution , 'linux' ) ;
257418 await expect (
258- distribution [ 'findPackageForDownload' ] ( version )
259- ) . rejects . toThrow ( 'Only major versions are supported' ) ;
419+ distribution [ 'findPackageForDownload' ] ( distribution [ 'version' ] )
420+ ) . rejects . toThrow (
421+ 'No SHA-256 checksum is published for Corretto 17.0.1.12.1 (linux, x64, jdk)'
422+ ) ;
423+ } ) ;
424+
425+ it ( 'does not substitute a JDK for an exact Linux JRE request' , async ( ) => {
426+ const distribution = new CorrettoDistribution ( {
427+ version : '25.0.5.0.10' ,
428+ architecture : 'x64' ,
429+ packageType : 'jre' ,
430+ checkLatest : false
431+ } ) ;
432+ mockPlatform ( distribution , 'linux' ) ;
433+ await expect (
434+ distribution [ 'findPackageForDownload' ] ( distribution [ 'version' ] )
435+ ) . rejects . toThrow ( 'Corretto JRE archives are only available for Windows' ) ;
436+ expect ( spyHttpClient ) . not . toHaveBeenCalled ( ) ;
437+ } ) ;
438+
439+ it ( 'resolves catalog-only releases without a GitHub release' , async ( ) => {
440+ spyHttpClient . mockResolvedValueOnce ( {
441+ statusCode : 404 ,
442+ headers : { } ,
443+ result : null
444+ } ) ;
445+ const distribution = new CorrettoDistribution ( {
446+ version : '15.0.2.7.1' ,
447+ architecture : 'x64' ,
448+ packageType : 'jdk' ,
449+ checkLatest : false
450+ } ) ;
451+ mockPlatform ( distribution , 'linux' ) ;
452+ expect (
453+ await distribution [ 'findPackageForDownload' ] ( distribution [ 'version' ] )
454+ ) . toEqual ( {
455+ version : '15.0.2+7.1' ,
456+ url : 'https://corretto.aws/downloads/resources/15.0.2.7.1/amazon-corretto-15.0.2.7.1-linux-x64.tar.gz' ,
457+ checksum : {
458+ algorithm : 'sha256' ,
459+ value : manifestData . linux . x64 . jdk [ '15' ] [ 'tar.gz' ] . checksum_sha256 ,
460+ source :
461+ 'https://corretto.github.io/corretto-downloads/latest_links/indexmap_with_checksum.json'
462+ }
463+ } ) ;
464+ } ) ;
465+
466+ it ( 'falls back to the catalog when the GitHub lookup fails' , async ( ) => {
467+ spyHttpClient . mockRejectedValueOnce ( new Error ( 'GitHub rate limit' ) ) ;
468+ const distribution = new CorrettoDistribution ( {
469+ version : '15.0.2.7.1' ,
470+ architecture : 'x64' ,
471+ packageType : 'jdk' ,
472+ checkLatest : false
473+ } ) ;
474+ mockPlatform ( distribution , 'linux' ) ;
475+
476+ expect (
477+ await distribution [ 'findPackageForDownload' ] ( distribution [ 'version' ] )
478+ ) . toEqual ( {
479+ version : '15.0.2+7.1' ,
480+ url : 'https://corretto.aws/downloads/resources/15.0.2.7.1/amazon-corretto-15.0.2.7.1-linux-x64.tar.gz' ,
481+ checksum : {
482+ algorithm : 'sha256' ,
483+ value : manifestData . linux . x64 . jdk [ '15' ] [ 'tar.gz' ] . checksum_sha256 ,
484+ source :
485+ 'https://corretto.github.io/corretto-downloads/latest_links/indexmap_with_checksum.json'
486+ }
487+ } ) ;
488+ expect ( spyHttpClient ) . toHaveBeenCalledTimes ( 2 ) ;
489+ } ) ;
490+
491+ it ( 'reports missing release metadata without substituting the latest release' , async ( ) => {
492+ spyHttpClient . mockResolvedValueOnce ( {
493+ statusCode : 404 ,
494+ headers : { } ,
495+ result : null
496+ } ) ;
497+ const distribution = new CorrettoDistribution ( {
498+ version : '17.0.0.0.999' ,
499+ architecture : 'x64' ,
500+ packageType : 'jdk' ,
501+ checkLatest : false
502+ } ) ;
503+ mockPlatform ( distribution , 'linux' ) ;
504+ await expect (
505+ distribution [ 'findPackageForDownload' ] ( distribution [ 'version' ] )
506+ ) . rejects . toThrow (
507+ "Corretto release 17.0.0.0.999 was not found in Amazon's GitHub releases or current download catalog"
508+ ) ;
509+ } ) ;
510+
511+ it ( 'does not normalize zero-padded major-only inputs' , ( ) => {
512+ expect (
513+ ( ) =>
514+ new CorrettoDistribution ( {
515+ version : '08' ,
516+ architecture : 'x64' ,
517+ packageType : 'jdk' ,
518+ checkLatest : false
519+ } )
520+ ) . toThrow (
521+ "The string '08' is not valid SemVer notation for a Java version"
522+ ) ;
260523 } ) ;
261524
262525 it ( 'with unfound version throw could not find error' , async ( ) => {
0 commit comments