use of org.thingsboard.server.common.data.oauth2.OAuth2Info in project thingsboard by thingsboard.
the class BaseOAuth2ServiceTest method testSaveHttpsAndMixedDomainsTogether.
@Test(expected = DataValidationException.class)
public void testSaveHttpsAndMixedDomainsTogether() {
OAuth2Info oAuth2Info = new OAuth2Info(true, Lists.newArrayList(OAuth2ParamsInfo.builder().domainInfos(Lists.newArrayList(OAuth2DomainInfo.builder().name("first-domain").scheme(SchemeType.HTTPS).build(), OAuth2DomainInfo.builder().name("first-domain").scheme(SchemeType.MIXED).build(), OAuth2DomainInfo.builder().name("third-domain").scheme(SchemeType.HTTPS).build())).clientRegistrations(Lists.newArrayList(validRegistrationInfo(), validRegistrationInfo(), validRegistrationInfo())).build()));
oAuth2Service.saveOAuth2Info(oAuth2Info);
}
use of org.thingsboard.server.common.data.oauth2.OAuth2Info in project thingsboard by thingsboard.
the class BaseOAuth2ServiceTest method testUpdateClientsParams.
@Test
public void testUpdateClientsParams() {
OAuth2Info oAuth2Info = createDefaultOAuth2Info();
oAuth2Service.saveOAuth2Info(oAuth2Info);
OAuth2Info foundOAuth2Info = oAuth2Service.findOAuth2Info();
Assert.assertNotNull(foundOAuth2Info);
Assert.assertEquals(oAuth2Info, foundOAuth2Info);
OAuth2Info newOAuth2Info = new OAuth2Info(true, Lists.newArrayList(OAuth2ParamsInfo.builder().domainInfos(Lists.newArrayList(OAuth2DomainInfo.builder().name("another-domain").scheme(SchemeType.HTTPS).build())).mobileInfos(Collections.emptyList()).clientRegistrations(Lists.newArrayList(validRegistrationInfo())).build(), OAuth2ParamsInfo.builder().domainInfos(Lists.newArrayList(OAuth2DomainInfo.builder().name("test-domain").scheme(SchemeType.MIXED).build())).mobileInfos(Collections.emptyList()).clientRegistrations(Lists.newArrayList(validRegistrationInfo())).build()));
oAuth2Service.saveOAuth2Info(newOAuth2Info);
OAuth2Info foundAfterUpdateOAuth2Info = oAuth2Service.findOAuth2Info();
Assert.assertNotNull(foundAfterUpdateOAuth2Info);
Assert.assertEquals(newOAuth2Info, foundAfterUpdateOAuth2Info);
}
use of org.thingsboard.server.common.data.oauth2.OAuth2Info in project thingsboard by thingsboard.
the class BaseOAuth2ServiceTest method testGetDisabledOAuth2Clients.
@Test
public void testGetDisabledOAuth2Clients() {
OAuth2Info oAuth2Info = new OAuth2Info(true, Lists.newArrayList(OAuth2ParamsInfo.builder().domainInfos(Lists.newArrayList(OAuth2DomainInfo.builder().name("first-domain").scheme(SchemeType.HTTP).build(), OAuth2DomainInfo.builder().name("second-domain").scheme(SchemeType.MIXED).build(), OAuth2DomainInfo.builder().name("third-domain").scheme(SchemeType.HTTPS).build())).clientRegistrations(Lists.newArrayList(validRegistrationInfo(), validRegistrationInfo(), validRegistrationInfo())).build(), OAuth2ParamsInfo.builder().domainInfos(Lists.newArrayList(OAuth2DomainInfo.builder().name("second-domain").scheme(SchemeType.HTTP).build(), OAuth2DomainInfo.builder().name("fourth-domain").scheme(SchemeType.MIXED).build())).clientRegistrations(Lists.newArrayList(validRegistrationInfo(), validRegistrationInfo())).build()));
oAuth2Service.saveOAuth2Info(oAuth2Info);
List<OAuth2ClientInfo> secondDomainHttpClients = oAuth2Service.getOAuth2Clients("http", "second-domain", null, null);
Assert.assertEquals(5, secondDomainHttpClients.size());
oAuth2Info.setEnabled(false);
oAuth2Service.saveOAuth2Info(oAuth2Info);
List<OAuth2ClientInfo> secondDomainHttpDisabledClients = oAuth2Service.getOAuth2Clients("http", "second-domain", null, null);
Assert.assertEquals(0, secondDomainHttpDisabledClients.size());
}
use of org.thingsboard.server.common.data.oauth2.OAuth2Info in project thingsboard by thingsboard.
the class BaseOAuth2ServiceTest method testDisableParams.
@Test
public void testDisableParams() {
OAuth2Info oAuth2Info = createDefaultOAuth2Info();
oAuth2Info.setEnabled(true);
oAuth2Service.saveOAuth2Info(oAuth2Info);
OAuth2Info foundOAuth2Info = oAuth2Service.findOAuth2Info();
Assert.assertNotNull(foundOAuth2Info);
Assert.assertEquals(oAuth2Info, foundOAuth2Info);
oAuth2Info.setEnabled(false);
oAuth2Service.saveOAuth2Info(oAuth2Info);
OAuth2Info foundDisabledOAuth2Info = oAuth2Service.findOAuth2Info();
Assert.assertEquals(oAuth2Info, foundDisabledOAuth2Info);
}
use of org.thingsboard.server.common.data.oauth2.OAuth2Info in project thingsboard by thingsboard.
the class BaseOAuth2ServiceTest method testFindAppSecret.
@Test
public void testFindAppSecret() {
OAuth2Info oAuth2Info = new OAuth2Info(true, Lists.newArrayList(OAuth2ParamsInfo.builder().domainInfos(Lists.newArrayList(OAuth2DomainInfo.builder().name("first-domain").scheme(SchemeType.HTTP).build(), OAuth2DomainInfo.builder().name("second-domain").scheme(SchemeType.MIXED).build(), OAuth2DomainInfo.builder().name("third-domain").scheme(SchemeType.HTTPS).build())).mobileInfos(Lists.newArrayList(validMobileInfo("com.test.pkg1", "testPkg1AppSecret"), validMobileInfo("com.test.pkg2", "testPkg2AppSecret"))).clientRegistrations(Lists.newArrayList(validRegistrationInfo(), validRegistrationInfo(), validRegistrationInfo())).build(), OAuth2ParamsInfo.builder().domainInfos(Lists.newArrayList(OAuth2DomainInfo.builder().name("second-domain").scheme(SchemeType.HTTP).build(), OAuth2DomainInfo.builder().name("fourth-domain").scheme(SchemeType.MIXED).build())).mobileInfos(Collections.emptyList()).clientRegistrations(Lists.newArrayList(validRegistrationInfo(), validRegistrationInfo())).build()));
oAuth2Service.saveOAuth2Info(oAuth2Info);
OAuth2Info foundOAuth2Info = oAuth2Service.findOAuth2Info();
Assert.assertEquals(oAuth2Info, foundOAuth2Info);
List<OAuth2ClientInfo> firstDomainHttpClients = oAuth2Service.getOAuth2Clients("http", "first-domain", "com.test.pkg1", null);
Assert.assertEquals(3, firstDomainHttpClients.size());
for (OAuth2ClientInfo clientInfo : firstDomainHttpClients) {
String[] segments = clientInfo.getUrl().split("/");
String registrationId = segments[segments.length - 1];
String appSecret = oAuth2Service.findAppSecret(UUID.fromString(registrationId), "com.test.pkg1");
Assert.assertNotNull(appSecret);
Assert.assertEquals("testPkg1AppSecret", appSecret);
appSecret = oAuth2Service.findAppSecret(UUID.fromString(registrationId), "com.test.pkg2");
Assert.assertNotNull(appSecret);
Assert.assertEquals("testPkg2AppSecret", appSecret);
appSecret = oAuth2Service.findAppSecret(UUID.fromString(registrationId), "com.test.pkg3");
Assert.assertNull(appSecret);
}
}
Aggregations