FormSigner implements HttpRequestFilter, RequestSigner { public HttpRequest filter(HttpRequest request) throws HttpException { checkNotNull(request.getFirstHeaderOrNull(HttpHeaders.HOST), "request is not ready to sign; host not present"); Multimap<String, String> decodedParams = queryParser().apply(request.getPayload().getRawContent().toString()); decodedParams.replaceValues(VERSION, ImmutableSet.of(apiVersion)); addSigningParams(decodedParams); validateParams(decodedParams); String stringToSign = createStringToSign(request, decodedParams); String signature = sign(stringToSign); addSignature(decodedParams, signature); request = setPayload(request, decodedParams); utils.logRequest(signatureLog, request, "<<"); return request; } @Inject  FormSigner(SignatureWire signatureWire, @ApiVersion String apiVersion,
         @org.jclouds.location.Provider Supplier<Credentials> creds, @TimeStamp Provider<String> dateService,
         Crypto crypto, HttpUtils utils); HttpRequest filter(HttpRequest request); @VisibleForTesting String sign(String toSign); @VisibleForTesting String createStringToSign(HttpRequest request, Multimap<String, String> decodedParams); String createStringToSign(HttpRequest input); static final Set<String> mandatoryParametersForSignature; }
@Test void testAddsSecurityToken() { HttpRequest filtered = filter(new SessionCredentialsHandlerTest().expected()).filter(request); assertEquals( filtered.getPayload().getRawContent(), "Action=DescribeImages&ImageId.1=ami-2bb65342&SecurityToken=AQoEXAMPLEH4aoAH0gNCAPyJxz4BlCFFxWNE1OPTgk5TthT&Signature=/8ReFVH1tvyNORsJb%2BSBieT9zvdqREQQr/olwmxC7VY%3D&SignatureMethod=HmacSHA256&SignatureVersion=2&Timestamp=2009-11-08T15%3A54%3A08.897Z&Version=apiVersion&AWSAccessKeyId=AKIAIOSFODNN7EXAMPLE"); }
@Test void testBuildCanonicalizedStringSetsVersion() { HttpRequest filtered = staticCredentialsFilter.filter(request); assertEquals(filtered.getPayload().getRawContent(), "Action=DescribeImages&ImageId.1=ami-2bb65342&Signature=ugnt4m2eHE7Ka/vXTr9EhKZq7bhxOfvW0y4pAEqF97w%3D&SignatureMethod=HmacSHA256&SignatureVersion=2&Timestamp=2009-11-08T15%3A54%3A08.897Z&Version=apiVersion&AWSAccessKeyId=identity"); }