use of org.apache.servicecomb.registry.api.registry.Microservice in project java-chassis by ServiceComb.
the class TestAccessController method testIsValidOfBlackByServiceName.
@Test
public void testIsValidOfBlackByServiceName() {
ArchaiusUtils.setProperty("servicecomb.publicKey.accessControl.black.list1.propertyName", "serviceName");
ArchaiusUtils.setProperty("servicecomb.publicKey.accessControl.black.list1.category", "property");
ArchaiusUtils.setProperty("servicecomb.publicKey.accessControl.black.list1.rule", "trust*");
AccessController controller = new AccessController();
Microservice service = new Microservice();
service.setServiceName("trustCustomer");
Assert.assertTrue(!controller.isAllowed(service));
service.setServiceName("nottrustCustomer");
Assert.assertTrue(controller.isAllowed(service));
ArchaiusUtils.setProperty("servicecomb.publicKey.accessControl.black.list1.rule", "*trust");
service.setServiceName("Customer_trust");
Assert.assertTrue(!controller.isAllowed(service));
service.setServiceName("Customer_trust_not");
Assert.assertTrue(controller.isAllowed(service));
ArchaiusUtils.setProperty("servicecomb.publicKey.accessControl.black.list1.rule", "trust");
service.setServiceName("trust");
Assert.assertTrue(!controller.isAllowed(service));
service.setServiceName("Customer_trust");
Assert.assertTrue(controller.isAllowed(service));
}
use of org.apache.servicecomb.registry.api.registry.Microservice in project java-chassis by ServiceComb.
the class TestAccessController method testIsValidOfWhiteByProperties.
@Test
public void testIsValidOfWhiteByProperties() {
ArchaiusUtils.setProperty("servicecomb.publicKey.accessControl.white.list1.propertyName", "tag");
ArchaiusUtils.setProperty("servicecomb.publicKey.accessControl.white.list1.category", "property");
ArchaiusUtils.setProperty("servicecomb.publicKey.accessControl.white.list1.rule", "test");
AccessController controller = new AccessController();
Microservice service = new Microservice();
Map<String, String> map = new HashMap<>();
map.put("tag", "test");
service.setProperties(map);
Assert.assertTrue(controller.isAllowed(service));
map.put("tag", "testa");
service.setProperties(map);
Assert.assertTrue(!controller.isAllowed(service));
}
use of org.apache.servicecomb.registry.api.registry.Microservice in project java-chassis by ServiceComb.
the class MicroserviceRegisterTask method checkSchemaIdSet.
private boolean checkSchemaIdSet() {
Microservice existMicroservice = srClient.getMicroservice(microservice.getServiceId());
if (existMicroservice == null) {
LOGGER.error("Error to get microservice from service center when check schema set");
return false;
}
Set<String> existSchemas = new HashSet<>(existMicroservice.getSchemas());
Set<String> localSchemas = new HashSet<>(microservice.getSchemas());
schemaIdSetMatch = existSchemas.equals(localSchemas);
if (!schemaIdSetMatch) {
LOGGER.warn("SchemaIds is different between local and service center. " + "serviceId=[{}] appId=[{}], name=[{}], version=[{}], env=[{}], local schemaIds={}, service center schemaIds={}", microservice.getServiceId(), microservice.getAppId(), microservice.getServiceName(), microservice.getVersion(), microservice.getEnvironment(), localSchemas, existSchemas);
// because even schema ids not same, will also check content to see if should fail.
return true;
}
LOGGER.info("SchemaIds are equals to service center. serviceId=[{}], appId=[{}], name=[{}], version=[{}], env=[{}], schemaIds={}", microservice.getServiceId(), microservice.getAppId(), microservice.getServiceName(), microservice.getVersion(), microservice.getEnvironment(), localSchemas);
return true;
}
use of org.apache.servicecomb.registry.api.registry.Microservice in project java-chassis by ServiceComb.
the class TestMicroserviceFactory method testSetDescription.
@Test
public void testSetDescription() {
MicroserviceFactory factory = new MicroserviceFactory();
Configuration configuration = ConfigUtil.createLocalConfig();
configuration.setProperty(BootStrapProperties.CONFIG_SERVICE_DESCRIPTION, new String[] { "test1", "test2" });
Microservice microservice = factory.create(configuration);
Assert.assertEquals("test1,test2", microservice.getDescription());
}
use of org.apache.servicecomb.registry.api.registry.Microservice in project java-chassis by ServiceComb.
the class TestMicroserviceFactory method testSetDescriptionOnBlankDescription.
@Test
public void testSetDescriptionOnBlankDescription() {
Configuration configuration = ConfigUtil.createLocalConfig();
configuration.setProperty(BootStrapProperties.CONFIG_SERVICE_DESCRIPTION, new String[] { " ", " " });
MicroserviceFactory factory = new MicroserviceFactory();
Microservice microservice = factory.create(configuration);
Assert.assertEquals(" , ", microservice.getDescription());
}
Aggregations