Search in sources :

Example 71 with Invocation

use of org.apache.dubbo.rpc.Invocation in project dubbo by alibaba.

the class AccessKeyAuthenticatorTest method testSignForRequest.

@Test
void testSignForRequest() {
    URL url = URL.valueOf("dubbo://10.10.10.10:2181").addParameter(Constants.ACCESS_KEY_ID_KEY, "ak").addParameter(CommonConstants.APPLICATION_KEY, "test").addParameter(Constants.SECRET_ACCESS_KEY_KEY, "sk");
    Invocation invocation = new RpcInvocation();
    AccessKeyAuthenticator helper = mock(AccessKeyAuthenticator.class);
    doCallRealMethod().when(helper).sign(invocation, url);
    when(helper.getSignature(eq(url), eq(invocation), eq("sk"), anyString())).thenReturn("dubbo");
    AccessKeyPair accessKeyPair = mock(AccessKeyPair.class);
    when(accessKeyPair.getSecretKey()).thenReturn("sk");
    when(helper.getAccessKeyPair(invocation, url)).thenReturn(accessKeyPair);
    helper.sign(invocation, url);
    assertEquals(String.valueOf(invocation.getAttachment(CommonConstants.CONSUMER)), url.getParameter(CommonConstants.APPLICATION_KEY));
    assertNotNull(invocation.getAttachments().get(Constants.REQUEST_SIGNATURE_KEY));
    assertEquals(invocation.getAttachments().get(Constants.REQUEST_SIGNATURE_KEY), "dubbo");
}
Also used : RpcInvocation(org.apache.dubbo.rpc.RpcInvocation) Invocation(org.apache.dubbo.rpc.Invocation) RpcInvocation(org.apache.dubbo.rpc.RpcInvocation) AccessKeyPair(org.apache.dubbo.auth.model.AccessKeyPair) URL(org.apache.dubbo.common.URL) Test(org.junit.jupiter.api.Test)

Example 72 with Invocation

use of org.apache.dubbo.rpc.Invocation in project dubbo by alibaba.

the class AccessKeyAuthenticatorTest method testGetSignatureWithParameter.

@Test
void testGetSignatureWithParameter() {
    URL url = mock(URL.class);
    when(url.getParameter(Constants.PARAMETER_SIGNATURE_ENABLE_KEY, false)).thenReturn(true);
    Invocation invocation = mock(Invocation.class);
    String secretKey = "123456";
    Object[] params = { "dubbo", new ArrayList() };
    when(invocation.getArguments()).thenReturn(params);
    AccessKeyAuthenticator helper = new AccessKeyAuthenticator();
    String signature = helper.getSignature(url, invocation, secretKey, String.valueOf(System.currentTimeMillis()));
    assertNotNull(signature);
    Object[] fakeParams = { "dubbo1", new ArrayList<>() };
    when(invocation.getArguments()).thenReturn(fakeParams);
    String signature1 = helper.getSignature(url, invocation, secretKey, String.valueOf(System.currentTimeMillis()));
    assertNotEquals(signature, signature1);
}
Also used : Invocation(org.apache.dubbo.rpc.Invocation) RpcInvocation(org.apache.dubbo.rpc.RpcInvocation) ArrayList(java.util.ArrayList) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) URL(org.apache.dubbo.common.URL) Test(org.junit.jupiter.api.Test)

Example 73 with Invocation

use of org.apache.dubbo.rpc.Invocation in project dubbo by alibaba.

the class AccessKeyAuthenticatorTest method testAuthenticateRequest.

@Test
void testAuthenticateRequest() throws RpcAuthenticationException {
    URL url = URL.valueOf("dubbo://10.10.10.10:2181").addParameter(Constants.ACCESS_KEY_ID_KEY, "ak").addParameter(CommonConstants.APPLICATION_KEY, "test").addParameter(Constants.SECRET_ACCESS_KEY_KEY, "sk");
    Invocation invocation = new RpcInvocation();
    invocation.setAttachment(Constants.ACCESS_KEY_ID_KEY, "ak");
    invocation.setAttachment(Constants.REQUEST_SIGNATURE_KEY, "dubbo");
    invocation.setAttachment(Constants.REQUEST_TIMESTAMP_KEY, String.valueOf(System.currentTimeMillis()));
    invocation.setAttachment(CommonConstants.CONSUMER, "test");
    AccessKeyAuthenticator helper = mock(AccessKeyAuthenticator.class);
    doCallRealMethod().when(helper).authenticate(invocation, url);
    when(helper.getSignature(eq(url), eq(invocation), eq("sk"), anyString())).thenReturn("dubbo");
    AccessKeyPair accessKeyPair = mock(AccessKeyPair.class);
    when(accessKeyPair.getSecretKey()).thenReturn("sk");
    when(helper.getAccessKeyPair(invocation, url)).thenReturn(accessKeyPair);
    assertDoesNotThrow(() -> helper.authenticate(invocation, url));
}
Also used : RpcInvocation(org.apache.dubbo.rpc.RpcInvocation) Invocation(org.apache.dubbo.rpc.Invocation) RpcInvocation(org.apache.dubbo.rpc.RpcInvocation) AccessKeyPair(org.apache.dubbo.auth.model.AccessKeyPair) URL(org.apache.dubbo.common.URL) Test(org.junit.jupiter.api.Test)

Example 74 with Invocation

use of org.apache.dubbo.rpc.Invocation in project dubbo by alibaba.

the class ConsumerSignFilterTest method testAuthEnabled.

@Test
void testAuthEnabled() {
    URL url = URL.valueOf("dubbo://10.10.10.10:2181").addParameter(Constants.ACCESS_KEY_ID_KEY, "ak").addParameter(Constants.SECRET_ACCESS_KEY_KEY, "sk").addParameter(CommonConstants.APPLICATION_KEY, "test").addParameter(Constants.SERVICE_AUTH, true);
    Invoker invoker = mock(Invoker.class);
    Invocation invocation = mock(Invocation.class);
    when(invoker.getUrl()).thenReturn(url);
    ConsumerSignFilter consumerSignFilter = new ConsumerSignFilter();
    consumerSignFilter.invoke(invoker, invocation);
    verify(invocation, times(1)).setAttachment(eq(Constants.REQUEST_SIGNATURE_KEY), anyString());
}
Also used : Invoker(org.apache.dubbo.rpc.Invoker) Invocation(org.apache.dubbo.rpc.Invocation) URL(org.apache.dubbo.common.URL) Test(org.junit.jupiter.api.Test)

Example 75 with Invocation

use of org.apache.dubbo.rpc.Invocation in project dubbo by alibaba.

the class ThriftNativeCodec method encodeRequest.

protected void encodeRequest(Channel channel, ChannelBuffer buffer, Request request) throws IOException {
    Invocation invocation = (Invocation) request.getData();
    TProtocol protocol = newProtocol(channel.getUrl(), buffer);
    try {
        protocol.writeMessageBegin(new TMessage(invocation.getMethodName(), TMessageType.CALL, thriftSeq.getAndIncrement()));
        protocol.writeStructBegin(new TStruct(invocation.getMethodName() + "_args"));
        for (int i = 0; i < invocation.getParameterTypes().length; i++) {
            Class<?> type = invocation.getParameterTypes()[i];
        }
    } catch (TException e) {
        throw new IOException(e.getMessage(), e);
    }
}
Also used : TException(org.apache.thrift.TException) Invocation(org.apache.dubbo.rpc.Invocation) TProtocol(org.apache.thrift.protocol.TProtocol) TMessage(org.apache.thrift.protocol.TMessage) IOException(java.io.IOException) TStruct(org.apache.thrift.protocol.TStruct)

Aggregations

Invocation (org.apache.dubbo.rpc.Invocation)98 Test (org.junit.jupiter.api.Test)78 URL (org.apache.dubbo.common.URL)77 Invoker (org.apache.dubbo.rpc.Invoker)44 RpcInvocation (org.apache.dubbo.rpc.RpcInvocation)44 Result (org.apache.dubbo.rpc.Result)33 AppResponse (org.apache.dubbo.rpc.AppResponse)29 RpcException (org.apache.dubbo.rpc.RpcException)18 MockInvocation (org.apache.dubbo.rpc.support.MockInvocation)17 HashMap (java.util.HashMap)16 AsyncRpcResult (org.apache.dubbo.rpc.AsyncRpcResult)13 BlockMyInvoker (org.apache.dubbo.rpc.support.BlockMyInvoker)11 MyInvoker (org.apache.dubbo.rpc.support.MyInvoker)10 ArrayList (java.util.ArrayList)8 Person (org.apache.dubbo.rpc.support.Person)7 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)6 IMetricManager (com.alibaba.metrics.IMetricManager)5 Method (java.lang.reflect.Method)5 DemoService (org.apache.dubbo.monitor.dubbo.service.DemoService)5 FastCompass (com.alibaba.metrics.FastCompass)4