From 8a91d34f22554929edd63d58fd45f6fd80a7236b Mon Sep 17 00:00:00 2001 From: tamarleviCm Date: Tue, 5 Mar 2024 15:04:28 +0200 Subject: [PATCH 1/7] fix test --- test/integration/project_test.go | 6 ++++-- test/integration/scan_test.go | 13 +++++++------ 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/test/integration/project_test.go b/test/integration/project_test.go index 015f6419b..0c27fb02d 100644 --- a/test/integration/project_test.go +++ b/test/integration/project_test.go @@ -106,12 +106,14 @@ func TestProjectCreate_ApplicationDoesntExist_FailAndReturnErrorMessage(t *testi func TestProjectCreate_ApplicationExists_CreateProjectSuccessfully(t *testing.T) { - err, _ := executeCommand( + err, outBuffer := executeCommand( t, "project", "create", flag(params.FormatFlag), printer.FormatJSON, flag(params.ProjectName), projectNameRandom, flag(params.ApplicationName), "my-application", ) - + createdProject := wrappers.ProjectResponseModel{} + unmarshall(t, outBuffer, &createdProject, "Reading project create response JSON should pass") + defer deleteProject(t, createdProject.ID) assert.NilError(t, err) } diff --git a/test/integration/scan_test.go b/test/integration/scan_test.go index d738f5c69..a447c5c3e 100644 --- a/test/integration/scan_test.go +++ b/test/integration/scan_test.go @@ -68,7 +68,7 @@ func TestScanCreateEmptyProjectName(t *testing.T) { assertError(t, err, "Project name is required") // Creating a scan with empty project name should fail } -func TestScanCreate_ExistingApplicationAndExistingProject_CreateScanSuccessfully(t *testing.T) { +func TestScanCreateUpdateProjectWithApplication(t *testing.T) { args := []string{ "scan", "create", flag(params.ApplicationName), "my-application", @@ -82,7 +82,7 @@ func TestScanCreate_ExistingApplicationAndExistingProject_CreateScanSuccessfully assert.NilError(t, err) } -func TestScanCreate_ExistingApplicationAndNotExistingProject_CreatingNewProjectAndCreateScanSuccessfully(t *testing.T) { +func TestScanCreateWithApplication(t *testing.T) { args := []string{ "scan", "create", flag(params.ApplicationName), "my-application", @@ -91,12 +91,13 @@ func TestScanCreate_ExistingApplicationAndNotExistingProject_CreatingNewProjectA flag(params.ScanTypes), "sast", flag(params.BranchFlag), "dummy_branch", } - - err, _ := executeCommand(t, args...) - assert.NilError(t, err) + scanID, projectID := executeCreateScan(t, args) + defer deleteProject(t, projectID) + assert.Assert(t, scanID != "", "Scan ID should not be empty") + assert.Assert(t, projectID != "", "Project ID should not be empty") } -func TestScanCreate_ApplicationDoesntExist_FailScanWithError(t *testing.T) { +func TestScanCreateApplicationDoesntExist(t *testing.T) { args := []string{ "scan", "create", flag(params.ApplicationName), "application-that-doesnt-exist", From ee36665759a5c751270017138f6cf22135028164 Mon Sep 17 00:00:00 2001 From: tamarleviCm Date: Wed, 6 Mar 2024 10:41:06 +0200 Subject: [PATCH 2/7] fix test --- test/integration/scan_test.go | 1 + 1 file changed, 1 insertion(+) diff --git a/test/integration/scan_test.go b/test/integration/scan_test.go index a447c5c3e..15d40cb16 100644 --- a/test/integration/scan_test.go +++ b/test/integration/scan_test.go @@ -90,6 +90,7 @@ func TestScanCreateWithApplication(t *testing.T) { flag(params.SourcesFlag), ".", flag(params.ScanTypes), "sast", flag(params.BranchFlag), "dummy_branch", + flag(params.ScanInfoFormatFlag), printer.FormatJSON, } scanID, projectID := executeCreateScan(t, args) defer deleteProject(t, projectID) From 258d756ef908dd5b4cffd4c094308708ba0a9347 Mon Sep 17 00:00:00 2001 From: tamarleviCm Date: Wed, 6 Mar 2024 12:02:06 +0200 Subject: [PATCH 3/7] names --- test/integration/scan_test.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/test/integration/scan_test.go b/test/integration/scan_test.go index 15d40cb16..650b22112 100644 --- a/test/integration/scan_test.go +++ b/test/integration/scan_test.go @@ -68,7 +68,7 @@ func TestScanCreateEmptyProjectName(t *testing.T) { assertError(t, err, "Project name is required") // Creating a scan with empty project name should fail } -func TestScanCreateUpdateProjectWithApplication(t *testing.T) { +func TestScanCreate_ExistingApplicationAndExistingProject_CreateScanSuccessfully(t *testing.T) { args := []string{ "scan", "create", flag(params.ApplicationName), "my-application", @@ -82,7 +82,7 @@ func TestScanCreateUpdateProjectWithApplication(t *testing.T) { assert.NilError(t, err) } -func TestScanCreateWithApplication(t *testing.T) { +func TestScanCreate_ExistingApplicationAndNotExistingProject_CreatingNewProjectAndCreateScanSuccessfully(t *testing.T) { args := []string{ "scan", "create", flag(params.ApplicationName), "my-application", @@ -98,7 +98,7 @@ func TestScanCreateWithApplication(t *testing.T) { assert.Assert(t, projectID != "", "Project ID should not be empty") } -func TestScanCreateApplicationDoesntExist(t *testing.T) { +func TestScanCreate_ApplicationDoesntExist_FailScanWithError(t *testing.T) { args := []string{ "scan", "create", flag(params.ApplicationName), "application-that-doesnt-exist", From 1e3e7fbd483d13931502e5515f8dccc526905719 Mon Sep 17 00:00:00 2001 From: tamarleviCm Date: Wed, 6 Mar 2024 12:56:50 +0200 Subject: [PATCH 4/7] crypto --- go.mod | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/go.mod b/go.mod index db66c9b9d..fc9a08438 100644 --- a/go.mod +++ b/go.mod @@ -15,7 +15,7 @@ require ( github.com/spf13/cobra v1.8.0 github.com/spf13/viper v1.18.2 github.com/tomnomnom/linkheader v0.0.0-20180905144013-02ca5825eb80 - golang.org/x/crypto v0.18.0 + golang.org/x/crypto v0.21.0 golang.org/x/text v0.14.0 gotest.tools v2.2.0+incompatible ) @@ -39,7 +39,7 @@ require ( go.uber.org/atomic v1.9.0 // indirect go.uber.org/multierr v1.9.0 // indirect golang.org/x/exp v0.0.0-20230905200255-921286631fa9 // indirect - golang.org/x/sys v0.16.0 // indirect + golang.org/x/sys v0.18.0 // indirect gopkg.in/ini.v1 v1.67.0 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect ) From a386a2c9bd8bef1a8e02cf61697ef7cebdc2e4e5 Mon Sep 17 00:00:00 2001 From: tamarleviCm Date: Wed, 6 Mar 2024 13:29:36 +0200 Subject: [PATCH 5/7] crypto --- go.mod | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/go.mod b/go.mod index fc9a08438..db66c9b9d 100644 --- a/go.mod +++ b/go.mod @@ -15,7 +15,7 @@ require ( github.com/spf13/cobra v1.8.0 github.com/spf13/viper v1.18.2 github.com/tomnomnom/linkheader v0.0.0-20180905144013-02ca5825eb80 - golang.org/x/crypto v0.21.0 + golang.org/x/crypto v0.18.0 golang.org/x/text v0.14.0 gotest.tools v2.2.0+incompatible ) @@ -39,7 +39,7 @@ require ( go.uber.org/atomic v1.9.0 // indirect go.uber.org/multierr v1.9.0 // indirect golang.org/x/exp v0.0.0-20230905200255-921286631fa9 // indirect - golang.org/x/sys v0.18.0 // indirect + golang.org/x/sys v0.16.0 // indirect gopkg.in/ini.v1 v1.67.0 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect ) From 4e3d9c97eb8a32bb35585da098f19e0912729c43 Mon Sep 17 00:00:00 2001 From: tamarleviCm Date: Wed, 6 Mar 2024 15:47:37 +0200 Subject: [PATCH 6/7] adding assert --- test/integration/project_test.go | 1 + 1 file changed, 1 insertion(+) diff --git a/test/integration/project_test.go b/test/integration/project_test.go index 0c27fb02d..dfb0d836d 100644 --- a/test/integration/project_test.go +++ b/test/integration/project_test.go @@ -115,6 +115,7 @@ func TestProjectCreate_ApplicationExists_CreateProjectSuccessfully(t *testing.T) unmarshall(t, outBuffer, &createdProject, "Reading project create response JSON should pass") defer deleteProject(t, createdProject.ID) assert.NilError(t, err) + assert.Assert(t, createdProject.ID != "", "Project ID should not be empty") } func TestCreateWithInvalidGroup(t *testing.T) { From 048b0459662a88c27d771646fc4990a7fd4861f6 Mon Sep 17 00:00:00 2001 From: tamarleviCm Date: Thu, 7 Mar 2024 12:48:40 +0200 Subject: [PATCH 7/7] adding application ids to project creation print --- internal/commands/project.go | 26 ++++++++++++++------------ test/integration/project_test.go | 1 + 2 files changed, 15 insertions(+), 12 deletions(-) diff --git a/internal/commands/project.go b/internal/commands/project.go index 22667cc39..7ed7b09c7 100644 --- a/internal/commands/project.go +++ b/internal/commands/project.go @@ -545,20 +545,22 @@ func toProjectViews(models []wrappers.ProjectResponseModel) []projectView { func toProjectView(model wrappers.ProjectResponseModel) projectView { //nolint:gocritic return projectView{ - ID: model.ID, - Name: model.Name, - CreatedAt: model.CreatedAt, - UpdatedAt: model.UpdatedAt, - Tags: model.Tags, - Groups: model.Groups, + ID: model.ID, + Name: model.Name, + CreatedAt: model.CreatedAt, + UpdatedAt: model.UpdatedAt, + Tags: model.Tags, + Groups: model.Groups, + ApplicationIds: model.ApplicationIds, } } type projectView struct { - ID string `format:"name:Project ID"` - Name string - CreatedAt time.Time `format:"name:Created at;time:01-02-06 15:04:05"` - UpdatedAt time.Time `format:"name:Updated at;time:01-02-06 15:04:05"` - Tags map[string]string - Groups []string + ID string `format:"name:Project ID"` + Name string + CreatedAt time.Time `format:"name:Created at;time:01-02-06 15:04:05"` + UpdatedAt time.Time `format:"name:Updated at;time:01-02-06 15:04:05"` + Tags map[string]string + Groups []string + ApplicationIds []string } diff --git a/test/integration/project_test.go b/test/integration/project_test.go index dfb0d836d..953703209 100644 --- a/test/integration/project_test.go +++ b/test/integration/project_test.go @@ -116,6 +116,7 @@ func TestProjectCreate_ApplicationExists_CreateProjectSuccessfully(t *testing.T) defer deleteProject(t, createdProject.ID) assert.NilError(t, err) assert.Assert(t, createdProject.ID != "", "Project ID should not be empty") + assert.Assert(t, len(createdProject.ApplicationIds) == 1, "The project must be connected to the application") } func TestCreateWithInvalidGroup(t *testing.T) {