@@ -9,7 +9,6 @@ import semver = require('semver/preload');
99
1010jest . mock ( 'os' ) ;
1111jest . mock ( '@actions/core' ) ;
12- jest . mock ( 'semver' ) ;
1312jest . mock ( '@actions/core' ) ;
1413jest . mock ( 'fs' , ( ) => ( {
1514 promises : {
@@ -183,7 +182,12 @@ describe('JFrog CLI Configuration', () => {
183182
184183 // Expect the custom server ID to be used.
185184 let customServerId : string = 'custom-server-id' ;
186- jest . spyOn ( core , 'getInput' ) . mockReturnValue ( customServerId ) ;
185+ jest . spyOn ( core , 'getInput' ) . mockImplementation ( ( name : string ) => {
186+ if ( name === customServerId ) {
187+ return 'custom-server-id' ; // Return this value for the specific argument
188+ }
189+ return '' ; // Default return value for other arguments
190+ } ) ;
187191 testConfigCommand ( customServerId ) ;
188192
189193 // Expect the servers env var to include both servers.
@@ -409,7 +413,6 @@ describe('Job Summaries', () => {
409413} ) ;
410414
411415describe ( 'isJobSummarySupported' , ( ) => {
412- const MIN_CLI_VERSION_JOB_SUMMARY : string = '2.66.0' ;
413416 const LATEST_CLI_VERSION : string = 'latest' ;
414417
415418 beforeEach ( ( ) => {
@@ -424,17 +427,13 @@ describe('isJobSummarySupported', () => {
424427 it ( 'should return true if the version is greater than or equal to the minimum supported version' , ( ) => {
425428 const version : string = '2.66.0' ;
426429 jest . spyOn ( core , 'getInput' ) . mockReturnValue ( version ) ;
427- ( semver . gte as jest . Mock ) . mockReturnValue ( true ) ;
428430 expect ( Utils . isJobSummarySupported ( ) ) . toBe ( true ) ;
429- expect ( semver . gte ) . toHaveBeenCalledWith ( version , MIN_CLI_VERSION_JOB_SUMMARY ) ;
430431 } ) ;
431432
432433 it ( 'should return false if the version is less than the minimum supported version' , ( ) => {
433434 const version : string = '2.65.0' ;
434435 jest . spyOn ( core , 'getInput' ) . mockReturnValue ( version ) ;
435- ( semver . gte as jest . Mock ) . mockReturnValue ( false ) ;
436436 expect ( Utils . isJobSummarySupported ( ) ) . toBe ( false ) ;
437- expect ( semver . gte ) . toHaveBeenCalledWith ( version , MIN_CLI_VERSION_JOB_SUMMARY ) ;
438437 } ) ;
439438} ) ;
440439
@@ -740,4 +739,43 @@ describe('handleOidcAuth', () => {
740739 const result : JfrogCredentials = await ( Utils as any ) . handleOidcAuth ( credentials ) ;
741740 expect ( result . accessToken ) . toBe ( 'forced-manual-token' ) ;
742741 } ) ;
742+ it ( 'should include OIDC flags only for supported versions' , ( ) => {
743+ const creds : JfrogCredentials = {
744+ jfrogUrl : 'https://example.jfrog.io' ,
745+ oidcProviderName : 'setup-jfrog-cli' ,
746+ oidcTokenId : 'abc-123' ,
747+ oidcAudience : 'jfrog-github' ,
748+ } as JfrogCredentials ;
749+
750+ jest . spyOn ( core , 'getInput' ) . mockImplementation ( ( name : string ) => {
751+ if ( name === Utils . CLI_VERSION_ARG ) return '2.75.0' ; // Supported version
752+ return '' ;
753+ } ) ;
754+
755+ const args : string [ ] | undefined = Utils . getSeparateEnvConfigArgs ( creds ) ;
756+ expect ( args ) . toContain ( '--oidc-provider-name=setup-jfrog-cli' ) ;
757+ expect ( args ) . toContain ( '--oidc-provider-type=Github' ) ;
758+ expect ( args ) . toContain ( '--oidc-token-id=abc-123' ) ;
759+ expect ( args ) . toContain ( '--oidc-audience=jfrog-github' ) ;
760+ } ) ;
761+
762+ it ( 'should not include OIDC flags for unsupported versions' , ( ) => {
763+ const creds : JfrogCredentials = {
764+ jfrogUrl : 'https://example.jfrog.io' ,
765+ oidcProviderName : 'setup-jfrog-cli' ,
766+ oidcTokenId : 'abc-123' ,
767+ oidcAudience : 'jfrog-github' ,
768+ } as JfrogCredentials ;
769+
770+ jest . spyOn ( core , 'getInput' ) . mockImplementation ( ( name : string ) => {
771+ if ( name === Utils . CLI_VERSION_ARG ) return '2.74.0' ; // Unsupported version
772+ return '' ;
773+ } ) ;
774+
775+ const args : string [ ] | undefined = Utils . getSeparateEnvConfigArgs ( creds ) ;
776+ expect ( args ) . not . toContain ( '--oidc-provider-name=setup-jfrog-cli' ) ;
777+ expect ( args ) . not . toContain ( '--oidc-provider-type=Github' ) ;
778+ expect ( args ) . not . toContain ( '--oidc-token-id=abc-123' ) ;
779+ expect ( args ) . not . toContain ( '--oidc-audience=jfrog-github' ) ;
780+ } ) ;
743781} ) ;
0 commit comments