Search in sources :

Example 71 with Microservice

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));
}
Also used : AccessController(org.apache.servicecomb.authentication.provider.AccessController) Microservice(org.apache.servicecomb.registry.api.registry.Microservice) Test(org.junit.Test)

Example 72 with Microservice

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));
}
Also used : Expectations(mockit.Expectations) Microservice(org.apache.servicecomb.registry.api.registry.Microservice) RSAKeyPairEntry(org.apache.servicecomb.foundation.common.utils.RSAKeyPairEntry) HashMap(java.util.HashMap) MicroserviceInstance(org.apache.servicecomb.registry.api.registry.MicroserviceInstance) RSAConsumerTokenManager(org.apache.servicecomb.authentication.consumer.RSAConsumerTokenManager) Test(org.junit.Test)

Example 73 with Microservice

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());
}
Also used : Microservice(org.apache.servicecomb.registry.api.registry.Microservice) InstanceStore(org.apache.servicecomb.registry.lightweight.store.InstanceStore) Test(org.junit.jupiter.api.Test)

Example 74 with Microservice

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;
}
Also used : Microservice(org.apache.servicecomb.registry.api.registry.Microservice) HashSet(java.util.HashSet) GetMapping(org.springframework.web.bind.annotation.GetMapping)

Example 75 with Microservice

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());
}
Also used : Microservice(org.apache.servicecomb.registry.api.registry.Microservice) ServiceRegistry(org.apache.servicecomb.serviceregistry.ServiceRegistry) Test(org.junit.Test)

Aggregations

Microservice (org.apache.servicecomb.registry.api.registry.Microservice)86 Test (org.junit.Test)53 MicroserviceInstance (org.apache.servicecomb.registry.api.registry.MicroserviceInstance)20 Expectations (mockit.Expectations)15 ArrayList (java.util.ArrayList)14 List (java.util.List)13 GetSchemaResponse (org.apache.servicecomb.serviceregistry.api.response.GetSchemaResponse)10 Holder (org.apache.servicecomb.serviceregistry.client.http.Holder)10 HashMap (java.util.HashMap)9 MicroserviceFactory (org.apache.servicecomb.registry.api.registry.MicroserviceFactory)9 Swagger (io.swagger.models.Swagger)8 Before (org.junit.Before)8 MockUp (mockit.MockUp)6 Configuration (org.apache.commons.configuration.Configuration)6 AccessController (org.apache.servicecomb.authentication.provider.AccessController)6 Subscribe (com.google.common.eventbus.Subscribe)5 MicroserviceInstances (org.apache.servicecomb.registry.api.registry.MicroserviceInstances)5 EventBus (com.google.common.eventbus.EventBus)4 Version (org.apache.servicecomb.foundation.common.Version)4 HashSet (java.util.HashSet)3