@@ -9,7 +9,6 @@ import semver = require('semver/preload');
9
9
10
10
jest . mock ( 'os' ) ;
11
11
jest . mock ( '@actions/core' ) ;
12
- jest . mock ( 'semver' ) ;
13
12
jest . mock ( '@actions/core' ) ;
14
13
jest . mock ( 'fs' , ( ) => ( {
15
14
promises : {
@@ -183,7 +182,12 @@ describe('JFrog CLI Configuration', () => {
183
182
184
183
// Expect the custom server ID to be used.
185
184
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
+ } ) ;
187
191
testConfigCommand ( customServerId ) ;
188
192
189
193
// Expect the servers env var to include both servers.
@@ -409,7 +413,6 @@ describe('Job Summaries', () => {
409
413
} ) ;
410
414
411
415
describe ( 'isJobSummarySupported' , ( ) => {
412
- const MIN_CLI_VERSION_JOB_SUMMARY : string = '2.66.0' ;
413
416
const LATEST_CLI_VERSION : string = 'latest' ;
414
417
415
418
beforeEach ( ( ) => {
@@ -424,17 +427,13 @@ describe('isJobSummarySupported', () => {
424
427
it ( 'should return true if the version is greater than or equal to the minimum supported version' , ( ) => {
425
428
const version : string = '2.66.0' ;
426
429
jest . spyOn ( core , 'getInput' ) . mockReturnValue ( version ) ;
427
- ( semver . gte as jest . Mock ) . mockReturnValue ( true ) ;
428
430
expect ( Utils . isJobSummarySupported ( ) ) . toBe ( true ) ;
429
- expect ( semver . gte ) . toHaveBeenCalledWith ( version , MIN_CLI_VERSION_JOB_SUMMARY ) ;
430
431
} ) ;
431
432
432
433
it ( 'should return false if the version is less than the minimum supported version' , ( ) => {
433
434
const version : string = '2.65.0' ;
434
435
jest . spyOn ( core , 'getInput' ) . mockReturnValue ( version ) ;
435
- ( semver . gte as jest . Mock ) . mockReturnValue ( false ) ;
436
436
expect ( Utils . isJobSummarySupported ( ) ) . toBe ( false ) ;
437
- expect ( semver . gte ) . toHaveBeenCalledWith ( version , MIN_CLI_VERSION_JOB_SUMMARY ) ;
438
437
} ) ;
439
438
} ) ;
440
439
@@ -740,4 +739,43 @@ describe('handleOidcAuth', () => {
740
739
const result : JfrogCredentials = await ( Utils as any ) . handleOidcAuth ( credentials ) ;
741
740
expect ( result . accessToken ) . toBe ( 'forced-manual-token' ) ;
742
741
} ) ;
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
+ } ) ;
743
781
} ) ;
0 commit comments