Skip to content

Commit 8bd5660

Browse files
authored
add tenant update params (#304)
* add tenant update params * fix backward comp * fix tests
1 parent adc5cff commit 8bd5660

4 files changed

Lines changed: 114 additions & 12 deletions

File tree

src/main/java/com/descope/model/tenant/Tenant.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,9 @@ public class Tenant {
1818
Map<String, Object> customAttributes;
1919
String authType;
2020
List<String> domains;
21+
Boolean disabled;
22+
Boolean enforceSSO;
23+
List<String> enforceSSOExclusions;
24+
List<String> federatedAppIds;
25+
String roleInheritance;
2126
}

src/main/java/com/descope/sdk/mgmt/TenantService.java

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,9 +75,8 @@ void createWithId(String id, String name, List<String> selfProvisioningDomains,
7575

7676
/**
7777
* Update an existing tenant's name and domains. IMPORTANT: All parameters are
78-
* required and will
79-
* override whatever value is currently set in the existing tenant. Use
80-
* carefully.
78+
* required and will override whatever value is currently set in the existing
79+
* tenant. Use carefully.
8180
*
8281
* @param id - Tenant ID
8382
* @param name - The tenant name must be unique per project.
@@ -90,6 +89,26 @@ void createWithId(String id, String name, List<String> selfProvisioningDomains,
9089
void update(String id, String name, List<String> selfProvisioningDomains, Map<String, Object> customAttributes)
9190
throws DescopeException;
9291

92+
/**
93+
* Update an existing tenant. IMPORTANT: All set parameters will override
94+
* whatever value is currently set in the existing tenant. Use carefully.
95+
*
96+
* @param id - Tenant ID (required)
97+
* @param name - The tenant name must be unique per project (required)
98+
* @param selfProvisioningDomains - Users authenticating from these domains will be associated with this tenant
99+
* @param customAttributes - Custom attributes to apply to tenant (needs to be pre-configured)
100+
* @param authType - The authentication type for the tenant
101+
* @param disabled - Whether the tenant is disabled
102+
* @param enforceSSO - Whether SSO is enforced for this tenant
103+
* @param enforceSSOExclusions - List of user IDs excluded from SSO enforcement
104+
* @param federatedAppIds - List of federated app IDs associated with the tenant
105+
* @param roleInheritance - The role inheritance setting for the tenant
106+
* @throws DescopeException in case of errors
107+
*/
108+
void update(String id, String name, List<String> selfProvisioningDomains, Map<String, Object> customAttributes,
109+
String authType, Boolean disabled, Boolean enforceSSO, List<String> enforceSSOExclusions,
110+
List<String> federatedAppIds, String roleInheritance) throws DescopeException;
111+
93112
/**
94113
* Delete an existing tenant. IMPORTANT: This action is irreversible. Use
95114
* carefully.

src/main/java/com/descope/sdk/mgmt/impl/TenantServiceImpl.java

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -90,21 +90,30 @@ private String create(Tenant tenant) {
9090
@Override
9191
public void update(String id, String name, List<String> selfProvisioningDomains, Map<String, Object> customAttributes)
9292
throws DescopeException {
93+
update(id, name, selfProvisioningDomains, customAttributes, null, null, null, null, null, null);
94+
}
95+
96+
@Override
97+
public void update(String id, String name, List<String> selfProvisioningDomains, Map<String, Object> customAttributes,
98+
String authType, Boolean disabled, Boolean enforceSSO, List<String> enforceSSOExclusions,
99+
List<String> federatedAppIds, String roleInheritance) throws DescopeException {
93100
if (StringUtils.isAnyBlank(id, name)) {
94101
throw ServerCommonException.invalidArgument("id or name");
95102
}
96-
update(Tenant.builder()
103+
URI updateTenantUri = composeUpdateTenantUri();
104+
ApiProxy apiProxy = getApiProxy();
105+
apiProxy.post(updateTenantUri, Tenant.builder()
97106
.id(id)
98107
.name(name)
99108
.selfProvisioningDomains(selfProvisioningDomains)
100109
.customAttributes(customAttributes)
101-
.build());
102-
}
103-
104-
private void update(Tenant tenant) {
105-
URI updateTenantUri = composeUpdateTenantUri();
106-
ApiProxy apiProxy = getApiProxy();
107-
apiProxy.post(updateTenantUri, tenant, Void.class);
110+
.authType(authType)
111+
.disabled(disabled)
112+
.enforceSSO(enforceSSO)
113+
.enforceSSOExclusions(enforceSSOExclusions)
114+
.federatedAppIds(federatedAppIds)
115+
.roleInheritance(roleInheritance)
116+
.build(), Void.class);
108117
}
109118

110119
@Override

src/test/java/com/descope/sdk/mgmt/impl/TenantServiceImplTest.java

Lines changed: 70 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
import static org.mockito.Mockito.times;
1313
import static org.mockito.Mockito.verify;
1414

15+
import org.mockito.ArgumentCaptor;
16+
1517
import com.descope.enums.TenantAuthType;
1618
import com.descope.exception.RateLimitExceededException;
1719
import com.descope.exception.ServerCommonException;
@@ -120,7 +122,74 @@ void testUpdateForSuccess() {
120122
mockedApiProxyBuilder.when(
121123
() -> ApiProxyBuilder.buildProxy(any(), any())).thenReturn(apiProxy);
122124
tenantService.update("someLoginId", "someName", selfProvisioningDomains, null);
123-
verify(apiProxy, times(1)).post(any(), any(), any());
125+
ArgumentCaptor<Tenant> captor = ArgumentCaptor.forClass(Tenant.class);
126+
verify(apiProxy, times(1)).post(any(), captor.capture(), any());
127+
Tenant sent = captor.getValue();
128+
assertThat(sent.getId()).isEqualTo("someLoginId");
129+
assertThat(sent.getName()).isEqualTo("someName");
130+
assertThat(sent.getSelfProvisioningDomains()).isEqualTo(selfProvisioningDomains);
131+
assertThat(sent.getCustomAttributes()).isNull();
132+
assertThat(sent.getAuthType()).isNull();
133+
assertThat(sent.getDisabled()).isNull();
134+
assertThat(sent.getEnforceSSO()).isNull();
135+
assertThat(sent.getEnforceSSOExclusions()).isNull();
136+
assertThat(sent.getFederatedAppIds()).isNull();
137+
assertThat(sent.getRoleInheritance()).isNull();
138+
}
139+
}
140+
141+
@Test
142+
void testUpdateFullForEmptyId() {
143+
ServerCommonException thrown = assertThrows(
144+
ServerCommonException.class,
145+
() -> tenantService.update("", "", selfProvisioningDomains, null, null, null, null, null, null, null));
146+
assertNotNull(thrown);
147+
assertEquals("The id or name argument is invalid", thrown.getMessage());
148+
}
149+
150+
@Test
151+
void testUpdateFullForSuccess() {
152+
ApiProxy apiProxy = mock(ApiProxy.class);
153+
doReturn(mockTenant).when(apiProxy).post(any(), any(), any());
154+
try (MockedStatic<ApiProxyBuilder> mockedApiProxyBuilder = mockStatic(ApiProxyBuilder.class)) {
155+
mockedApiProxyBuilder.when(
156+
() -> ApiProxyBuilder.buildProxy(any(), any())).thenReturn(apiProxy);
157+
tenantService.update("someId", "someName", selfProvisioningDomains, null,
158+
"saml", true, true, Arrays.asList("user1"), Arrays.asList("app1"), "inherit");
159+
ArgumentCaptor<Tenant> captor = ArgumentCaptor.forClass(Tenant.class);
160+
verify(apiProxy, times(1)).post(any(), captor.capture(), any());
161+
Tenant sent = captor.getValue();
162+
assertThat(sent.getId()).isEqualTo("someId");
163+
assertThat(sent.getName()).isEqualTo("someName");
164+
assertThat(sent.getSelfProvisioningDomains()).isEqualTo(selfProvisioningDomains);
165+
assertThat(sent.getAuthType()).isEqualTo("saml");
166+
assertThat(sent.getDisabled()).isTrue();
167+
assertThat(sent.getEnforceSSO()).isTrue();
168+
assertThat(sent.getEnforceSSOExclusions()).containsExactly("user1");
169+
assertThat(sent.getFederatedAppIds()).containsExactly("app1");
170+
assertThat(sent.getRoleInheritance()).isEqualTo("inherit");
171+
}
172+
}
173+
174+
@Test
175+
void testUpdateFullWithNullOptionalFieldsForSuccess() {
176+
ApiProxy apiProxy = mock(ApiProxy.class);
177+
doReturn(mockTenant).when(apiProxy).post(any(), any(), any());
178+
try (MockedStatic<ApiProxyBuilder> mockedApiProxyBuilder = mockStatic(ApiProxyBuilder.class)) {
179+
mockedApiProxyBuilder.when(
180+
() -> ApiProxyBuilder.buildProxy(any(), any())).thenReturn(apiProxy);
181+
tenantService.update("someId", "someName", null, null, null, null, null, null, null, null);
182+
ArgumentCaptor<Tenant> captor = ArgumentCaptor.forClass(Tenant.class);
183+
verify(apiProxy, times(1)).post(any(), captor.capture(), any());
184+
Tenant sent = captor.getValue();
185+
assertThat(sent.getId()).isEqualTo("someId");
186+
assertThat(sent.getName()).isEqualTo("someName");
187+
assertThat(sent.getAuthType()).isNull();
188+
assertThat(sent.getDisabled()).isNull();
189+
assertThat(sent.getEnforceSSO()).isNull();
190+
assertThat(sent.getEnforceSSOExclusions()).isNull();
191+
assertThat(sent.getFederatedAppIds()).isNull();
192+
assertThat(sent.getRoleInheritance()).isNull();
124193
}
125194
}
126195

0 commit comments

Comments
 (0)