|
|
|
@ -15,19 +15,33 @@ |
|
|
|
*/ |
|
|
|
package org.thingsboard.server.controller; |
|
|
|
|
|
|
|
import com.fasterxml.jackson.databind.JsonNode; |
|
|
|
import com.fasterxml.jackson.databind.node.ObjectNode; |
|
|
|
import com.google.common.collect.Lists; |
|
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
|
import org.junit.Assert; |
|
|
|
import org.junit.Test; |
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
import org.thingsboard.common.util.JacksonUtil; |
|
|
|
import org.thingsboard.server.common.data.AdminSettings; |
|
|
|
import org.thingsboard.server.common.data.ApiUsageState; |
|
|
|
import org.thingsboard.server.common.data.Customer; |
|
|
|
import org.thingsboard.server.common.data.Device; |
|
|
|
import org.thingsboard.server.common.data.EntityType; |
|
|
|
import org.thingsboard.server.common.data.FeaturesInfo; |
|
|
|
import org.thingsboard.server.common.data.Tenant; |
|
|
|
import org.thingsboard.server.common.data.TenantProfile; |
|
|
|
import org.thingsboard.server.common.data.User; |
|
|
|
import org.thingsboard.server.common.data.asset.Asset; |
|
|
|
import org.thingsboard.server.common.data.id.TenantId; |
|
|
|
import org.thingsboard.server.common.data.oauth2.MapperType; |
|
|
|
import org.thingsboard.server.common.data.oauth2.OAuth2CustomMapperConfig; |
|
|
|
import org.thingsboard.server.common.data.oauth2.OAuth2DomainInfo; |
|
|
|
import org.thingsboard.server.common.data.oauth2.OAuth2Info; |
|
|
|
import org.thingsboard.server.common.data.oauth2.OAuth2MapperConfig; |
|
|
|
import org.thingsboard.server.common.data.oauth2.OAuth2ParamsInfo; |
|
|
|
import org.thingsboard.server.common.data.oauth2.OAuth2RegistrationInfo; |
|
|
|
import org.thingsboard.server.common.data.oauth2.SchemeType; |
|
|
|
import org.thingsboard.server.common.data.page.PageData; |
|
|
|
import org.thingsboard.server.common.data.query.EntityCountQuery; |
|
|
|
import org.thingsboard.server.common.data.query.EntityData; |
|
|
|
@ -41,10 +55,14 @@ import org.thingsboard.server.service.ws.telemetry.cmd.v2.EntityCountUpdate; |
|
|
|
import org.thingsboard.server.service.ws.telemetry.cmd.v2.EntityDataUpdate; |
|
|
|
|
|
|
|
import java.util.ArrayList; |
|
|
|
import java.util.Arrays; |
|
|
|
import java.util.Collections; |
|
|
|
import java.util.List; |
|
|
|
import java.util.UUID; |
|
|
|
import java.util.concurrent.TimeUnit; |
|
|
|
|
|
|
|
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; |
|
|
|
|
|
|
|
@Slf4j |
|
|
|
public abstract class BaseHomePageApiTest extends AbstractControllerTest { |
|
|
|
|
|
|
|
@ -238,4 +256,120 @@ public abstract class BaseHomePageApiTest extends AbstractControllerTest { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
@Test |
|
|
|
public void testGetFeaturesInfo() throws Exception { |
|
|
|
loginSysAdmin(); |
|
|
|
|
|
|
|
FeaturesInfo featuresInfo = doGet("/api/admin/featuresInfo", FeaturesInfo.class); |
|
|
|
Assert.assertNotNull(featuresInfo); |
|
|
|
Assert.assertFalse(featuresInfo.isEmailEnabled()); |
|
|
|
Assert.assertFalse(featuresInfo.isSmsEnabled()); |
|
|
|
Assert.assertFalse(featuresInfo.isTwoFaEnabled()); |
|
|
|
Assert.assertFalse(featuresInfo.isNotificationEnabled()); |
|
|
|
Assert.assertFalse(featuresInfo.isOauthEnabled()); |
|
|
|
|
|
|
|
AdminSettings mailSettings = doGet("/api/admin/settings/mail", AdminSettings.class); |
|
|
|
|
|
|
|
JsonNode jsonValue = mailSettings.getJsonValue(); |
|
|
|
((ObjectNode) jsonValue).put("mailFrom", "test@thingsboard.org"); |
|
|
|
mailSettings.setJsonValue(jsonValue); |
|
|
|
|
|
|
|
doPost("/api/admin/settings", mailSettings).andExpect(status().isOk()); |
|
|
|
|
|
|
|
featuresInfo = doGet("/api/admin/featuresInfo", FeaturesInfo.class); |
|
|
|
Assert.assertTrue(featuresInfo.isEmailEnabled()); |
|
|
|
Assert.assertFalse(featuresInfo.isSmsEnabled()); |
|
|
|
Assert.assertFalse(featuresInfo.isTwoFaEnabled()); |
|
|
|
Assert.assertFalse(featuresInfo.isNotificationEnabled()); |
|
|
|
Assert.assertFalse(featuresInfo.isOauthEnabled()); |
|
|
|
|
|
|
|
AdminSettings smsSettings = new AdminSettings(); |
|
|
|
smsSettings.setKey("sms"); |
|
|
|
smsSettings.setJsonValue(JacksonUtil.newObjectNode()); |
|
|
|
doPost("/api/admin/settings", smsSettings).andExpect(status().isOk()); |
|
|
|
|
|
|
|
featuresInfo = doGet("/api/admin/featuresInfo", FeaturesInfo.class); |
|
|
|
Assert.assertTrue(featuresInfo.isEmailEnabled()); |
|
|
|
Assert.assertTrue(featuresInfo.isSmsEnabled()); |
|
|
|
Assert.assertFalse(featuresInfo.isTwoFaEnabled()); |
|
|
|
Assert.assertFalse(featuresInfo.isNotificationEnabled()); |
|
|
|
Assert.assertFalse(featuresInfo.isOauthEnabled()); |
|
|
|
|
|
|
|
AdminSettings twoFaSettingsSettings = new AdminSettings(); |
|
|
|
twoFaSettingsSettings.setKey("twoFaSettings"); |
|
|
|
twoFaSettingsSettings.setJsonValue(JacksonUtil.newObjectNode()); |
|
|
|
doPost("/api/admin/settings", twoFaSettingsSettings).andExpect(status().isOk()); |
|
|
|
|
|
|
|
featuresInfo = doGet("/api/admin/featuresInfo", FeaturesInfo.class); |
|
|
|
Assert.assertTrue(featuresInfo.isEmailEnabled()); |
|
|
|
Assert.assertTrue(featuresInfo.isSmsEnabled()); |
|
|
|
Assert.assertTrue(featuresInfo.isTwoFaEnabled()); |
|
|
|
Assert.assertFalse(featuresInfo.isNotificationEnabled()); |
|
|
|
Assert.assertFalse(featuresInfo.isOauthEnabled()); |
|
|
|
|
|
|
|
AdminSettings notificationsSettings = new AdminSettings(); |
|
|
|
notificationsSettings.setKey("notifications"); |
|
|
|
notificationsSettings.setJsonValue(JacksonUtil.newObjectNode()); |
|
|
|
doPost("/api/admin/settings", notificationsSettings).andExpect(status().isOk()); |
|
|
|
|
|
|
|
featuresInfo = doGet("/api/admin/featuresInfo", FeaturesInfo.class); |
|
|
|
Assert.assertTrue(featuresInfo.isEmailEnabled()); |
|
|
|
Assert.assertTrue(featuresInfo.isSmsEnabled()); |
|
|
|
Assert.assertTrue(featuresInfo.isTwoFaEnabled()); |
|
|
|
Assert.assertTrue(featuresInfo.isNotificationEnabled()); |
|
|
|
Assert.assertFalse(featuresInfo.isOauthEnabled()); |
|
|
|
|
|
|
|
OAuth2Info oAuth2Info = createDefaultOAuth2Info(); |
|
|
|
|
|
|
|
doPost("/api/oauth2/config", oAuth2Info).andExpect(status().isOk()); |
|
|
|
|
|
|
|
featuresInfo = doGet("/api/admin/featuresInfo", FeaturesInfo.class); |
|
|
|
Assert.assertNotNull(featuresInfo); |
|
|
|
Assert.assertTrue(featuresInfo.isEmailEnabled()); |
|
|
|
Assert.assertTrue(featuresInfo.isSmsEnabled()); |
|
|
|
Assert.assertTrue(featuresInfo.isTwoFaEnabled()); |
|
|
|
Assert.assertTrue(featuresInfo.isNotificationEnabled()); |
|
|
|
Assert.assertTrue(featuresInfo.isOauthEnabled()); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private OAuth2Info createDefaultOAuth2Info() { |
|
|
|
return new OAuth2Info(true, Lists.newArrayList( |
|
|
|
OAuth2ParamsInfo.builder() |
|
|
|
.domainInfos(Lists.newArrayList( |
|
|
|
OAuth2DomainInfo.builder().name("domain").scheme(SchemeType.MIXED).build() |
|
|
|
)) |
|
|
|
.mobileInfos(Collections.emptyList()) |
|
|
|
.clientRegistrations(Lists.newArrayList( |
|
|
|
validRegistrationInfo() |
|
|
|
)) |
|
|
|
.build() |
|
|
|
)); |
|
|
|
} |
|
|
|
|
|
|
|
private OAuth2RegistrationInfo validRegistrationInfo() { |
|
|
|
return OAuth2RegistrationInfo.builder() |
|
|
|
.clientId(UUID.randomUUID().toString()) |
|
|
|
.clientSecret(UUID.randomUUID().toString()) |
|
|
|
.authorizationUri(UUID.randomUUID().toString()) |
|
|
|
.accessTokenUri(UUID.randomUUID().toString()) |
|
|
|
.scope(Arrays.asList(UUID.randomUUID().toString(), UUID.randomUUID().toString())) |
|
|
|
.platforms(Collections.emptyList()) |
|
|
|
.userInfoUri(UUID.randomUUID().toString()) |
|
|
|
.userNameAttributeName(UUID.randomUUID().toString()) |
|
|
|
.jwkSetUri(UUID.randomUUID().toString()) |
|
|
|
.clientAuthenticationMethod(UUID.randomUUID().toString()) |
|
|
|
.loginButtonLabel(UUID.randomUUID().toString()) |
|
|
|
.mapperConfig( |
|
|
|
OAuth2MapperConfig.builder() |
|
|
|
.type(MapperType.CUSTOM) |
|
|
|
.custom( |
|
|
|
OAuth2CustomMapperConfig.builder() |
|
|
|
.url(UUID.randomUUID().toString()) |
|
|
|
.build() |
|
|
|
) |
|
|
|
.build() |
|
|
|
) |
|
|
|
.build(); |
|
|
|
} |
|
|
|
} |
|
|
|
|