Search in sources :

Example 31 with HttpRestResult

use of com.alibaba.nacos.common.http.HttpRestResult in project nacos by alibaba.

the class NacosClientAuthServiceImplTest method testTestLoginServerListLoginInWindow.

@Test
public void testTestLoginServerListLoginInWindow() throws Exception {
    // given
    NacosRestTemplate nacosRestTemplate = mock(NacosRestTemplate.class);
    HttpRestResult<Object> result = new HttpRestResult<>();
    result.setData("{\"accessToken\":\"ttttttttttttttttt\",\"tokenTtl\":1000}");
    result.setCode(200);
    when(nacosRestTemplate.postForm(any(), (Header) any(), any(), any(), any())).thenReturn(result);
    Properties properties = new Properties();
    properties.setProperty(PropertyKeyConst.USERNAME, "aaa");
    properties.setProperty(PropertyKeyConst.PASSWORD, "123456");
    List<String> serverList = new ArrayList<>();
    serverList.add("localhost");
    NacosClientAuthServiceImpl nacosClientAuthService = new NacosClientAuthServiceImpl();
    nacosClientAuthService.setServerList(serverList);
    nacosClientAuthService.setNacosRestTemplate(nacosRestTemplate);
    // when
    nacosClientAuthService.login(properties);
    // then
    boolean ret = nacosClientAuthService.login(properties);
    Assert.assertTrue(ret);
}
Also used : HttpRestResult(com.alibaba.nacos.common.http.HttpRestResult) ArrayList(java.util.ArrayList) Properties(java.util.Properties) NacosRestTemplate(com.alibaba.nacos.common.http.client.NacosRestTemplate) Test(org.junit.Test)

Example 32 with HttpRestResult

use of com.alibaba.nacos.common.http.HttpRestResult in project nacos by alibaba.

the class SecurityProxyTest method testTestLoginServerListSuccess.

@Test
public void testTestLoginServerListSuccess() throws Exception {
    // given
    NacosRestTemplate nacosRestTemplate = mock(NacosRestTemplate.class);
    HttpRestResult<Object> result = new HttpRestResult<>();
    result.setData("{\"accessToken\":\"ttttttttttttttttt\",\"tokenTtl\":1000}");
    result.setCode(200);
    when(nacosRestTemplate.postForm(any(), (Header) any(), any(), any(), any())).thenReturn(result);
    Properties properties = new Properties();
    properties.setProperty(PropertyKeyConst.USERNAME, "aaa");
    properties.setProperty(PropertyKeyConst.PASSWORD, "123456");
    SecurityProxy securityProxy = new SecurityProxy(properties, nacosRestTemplate);
    // when
    boolean ret = securityProxy.login(Collections.singletonList("localhost"));
    // then
    Assert.assertTrue(ret);
}
Also used : HttpRestResult(com.alibaba.nacos.common.http.HttpRestResult) Properties(java.util.Properties) NacosRestTemplate(com.alibaba.nacos.common.http.client.NacosRestTemplate) Test(org.junit.Test)

Example 33 with HttpRestResult

use of com.alibaba.nacos.common.http.HttpRestResult in project nacos by alibaba.

the class SecurityProxyTest method testTestLoginServerListLoginInWindow.

@Test
public void testTestLoginServerListLoginInWindow() throws Exception {
    // given
    NacosRestTemplate nacosRestTemplate = mock(NacosRestTemplate.class);
    HttpRestResult<Object> result = new HttpRestResult<>();
    result.setData("{\"accessToken\":\"ttttttttttttttttt\",\"tokenTtl\":1000}");
    result.setCode(200);
    when(nacosRestTemplate.postForm(any(), (Header) any(), any(), any(), any())).thenReturn(result);
    Properties properties = new Properties();
    properties.setProperty(PropertyKeyConst.USERNAME, "aaa");
    properties.setProperty(PropertyKeyConst.PASSWORD, "123456");
    SecurityProxy securityProxy = new SecurityProxy(properties, nacosRestTemplate);
    // when
    securityProxy.login(Collections.singletonList("localhost"));
    // then
    boolean ret = securityProxy.login(Collections.singletonList("localhost"));
    // then
    Assert.assertTrue(ret);
}
Also used : HttpRestResult(com.alibaba.nacos.common.http.HttpRestResult) Properties(java.util.Properties) NacosRestTemplate(com.alibaba.nacos.common.http.client.NacosRestTemplate) Test(org.junit.Test)

Aggregations

HttpRestResult (com.alibaba.nacos.common.http.HttpRestResult)33 NacosRestTemplate (com.alibaba.nacos.common.http.client.NacosRestTemplate)29 Properties (java.util.Properties)29 Test (org.junit.Test)29 Field (java.lang.reflect.Field)19 ServiceInfoHolder (com.alibaba.nacos.client.naming.cache.ServiceInfoHolder)18 ServerListManager (com.alibaba.nacos.client.naming.core.ServerListManager)18 SecurityProxy (com.alibaba.nacos.client.security.SecurityProxy)18 ArrayList (java.util.ArrayList)5 HashMap (java.util.HashMap)5 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)5 Instance (com.alibaba.nacos.api.naming.pojo.Instance)3 Service (com.alibaba.nacos.api.naming.pojo.Service)3 NoneSelector (com.alibaba.nacos.api.selector.NoneSelector)3 Header (com.alibaba.nacos.common.http.param.Header)3 ServiceInfo (com.alibaba.nacos.api.naming.pojo.ServiceInfo)2 BeatInfo (com.alibaba.nacos.client.naming.beat.BeatInfo)1 DefaultClientHttpResponse (com.alibaba.nacos.common.http.client.response.DefaultClientHttpResponse)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1