Skip to content

Commit

Permalink
Revert "Fix deployment failure with CF if password contains special c…
Browse files Browse the repository at this point in the history
…har (#5197)" (#5215)

This reverts commit 8205624.

Co-authored-by: Valentin Uchkunev <[email protected]>
  • Loading branch information
bitmaskit and Valentin Uchkunev authored Dec 23, 2024
1 parent aa1e675 commit 93c4ea6
Show file tree
Hide file tree
Showing 22 changed files with 158 additions and 234 deletions.
4 changes: 2 additions & 2 deletions cmd/abapEnvironmentCreateSystem_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
38 changes: 19 additions & 19 deletions cmd/abapEnvironmentPushATCSystemConfig_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
})
Expand All @@ -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)
}
})
Expand Down Expand Up @@ -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
Expand All @@ -118,7 +118,7 @@ cache-control: no-cache, no-store, must-revalidate
{"Some Error Messages possible in here!"}
--B772E21DAA42B9571C778276B829D6C21--
--B772E21DAA42B9571C778276B829D6C20--`

client := &abaputils.ClientMock{
Expand Down Expand Up @@ -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
Expand All @@ -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{
Expand Down Expand Up @@ -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",
Expand Down
20 changes: 10 additions & 10 deletions cmd/abapEnvironmentRunATCCheck_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand All @@ -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"])
Expand All @@ -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)
}
})
Expand All @@ -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)
}
})
Expand Down
8 changes: 4 additions & 4 deletions cmd/abapEnvironmentRunAUnitTest_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
})
Expand All @@ -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)
}
})
Expand Down
2 changes: 0 additions & 2 deletions cmd/abapLandscapePortalUpdateAddOnProduct_test.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
//go:build unit

package cmd

import (
Expand Down
19 changes: 11 additions & 8 deletions cmd/cloudFoundryCreateServiceKey_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
//go:build unit
// +build unit

package cmd

Expand Down Expand Up @@ -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)
}
Expand All @@ -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)
}
Expand All @@ -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)
}
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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")
})
}
Loading

0 comments on commit 93c4ea6

Please sign in to comment.