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);
}
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);
}
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);
}
Aggregations