Skip to content

Commit

Permalink
added test cases for get certs form template
Browse files Browse the repository at this point in the history
Signed-off-by: Jay Sharma <[email protected]>
  • Loading branch information
jayvikramsharma1 committed Oct 16, 2023
1 parent fd81ccd commit 4f4745c
Show file tree
Hide file tree
Showing 2 changed files with 81 additions and 50 deletions.
71 changes: 51 additions & 20 deletions components/automate-cli/cmd/chef-automate/certRotate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2559,6 +2559,47 @@ func TestPopulateCertificateConfig(t *testing.T) {
})
}

func TestGetCertsFromTemplate(t *testing.T) {
type testCaseInfo struct {
description string
filepath string
isError bool
ExpectedError string
}
testCases := []testCaseInfo{
{
description: "get to certificates from correct template file path",
filepath: "../../pkg/testfiles/onprem/certs-config.toml",
isError: false,
ExpectedError: "",
},
{
description: "get to certificates from incorrect template file path",
filepath: "../../pkg/testfiles/onprem/certs-config1.toml",
isError: true,
ExpectedError: "Error in fetching certificates from template file",
},
{
description: "get to certificates from empty template file path",
filepath: "",
isError: true,
ExpectedError: "Cluster certificate file is required",
},
}
for _, testCase := range testCases {
t.Run(testCase.description, func(t *testing.T) {
output, err := getCertsFromTemplate(testCase.filepath)
if testCase.isError {
assert.Error(t, err)
} else {
assert.NoError(t, err)
assert.ObjectsAreEqual(mockCertifiateTemplate(), output)
}
})
}

}

func TestWriteCertificateConfigToFile(t *testing.T) {
_, infra := getMockCertRotateFlowAndInfra()
type testCaseInfo struct {
Expand Down Expand Up @@ -3038,71 +3079,61 @@ func mockCertShowCertificates() *certShowCertificates {
OpensearchAdminKey: admin_key,
AutomateCertsByIP: []CertByIP{
{
IP: "10.1.0.1",
PublicKey: public_key,
PrivateKey: private_key,
},
{
IP: "10.1.0.2",
IP: ValidIP,
PublicKey: public_key,
PrivateKey: private_key,
},
{
IP: "10.1.0.3",
IP: ValidIP1,
PublicKey: public_key,
PrivateKey: private_key,
},
},
ChefServerCertsByIP: []CertByIP{
{
IP: "10.2.0.1",
PublicKey: public_key,
PrivateKey: private_key,
},
{
IP: "10.2.0.2",
IP: ValidIP2,
PublicKey: public_key,
PrivateKey: private_key,
},
{
IP: "10.2.0.3",
IP: ValidIP3,
PublicKey: public_key,
PrivateKey: private_key,
},
},
OpensearchCertsByIP: []CertByIP{
{
IP: "10.3.0.1",
IP: ValidIP4,
PublicKey: public_key,
PrivateKey: private_key,
NodesDn: "test_node_dn",
},
{
IP: "10.3.0.2",
IP: ValidIP5,
PublicKey: public_key,
PrivateKey: private_key,
NodesDn: "test_node_dn",
},
{
IP: "10.3.0.3",
IP: ValidIP6,
PublicKey: public_key,
PrivateKey: private_key,
NodesDn: "test_node_dn",
},
},
PostgresqlCertsByIP: []CertByIP{
{
IP: "10.4.0.1",
IP: ValidIP7,
PublicKey: public_key,
PrivateKey: private_key,
},
{
IP: "10.4.0.2",
IP: ValidIP8,
PublicKey: public_key,
PrivateKey: private_key,
},
{
IP: "10.4.0.3",
IP: ValidIP9,
PublicKey: public_key,
PrivateKey: private_key,
},
Expand Down
60 changes: 30 additions & 30 deletions components/automate-cli/pkg/testfiles/onprem/certs-config.toml
Original file line number Diff line number Diff line change
@@ -1,52 +1,52 @@
[automate]
root_ca = "../../../../lib/config/testdata/root-ca.pem"
root_ca = "../../pkg/testfiles/certs/test_root_ca.pem"

[[automate.ips]]
ip = "10.1.0.130"
public_key = "/home/ubuntu/certs/automate1.pem"
private_key = "/home/ubuntu/certs/automate1-key.pem"
ip = "198.51.100.0"
public_key = "../../pkg/testfiles/certs/test_a2_public_key_1.pem"
private_key = "../../pkg/testfiles/certs/test_a2_private_key_1.pem"

[chef_server]
root_ca = "/home/ubuntu/certs/root-ca.pem"
root_ca = "../../pkg/testfiles/certs/test_root_ca.pem"

[[chef_server.ips]]
ip = "10.1.0.16"
public_key = "/home/ubuntu/certs/cs1.pem"
private_key = "/home/ubuntu/certs/cs1-key.pem"
ip = "198.51.100.2"
public_key = "../../pkg/testfiles/certs/test_cs_public_key_1.pem"
private_key = "../../pkg/testfiles/certs/test_cs_private_key_1.pem"

[postgresql]
root_ca = "/home/ubuntu/certs/root-ca.pem"
root_ca = "../../pkg/testfiles/certs/test_root_ca.pem"

[[postgresql.ips]]
ip = "10.1.0.141"
public_key = "/home/ubuntu/certs/pg1.pem"
private_key = "/home/ubuntu/certs/pg1-key.pem"
ip = "198.51.100.7"
public_key = "../../pkg/testfiles/certs/test_pg_public_key_1.pem"
private_key = "../../pkg/testfiles/certs/test_pg_private_key_1.pem"

[[postgresql.ips]]
ip = "10.1.1.190"
public_key = "/home/ubuntu/certs/pg2.pem"
private_key = "/home/ubuntu/certs/pg2-key.pem"
ip = "198.51.100.8"
public_key = "../../pkg/testfiles/certs/test_os_public_key_1.pem"
private_key = "../../pkg/testfiles/certs/test_pg_public_key_2.pem"

[[postgresql.ips]]
ip = "10.1.2.130"
public_key = "/home/ubuntu/certs/pg3.pem"
private_key = "/home/ubuntu/certs/pg3-key.pem"
ip = "198.51.100.9"
public_key = "../../pkg/testfiles/certs/test_pg_public_key_3.pem"
private_key = "../../pkg/testfiles/certs/test_pg_private_key_3.pem"

[opensearch]
root_ca = "/home/ubuntu/certs/root-ca.pem"
admin_public_key = "/home/ubuntu/certs/os-admin.pem"
admin_private_key = "/home/ubuntu/certs/os-admin-key.pem"
root_ca = "../../pkg/testfiles/certs/test_root_ca.pem"
admin_public_key = "../../pkg/testfiles/certs/test_admin_cert.pem"
admin_private_key = "../../pkg/testfiles/certs/test_admin_key.pem"
[[opensearch.ips]]
ip = "10.1.0.176"
public_key = "/home/ubuntu/certs/os1.pem"
private_key = "/home/ubuntu/certs/os1-key.pem"
ip = "198.51.100.4"
public_key = "../../pkg/testfiles/certs/test_os_public_key_1.pem"
private_key = "../../pkg/testfiles/certs/test_os_private_key_1.pem"

[[opensearch.ips]]
ip = "10.1.1.125"
public_key = "/home/ubuntu/certs/os2.pem"
private_key = "/home/ubuntu/certs/os2-key.pem"
ip = "198.51.100.5"
public_key = "../../pkg/testfiles/certs/test_os_public_key_2.pem"
private_key = "../../pkg/testfiles/certs/test_os_private_key_2.pem"

[[opensearch.ips]]
ip = "10.1.2.247"
public_key = "/home/ubuntu/certs/os3.pem"
private_key = "/home/ubuntu/certs/os3-key.pem"
ip = "198.51.100.6"
public_key = "../../pkg/testfiles/certs/test_os_public_key_3.pem"
private_key = "../../pkg/testfiles/certs/test_os_private_key_3.pem"

0 comments on commit 4f4745c

Please sign in to comment.