Repository: chef/automate
Pull request #8258 (2023-10-12 08:21:07)

Test Security Pipeline
### :nut_and_bolt: Description: What code changed, and why?

<!-- /!\ Please ensure that you are NOT disclosing any customer information without their consent /!\ -->

### :chains: Related Resources

### :+1: Definition of Done

### :athletic_shoe: How to Build and Test the Change

### :white_check_mark: Checklist

**All PRs** must tick these:

- [ ] I have read the [CONTRIBUTING document](https://github.com/chef/automate/blob/master/CONTRIBUTING.md).
- [ ] All commits signed-off for the [Developer Certification of Origin](https://github.com/chef/chef/blob/master/CONTRIBUTING.md#developer-certification-of-origin-dco).

With occasional exceptions, all PRs **from Progress employees** must tick these:

- [ ] Is the code clear? *(complicated code or lots of comments--subdivide and use well-named methods, meaningful variable names, etc.)*
- [ ] Consistency checked? *(user notifications, user prompts, visual patterns, code patterns, variable names)*
- [ ] Repeated code blocks eliminated? *(adapt and reuse existing components, blocks, functions, etc.)*
- [ ] Spelling, grammar, typos checked? *(at a minimum use `make spell` in any component directory)*
- [ ] Code well-formatted? *(indents, line breaks, etc. improve rather than hinder readability)*

All PRs **from Progress employees** should tick these if appropriate:

- [ ] Tests added/updated? (all new code needs new tests)
- [ ] Docs added/updated? (all customer-facing changes)

*Please add a note next to any checkbox above if you are NOT ticking it.*

### :camera: Screenshots, if applicable


netlify[bot]: ### <span aria-hidden="true">👷</span> Deploy Preview for *chef-automate* processing.


|  Name | Link |
|:-:|------------------------|
|<span aria-hidden="true">🔨</span> Latest commit | 6fdf39b8869f0429a19ea210b807a6f43e7ab43a |
|<span aria-hidden="true">🔍</span> Latest deploy log | https://app.netlify.com/sites/chef-automate/deploys/6527ac76b9da5d000823259d |
sonarqube-for-infrastructure-prod[bot]: **SonarQube Quality Gate**

[![Quality Gate passed](https://raw.githubusercontent.com/SonarSource/sonarqube-static-resources/master/v97/checks/QualityGateBadge/passed-16px.png 'Quality Gate passed')](https://sonar.progress.com/dashboard?id=chef_automate_AYeOVEbqJ4YHsO5MtKWC&pullRequest=8258)

[![Bug](https://raw.githubusercontent.com/SonarSource/sonarqube-static-resources/master/v97/common/bug-16px.png 'Bug')](https://sonar.progress.com/project/issues?id=chef_automate_AYeOVEbqJ4YHsO5MtKWC&pullRequest=8258&resolved=false&types=BUG) [![A](https://raw.githubusercontent.com/SonarSource/sonarqube-static-resources/master/v97/checks/RatingBadge/A-16px.png 'A')](https://sonar.progress.com/project/issues?id=chef_automate_AYeOVEbqJ4YHsO5MtKWC&pullRequest=8258&resolved=false&types=BUG) [0 Bugs](https://sonar.progress.com/project/issues?id=chef_automate_AYeOVEbqJ4YHsO5MtKWC&pullRequest=8258&resolved=false&types=BUG)  
[![Vulnerability](https://raw.githubusercontent.com/SonarSource/sonarqube-static-resources/master/v97/common/vulnerability-16px.png 'Vulnerability')](https://sonar.progress.com/project/issues?id=chef_automate_AYeOVEbqJ4YHsO5MtKWC&pullRequest=8258&resolved=false&types=VULNERABILITY) [![A](https://raw.githubusercontent.com/SonarSource/sonarqube-static-resources/master/v97/checks/RatingBadge/A-16px.png 'A')](https://sonar.progress.com/project/issues?id=chef_automate_AYeOVEbqJ4YHsO5MtKWC&pullRequest=8258&resolved=false&types=VULNERABILITY) [0 Vulnerabilities](https://sonar.progress.com/project/issues?id=chef_automate_AYeOVEbqJ4YHsO5MtKWC&pullRequest=8258&resolved=false&types=VULNERABILITY)  
[![Security Hotspot](https://raw.githubusercontent.com/SonarSource/sonarqube-static-resources/master/v97/common/security_hotspot-16px.png 'Security Hotspot')](https://sonar.progress.com/security_hotspots?id=chef_automate_AYeOVEbqJ4YHsO5MtKWC&pullRequest=8258) [![A](https://raw.githubusercontent.com/SonarSource/sonarqube-static-resources/master/v97/checks/RatingBadge/A-16px.png 'A')](https://sonar.progress.com/security_hotspots?id=chef_automate_AYeOVEbqJ4YHsO5MtKWC&pullRequest=8258) [0 Security Hotspots](https://sonar.progress.com/security_hotspots?id=chef_automate_AYeOVEbqJ4YHsO5MtKWC&pullRequest=8258)  
[![Code Smell](https://raw.githubusercontent.com/SonarSource/sonarqube-static-resources/master/v97/common/code_smell-16px.png 'Code Smell')](https://sonar.progress.com/project/issues?id=chef_automate_AYeOVEbqJ4YHsO5MtKWC&pullRequest=8258&resolved=false&types=CODE_SMELL) [![A](https://raw.githubusercontent.com/SonarSource/sonarqube-static-resources/master/v97/checks/RatingBadge/A-16px.png 'A')](https://sonar.progress.com/project/issues?id=chef_automate_AYeOVEbqJ4YHsO5MtKWC&pullRequest=8258&resolved=false&types=CODE_SMELL) [0 Code Smells](https://sonar.progress.com/project/issues?id=chef_automate_AYeOVEbqJ4YHsO5MtKWC&pullRequest=8258&resolved=false&types=CODE_SMELL)

[![No Coverage information](https://raw.githubusercontent.com/SonarSource/sonarqube-static-resources/master/v97/checks/CoverageChart/NoCoverageInfo-16px.png 'No Coverage information')](https://sonar.progress.com/component_measures?id=chef_automate_AYeOVEbqJ4YHsO5MtKWC&pullRequest=8258&metric=coverage&view=list) No Coverage information  
[![No Duplication information](https://raw.githubusercontent.com/SonarSource/sonarqube-static-resources/master/v97/checks/Duplications/NoDuplicationInfo-16px.png 'No Duplication information')](https://sonar.progress.com/component_measures?id=chef_automate_AYeOVEbqJ4YHsO5MtKWC&pullRequest=8258&metric=duplicated_lines_density&view=list) No Duplication information



Patch:
diff --git a/VERSION b/VERSION
index b4d362caa..07ac59b28 100644
--- a/VERSION
+++ b/VERSION
@@ -1,1 +1,1 @@
-4.10.38
\ No newline at end of file
+4.10.40
\ No newline at end of file
diff --git a/components/automate-cli/cmd/chef-automate/verify.go b/components/automate-cli/cmd/chef-automate/verify.go
index 19b00fcc0..f605adb01 100644
--- a/components/automate-cli/cmd/chef-automate/verify.go
+++ b/components/automate-cli/cmd/chef-automate/verify.go
@@ -18,6 +18,7 @@ import (
 	"github.com/chef/automate/components/automate-cli/pkg/verifyserver/server"
 	"github.com/chef/automate/components/automate-cli/pkg/verifysystemdcreate"
 	"github.com/chef/automate/components/automate-deployment/pkg/cli"
+	"github.com/chef/automate/lib/arrayutils"
 	"github.com/chef/automate/lib/config"
 	"github.com/chef/automate/lib/httputils"
 	"github.com/chef/automate/lib/logger"
@@ -484,8 +485,11 @@ func (v *verifyCmdFlow) runVerifyServiceForRemote(batchCheckConfig models.Config
 			return nil, err
 		}
 
+		// Remove duplicates
+		hostIpWihtoutDuplicates := arrayutils.RemoveStringDuplicates(hostIPs)
+
 		// Starting automate-verify service on remote nodes
-		err = v.startServiceOnRemoteNodes(destFileName, sshConfig, hostIPs)
+		err = v.startServiceOnRemoteNodes(destFileName, sshConfig, hostIpWihtoutDuplicates)
 		if err != nil {
 			return nil, err
 		}
diff --git a/integration/helpers/ssl_filters.jq b/integration/helpers/ssl_filters.jq
index b58bca9b9..4dcc7244e 100644
--- a/integration/helpers/ssl_filters.jq
+++ b/integration/helpers/ssl_filters.jq
@@ -40,8 +40,10 @@ map(select(
          (.id != "HSTS" or .port != "10161") and
          (.id != "HSTS" or .port != "10143") and
          (.id != "HSTS" or .port != "10200") and
+         (.id != "HSTS" or .port != "10201") and
          (.id != "security_headers" or .port != "10161") and
          (.id != "security_headers" or .port != "10200") and
+         (.id != "security_headers" or .port != "10201") and
          (.id != "security_headers" or .port != "10104") and
 
          # automate-cs erlang-services
diff --git a/lib/arrayutils/remove_duplicate.go b/lib/arrayutils/remove_duplicate.go
new file mode 100644
index 000000000..291dcadde
--- /dev/null
+++ b/lib/arrayutils/remove_duplicate.go
@@ -0,0 +1,21 @@
+package arrayutils
+
+func RemoveStringDuplicates(inputArray []string) []string {
+	arrayWithoutDuplicate := []string{}
+	for _, item := range inputArray {
+		if !contains(arrayWithoutDuplicate, item) {
+			arrayWithoutDuplicate = append(arrayWithoutDuplicate, item)
+		}
+	}
+	return arrayWithoutDuplicate
+}
+
+func contains(arrayWithoutDuplicate []string, item string) bool {
+	index := -1
+	for i := range arrayWithoutDuplicate {
+		if item == arrayWithoutDuplicate[i] {
+			index = i
+		}
+	}
+	return index >= 0
+}


Test patch:
diff --git a/lib/arrayutils/remove_duplicate_test.go b/lib/arrayutils/remove_duplicate_test.go
new file mode 100644
index 000000000..525b24597
--- /dev/null
+++ b/lib/arrayutils/remove_duplicate_test.go
@@ -0,0 +1,51 @@
+package arrayutils_test
+
+import (
+	"testing"
+
+	"github.com/bmizerany/assert"
+	"github.com/chef/automate/lib/arrayutils"
+)
+
+func TestRemoveStringDuplicates(t *testing.T) {
+
+	testCases := []struct {
+		title         string
+		inputArray    []string
+		expectedArray []string
+		wantErr       bool
+		expectedErr   error
+	}{
+		{
+			title:         "Have duplicate value",
+			inputArray:    []string{"0.0.0.0", "0.0.0.0", "0.0.0.1"},
+			expectedArray: []string{"0.0.0.0", "0.0.0.1"},
+			wantErr:       false,
+			expectedErr:   nil,
+		},
+		{
+			title:         "Have no duplicate value",
+			inputArray:    []string{"0.0.0.0", "0.0.0.1"},
+			expectedArray: []string{"0.0.0.0", "0.0.0.1"},
+			wantErr:       false,
+			expectedErr:   nil,
+		},
+		{
+			title:         "empty array",
+			inputArray:    []string{},
+			expectedArray: []string{},
+			wantErr:       false,
+			expectedErr:   nil,
+		},
+	}
+	for _, testCase := range testCases {
+		t.Run(testCase.title, func(t *testing.T) {
+			output := arrayutils.RemoveStringDuplicates(testCase.inputArray)
+			if !testCase.wantErr {
+				// assert.Error(t, err)
+				assert.Equal(t, testCase.expectedArray, output)
+			}
+		})
+	}
+
+}