@@ -55,7 +55,7 @@ const (
5555 SCSScoreCardError = "SCS scan failed to start: Scorecard scan is missing required flags, please include in the ast-cli arguments: " +
5656 "--scs-repo-url your_repo_url --scs-repo-token your_repo_token"
5757 outputFileName = "test_output.log"
58- noUpdatesForExistingProject = "No applicationId or tags to update. Skipping project update."
58+ noUpdatesForExistingProject = "No tags to update. Skipping project update."
5959)
6060
6161func TestScanHelp (t * testing.T ) {
@@ -193,18 +193,13 @@ func TestCreateScanWithThreshold_ShouldSuccess(t *testing.T) {
193193 execCmdNilAssertion (t , "scan" , "create" , "--project-name" , "MOCK" , "-s" , dummyRepo , "-b" , "dummy_branch" , "--scan-types" , "sast" , "--threshold" , "sca-low=1 ; sast-medium=2" )
194194}
195195
196- func TestScanCreate_ExistingApplicationAndProject_CreateProjectUnderApplicationSuccessfully (t * testing.T ) {
197- execCmdNilAssertion (t , "scan" , "create" , "--project-name" , "MOCK" , "--application-name" , "MOCK" , "-s" , dummyRepo , "-b" , "dummy_branch" )
198- }
199-
200196func TestScanCreate_ApplicationNameIsNotExactMatch_FailedToCreateScan (t * testing.T ) {
201- err := execCmdNotNilAssertion (t , "scan" , "create" , "--project-name" , "MOCK " , "--application-name" , "MOC" , "-s" , dummyRepo , "-b" , "dummy_branch" )
197+ err := execCmdNotNilAssertion (t , "scan" , "create" , "--project-name" , "non-existing-project " , "--application-name" , "MOC" , "-s" , dummyRepo , "-b" , "dummy_branch" )
202198 assert .Assert (t , err .Error () == errorConstants .ApplicationDoesntExistOrNoPermission )
203199}
204200
205- func TestScanCreate_ExistingProjectAndApplicationWithNoPermission_FailedToCreateScan (t * testing.T ) {
206- err := execCmdNotNilAssertion (t , "scan" , "create" , "--project-name" , "MOCK" , "--application-name" , mock .ApplicationDoesntExist , "-s" , dummyRepo , "-b" , "dummy_branch" )
207- assert .Assert (t , err .Error () == errorConstants .ApplicationDoesntExistOrNoPermission )
201+ func TestScanCreate_ExistingProjectAndApplicationWithNoPermission_ShouldCreateScan (t * testing.T ) {
202+ execCmdNilAssertion (t , "scan" , "create" , "--project-name" , "MOCK" , "--application-name" , mock .ApplicationDoesntExist , "-s" , dummyRepo , "-b" , "dummy_branch" )
208203}
209204
210205func TestScanCreate_ExistingApplicationWithNoPermission_FailedToCreateScan (t * testing.T ) {
@@ -213,20 +208,16 @@ func TestScanCreate_ExistingApplicationWithNoPermission_FailedToCreateScan(t *te
213208}
214209
215210func TestScanCreate_OnReceivingHttpBadRequestStatusCode_FailedToCreateScan (t * testing.T ) {
216- err := execCmdNotNilAssertion (t , "scan" , "create" , "--project-name" , "MOCK " , "--application-name" , mock .FakeBadRequest400 , "-s" , dummyRepo , "-b" , "dummy_branch" )
211+ err := execCmdNotNilAssertion (t , "scan" , "create" , "--project-name" , "non-existing-project " , "--application-name" , mock .FakeBadRequest400 , "-s" , dummyRepo , "-b" , "dummy_branch" )
217212 assert .Assert (t , err .Error () == errorConstants .FailedToGetApplication )
218213}
219214
220215func TestScanCreate_OnReceivingHttpInternalServerErrorStatusCode_FailedToCreateScan (t * testing.T ) {
221- err := execCmdNotNilAssertion (t , "scan" , "create" , "--project-name" , "MOCK" , "--application-name" , mock .FakeInternalServerError500 , "-s" , dummyRepo , "-b" , "dummy_branch" )
216+ err := execCmdNotNilAssertion (t , "scan" , "create" , "--project-name" , "non-existing-project" ,
217+ "--application-name" , mock .FakeInternalServerError500 , "-s" , dummyRepo , "-b" , "dummy_branch" )
222218 assert .Assert (t , err .Error () == errorConstants .FailedToGetApplication )
223219}
224220
225- func TestCreateScanInsideApplicationProjectExistNoPermissions (t * testing.T ) {
226- err := execCmdNotNilAssertion (t , "scan" , "create" , "--project-name" , "MOCK" , "--application-name" , mock .NoPermissionApp , "-s" , dummyRepo , "-b" , "dummy_branch" )
227- assert .Assert (t , err .Error () == errorConstants .ApplicationDoesntExistOrNoPermission )
228- }
229-
230221func TestCreateScanSourceDirectory (t * testing.T ) {
231222 baseArgs := []string {"scan" , "create" , "--project-name" , "MOCK" , "-b" , "dummy_branch" }
232223 execCmdNilAssertion (t , append (baseArgs , "-s" , "data" , "--file-filter" , "!.java" )... )
@@ -411,6 +402,23 @@ func TestCreateScan_WhenProjectNotExists_ShouldCreateProjectAndAssignGroup(t *te
411402 assert .Equal (t , strings .Contains (stdoutString , "Updating project groups" ), true , "Expected output: %s" , "Updating project groups" )
412403}
413404
405+ func TestCreateScan_WhenProjectNotExists_ShouldCreateProjectAndAssociateApplication (t * testing.T ) {
406+ file := createOutputFile (t , outputFileName )
407+ defer deleteOutputFile (file )
408+ defer logger .SetOutput (os .Stdout )
409+
410+ baseArgs := []string {"scan" , "create" , "--project-name" , "newProject" , "-s" , "." , "--branch" , "main" , "--application-name" , mock .ExistingApplication , "--debug" }
411+ execCmdNilAssertion (
412+ t ,
413+ baseArgs ... ,
414+ )
415+ stdoutString , err := util .ReadFileAsString (file .Name ())
416+ if err != nil {
417+ t .Fatalf ("Failed to read log file: %v" , err )
418+ }
419+ assert .Equal (t , strings .Contains (stdoutString , "application association done successfully" ), true , "Expected output: %s" , "application association done successfully" )
420+ }
421+
414422func TestScanWorkflowMissingID (t * testing.T ) {
415423 err := execCmdNotNilAssertion (t , "scan" , "workflow" )
416424 assert .Error (t , err , "Please provide a scan ID" , err .Error ())
@@ -624,6 +632,20 @@ func TestCreateScan_WhenProjectExists_ShouldIgnoreGroups(t *testing.T) {
624632 }
625633 assert .Equal (t , strings .Contains (stdoutString , noUpdatesForExistingProject ), true , "Expected output: %s" , noUpdatesForExistingProject )
626634}
635+
636+ func TestCreateScan_WhenProjectExists_ShouldIgnoreApplication (t * testing.T ) {
637+ file := createOutputFile (t , outputFileName )
638+ defer deleteOutputFile (file )
639+ defer logger .SetOutput (os .Stdout )
640+ baseArgs := []string {scanCommand , "create" , "--project-name" , "MOCK" , "-s" , dummyRepo , "-b" , "dummy_branch" ,
641+ "--debug" , "--application-name" , "anyApplication" }
642+ execCmdNilAssertion (t , baseArgs ... )
643+ stdoutString , err := util .ReadFileAsString (file .Name ())
644+ if err != nil {
645+ t .Fatalf ("Failed to read log file: %v" , err )
646+ }
647+ assert .Equal (t , strings .Contains (stdoutString , noUpdatesForExistingProject ), true , "Expected output: %s" , noUpdatesForExistingProject )
648+ }
627649func TestScanCreateLastSastScanTimeWithInvalidValue (t * testing.T ) {
628650 baseArgs := []string {"scan" , "create" , "--project-name" , "MOCK" , "-s" , dummyRepo , "-b" , "dummy_branch" , "--sca-exploitable-path" , "true" , "--sca-last-sast-scan-time" , "notaniteger" }
629651 err := execCmdNotNilAssertion (t , baseArgs ... )
0 commit comments