use of org.thingsboard.server.common.data.oauth2.OAuth2RegistrationInfo in project thingsboard by thingsboard.
the class BaseOAuth2ServiceTest method testGetOAuth2ClientsForHttpAndHttps.
@Test
public void testGetOAuth2ClientsForHttpAndHttps() {
List<OAuth2RegistrationInfo> firstGroup = Lists.newArrayList(validRegistrationInfo(), validRegistrationInfo(), validRegistrationInfo(), validRegistrationInfo());
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("first-domain").scheme(SchemeType.HTTPS).build())).mobileInfos(Collections.emptyList()).clientRegistrations(firstGroup).build()));
oAuth2Service.saveOAuth2Info(oAuth2Info);
OAuth2Info foundOAuth2Info = oAuth2Service.findOAuth2Info();
Assert.assertNotNull(foundOAuth2Info);
Assert.assertEquals(oAuth2Info, foundOAuth2Info);
List<OAuth2ClientInfo> firstGroupClientInfos = firstGroup.stream().map(registrationInfo -> new OAuth2ClientInfo(registrationInfo.getLoginButtonLabel(), registrationInfo.getLoginButtonIcon(), null)).collect(Collectors.toList());
List<OAuth2ClientInfo> firstDomainHttpClients = oAuth2Service.getOAuth2Clients("http", "first-domain", null, null);
Assert.assertEquals(firstGroupClientInfos.size(), firstDomainHttpClients.size());
firstGroupClientInfos.forEach(firstGroupClientInfo -> {
Assert.assertTrue(firstDomainHttpClients.stream().anyMatch(clientInfo -> clientInfo.getIcon().equals(firstGroupClientInfo.getIcon()) && clientInfo.getName().equals(firstGroupClientInfo.getName())));
});
List<OAuth2ClientInfo> firstDomainHttpsClients = oAuth2Service.getOAuth2Clients("https", "first-domain", null, null);
Assert.assertEquals(firstGroupClientInfos.size(), firstDomainHttpsClients.size());
firstGroupClientInfos.forEach(firstGroupClientInfo -> {
Assert.assertTrue(firstDomainHttpsClients.stream().anyMatch(clientInfo -> clientInfo.getIcon().equals(firstGroupClientInfo.getIcon()) && clientInfo.getName().equals(firstGroupClientInfo.getName())));
});
}
use of org.thingsboard.server.common.data.oauth2.OAuth2RegistrationInfo in project thingsboard by thingsboard.
the class BaseOAuth2ServiceTest method testGetOAuth2Clients.
@Test
public void testGetOAuth2Clients() {
List<OAuth2RegistrationInfo> firstGroup = Lists.newArrayList(validRegistrationInfo(), validRegistrationInfo(), validRegistrationInfo(), validRegistrationInfo());
List<OAuth2RegistrationInfo> secondGroup = Lists.newArrayList(validRegistrationInfo(), validRegistrationInfo());
List<OAuth2RegistrationInfo> thirdGroup = Lists.newArrayList(validRegistrationInfo());
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(Collections.emptyList()).clientRegistrations(firstGroup).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(secondGroup).build(), OAuth2ParamsInfo.builder().domainInfos(Lists.newArrayList(OAuth2DomainInfo.builder().name("second-domain").scheme(SchemeType.HTTPS).build(), OAuth2DomainInfo.builder().name("fifth-domain").scheme(SchemeType.HTTP).build())).mobileInfos(Collections.emptyList()).clientRegistrations(thirdGroup).build()));
oAuth2Service.saveOAuth2Info(oAuth2Info);
OAuth2Info foundOAuth2Info = oAuth2Service.findOAuth2Info();
Assert.assertNotNull(foundOAuth2Info);
Assert.assertEquals(oAuth2Info, foundOAuth2Info);
List<OAuth2ClientInfo> firstGroupClientInfos = firstGroup.stream().map(registrationInfo -> new OAuth2ClientInfo(registrationInfo.getLoginButtonLabel(), registrationInfo.getLoginButtonIcon(), null)).collect(Collectors.toList());
List<OAuth2ClientInfo> secondGroupClientInfos = secondGroup.stream().map(registrationInfo -> new OAuth2ClientInfo(registrationInfo.getLoginButtonLabel(), registrationInfo.getLoginButtonIcon(), null)).collect(Collectors.toList());
List<OAuth2ClientInfo> thirdGroupClientInfos = thirdGroup.stream().map(registrationInfo -> new OAuth2ClientInfo(registrationInfo.getLoginButtonLabel(), registrationInfo.getLoginButtonIcon(), null)).collect(Collectors.toList());
List<OAuth2ClientInfo> nonExistentDomainClients = oAuth2Service.getOAuth2Clients("http", "non-existent-domain", null, null);
Assert.assertTrue(nonExistentDomainClients.isEmpty());
List<OAuth2ClientInfo> firstDomainHttpClients = oAuth2Service.getOAuth2Clients("http", "first-domain", null, null);
Assert.assertEquals(firstGroupClientInfos.size(), firstDomainHttpClients.size());
firstGroupClientInfos.forEach(firstGroupClientInfo -> {
Assert.assertTrue(firstDomainHttpClients.stream().anyMatch(clientInfo -> clientInfo.getIcon().equals(firstGroupClientInfo.getIcon()) && clientInfo.getName().equals(firstGroupClientInfo.getName())));
});
List<OAuth2ClientInfo> firstDomainHttpsClients = oAuth2Service.getOAuth2Clients("https", "first-domain", null, null);
Assert.assertTrue(firstDomainHttpsClients.isEmpty());
List<OAuth2ClientInfo> fourthDomainHttpClients = oAuth2Service.getOAuth2Clients("http", "fourth-domain", null, null);
Assert.assertEquals(secondGroupClientInfos.size(), fourthDomainHttpClients.size());
secondGroupClientInfos.forEach(secondGroupClientInfo -> {
Assert.assertTrue(fourthDomainHttpClients.stream().anyMatch(clientInfo -> clientInfo.getIcon().equals(secondGroupClientInfo.getIcon()) && clientInfo.getName().equals(secondGroupClientInfo.getName())));
});
List<OAuth2ClientInfo> fourthDomainHttpsClients = oAuth2Service.getOAuth2Clients("https", "fourth-domain", null, null);
Assert.assertEquals(secondGroupClientInfos.size(), fourthDomainHttpsClients.size());
secondGroupClientInfos.forEach(secondGroupClientInfo -> {
Assert.assertTrue(fourthDomainHttpsClients.stream().anyMatch(clientInfo -> clientInfo.getIcon().equals(secondGroupClientInfo.getIcon()) && clientInfo.getName().equals(secondGroupClientInfo.getName())));
});
List<OAuth2ClientInfo> secondDomainHttpClients = oAuth2Service.getOAuth2Clients("http", "second-domain", null, null);
Assert.assertEquals(firstGroupClientInfos.size() + secondGroupClientInfos.size(), secondDomainHttpClients.size());
firstGroupClientInfos.forEach(firstGroupClientInfo -> {
Assert.assertTrue(secondDomainHttpClients.stream().anyMatch(clientInfo -> clientInfo.getIcon().equals(firstGroupClientInfo.getIcon()) && clientInfo.getName().equals(firstGroupClientInfo.getName())));
});
secondGroupClientInfos.forEach(secondGroupClientInfo -> {
Assert.assertTrue(secondDomainHttpClients.stream().anyMatch(clientInfo -> clientInfo.getIcon().equals(secondGroupClientInfo.getIcon()) && clientInfo.getName().equals(secondGroupClientInfo.getName())));
});
List<OAuth2ClientInfo> secondDomainHttpsClients = oAuth2Service.getOAuth2Clients("https", "second-domain", null, null);
Assert.assertEquals(firstGroupClientInfos.size() + thirdGroupClientInfos.size(), secondDomainHttpsClients.size());
firstGroupClientInfos.forEach(firstGroupClientInfo -> {
Assert.assertTrue(secondDomainHttpsClients.stream().anyMatch(clientInfo -> clientInfo.getIcon().equals(firstGroupClientInfo.getIcon()) && clientInfo.getName().equals(firstGroupClientInfo.getName())));
});
thirdGroupClientInfos.forEach(thirdGroupClientInfo -> {
Assert.assertTrue(secondDomainHttpsClients.stream().anyMatch(clientInfo -> clientInfo.getIcon().equals(thirdGroupClientInfo.getIcon()) && clientInfo.getName().equals(thirdGroupClientInfo.getName())));
});
}
Aggregations