SharedKeyLiteAuthentication implements HttpRequestFilter { @VisibleForTesting void appendUriPath(HttpRequest request, StringBuilder toSign) { toSign.append(request.getEndpoint().getRawPath()); if (request.getEndpoint().getQuery() != null) { StringBuilder paramsToSign = new StringBuilder("?"); String[] params = request.getEndpoint().getQuery().split("&"); for (String param : params) { String[] paramNameAndValue = param.split("="); if ("comp".equals(paramNameAndValue[0])) { paramsToSign.append(param); } } if (paramsToSign.length() > 1) { toSign.append(paramsToSign); } } } @Inject  SharedKeyLiteAuthentication(SignatureWire signatureWire,
         @org.jclouds.location.Provider Supplier<Credentials> creds, @TimeStamp Provider<String> timeStampProvider,
         Crypto crypto, HttpUtils utils); HttpRequest filter(HttpRequest request); String createStringToSign(HttpRequest request); String signString(String toSign);  }
@Test void testAclQueryStringRoot() { URI host = URI.create("http: HttpRequest request = HttpRequest.builder().method(HttpMethod.GET).endpoint(host).build(); StringBuilder builder = new StringBuilder(); filter.appendUriPath(request, builder); assertEquals(builder.toString(), "/?comp=list"); }
@Test void testAclQueryStringResTypeNotSignificant() { URI host = URI.create("http: HttpRequest request = HttpRequest.builder().method(HttpMethod.GET).endpoint(host).build(); StringBuilder builder = new StringBuilder(); filter.appendUriPath(request, builder); assertEquals(builder.toString(), "/mycontainer"); }
@Test void testAclQueryStringComp() { URI host = URI.create("http: HttpRequest request = HttpRequest.builder().method(HttpMethod.GET).endpoint(host).build(); StringBuilder builder = new StringBuilder(); filter.appendUriPath(request, builder); assertEquals(builder.toString(), "/mycontainer?comp=list"); }
@Test void testAclQueryStringRelativeWithExtraJunk() { URI host = URI.create("http: + ".blob.core.windows.net/mycontainer?comp=list&marker=marker&maxresults=1&prefix=prefix"); HttpRequest request = HttpRequest.builder().method(HttpMethod.GET).endpoint(host).build(); StringBuilder builder = new StringBuilder(); filter.appendUriPath(request, builder); assertEquals(builder.toString(), "/mycontainer?comp=list"); }