Skip to content
This repository was archived by the owner on Jun 5, 2025. It is now read-only.

Commit 889876f

Browse files
authored
Merge pull request #109 from Venafi/contacts-support
Fixed Contacts behavior
2 parents 580e7cf + 0193476 commit 889876f

3 files changed

Lines changed: 52 additions & 12 deletions

File tree

src/main/java/com/venafi/vcert/sdk/connectors/cloud/CloudConnectorUtils.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ public static void setCitToApp(String policyName, CertificateIssuingTemplate cit
137137
}
138138
}
139139

140-
//if the applications doesn't exist, the response will contains an error with code 20215,
140+
//if the applications doesn't exist, the response will contain an error with code 20215,
141141
// then it will needed to create it
142142
if( application == null )
143143
//create the application and related it with the cit
@@ -181,9 +181,11 @@ private static void addCitToApp(CertificateIssuingTemplate cit, Application appl
181181
citAliasIdMap.put(cit.name(), cit.id());
182182
}
183183

184-
// Updating the owners list of the Application
185-
List<Application.OwnerIdsAndType> ownersList = CloudConnectorUtils.resolveUsersToCloudOwners(usersList, apiKey, cloud);
186-
application.ownerIdsAndTypes(ownersList);
184+
if (usersList != null && usersList.length > 0){
185+
// Updating the owners list of the Application
186+
List<Application.OwnerIdsAndType> ownersList = CloudConnectorUtils.resolveUsersToCloudOwners(usersList, apiKey, cloud);
187+
application.ownerIdsAndTypes(ownersList);
188+
}
187189

188190
//getting the appId because it will be used to invoke the API to update the related Application
189191
String appId = application.id();

src/test/java/com/venafi/vcert/sdk/connectors/cloud/CloudConnectorPolicyAT.java

Lines changed: 46 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -108,8 +108,21 @@ public void getUserByName() throws VCertException{
108108
}
109109

110110
@Test
111-
@DisplayName("Cloud - Testing get and set users from Policy Specification into Application")
112-
public void createAndGetPolicyContacts() throws VCertException {
111+
@DisplayName("Cloud - Testing policy creation with empty users list")
112+
public void createPolicyWithNoUsers() throws VCertException {
113+
CloudConnector connector = connectorResource.connector();
114+
String policyName = CloudTestUtils.getRandomZone();
115+
PolicySpecification policySpecification = CloudTestUtils.getPolicySpecification();
116+
connector.setPolicy(policyName, policySpecification);
117+
PolicySpecification psReturned = connector.getPolicy(policyName);
118+
119+
Assertions.assertEquals(1, psReturned.users().length);
120+
Assertions.assertEquals("jenkins@opensource.qa.venafi.io", psReturned.users()[0]);
121+
}
122+
123+
@Test
124+
@DisplayName("Cloud - Testing policy creation with a users list")
125+
public void createPolicyWithUsers() throws VCertException {
113126
CloudConnector connector = connectorResource.connector();
114127
String policyName = CloudTestUtils.getRandomZone();
115128
PolicySpecification policySpecification = CloudTestUtils.getPolicySpecification();
@@ -123,8 +136,8 @@ public void createAndGetPolicyContacts() throws VCertException {
123136
}
124137

125138
@Test
126-
@DisplayName("Cloud - Testing setting contacts that are duplicated on VaaS")
127-
public void testPolicyContactsUpdated() throws VCertException {
139+
@DisplayName("Cloud - Testing updating a policy with a policy specification with no user list")
140+
public void updatePolicyWithNoUsers() throws VCertException {
128141
CloudConnector connector = connectorResource.connector();
129142
String policyName = CloudTestUtils.getRandomZone();
130143
PolicySpecification policySpecification = CloudTestUtils.getPolicySpecification();
@@ -136,12 +149,38 @@ public void testPolicyContactsUpdated() throws VCertException {
136149
Assertions.assertEquals("pki-admin@opensource.qa.venafi.io", psReturned.users()[0]);
137150
Assertions.assertEquals("resource-owner@opensource.qa.venafi.io", psReturned.users()[1]);
138151

152+
//Updating the Policy Specification with no users
153+
PolicySpecification ps2 = CloudTestUtils.getPolicySpecification();
154+
connector.setPolicy(policyName, ps2);
155+
PolicySpecification psReturned2 = connector.getPolicy(policyName);
156+
157+
Assertions.assertEquals(2, psReturned2.users().length);
158+
Assertions.assertEquals("pki-admin@opensource.qa.venafi.io", psReturned.users()[0]);
159+
Assertions.assertEquals("resource-owner@opensource.qa.venafi.io", psReturned.users()[1]); }
160+
161+
162+
@Test
163+
@DisplayName("Cloud - Testing updating a policy with a policy specification with a users list")
164+
public void updatePolicyWithUsers() throws VCertException {
165+
CloudConnector connector = connectorResource.connector();
166+
String policyName = CloudTestUtils.getRandomZone();
167+
PolicySpecification policySpecification = CloudTestUtils.getPolicySpecification();
168+
policySpecification.users(new String[]{"jenkins@opensource.qa.venafi.io"});
169+
connector.setPolicy(policyName, policySpecification);
170+
PolicySpecification psReturned = connector.getPolicy(policyName);
171+
172+
Assertions.assertEquals(1, psReturned.users().length);
173+
Assertions.assertEquals("jenkins@opensource.qa.venafi.io", psReturned.users()[0]);
174+
175+
176+
139177
//Updating the Policy Specification to include just one owner
140178
PolicySpecification ps2 = CloudTestUtils.getPolicySpecification();
179+
ps2.users(new String[]{"pki-admin@opensource.qa.venafi.io","resource-owner@opensource.qa.venafi.io"});
141180
connector.setPolicy(policyName, ps2);
142181
PolicySpecification psReturned2 = connector.getPolicy(policyName);
143182

144-
Assertions.assertEquals(1, psReturned2.users().length);
145-
Assertions.assertEquals("jenkins@opensource.qa.venafi.io", psReturned2.users()[0]);
146-
}
183+
Assertions.assertEquals(2, psReturned2.users().length);
184+
Assertions.assertEquals("pki-admin@opensource.qa.venafi.io", psReturned2.users()[0]);
185+
Assertions.assertEquals("resource-owner@opensource.qa.venafi.io", psReturned2.users()[1]); }
147186
}

src/test/java/com/venafi/vcert/sdk/connectors/cloud/CloudTestUtils.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ public static String getRandomZone() {
1414

1515
public static PolicySpecification getPolicySpecification() {
1616
PolicySpecification policySpecification = PolicySpecification.builder()
17-
.users(new String[]{"jenkins@opensource.qa.venafi.io"})
1817
.policy( Policy.builder()
1918
.domains(new String[]{"venafi.com","kwan.com"})
2019
.maxValidDays(120)

0 commit comments

Comments
 (0)