From 93c4ea61aa8393fe5467a4cc9dc412f9a7b802bf Mon Sep 17 00:00:00 2001 From: Valentin <16714035+bitmaskit@users.noreply.github.com> Date: Mon, 23 Dec 2024 13:33:12 +0200 Subject: [PATCH] Revert "Fix deployment failure with CF if password contains special char (#5197)" (#5215) This reverts commit 8205624a22920f2ebe1e7999bf1b384aeae04e5d. Co-authored-by: Valentin Uchkunev --- cmd/abapEnvironmentCreateSystem_test.go | 4 +- ...abapEnvironmentPushATCSystemConfig_test.go | 38 +++++------ cmd/abapEnvironmentRunATCCheck_test.go | 20 +++--- cmd/abapEnvironmentRunAUnitTest_test.go | 8 +-- ...pLandscapePortalUpdateAddOnProduct_test.go | 2 - cmd/cloudFoundryCreateServiceKey_test.go | 19 +++--- cmd/cloudFoundryCreateService_test.go | 41 ++++++------ cmd/gcpPublishEvent_test.go | 2 - cmd/integrationArtifactDeploy_test.go | 5 +- cmd/integrationArtifactTransport.go | 3 +- cmd/malwareExecuteScan_test.go | 36 +++++------ cmd/readPipelineEnv_test.go | 2 - pkg/abaputils/abaputils.go | 48 +++++++------- pkg/abaputils/abaputils_test.go | 2 +- pkg/abaputils/sap_com_0510.go | 4 +- pkg/abaputils/sap_com_0948.go | 4 +- pkg/cloudfoundry/Authentication.go | 56 +++++++---------- pkg/cloudfoundry/Authentication_test.go | 63 ------------------- pkg/cloudfoundry/CloudFoundry_test.go | 21 ++++--- pkg/cloudfoundry/ManifestUtils_test.go | 1 + pkg/cloudfoundry/Vars_test.go | 1 + pkg/cpi/mockingUtils.go | 12 ++-- 22 files changed, 158 insertions(+), 234 deletions(-) delete mode 100644 pkg/cloudfoundry/Authentication_test.go diff --git a/cmd/abapEnvironmentCreateSystem_test.go b/cmd/abapEnvironmentCreateSystem_test.go index 667c999c7d..770eafd59e 100644 --- a/cmd/abapEnvironmentCreateSystem_test.go +++ b/cmd/abapEnvironmentCreateSystem_test.go @@ -32,7 +32,7 @@ func TestRunAbapEnvironmentCreateSystem(t *testing.T) { err := runAbapEnvironmentCreateSystem(&config, nil, cf, u) if assert.NoError(t, err) { assert.Equal(t, []mock.ExecCall{ - {Execution: (*mock.Execution)(nil), Async: false, Exec: "cf", Params: []string{"login", "-a", "https://api.endpoint.com", "-o", "testOrg", "-s", "testSpace", "-u", "'testUser'", "-p", "'testPassword'"}}, + {Execution: (*mock.Execution)(nil), Async: false, Exec: "cf", Params: []string{"login", "-a", "https://api.endpoint.com", "-o", "testOrg", "-s", "testSpace", "-u", "testUser", "-p", "testPassword"}}, {Execution: (*mock.Execution)(nil), Async: false, Exec: "cf", Params: []string{"create-service", config.CfService, config.CfServicePlan, config.CfServiceInstance, "-c", "{\"is_development_allowed\":false}", "--wait"}}, {Execution: (*mock.Execution)(nil), Async: false, Exec: "cf", Params: []string{"logout"}}}, m.Calls) @@ -79,7 +79,7 @@ func TestRunAbapEnvironmentCreateSystem(t *testing.T) { err = runAbapEnvironmentCreateSystem(&config, nil, cf, u) if assert.NoError(t, err) { assert.Equal(t, []mock.ExecCall{ - {Execution: (*mock.Execution)(nil), Async: false, Exec: "cf", Params: []string{"login", "-a", "https://api.endpoint.com", "-o", "testOrg", "-s", "testSpace", "-u", "'testUser'", "-p", "'testPassword'"}}, + {Execution: (*mock.Execution)(nil), Async: false, Exec: "cf", Params: []string{"login", "-a", "https://api.endpoint.com", "-o", "testOrg", "-s", "testSpace", "-u", "testUser", "-p", "testPassword"}}, {Execution: (*mock.Execution)(nil), Async: false, Exec: "cf", Params: []string{"create-service-push", "--no-push", "--service-manifest", "customManifest.yml"}}, {Execution: (*mock.Execution)(nil), Async: false, Exec: "cf", Params: []string{"logout"}}}, m.Calls) diff --git a/cmd/abapEnvironmentPushATCSystemConfig_test.go b/cmd/abapEnvironmentPushATCSystemConfig_test.go index d57b626bf3..66c6c7d65b 100644 --- a/cmd/abapEnvironmentPushATCSystemConfig_test.go +++ b/cmd/abapEnvironmentPushATCSystemConfig_test.go @@ -28,8 +28,8 @@ func TestFetchXcsrfTokenFromHead(t *testing.T) { Password: "Test", URL: "https://api.endpoint.com/Entity/", } - token, err := fetchXcsrfTokenFromHead(con, client) - if err == nil { + token, error := fetchXcsrfTokenFromHead(con, client) + if error == nil { assert.Equal(t, tokenExpected, token) } }) @@ -46,8 +46,8 @@ func TestFetchXcsrfTokenFromHead(t *testing.T) { Password: "Test", URL: "https://api.endpoint.com/Entity/", } - token, err := fetchXcsrfTokenFromHead(con, client) - if err == nil { + token, error := fetchXcsrfTokenFromHead(con, client) + if error == nil { assert.Equal(t, tokenExpected, token) } }) @@ -77,39 +77,39 @@ func TestHandleHttpResponse(t *testing.T) { --B772E21DAA42B9571C778276B829D6C20 Content-Type: multipart/mixed; boundary=B772E21DAA42B9571C778276B829D6C21 Content-Length: 1973 - + --B772E21DAA42B9571C778276B829D6C21 Content-Type: application/http Content-Length: 646 content-transfer-encoding: binary content-id: 1 - + HTTP/1.1 200 OK Content-Type: application/json;odata.metadata=minimal;charset=utf-8 Content-Length: 465 odata-version: 4.0 cache-control: no-cache, no-store, must-revalidate - + {"@odata.context":"$metadata#configuration/$entity","@odata.metadataEtag":"W/\"20220211135922\"","root_id":"1","conf_id":"aef8f52b-fe16-1edc-a3fe-27a1e0226c7b","conf_name":"Z_CONFIG_VIA_PIPELINE_STEP","checkvariant":"ABAP_CLOUD_DEVELOPMENT_DEFAULT","pseudo_comment_policy":"SP","last_changed_by":"CC0000000017","last_changed_at":"2022-03-02T11:16:51.336172Z","block_findings":"0","inform_findings":"1","transport_check_policy":"C","check_tasks":true,"check_requests":false,"check_tocs":true,"is_default":false,"is_proxy_variant":false,"SAP__Messages":[]} --B772E21DAA42B9571C778276B829D6C21 Content-Type: application/http Content-Length: 428 content-transfer-encoding: binary content-id: 2 - + HTTP/1.1 200 OK Content-Type: application/json;odata.metadata=minimal;charset=utf-8 Content-Length: 247 odata-version: 4.0 cache-control: no-cache, no-store, must-revalidate - + {"@odata.context":"$metadata#priority/$entity","@odata.metadataEtag":"W/\"20220211135922\"","root_id":"1","conf_id":"aef8f52b-fe16-1edc-a3fe-27a1e0226c7b","test":"CL_CI_ARS_COMPATIBILITY_CHECK","message_id":"010","default_priority":1,"priority":2} --B772E21DAA42B9571C778276B829D6C21 Content-Type: application/http Content-Length: 428 content-transfer-encoding: binary content-id: 3 - + HTTP/1.1 4** OK Content-Type: application/json;odata.metadata=minimal;charset=utf-8 Content-Length: 247 @@ -118,7 +118,7 @@ cache-control: no-cache, no-store, must-revalidate {"Some Error Messages possible in here!"} --B772E21DAA42B9571C778276B829D6C21-- - + --B772E21DAA42B9571C778276B829D6C20--` client := &abaputils.ClientMock{ @@ -150,39 +150,39 @@ cache-control: no-cache, no-store, must-revalidate --B772E21DAA42B9571C778276B829D6C20 Content-Type: multipart/mixed; boundary=B772E21DAA42B9571C778276B829D6C21 Content-Length: 1973 - + --B772E21DAA42B9571C778276B829D6C21 Content-Type: application/http Content-Length: 646 content-transfer-encoding: binary content-id: 1 - + HTTP/1.1 200 OK Content-Type: application/json;odata.metadata=minimal;charset=utf-8 Content-Length: 465 odata-version: 4.0 cache-control: no-cache, no-store, must-revalidate - + {"@odata.context":"$metadata#configuration/$entity","@odata.metadataEtag":"W/\"20220211135922\"","root_id":"1","conf_id":"aef8f52b-fe16-1edc-a3fe-27a1e0226c7b","conf_name":"Z_CONFIG_VIA_PIPELINE_STEP","checkvariant":"ABAP_CLOUD_DEVELOPMENT_DEFAULT","pseudo_comment_policy":"SP","last_changed_by":"CC0000000017","last_changed_at":"2022-03-02T11:16:51.336172Z","block_findings":"0","inform_findings":"1","transport_check_policy":"C","check_tasks":true,"check_requests":false,"check_tocs":true,"is_default":false,"is_proxy_variant":false,"SAP__Messages":[]} --B772E21DAA42B9571C778276B829D6C21 Content-Type: application/http Content-Length: 428 content-transfer-encoding: binary content-id: 2 - + HTTP/1.1 200 OK Content-Type: application/json;odata.metadata=minimal;charset=utf-8 Content-Length: 247 odata-version: 4.0 cache-control: no-cache, no-store, must-revalidate - + {"@odata.context":"$metadata#priority/$entity","@odata.metadataEtag":"W/\"20220211135922\"","root_id":"1","conf_id":"aef8f52b-fe16-1edc-a3fe-27a1e0226c7b","test":"CL_CI_ARS_COMPATIBILITY_CHECK","message_id":"010","default_priority":1,"priority":2} --B772E21DAA42B9571C778276B829D6C21 Content-Type: application/http Content-Length: 428 content-transfer-encoding: binary content-id: 3 - + HTTP/1.1 200 OK Content-Type: application/json;odata.metadata=minimal;charset=utf-8 Content-Length: 247 @@ -191,7 +191,7 @@ cache-control: no-cache, no-store, must-revalidate {"@odata.context":"$metadata#priority/$entity","@odata.metadataEtag":"W/\"20220211135922\"","root_id":"1","conf_id":"aef8f52b-fe16-1edc-a3fe-27a1e0226c7b","test":"CL_CI_ARS_COMPATIBILITY_CHECK","message_id":"011","default_priority":2,"priority":1} --B772E21DAA42B9571C778276B829D6C21-- - + --B772E21DAA42B9571C778276B829D6C20--` client := &abaputils.ClientMock{ @@ -328,7 +328,7 @@ Content-Type: application/json "transport_check_policy": "C", "check_tasks": true, "check_requests": false, - "check_tocs": true, + "check_tocs": true, "_priorities": [ { "test": "CL_CI_TEST_AMDP_HDB_MIGRATION", diff --git a/cmd/abapEnvironmentRunATCCheck_test.go b/cmd/abapEnvironmentRunATCCheck_test.go index e0d6104747..ea607c5f32 100644 --- a/cmd/abapEnvironmentRunATCCheck_test.go +++ b/cmd/abapEnvironmentRunATCCheck_test.go @@ -29,9 +29,9 @@ func TestHostConfig(t *testing.T) { Exec: execRunner, } var con abaputils.ConnectionDetailsHTTP - con, err := autils.GetAbapCommunicationArrangementInfo(options.AbapEnvOptions, "") + con, error := autils.GetAbapCommunicationArrangementInfo(options.AbapEnvOptions, "") - if err == nil { + if error == nil { assert.Equal(t, "testUser", con.User) assert.Equal(t, "testPassword", con.Password) assert.Equal(t, "https://api.endpoint.com", con.URL) @@ -82,8 +82,8 @@ func TestHostConfig(t *testing.T) { Exec: execRunner, } var con abaputils.ConnectionDetailsHTTP - con, err := autils.GetAbapCommunicationArrangementInfo(options.AbapEnvOptions, "") - if err == nil { + con, error := autils.GetAbapCommunicationArrangementInfo(options.AbapEnvOptions, "") + if error == nil { assert.Equal(t, "", con.User) assert.Equal(t, "", con.Password) assert.Equal(t, "", con.URL) @@ -106,8 +106,8 @@ func TestATCTrigger(t *testing.T) { Password: "Test", URL: "https://api.endpoint.com/Entity/", } - resp, err := runATC("GET", con, []byte(client.Body), client) - if err == nil { + resp, error := runATC("GET", con, []byte(client.Body), client) + if error == nil { assert.Equal(t, tokenExpected, resp.Header["X-Csrf-Token"][0]) assert.Equal(t, int64(0), resp.ContentLength) assert.Equal(t, []string([]string(nil)), resp.Header["Location"]) @@ -129,8 +129,8 @@ func TestFetchXcsrfToken(t *testing.T) { Password: "Test", URL: "https://api.endpoint.com/Entity/", } - token, err := fetchXcsrfToken("GET", con, []byte(client.Body), client) - if err == nil { + token, error := fetchXcsrfToken("GET", con, []byte(client.Body), client) + if error == nil { assert.Equal(t, tokenExpected, token) } }) @@ -147,8 +147,8 @@ func TestFetchXcsrfToken(t *testing.T) { Password: "Test", URL: "https://api.endpoint.com/Entity/", } - token, err := fetchXcsrfToken("GET", con, []byte(client.Body), client) - if err == nil { + token, error := fetchXcsrfToken("GET", con, []byte(client.Body), client) + if error == nil { assert.Equal(t, tokenExpected, token) } }) diff --git a/cmd/abapEnvironmentRunAUnitTest_test.go b/cmd/abapEnvironmentRunAUnitTest_test.go index 73f64006e5..89c153e124 100644 --- a/cmd/abapEnvironmentRunAUnitTest_test.go +++ b/cmd/abapEnvironmentRunAUnitTest_test.go @@ -582,8 +582,8 @@ func TestRunAbapEnvironmentRunAUnitTest(t *testing.T) { Password: "Test", URL: "https://api.endpoint.com/Entity/", } - token, err := fetchAUnitXcsrfToken("GET", con, []byte(client.Body), client) - if assert.Equal(t, nil, err) { + token, error := fetchAUnitXcsrfToken("GET", con, []byte(client.Body), client) + if assert.Equal(t, nil, error) { assert.Equal(t, tokenExpected, token) } }) @@ -603,8 +603,8 @@ func TestRunAbapEnvironmentRunAUnitTest(t *testing.T) { Password: "Test", URL: "https://api.endpoint.com/Entity/", } - token, err := fetchAUnitXcsrfToken("GET", con, []byte(client.Body), client) - if assert.Equal(t, nil, err) { + token, error := fetchAUnitXcsrfToken("GET", con, []byte(client.Body), client) + if assert.Equal(t, nil, error) { assert.Equal(t, tokenExpected, token) } }) diff --git a/cmd/abapLandscapePortalUpdateAddOnProduct_test.go b/cmd/abapLandscapePortalUpdateAddOnProduct_test.go index d8d458d93f..7c1725db3f 100644 --- a/cmd/abapLandscapePortalUpdateAddOnProduct_test.go +++ b/cmd/abapLandscapePortalUpdateAddOnProduct_test.go @@ -1,5 +1,3 @@ -//go:build unit - package cmd import ( diff --git a/cmd/cloudFoundryCreateServiceKey_test.go b/cmd/cloudFoundryCreateServiceKey_test.go index b2c1172e80..dc886c7332 100644 --- a/cmd/cloudFoundryCreateServiceKey_test.go +++ b/cmd/cloudFoundryCreateServiceKey_test.go @@ -1,4 +1,5 @@ //go:build unit +// +build unit package cmd @@ -29,8 +30,8 @@ func TestCloudFoundryCreateServiceKey(t *testing.T) { cfUtilsMock := cloudfoundry.CfUtilsMock{} defer cfUtilsMock.Cleanup() - err := runCloudFoundryCreateServiceKey(&config, &telemetryData, &execRunner, &cfUtilsMock) - if err == nil { + error := runCloudFoundryCreateServiceKey(&config, &telemetryData, &execRunner, &cfUtilsMock) + if error == nil { assert.Equal(t, "cf", execRunner.Calls[0].Exec) assert.Equal(t, []string{"create-service-key", "testInstance", "testKey"}, execRunner.Calls[0].Params) } @@ -51,7 +52,8 @@ func TestCloudFoundryCreateServiceKey(t *testing.T) { cfUtilsMock := cloudfoundry.CfUtilsMock{} defer cfUtilsMock.Cleanup() - if err := runCloudFoundryCreateServiceKey(&config, &telemetryData, &execRunner, &cfUtilsMock); err == nil { + error := runCloudFoundryCreateServiceKey(&config, &telemetryData, &execRunner, &cfUtilsMock) + if error == nil { assert.Equal(t, "cf", execRunner.Calls[0].Exec) assert.Equal(t, []string{"create-service-key", "testInstance", "testKey", "-c", "testconfig.yml"}, execRunner.Calls[0].Params) } @@ -72,7 +74,8 @@ func TestCloudFoundryCreateServiceKey(t *testing.T) { cfUtilsMock := cloudfoundry.CfUtilsMock{} defer cfUtilsMock.Cleanup() - if err := runCloudFoundryCreateServiceKey(&config, &telemetryData, &execRunner, &cfUtilsMock); err == nil { + error := runCloudFoundryCreateServiceKey(&config, &telemetryData, &execRunner, &cfUtilsMock) + if error == nil { assert.Equal(t, "cf", execRunner.Calls[0].Exec) assert.Equal(t, []string{"create-service-key", "testInstance", "testKey", "-c", "{\"scenario_id\":\"SAP_COM_0510\",\"type\":\"basic\"}", cfCliSynchronousRequestFlag}, execRunner.Calls[0].Params) } @@ -100,8 +103,8 @@ func TestCloudFoundryCreateServiceKeyErrorMessages(t *testing.T) { } defer cfUtilsMock.Cleanup() - err := runCloudFoundryCreateServiceKey(&config, &telemetryData, &execRunner, &cfUtilsMock) - assert.Equal(t, err.Error(), "Error while logging in occurred: "+errorMessage, "Wrong error message") + error := runCloudFoundryCreateServiceKey(&config, &telemetryData, &execRunner, &cfUtilsMock) + assert.Equal(t, error.Error(), "Error while logging in occurred: "+errorMessage, "Wrong error message") }) t.Run("CF Logout Error", func(t *testing.T) { @@ -149,7 +152,7 @@ func TestCloudFoundryCreateServiceKeyErrorMessages(t *testing.T) { } defer cfUtilsMock.Cleanup() - err := runCloudFoundryCreateServiceKey(&config, &telemetryData, &execRunner, &cfUtilsMock) - assert.Equal(t, err.Error(), "Failed to Create Service Key: "+errorMessage, "Wrong error message") + error := runCloudFoundryCreateServiceKey(&config, &telemetryData, &execRunner, &cfUtilsMock) + assert.Equal(t, error.Error(), "Failed to Create Service Key: "+errorMessage, "Wrong error message") }) } diff --git a/cmd/cloudFoundryCreateService_test.go b/cmd/cloudFoundryCreateService_test.go index 5ccab894ab..1af31a4ebd 100644 --- a/cmd/cloudFoundryCreateService_test.go +++ b/cmd/cloudFoundryCreateService_test.go @@ -1,4 +1,5 @@ //go:build unit +// +build unit package cmd @@ -37,9 +38,9 @@ func TestCloudFoundryCreateService(t *testing.T) { CfServicePlan: "testPlan", CfAsync: false, } - err := runCloudFoundryCreateService(&config, &telemetryData, cf) - if assert.NoError(t, err) { - assert.Equal(t, []mock.ExecCall{{Execution: (*mock.Execution)(nil), Async: false, Exec: "cf", Params: []string{"login", "-a", "https://api.endpoint.com", "-o", "testOrg", "-s", "testSpace", "-u", "'testUser'", "-p", "'testPassword'"}}, + error := runCloudFoundryCreateService(&config, &telemetryData, cf) + if assert.NoError(t, error) { + assert.Equal(t, []mock.ExecCall{{Execution: (*mock.Execution)(nil), Async: false, Exec: "cf", Params: []string{"login", "-a", "https://api.endpoint.com", "-o", "testOrg", "-s", "testSpace", "-u", "testUser", "-p", "testPassword"}}, {Execution: (*mock.Execution)(nil), Async: false, Exec: "cf", Params: []string{"create-service", "testService", "testPlan", "testName", "--wait"}}, {Execution: (*mock.Execution)(nil), Async: false, Exec: "cf", Params: []string{"logout"}}}, m.Calls) @@ -60,9 +61,9 @@ func TestCloudFoundryCreateService(t *testing.T) { CfServiceTags: "testTag, testTag2", CfAsync: true, } - err := runCloudFoundryCreateService(&config, &telemetryData, cf) - if assert.NoError(t, err) { - assert.Equal(t, []mock.ExecCall{{Execution: (*mock.Execution)(nil), Async: false, Exec: "cf", Params: []string{"login", "-a", "https://api.endpoint.com", "-o", "testOrg", "-s", "testSpace", "-u", "'testUser'", "-p", "'testPassword'"}}, + error := runCloudFoundryCreateService(&config, &telemetryData, cf) + if assert.NoError(t, error) { + assert.Equal(t, []mock.ExecCall{{Execution: (*mock.Execution)(nil), Async: false, Exec: "cf", Params: []string{"login", "-a", "https://api.endpoint.com", "-o", "testOrg", "-s", "testSpace", "-u", "testUser", "-p", "testPassword"}}, {Execution: (*mock.Execution)(nil), Async: false, Exec: "cf", Params: []string{"create-service", "testService", "testPlan", "testName", "-t", "testTag, testTag2"}}, {Execution: (*mock.Execution)(nil), Async: false, Exec: "cf", Params: []string{"logout"}}}, m.Calls) @@ -82,9 +83,9 @@ func TestCloudFoundryCreateService(t *testing.T) { CfServiceBroker: "testBroker", CfAsync: true, } - err := runCloudFoundryCreateService(&config, &telemetryData, cf) - if assert.NoError(t, err) { - assert.Equal(t, []mock.ExecCall{{Execution: (*mock.Execution)(nil), Async: false, Exec: "cf", Params: []string{"login", "-a", "https://api.endpoint.com", "-o", "testOrg", "-s", "testSpace", "-u", "'testUser'", "-p", "'testPassword'"}}, + error := runCloudFoundryCreateService(&config, &telemetryData, cf) + if assert.NoError(t, error) { + assert.Equal(t, []mock.ExecCall{{Execution: (*mock.Execution)(nil), Async: false, Exec: "cf", Params: []string{"login", "-a", "https://api.endpoint.com", "-o", "testOrg", "-s", "testSpace", "-u", "testUser", "-p", "testPassword"}}, {Execution: (*mock.Execution)(nil), Async: false, Exec: "cf", Params: []string{"create-service", "testService", "testPlan", "testName", "-b", "testBroker"}}, {Execution: (*mock.Execution)(nil), Async: false, Exec: "cf", Params: []string{"logout"}}}, m.Calls) @@ -104,9 +105,9 @@ func TestCloudFoundryCreateService(t *testing.T) { CfCreateServiceConfig: "testConfig.json", CfAsync: true, } - err := runCloudFoundryCreateService(&config, &telemetryData, cf) - if assert.NoError(t, err) { - assert.Equal(t, []mock.ExecCall{{Execution: (*mock.Execution)(nil), Async: false, Exec: "cf", Params: []string{"login", "-a", "https://api.endpoint.com", "-o", "testOrg", "-s", "testSpace", "-u", "'testUser'", "-p", "'testPassword'"}}, + error := runCloudFoundryCreateService(&config, &telemetryData, cf) + if assert.NoError(t, error) { + assert.Equal(t, []mock.ExecCall{{Execution: (*mock.Execution)(nil), Async: false, Exec: "cf", Params: []string{"login", "-a", "https://api.endpoint.com", "-o", "testOrg", "-s", "testSpace", "-u", "testUser", "-p", "testPassword"}}, {Execution: (*mock.Execution)(nil), Async: false, Exec: "cf", Params: []string{"create-service", "testService", "testPlan", "testName", "-c", "testConfig.json"}}, {Execution: (*mock.Execution)(nil), Async: false, Exec: "cf", Params: []string{"logout"}}}, m.Calls) @@ -116,8 +117,8 @@ func TestCloudFoundryCreateService(t *testing.T) { t.Run("Create service: failure, no config", func(t *testing.T) { defer cfMockCleanup(m) config := cloudFoundryCreateServiceOptions{} - err := runCloudFoundryCreateService(&config, &telemetryData, cf) - assert.EqualError(t, err, "Error while logging in: Failed to login to Cloud Foundry: Parameters missing. Please provide the Cloud Foundry Endpoint, Org, Space, Username and Password") + error := runCloudFoundryCreateService(&config, &telemetryData, cf) + assert.EqualError(t, error, "Error while logging in: Failed to login to Cloud Foundry: Parameters missing. Please provide the Cloud Foundry Endpoint, Org, Space, Username and Password") }) t.Run("Create service: variable substitution in-line", func(t *testing.T) { @@ -162,9 +163,9 @@ func TestCloudFoundryCreateService(t *testing.T) { ManifestVariables: manifestVariables, CfAsync: false, // should be ignored } - err = runCloudFoundryCreateService(&config, &telemetryData, cf) - if assert.NoError(t, err) { - assert.Equal(t, []mock.ExecCall{{Execution: (*mock.Execution)(nil), Async: false, Exec: "cf", Params: []string{"login", "-a", "https://api.endpoint.com", "-o", "testOrg", "-s", "testSpace", "-u", "'testUser'", "-p", "'testPassword'"}}, + error := runCloudFoundryCreateService(&config, &telemetryData, cf) + if assert.NoError(t, error) { + assert.Equal(t, []mock.ExecCall{{Execution: (*mock.Execution)(nil), Async: false, Exec: "cf", Params: []string{"login", "-a", "https://api.endpoint.com", "-o", "testOrg", "-s", "testSpace", "-u", "testUser", "-p", "testPassword"}}, {Execution: (*mock.Execution)(nil), Async: false, Exec: "cf", Params: []string{"create-service-push", "--no-push", "--service-manifest", "manifestTest.yml", "--var", "name1=Test1", "--var", "name2=Test2"}}, {Execution: (*mock.Execution)(nil), Async: false, Exec: "cf", Params: []string{"logout"}}}, m.Calls) @@ -219,9 +220,9 @@ func TestCloudFoundryCreateService(t *testing.T) { ManifestVariablesFiles: manifestVariablesFiles, ManifestVariables: []string{"a=b", "x=y"}, } - err = runCloudFoundryCreateService(&config, &telemetryData, cf) - if assert.NoError(t, err) { - assert.Equal(t, []mock.ExecCall{{Execution: (*mock.Execution)(nil), Async: false, Exec: "cf", Params: []string{"login", "-a", "https://api.endpoint.com", "-o", "testOrg", "-s", "testSpace", "-u", "'testUser'", "-p", "'testPassword'"}}, + error := runCloudFoundryCreateService(&config, &telemetryData, cf) + if assert.NoError(t, error) { + assert.Equal(t, []mock.ExecCall{{Execution: (*mock.Execution)(nil), Async: false, Exec: "cf", Params: []string{"login", "-a", "https://api.endpoint.com", "-o", "testOrg", "-s", "testSpace", "-u", "testUser", "-p", "testPassword"}}, {Execution: (*mock.Execution)(nil), Async: false, Exec: "cf", Params: []string{"create-service-push", "--no-push", "--service-manifest", "manifestTest.yml", "--vars-file", "varsTest.yml", "--vars-file", "varsTest2.yml", "--var", "a=b", "--var", "x=y"}}, {Execution: (*mock.Execution)(nil), Async: false, Exec: "cf", Params: []string{"logout"}}}, m.Calls) diff --git a/cmd/gcpPublishEvent_test.go b/cmd/gcpPublishEvent_test.go index 393d93af66..cf3b43530f 100644 --- a/cmd/gcpPublishEvent_test.go +++ b/cmd/gcpPublishEvent_test.go @@ -1,5 +1,3 @@ -//go:build unit - package cmd import ( diff --git a/cmd/integrationArtifactDeploy_test.go b/cmd/integrationArtifactDeploy_test.go index f52169f47f..2b38a18e81 100644 --- a/cmd/integrationArtifactDeploy_test.go +++ b/cmd/integrationArtifactDeploy_test.go @@ -1,4 +1,5 @@ //go:build unit +// +build unit package cmd @@ -208,9 +209,9 @@ func (c *httpMockCpis) SendRequest(method string, url string, r io.Reader, heade } if c.CPIFunction == "" { c.CPIFunction = cpi.GetCPIFunctionNameByURLCheck(url, method, c.TestType) - resp, err := cpi.GetCPIFunctionMockResponse(c.CPIFunction, c.TestType) + resp, error := cpi.GetCPIFunctionMockResponse(c.CPIFunction, c.TestType) c.CPIFunction = "" - return resp, err + return resp, error } return cpi.GetCPIFunctionMockResponse(c.CPIFunction, c.TestType) diff --git a/cmd/integrationArtifactTransport.go b/cmd/integrationArtifactTransport.go index c285ede348..d2c67397fd 100644 --- a/cmd/integrationArtifactTransport.go +++ b/cmd/integrationArtifactTransport.go @@ -76,7 +76,8 @@ func CreateIntegrationArtifactTransportRequest(config *integrationArtifactTransp processId := jsonResponse.Path("processId").Data().(string) if processId != "" { - return pollTransportStatus(processId, retryCount, config, httpClient, apistruct.Host) + error := pollTransportStatus(processId, retryCount, config, httpClient, apistruct.Host) + return error } return errors.New("Invalid process id") } diff --git a/cmd/malwareExecuteScan_test.go b/cmd/malwareExecuteScan_test.go index ff87911078..99f84c9b26 100644 --- a/cmd/malwareExecuteScan_test.go +++ b/cmd/malwareExecuteScan_test.go @@ -77,9 +77,9 @@ func TestMalwareScanWithNoBuildtool(t *testing.T) { SHA256: "96ca802fbd54d31903f1115a1d95590c685160637d9262bd340ab30d0f817e85", } - err := runMalwareScan(&malwareScanConfig, nil, &utils) + error := runMalwareScan(&malwareScanConfig, nil, &utils) - assert.NoError(t, err) + assert.NoError(t, error) }) t.Run("Malware detected in file", func(t *testing.T) { @@ -92,8 +92,8 @@ func TestMalwareScanWithNoBuildtool(t *testing.T) { Finding: "Win.Test.EICAR_HDB-1", } - err := runMalwareScan(&malwareScanConfig, nil, &utils) - assert.EqualError(t, err, "Malware scan failed for file 'target/myFile'. Malware detected: true, encrypted content detected: false, finding: Win.Test.EICAR_HDB-1") + error := runMalwareScan(&malwareScanConfig, nil, &utils) + assert.EqualError(t, error, "Malware scan failed for file 'target/myFile'. Malware detected: true, encrypted content detected: false, finding: Win.Test.EICAR_HDB-1") }) t.Run("Encrypted content detected in file", func(t *testing.T) { @@ -105,8 +105,8 @@ func TestMalwareScanWithNoBuildtool(t *testing.T) { SHA256: "96ca802fbd54d31903f1115a1d95590c685160637d9262bd340ab30d0f817e85", } - err := runMalwareScan(&malwareScanConfig, nil, &utils) - assert.EqualError(t, err, "Malware scan failed for file 'target/myFile'. Malware detected: false, encrypted content detected: true, finding: ") + error := runMalwareScan(&malwareScanConfig, nil, &utils) + assert.EqualError(t, error, "Malware scan failed for file 'target/myFile'. Malware detected: false, encrypted content detected: true, finding: ") }) t.Run("Malware and encrypted content detected in file", func(t *testing.T) { @@ -119,8 +119,8 @@ func TestMalwareScanWithNoBuildtool(t *testing.T) { Finding: "Win.Test.EICAR_HDB-1", } - err := runMalwareScan(&malwareScanConfig, nil, &utils) - assert.EqualError(t, err, "Malware scan failed for file 'target/myFile'. Malware detected: true, encrypted content detected: true, finding: Win.Test.EICAR_HDB-1") + error := runMalwareScan(&malwareScanConfig, nil, &utils) + assert.EqualError(t, error, "Malware scan failed for file 'target/myFile'. Malware detected: true, encrypted content detected: true, finding: Win.Test.EICAR_HDB-1") }) t.Run("No file and no buildtool specified", func(t *testing.T) { @@ -131,8 +131,8 @@ func TestMalwareScanWithNoBuildtool(t *testing.T) { Timeout: "60", } - err := runMalwareScan(&malwareScanConfig, nil, nil) - assert.EqualError(t, err, "Please specify a file to be scanned") + error := runMalwareScan(&malwareScanConfig, nil, nil) + assert.EqualError(t, error, "Please specify a file to be scanned") }) t.Run("File to be scanned, can't be found", func(t *testing.T) { @@ -146,8 +146,8 @@ func TestMalwareScanWithNoBuildtool(t *testing.T) { ScanFile: "target/fileWhichDoesntExist", } - err := runMalwareScan(&malwareScanConfig, nil, &utils) - assert.EqualError(t, err, "the file 'target/fileWhichDoesntExist' does not exist: file does not exist") + error := runMalwareScan(&malwareScanConfig, nil, &utils) + assert.EqualError(t, error, "the file 'target/fileWhichDoesntExist' does not exist: file does not exist") }) } @@ -177,9 +177,9 @@ func TestMalwareScanWithDockerAsBuildtoolTests(t *testing.T) { ScanImage: "dockerimagename:latest", } - err := runMalwareScan(&malwareScanConfig, nil, &utils) + error := runMalwareScan(&malwareScanConfig, nil, &utils) - assert.NoError(t, err) + assert.NoError(t, error) }) t.Run("No file and no buildtool specified", func(t *testing.T) { @@ -190,8 +190,8 @@ func TestMalwareScanWithDockerAsBuildtoolTests(t *testing.T) { Timeout: "60", } - err := runMalwareScan(&malwareScanConfig, nil, &utils) - assert.EqualError(t, err, "Please specify a file to be scanned") + error := runMalwareScan(&malwareScanConfig, nil, &utils) + assert.EqualError(t, error, "Please specify a file to be scanned") }) } @@ -221,9 +221,9 @@ func TestMalwareScanWithOtherBuildtoolTests(t *testing.T) { ScanImage: "dockerimagename:latest", } - err := runMalwareScan(&malwareScanConfig, nil, &utils) + error := runMalwareScan(&malwareScanConfig, nil, &utils) - assert.NoError(t, err) + assert.NoError(t, error) }) } diff --git a/cmd/readPipelineEnv_test.go b/cmd/readPipelineEnv_test.go index 3019d2eb78..6efcb2ff61 100644 --- a/cmd/readPipelineEnv_test.go +++ b/cmd/readPipelineEnv_test.go @@ -1,5 +1,3 @@ -//go:build unit - package cmd import ( diff --git a/pkg/abaputils/abaputils.go b/pkg/abaputils/abaputils.go index fff862c5de..fe805037a7 100644 --- a/pkg/abaputils/abaputils.go +++ b/pkg/abaputils/abaputils.go @@ -38,44 +38,42 @@ type Communication interface { func (abaputils *AbapUtils) GetAbapCommunicationArrangementInfo(options AbapEnvironmentOptions, oDataURL string) (ConnectionDetailsHTTP, error) { c := abaputils.Exec var connectionDetails ConnectionDetailsHTTP - var err error + var error error - if options.Host == "" { + if options.Host != "" { + // Host, User and Password are directly provided -> check for host schema (double https) + match, err := regexp.MatchString(`^(https|HTTPS):\/\/.*`, options.Host) + if err != nil { + log.SetErrorCategory(log.ErrorConfiguration) + return connectionDetails, errors.Wrap(err, "Schema validation for host parameter failed. Check for https.") + } + var hostOdataURL = options.Host + oDataURL + if match { + connectionDetails.URL = hostOdataURL + connectionDetails.Host = options.Host + } else { + connectionDetails.URL = "https://" + hostOdataURL + connectionDetails.Host = "https://" + options.Host + } + connectionDetails.User = options.Username + connectionDetails.Password = options.Password + } else { if options.CfAPIEndpoint == "" || options.CfOrg == "" || options.CfSpace == "" || options.CfServiceInstance == "" || options.CfServiceKeyName == "" { var err = errors.New("Parameters missing. Please provide EITHER the Host of the ABAP server OR the Cloud Foundry API Endpoint, Organization, Space, Service Instance and Service Key") log.SetErrorCategory(log.ErrorConfiguration) return connectionDetails, err } // Url, User and Password should be read from a cf service key - var abapServiceKey, err = ReadServiceKeyAbapEnvironment(options, c) - if err != nil { - return connectionDetails, errors.Wrap(err, "Read service key failed") + var abapServiceKey, error = ReadServiceKeyAbapEnvironment(options, c) + if error != nil { + return connectionDetails, errors.Wrap(error, "Read service key failed") } connectionDetails.Host = abapServiceKey.URL connectionDetails.URL = abapServiceKey.URL + oDataURL connectionDetails.User = abapServiceKey.Abap.Username connectionDetails.Password = abapServiceKey.Abap.Password - return connectionDetails, err - } - - // Host, User and Password are directly provided -> check for host schema (double https) - match, err := regexp.MatchString(`^(https|HTTPS):\/\/.*`, options.Host) - if err != nil { - log.SetErrorCategory(log.ErrorConfiguration) - return connectionDetails, errors.Wrap(err, "Schema validation for host parameter failed. Check for https.") } - var hostOdataURL = options.Host + oDataURL - if match { - connectionDetails.URL = hostOdataURL - connectionDetails.Host = options.Host - } else { - connectionDetails.URL = "https://" + hostOdataURL - connectionDetails.Host = "https://" + options.Host - } - connectionDetails.User = options.Username - connectionDetails.Password = options.Password - - return connectionDetails, err + return connectionDetails, error } // ReadServiceKeyAbapEnvironment from Cloud Foundry and returns it. Depending on user/developer requirements if he wants to perform further Cloud Foundry actions diff --git a/pkg/abaputils/abaputils_test.go b/pkg/abaputils/abaputils_test.go index 6f36fc37a2..d9b0cafa2d 100644 --- a/pkg/abaputils/abaputils_test.go +++ b/pkg/abaputils/abaputils_test.go @@ -1,4 +1,5 @@ //go:build unit +// +build unit package abaputils @@ -72,7 +73,6 @@ func TestCloudFoundryGetAbapCommunicationInfo(t *testing.T) { assert.Equal(t, "", connectionDetails.Password) assert.Equal(t, "", connectionDetails.XCsrfToken) - assert.Error(t, err) assert.EqualError(t, err, "Read service key failed: Parsing the service key failed for all supported formats. Service key is empty") }) t.Run("CF GetAbapCommunicationArrangementInfo - Success V8", func(t *testing.T) { diff --git a/pkg/abaputils/sap_com_0510.go b/pkg/abaputils/sap_com_0510.go index ed6e5b3d1b..556fc1b74c 100644 --- a/pkg/abaputils/sap_com_0510.go +++ b/pkg/abaputils/sap_com_0510.go @@ -396,8 +396,8 @@ func (api *SAP_COM_0510) getLogProtocolQuery(page int) string { // ConvertTime formats an ABAP timestamp string from format /Date(1585576807000+0000)/ into a UNIX timestamp and returns it func (api *SAP_COM_0510) ConvertTime(logTimeStamp string) time.Time { seconds := strings.TrimPrefix(strings.TrimSuffix(logTimeStamp, "000+0000)/"), "/Date(") - n, err := strconv.ParseInt(seconds, 10, 64) - if err != nil { + n, error := strconv.ParseInt(seconds, 10, 64) + if error != nil { return time.Unix(0, 0).UTC() } t := time.Unix(n, 0).UTC() diff --git a/pkg/abaputils/sap_com_0948.go b/pkg/abaputils/sap_com_0948.go index d790faa13a..5d8477c190 100644 --- a/pkg/abaputils/sap_com_0948.go +++ b/pkg/abaputils/sap_com_0948.go @@ -452,8 +452,8 @@ func (api *SAP_COM_0948) getLogProtocolQuery(page int) string { // ConvertTime formats an ISO 8601 timestamp string from format 2024-05-02T09:25:40Z into a UNIX timestamp and returns it func (api *SAP_COM_0948) ConvertTime(logTimeStamp string) time.Time { - t, err := time.Parse(time.RFC3339, logTimeStamp) - if err != nil { + t, error := time.Parse(time.RFC3339, logTimeStamp) + if error != nil { return time.Unix(0, 0).UTC() } return t diff --git a/pkg/cloudfoundry/Authentication.go b/pkg/cloudfoundry/Authentication.go index 0f6f4d8657..014a829909 100644 --- a/pkg/cloudfoundry/Authentication.go +++ b/pkg/cloudfoundry/Authentication.go @@ -3,8 +3,6 @@ package cloudfoundry import ( "errors" "fmt" - "runtime" - "strings" "github.com/SAP/jenkins-library/pkg/command" "github.com/SAP/jenkins-library/pkg/log" @@ -13,13 +11,14 @@ import ( // LoginCheck checks if user is logged in to Cloud Foundry with the receiver provided // to the function call. func (cf *CFUtils) LoginCheck(options LoginOptions) (bool, error) { - // TODO: options are not used ? return cf.loggedIn, nil } // Login logs user in to Cloud Foundry via cf cli. // Checks if user is logged in first, if not perform 'cf login' command with appropriate parameters func (cf *CFUtils) Login(options LoginOptions) error { + var err error + _c := cf.Exec if _c == nil { @@ -30,29 +29,31 @@ func (cf *CFUtils) Login(options LoginOptions) error { return fmt.Errorf("Failed to login to Cloud Foundry: %w", errors.New("Parameters missing. Please provide the Cloud Foundry Endpoint, Org, Space, Username and Password")) } - if cf.loggedIn { - return nil - } - - log.Entry().Info("Logging in to Cloud Foundry") + var loggedIn bool - escapedUsername := escapeValuesForCLI(options.Username, getGOOS) - escapedPassword := escapeValuesForCLI(options.Password, getGOOS) + loggedIn, err = cf.LoginCheck(options) - cfLoginScript := []string{ - "login", - "-a", options.CfAPIEndpoint, - "-o", options.CfOrg, - "-s", options.CfSpace, - "-u", escapedUsername, - "-p", escapedPassword, + if loggedIn == true { + return err } - cfLoginScript = append(cfLoginScript, options.CfLoginOpts...) + if err == nil { + log.Entry().Info("Logging in to Cloud Foundry") - log.Entry().WithField("cfAPI:", options.CfAPIEndpoint).WithField("cfOrg", options.CfOrg).WithField("space", options.CfSpace).Info("Logging into Cloud Foundry..") + var cfLoginScript = append([]string{ + "login", + "-a", options.CfAPIEndpoint, + "-o", options.CfOrg, + "-s", options.CfSpace, + "-u", options.Username, + "-p", options.Password, + }, options.CfLoginOpts...) + + log.Entry().WithField("cfAPI:", options.CfAPIEndpoint).WithField("cfOrg", options.CfOrg).WithField("space", options.CfSpace).Info("Logging into Cloud Foundry..") + + err = _c.RunExecutable("cf", cfLoginScript...) + } - err := _c.RunExecutable("cf", cfLoginScript...) if err != nil { return fmt.Errorf("Failed to login to Cloud Foundry: %w", err) } @@ -61,17 +62,6 @@ func (cf *CFUtils) Login(options LoginOptions) error { return nil } -func escapeValuesForCLI(password string, getGOOS func() string) string { - switch getGOOS() { - case "windows": - return fmt.Sprintf("'%s'", strings.ReplaceAll(password, "'", `''`)) - case "linux", "darwin": - return fmt.Sprintf("'%s'", strings.ReplaceAll(password, "'", `'\''`)) - default: - return fmt.Sprintf("'%s'", strings.ReplaceAll(password, "'", `'\''`)) - } -} - // Logout logs User out of Cloud Foundry // Logout can be perforned via 'cf logout' command regardless if user is logged in or not func (cf *CFUtils) Logout() error { @@ -143,7 +133,3 @@ func (cf *CfUtilsMock) Cleanup() { cf.LoginError = nil cf.LogoutError = nil } - -func getGOOS() string { - return runtime.GOOS -} diff --git a/pkg/cloudfoundry/Authentication_test.go b/pkg/cloudfoundry/Authentication_test.go deleted file mode 100644 index 6d388c1841..0000000000 --- a/pkg/cloudfoundry/Authentication_test.go +++ /dev/null @@ -1,63 +0,0 @@ -//go:build unit - -package cloudfoundry - -import ( - "fmt" - "testing" - - "github.com/stretchr/testify/assert" -) - -func Test_escapeValuesForCLI(t *testing.T) { - tests := []struct { - name string - os string - input string - expected string - }{ - { - name: "Windows password without quotes", - os: "windows", - input: `mypassword`, - expected: `'mypassword'`, - }, - { - name: "Windows password with quotes", - os: "windows", - input: `my\"password`, - expected: `'my\"password'`, - }, - { - name: "Non-Windows password without single quotes", - os: "linux", - input: "mypassword", - expected: "'mypassword'", - }, - { - name: "Non-Windows password with single quotes", - os: "darwin", - input: `my'password`, - expected: `'my'\''password'`, - }, - { - name: "Linux password with all special characters", - os: "linux", - input: "~!@#$%^&*()_+{`}|:\"<>?-=[]\\;',./", - expected: "'~!@#$%^&*()_+{`}|:\"<>?-=[]\\;'\\'',./'", - }, - { - name: "Windows password with all special characters", - os: "windows", - input: "~!@#$%^&*()_+{`}|:\"<>?-=[]\\;',./", - expected: "'~!@#$%^&*()_+{`}|:\"<>?-=[]\\;'',./'", - }, - } - - for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - result := escapeValuesForCLI(tt.input, func() string { return tt.os }) - assert.Equal(t, tt.expected, result, fmt.Sprintf("Failed for OS: %s and password: %s", tt.os, tt.input)) - }) - } -} diff --git a/pkg/cloudfoundry/CloudFoundry_test.go b/pkg/cloudfoundry/CloudFoundry_test.go index e480f46e03..57aaf63629 100644 --- a/pkg/cloudfoundry/CloudFoundry_test.go +++ b/pkg/cloudfoundry/CloudFoundry_test.go @@ -1,4 +1,5 @@ //go:build unit +// +build unit package cloudfoundry @@ -86,8 +87,8 @@ func TestCloudFoundryLogin(t *testing.T) { "-a", "https://api.endpoint.com", "-o", "testOrg", "-s", "testSpace", - "-u", "'testUser'", - "-p", "'testPassword'", + "-u", "testUser", + "-p", "testPassword", }}, }, m.Calls) } @@ -116,8 +117,8 @@ func TestCloudFoundryLogin(t *testing.T) { "-a", "https://api.endpoint.com", "-o", "testOrg", "-s", "testSpace", - "-u", "'testUser'", - "-p", "'testPassword'", + "-u", "testUser", + "-p", "testPassword", }}, }, m.Calls) } @@ -149,8 +150,8 @@ func TestCloudFoundryLogin(t *testing.T) { "-a", "https://api.endpoint.com", "-o", "testOrg", "-s", "testSpace", - "-u", "'testUser'", - "-p", "'testPassword'", + "-u", "testUser", + "-p", "testPassword", "--skip-ssl-validation", "--origin", "ldap", }}, @@ -183,7 +184,7 @@ func TestCloudFoundryReadServiceKeyAbapEnvironment(t *testing.T) { const password = "test_password" const serviceKey = ` cf comment test \n\n - {"sap.cloud.service":"com.sap.cloud.abap","url": "` + testURL + `" ,"systemid":"H01","abap":{"username":"'` + username + `'","password":"'` + password + `'","communication_scenario_id": "SAP_COM_0510","communication_arrangement_id": "SK_I6CBIRFZPPJDKYNATQA32W","communication_system_id": "SK_I6CBIRFZPPJDKYNATQA32W","communication_inbound_user_id": "CC0000000001","communication_inbound_user_auth_mode": "2"},"binding":{"env": "cf","version": "0.0.1.1","type": "basic","id": "i6cBiRfZppJdKynaTqa32W"},"preserve_host_header": true}` + {"sap.cloud.service":"com.sap.cloud.abap","url": "` + testURL + `" ,"systemid":"H01","abap":{"username":"` + username + `","password":"` + password + `","communication_scenario_id": "SAP_COM_0510","communication_arrangement_id": "SK_I6CBIRFZPPJDKYNATQA32W","communication_system_id": "SK_I6CBIRFZPPJDKYNATQA32W","communication_inbound_user_id": "CC0000000001","communication_inbound_user_auth_mode": "2"},"binding":{"env": "cf","version": "0.0.1.1","type": "basic","id": "i6cBiRfZppJdKynaTqa32W"},"preserve_host_header": true}` m.StdoutReturn = map[string]string{"cf service-key testInstance testServiceKeyName": serviceKey} @@ -212,13 +213,13 @@ func TestCloudFoundryReadServiceKeyAbapEnvironment(t *testing.T) { "-a", "https://api.endpoint.com", "-o", "testOrg", "-s", "testSpace", - "-u", "'testUser'", - "-p", "'testPassword'", + "-u", "testUser", + "-p", "testPassword", }}, {Exec: "cf", Params: []string{"service-key", "testInstance", "testServiceKeyName"}}, {Exec: "cf", Params: []string{"logout"}}, }, m.Calls) } - assert.Equal(t, ` {"sap.cloud.service":"com.sap.cloud.abap","url": "`+testURL+`" ,"systemid":"H01","abap":{"username":"'`+username+`'","password":"'`+password+`'","communication_scenario_id": "SAP_COM_0510","communication_arrangement_id": "SK_I6CBIRFZPPJDKYNATQA32W","communication_system_id": "SK_I6CBIRFZPPJDKYNATQA32W","communication_inbound_user_id": "CC0000000001","communication_inbound_user_auth_mode": "2"},"binding":{"env": "cf","version": "0.0.1.1","type": "basic","id": "i6cBiRfZppJdKynaTqa32W"},"preserve_host_header": true}`, abapServiceKey) + assert.Equal(t, ` {"sap.cloud.service":"com.sap.cloud.abap","url": "`+testURL+`" ,"systemid":"H01","abap":{"username":"`+username+`","password":"`+password+`","communication_scenario_id": "SAP_COM_0510","communication_arrangement_id": "SK_I6CBIRFZPPJDKYNATQA32W","communication_system_id": "SK_I6CBIRFZPPJDKYNATQA32W","communication_inbound_user_id": "CC0000000001","communication_inbound_user_auth_mode": "2"},"binding":{"env": "cf","version": "0.0.1.1","type": "basic","id": "i6cBiRfZppJdKynaTqa32W"},"preserve_host_header": true}`, abapServiceKey) }) } diff --git a/pkg/cloudfoundry/ManifestUtils_test.go b/pkg/cloudfoundry/ManifestUtils_test.go index abe5a58666..c7f27d62d3 100644 --- a/pkg/cloudfoundry/ManifestUtils_test.go +++ b/pkg/cloudfoundry/ManifestUtils_test.go @@ -1,4 +1,5 @@ //go:build unit +// +build unit package cloudfoundry diff --git a/pkg/cloudfoundry/Vars_test.go b/pkg/cloudfoundry/Vars_test.go index 11d4600c06..66b74ee751 100644 --- a/pkg/cloudfoundry/Vars_test.go +++ b/pkg/cloudfoundry/Vars_test.go @@ -1,4 +1,5 @@ //go:build unit +// +build unit package cloudfoundry diff --git a/pkg/cpi/mockingUtils.go b/pkg/cpi/mockingUtils.go index 6c0fa13c04..50f4217ed6 100644 --- a/pkg/cpi/mockingUtils.go +++ b/pkg/cpi/mockingUtils.go @@ -309,9 +309,9 @@ func IntegrationDesigntimeArtifactUpdateMockResponse(testType string) (*http.Res // GetMockResponseByTestTypeAndMockFunctionName - Get mock response by testtype and mock function name func GetMockResponseByTestTypeAndMockFunctionName(mockFuntionName, testType string) (*http.Response, error) { - response, err := GetPositiveCaseResponseByTestType(testType) + response, error := GetPositiveCaseResponseByTestType(testType) - if response == nil && err == nil { + if response == nil && error == nil { switch mockFuntionName { @@ -355,7 +355,7 @@ func GetMockResponseByTestTypeAndMockFunctionName(mockFuntionName, testType stri return &res, errors.New("Unable to get integration artifact deploy error status, Response Status code:400") } } - return response, err + return response, error } // NegtiveResForIntegrationArtifactGenericCommandMockResponse -Nagative Case http response body @@ -377,9 +377,9 @@ func NegtiveResForIntegrationArtifactGenericCommandMockResponse(message string) // UpdateIntegrationDesigntimeArtifactMockResponse -Provide http respose body func UpdateIntegrationDesigntimeArtifactMockResponse(testType string) (*http.Response, error) { - response, err := GetRespBodyHTTPStatusCreated() + response, error := GetRespBodyHTTPStatusCreated() - if response == nil && err == nil { + if response == nil && error == nil { res := http.Response{ StatusCode: 400, @@ -393,7 +393,7 @@ func UpdateIntegrationDesigntimeArtifactMockResponse(testType string) (*http.Res } return &res, errors.New("Unable to get status of integration artifact, Response Status code:400") } - return response, err + return response, error } // IntegrationArtifactDownloadCommandMockResponsePositiveCaseRespBody -Provide http respose body for positive case