@@ -3,6 +3,7 @@ import { anyString, mock, instance, when, verify } from "ts-mockito";
33import { AstClient } from "../main/client/AstClient" ;
44import * as fs from "fs" ;
55import * as crypto from "crypto" ;
6+ import * as path from "path" ;
67
78// Mock AstClient and set up an instance from it
89const astClientMock = mock ( AstClient ) ;
@@ -16,23 +17,23 @@ const cxInstallerWindows = new CxInstaller("win32", astClientInstance);
1617describe ( "CxInstaller cases" , ( ) => {
1718 it ( 'CxInstaller getDownloadURL Linux Successful case' , async ( ) => {
1819 const testVersion = '2.3.48' ;
19- jest . spyOn ( cxInstallerLinux as any , 'readASTCLIVersion' ) . mockResolvedValue ( { version : testVersion , checksum : null } ) ;
20+ jest . spyOn ( cxInstallerLinux as any , 'readASTCLIVersion' ) . mockResolvedValue ( { version : testVersion , checksum : 'mock-checksum' } ) ;
2021 const { url } = await cxInstallerLinux . getDownloadURL ( ) ;
2122 const architecture = getArchitecture ( cxInstallerLinux . getPlatform ( ) ) ;
2223 expect ( url ) . toBe ( `https://download.checkmarx.com/CxOne/CLI/${ testVersion } /ast-cli_${ testVersion } _linux_${ architecture } .tar.gz` ) ;
2324 } ) ;
2425
2526 it ( 'CxInstaller getDownloadURL Mac Successful case' , async ( ) => {
2627 const testVersion = '2.3.48' ;
27- jest . spyOn ( cxInstallerMac as any , 'readASTCLIVersion' ) . mockResolvedValue ( { version : testVersion , checksum : null } ) ;
28+ jest . spyOn ( cxInstallerMac as any , 'readASTCLIVersion' ) . mockResolvedValue ( { version : testVersion , checksum : 'mock-checksum' } ) ;
2829 const { url } = await cxInstallerMac . getDownloadURL ( ) ;
2930 const architecture = getArchitecture ( cxInstallerMac . getPlatform ( ) ) ;
3031 expect ( url ) . toBe ( `https://download.checkmarx.com/CxOne/CLI/${ testVersion } /ast-cli_${ testVersion } _darwin_${ architecture } .tar.gz` ) ;
3132 } ) ;
3233
3334 it ( 'CxInstaller getDownloadURL Windows Successful case' , async ( ) => {
3435 const testVersion = '2.3.48' ;
35- jest . spyOn ( cxInstallerWindows as any , 'readASTCLIVersion' ) . mockResolvedValue ( { version : testVersion , checksum : null } ) ;
36+ jest . spyOn ( cxInstallerWindows as any , 'readASTCLIVersion' ) . mockResolvedValue ( { version : testVersion , checksum : 'mock-checksum' } ) ;
3637 const { url } = await cxInstallerWindows . getDownloadURL ( ) ;
3738 const architecture = getArchitecture ( cxInstallerWindows . getPlatform ( ) ) ;
3839 expect ( url ) . toBe ( `https://download.checkmarx.com/CxOne/CLI/${ testVersion } /ast-cli_${ testVersion } _windows_${ architecture } .zip` ) ;
@@ -42,17 +43,17 @@ describe("CxInstaller cases", () => {
4243describe ( "CxInstaller getExecutablePath cases" , ( ) => {
4344 it ( 'CxInstaller getExecutablePath Linux Successful case' , ( ) => {
4445 const executablePath = cxInstallerLinux . getExecutablePath ( ) ;
45- expect ( executablePath ) . toContain ( ` src/ main/ wrapper/ resources/cx` ) ;
46+ expect ( executablePath ) . toContain ( path . join ( ' src' , ' main' , ' wrapper' , ' resources' , 'cx' ) ) ;
4647 } ) ;
4748
4849 it ( 'CxInstaller getExecutablePath Mac Successful case' , ( ) => {
4950 const executablePath = cxInstallerMac . getExecutablePath ( ) ;
50- expect ( executablePath ) . toContain ( ` src/ main/ wrapper/ resources/cx` ) ;
51+ expect ( executablePath ) . toContain ( path . join ( ' src' , ' main' , ' wrapper' , ' resources' , 'cx' ) ) ;
5152 } ) ;
5253
5354 it ( 'CxInstaller getExecutablePath Windows Successful case' , ( ) => {
5455 const executablePath = cxInstallerWindows . getExecutablePath ( ) ;
55- expect ( executablePath ) . toContain ( ` src/ main/ wrapper/ resources/ cx.exe` ) ;
56+ expect ( executablePath ) . toContain ( path . join ( ' src' , ' main' , ' wrapper' , ' resources' , ' cx.exe' ) ) ;
5657 } ) ;
5758} ) ;
5859
@@ -143,13 +144,6 @@ describe("CxInstaller checksum verification cases", () => {
143144 expect ( exitSpy ) . toHaveBeenCalledWith ( 1 ) ;
144145 } ) ;
145146
146- it ( 'CxInstaller null checksum skips verification' , async ( ) => {
147- jest . spyOn ( localLinux as any , 'readASTCLIVersion' ) . mockResolvedValue ( { version : '9.9.99' , checksum : null } ) ;
148- when ( localMock . downloadFile ( anyString ( ) , anyString ( ) ) ) . thenResolve ( ) ;
149- await localLinux . downloadIfNotInstalledCLI ( ) ;
150- expect ( exitSpy ) . not . toHaveBeenCalled ( ) ;
151- } ) ;
152-
153147 it ( 'CxInstaller CX_CLI_LOCATION skips checksum verification' , async ( ) => {
154148 process . env . CX_CLI_LOCATION = 'https://internal.example.com/cli' ;
155149 jest . spyOn ( localLinux as any , 'readASTCLIVersion' ) . mockResolvedValue ( { version : '2.3.48' , checksum : 'irrelevant' } ) ;
0 commit comments