use of org.apache.dubbo.auth.model.AccessKeyPair 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");
}
use of org.apache.dubbo.auth.model.AccessKeyPair 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));
}
Aggregations