use of org.apache.servicecomb.registry.api.registry.Microservice in project java-chassis by ServiceComb.
the class TestAccessController method testIsValidOfBlackAndWhiteByServiceNameAndVersion.
@Test
public void testIsValidOfBlackAndWhiteByServiceNameAndVersion() {
ArchaiusUtils.setProperty("servicecomb.publicKey.accessControl.white.list1.propertyName", "serviceName");
ArchaiusUtils.setProperty("servicecomb.publicKey.accessControl.white.list1.category", "property");
ArchaiusUtils.setProperty("servicecomb.publicKey.accessControl.white.list1.rule", "trust*");
ArchaiusUtils.setProperty("servicecomb.publicKey.accessControl.black.list1.propertyName", "version");
ArchaiusUtils.setProperty("servicecomb.publicKey.accessControl.black.list1.category", "property");
ArchaiusUtils.setProperty("servicecomb.publicKey.accessControl.black.list1.rule", "0.0.1");
AccessController controller = new AccessController();
Microservice service = new Microservice();
service.setServiceName("trustCustomer");
service.setVersion("0.0.1");
Assert.assertTrue(!controller.isAllowed(service));
}
use of org.apache.servicecomb.registry.api.registry.Microservice in project java-chassis by ServiceComb.
the class TestRSAProviderTokenManager method testTokenFromValidatePool.
@Test
public void testTokenFromValidatePool() {
RSAKeyPairEntry rsaKeyPairEntry = RSAUtils.generateRSAKeyPair();
RSAKeypair4Auth.INSTANCE.setPrivateKey(rsaKeyPairEntry.getPrivateKey());
RSAKeypair4Auth.INSTANCE.setPublicKey(rsaKeyPairEntry.getPublicKey());
RSAKeypair4Auth.INSTANCE.setPublicKeyEncoded(rsaKeyPairEntry.getPublicKeyEncoded());
String serviceId = "c8636e5acf1f11e7b701286ed488fc20";
String instanceId = "e8a04b54cf2711e7b701286ed488fc20";
RSAConsumerTokenManager rsaConsumerTokenManager = new RSAConsumerTokenManager();
MicroserviceInstance microserviceInstance = new MicroserviceInstance();
microserviceInstance.setInstanceId(instanceId);
Map<String, String> properties = new HashMap<>();
microserviceInstance.setProperties(properties);
properties.put(DefinitionConst.INSTANCE_PUBKEY_PRO, rsaKeyPairEntry.getPublicKeyEncoded());
Microservice microservice = new Microservice();
microservice.setServiceId(serviceId);
new Expectations(RegistrationManager.INSTANCE) {
{
RegistrationManager.INSTANCE.getMicroservice();
result = microservice;
RegistrationManager.INSTANCE.getMicroserviceInstance();
result = microserviceInstance;
}
};
// Test Consumer first create token
String token = rsaConsumerTokenManager.getToken();
Assert.assertNotNull(token);
// use cache token
Assert.assertEquals(token, rsaConsumerTokenManager.getToken());
new Expectations(MicroserviceInstanceCache.class) {
{
MicroserviceInstanceCache.getOrCreate(serviceId, instanceId);
result = microserviceInstance;
MicroserviceInstanceCache.getOrCreate(serviceId);
result = microservice;
}
};
RSAProviderTokenManager rsaProviderTokenManager = new RSAProviderTokenManager();
// first validate need to verify use RSA
Assert.assertTrue(rsaProviderTokenManager.valid(token));
// second validate use validated pool
Assert.assertTrue(rsaProviderTokenManager.valid(token));
}
use of org.apache.servicecomb.registry.api.registry.Microservice in project java-chassis by ServiceComb.
the class StoreServiceTest method should_register_instance_when_microservice_exist.
@Test
void should_register_instance_when_microservice_exist() {
Microservice microservice = Json.decodeValue(Json.encode(self.getMicroservice()), Microservice.class);
store.addMicroservice(microservice, self.getSchemasSummary());
RegisterRequest request = self.buildRegisterRequest();
InstanceStore instanceStore = service.register(request);
assertThat(microservice).isNotSameAs(self.getMicroservice());
assertThat(store.findMicroserviceStore(self.getServiceId()).getMicroservice()).isSameAs(microservice);
assertThat(instanceStore.getInstance()).isSameAs(self.getInstance());
}
use of org.apache.servicecomb.registry.api.registry.Microservice in project java-chassis by ServiceComb.
the class ClientServerEndpoint method getRegisteredMicroservice.
@GetMapping(path = "/getRegisteredMicroservice")
public Set<String> getRegisteredMicroservice() {
List<Microservice> microserviceList = DiscoveryManager.INSTANCE.getAllMicroservices();
Set<String> names = new HashSet<>();
for (Microservice m : microserviceList) {
if (m.getServiceName().equals("demo-zeroconfig-schemadiscovery-registry-client") || m.getServiceName().equals("demo-zeroconfig-schemadiscovery-registry-server")) {
names.add(m.getServiceName());
}
}
return names;
}
use of org.apache.servicecomb.registry.api.registry.Microservice in project java-chassis by ServiceComb.
the class TestLocalServiceRegistry method registerMicroservice.
@Test
public void registerMicroservice() {
ServiceRegistry serviceRegistry = LocalServiceRegistryFactory.createLocal();
serviceRegistry.init();
serviceRegistry.run();
Microservice microservice = new Microservice();
microservice.setAppId("appId");
microservice.setServiceName("msName");
String serviceId = serviceRegistry.getServiceRegistryClient().registerMicroservice(microservice);
Microservice remoteMicroservice = serviceRegistry.getRemoteMicroservice(serviceId);
Assert.assertEquals(serviceId, remoteMicroservice.getServiceId());
}
Aggregations