Search in sources :

Example 41 with Secured

use of com.alibaba.nacos.auth.annotation.Secured in project nacos by alibaba.

the class NamingGrpcResourceParserTest method testParseWithFullContextForNamingRequest.

@Test
@Secured()
public void testParseWithFullContextForNamingRequest() throws NoSuchMethodException {
    Secured secured = getMethodSecure();
    AbstractNamingRequest request = mockNamingRequest("testNs", "testG", "testS");
    Resource actual = resourceParser.parse(request, secured);
    assertEquals("testNs", actual.getNamespaceId());
    assertEquals("testG", actual.getGroup());
    assertEquals("testS", actual.getName());
    assertEquals(Constants.Naming.NAMING_MODULE, actual.getType());
    assertEquals(MockNamingRequest.class.getSimpleName(), actual.getProperties().getProperty(com.alibaba.nacos.plugin.auth.constant.Constants.Resource.REQUEST_CLASS));
}
Also used : AbstractNamingRequest(com.alibaba.nacos.api.naming.remote.request.AbstractNamingRequest) Secured(com.alibaba.nacos.auth.annotation.Secured) Resource(com.alibaba.nacos.plugin.auth.api.Resource) Test(org.junit.Test) Secured(com.alibaba.nacos.auth.annotation.Secured)

Example 42 with Secured

use of com.alibaba.nacos.auth.annotation.Secured in project nacos by alibaba.

the class NamingGrpcResourceParserTest method testParseWithoutGroupForOtherRequest.

@Test
@Secured()
public void testParseWithoutGroupForOtherRequest() throws NoSuchMethodException {
    Secured secured = getMethodSecure();
    Request request = mockOtherRequest("testNs", null, "testS");
    Resource actual = resourceParser.parse(request, secured);
    assertEquals("testNs", actual.getNamespaceId());
    assertEquals(StringUtils.EMPTY, actual.getGroup());
    assertEquals("testS", actual.getName());
    assertEquals(Constants.Naming.NAMING_MODULE, actual.getType());
    assertEquals(NotifySubscriberRequest.class.getSimpleName(), actual.getProperties().getProperty(com.alibaba.nacos.plugin.auth.constant.Constants.Resource.REQUEST_CLASS));
}
Also used : NotifySubscriberRequest(com.alibaba.nacos.api.naming.remote.request.NotifySubscriberRequest) Secured(com.alibaba.nacos.auth.annotation.Secured) AbstractNamingRequest(com.alibaba.nacos.api.naming.remote.request.AbstractNamingRequest) NotifySubscriberRequest(com.alibaba.nacos.api.naming.remote.request.NotifySubscriberRequest) Request(com.alibaba.nacos.api.remote.request.Request) Resource(com.alibaba.nacos.plugin.auth.api.Resource) Test(org.junit.Test) Secured(com.alibaba.nacos.auth.annotation.Secured)

Example 43 with Secured

use of com.alibaba.nacos.auth.annotation.Secured in project nacos by alibaba.

the class NamingGrpcResourceParserTest method testParseWithoutNamespaceForOtherRequest.

@Test
@Secured()
public void testParseWithoutNamespaceForOtherRequest() throws NoSuchMethodException {
    Secured secured = getMethodSecure();
    Request request = mockOtherRequest(null, "testG", "testS");
    Resource actual = resourceParser.parse(request, secured);
    assertNull(actual.getNamespaceId());
    assertEquals("testG", actual.getGroup());
    assertEquals("testS", actual.getName());
    assertEquals(Constants.Naming.NAMING_MODULE, actual.getType());
    assertEquals(NotifySubscriberRequest.class.getSimpleName(), actual.getProperties().getProperty(com.alibaba.nacos.plugin.auth.constant.Constants.Resource.REQUEST_CLASS));
}
Also used : NotifySubscriberRequest(com.alibaba.nacos.api.naming.remote.request.NotifySubscriberRequest) Secured(com.alibaba.nacos.auth.annotation.Secured) AbstractNamingRequest(com.alibaba.nacos.api.naming.remote.request.AbstractNamingRequest) NotifySubscriberRequest(com.alibaba.nacos.api.naming.remote.request.NotifySubscriberRequest) Request(com.alibaba.nacos.api.remote.request.Request) Resource(com.alibaba.nacos.plugin.auth.api.Resource) Test(org.junit.Test) Secured(com.alibaba.nacos.auth.annotation.Secured)

Example 44 with Secured

use of com.alibaba.nacos.auth.annotation.Secured in project nacos by alibaba.

the class ConfigHttpResourceParserTest method testParseWithoutDataId.

@Test
@Secured(signType = Constants.Config.CONFIG_MODULE)
public void testParseWithoutDataId() throws NoSuchMethodException {
    Secured secured = getMethodSecure();
    Mockito.when(request.getParameter(eq("tenant"))).thenReturn("testNs");
    Mockito.when(request.getParameter(eq(Constants.GROUP))).thenReturn("testG");
    Resource actual = resourceParser.parse(request, secured);
    assertEquals("testNs", actual.getNamespaceId());
    assertEquals("testG", actual.getGroup());
    assertEquals(StringUtils.EMPTY, actual.getName());
    assertEquals(Constants.Config.CONFIG_MODULE, actual.getType());
}
Also used : Secured(com.alibaba.nacos.auth.annotation.Secured) Resource(com.alibaba.nacos.plugin.auth.api.Resource) Test(org.junit.Test) Secured(com.alibaba.nacos.auth.annotation.Secured)

Example 45 with Secured

use of com.alibaba.nacos.auth.annotation.Secured in project nacos by alibaba.

the class ConfigHttpResourceParserTest method testParseWithoutNamespace.

@Test
@Secured(signType = Constants.Config.CONFIG_MODULE)
public void testParseWithoutNamespace() throws NoSuchMethodException {
    Secured secured = getMethodSecure();
    Mockito.when(request.getParameter(eq(Constants.GROUP))).thenReturn("testG");
    Mockito.when(request.getParameter(eq(Constants.DATAID))).thenReturn("testD");
    Resource actual = resourceParser.parse(request, secured);
    assertEquals(StringUtils.EMPTY, actual.getNamespaceId());
    assertEquals("testG", actual.getGroup());
    assertEquals("testD", actual.getName());
    assertEquals(Constants.Config.CONFIG_MODULE, actual.getType());
}
Also used : Secured(com.alibaba.nacos.auth.annotation.Secured) Resource(com.alibaba.nacos.plugin.auth.api.Resource) Test(org.junit.Test) Secured(com.alibaba.nacos.auth.annotation.Secured)

Aggregations

Secured (com.alibaba.nacos.auth.annotation.Secured)104 Resource (com.alibaba.nacos.plugin.auth.api.Resource)34 Test (org.junit.Test)32 GetMapping (org.springframework.web.bind.annotation.GetMapping)20 CanDistro (com.alibaba.nacos.naming.web.CanDistro)17 Instance (com.alibaba.nacos.api.naming.pojo.Instance)16 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)15 PostMapping (org.springframework.web.bind.annotation.PostMapping)13 PutMapping (org.springframework.web.bind.annotation.PutMapping)13 DeleteMapping (org.springframework.web.bind.annotation.DeleteMapping)12 ConfigDataChangeEvent (com.alibaba.nacos.config.server.model.event.ConfigDataChangeEvent)10 Timestamp (java.sql.Timestamp)10 NacosException (com.alibaba.nacos.api.exception.NacosException)8 AbstractNamingRequest (com.alibaba.nacos.api.naming.remote.request.AbstractNamingRequest)8 Request (com.alibaba.nacos.api.remote.request.Request)8 ConfigInfo (com.alibaba.nacos.config.server.model.ConfigInfo)8 ServiceMetadata (com.alibaba.nacos.naming.core.v2.metadata.ServiceMetadata)7 ConfigBatchListenRequest (com.alibaba.nacos.api.config.remote.request.ConfigBatchListenRequest)6 HashMap (java.util.HashMap)6 ConfigAllInfo (com.alibaba.nacos.config.server.model.ConfigAllInfo)5