From a62494a117a38b92dadc43ad38acf3b6067f7958 Mon Sep 17 00:00:00 2001 From: Andrew Gaul Date: Tue, 14 Nov 2017 10:46:54 -0800 Subject: [PATCH] JCLOUDS-1110: Inject timeStamp into Atmos provider This addresses a unit test failure. --- .../atmos/blobstore/AtmosBlobRequestSigner.java | 16 +++++++++++++--- .../blobstore/AtmosBlobRequestSignerTest.java | 6 ++---- 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/apis/atmos/src/main/java/org/jclouds/atmos/blobstore/AtmosBlobRequestSigner.java b/apis/atmos/src/main/java/org/jclouds/atmos/blobstore/AtmosBlobRequestSigner.java index bdb647049f..d8b23e1a05 100644 --- a/apis/atmos/src/main/java/org/jclouds/atmos/blobstore/AtmosBlobRequestSigner.java +++ b/apis/atmos/src/main/java/org/jclouds/atmos/blobstore/AtmosBlobRequestSigner.java @@ -21,6 +21,7 @@ import static org.jclouds.blobstore.util.BlobStoreUtils.cleanRequest; import static org.jclouds.reflect.Reflection2.method; import java.net.URI; +import java.util.Date; import javax.inject.Inject; import javax.inject.Singleton; @@ -33,17 +34,19 @@ import org.jclouds.atmos.options.PutOptions; import org.jclouds.blobstore.BlobRequestSigner; import org.jclouds.blobstore.domain.Blob; import org.jclouds.blobstore.functions.BlobToHttpGetOptions; +import org.jclouds.date.DateService; +import org.jclouds.date.TimeStamp; import org.jclouds.domain.Credentials; import org.jclouds.http.HttpRequest; import org.jclouds.http.Uris; import org.jclouds.http.options.GetOptions; -import org.jclouds.location.Provider; import org.jclouds.reflect.Invocation; import com.google.common.base.Function; import com.google.common.base.Supplier; import com.google.common.collect.ImmutableList; import com.google.common.reflect.Invokable; +import com.google.inject.Provider; @Singleton public class AtmosBlobRequestSigner implements BlobRequestSigner { @@ -60,11 +63,15 @@ public class AtmosBlobRequestSigner implements BlobRequestSigner { private final SignRequest signer; private final URI endpoint; private final String identity; + private final DateService dateService; + private final Provider timeStampProvider; @Inject public AtmosBlobRequestSigner(Function processor, BlobToObject blobToObject, BlobToHttpGetOptions blob2ObjectGetOptions, SignRequest signer, - @Provider Supplier endpointProvider, @Provider Supplier creds) + @org.jclouds.location.Provider Supplier endpointProvider, + @org.jclouds.location.Provider Supplier creds, + DateService dateService, @TimeStamp Provider timeStampProvider) throws SecurityException, NoSuchMethodException { this.processor = checkNotNull(processor, "processor"); this.blobToObject = checkNotNull(blobToObject, "blobToObject"); @@ -75,6 +82,8 @@ public class AtmosBlobRequestSigner implements BlobRequestSigner { this.signer = signer; this.endpoint = endpointProvider.get(); this.identity = creds.get().identity; + this.dateService = dateService; + this.timeStampProvider = timeStampProvider; } @Override @@ -124,7 +133,8 @@ public class AtmosBlobRequestSigner implements BlobRequestSigner { } private HttpRequest sign(String method, String path, long timeInSeconds) { - String expires = String.valueOf(System.currentTimeMillis() / 1000 + timeInSeconds); + Date now = dateService.rfc1123DateParse(timeStampProvider.get()); + String expires = String.valueOf(now.getTime() / 1000 + timeInSeconds); String stringToSign = method + "\n" + path + "\n" + identity + "\n" + diff --git a/apis/atmos/src/test/java/org/jclouds/atmos/blobstore/AtmosBlobRequestSignerTest.java b/apis/atmos/src/test/java/org/jclouds/atmos/blobstore/AtmosBlobRequestSignerTest.java index d875427429..883873ae9b 100644 --- a/apis/atmos/src/test/java/org/jclouds/atmos/blobstore/AtmosBlobRequestSignerTest.java +++ b/apis/atmos/src/test/java/org/jclouds/atmos/blobstore/AtmosBlobRequestSignerTest.java @@ -59,10 +59,8 @@ public class AtmosBlobRequestSignerTest extends BaseRestAnnotationProcessingTest NoSuchMethodException, IOException { HttpRequest request = signer.signGetBlob("container", "name"); - assertRequestLineEquals(request, "GET https://accesspoint.atmosonline.com/rest/namespace/container/name HTTP/1.1"); - assertNonPayloadHeadersEqual( - request, - "Accept: */*\nDate: Thu, 05 Jun 2008 16:38:19 GMT\nx-emc-signature: DHDKwV6IPsJJvtrI9ktTiKq9us4=\nx-emc-uid: identity\n"); + assertRequestLineEquals(request, "GET https://accesspoint.atmosonline.com/rest/namespace/container/name?uid=identity&expires=1212684799&signature=oijXdvPjHQ/LwWDcdx9Eozsu77o%3D HTTP/1.1"); + assertNonPayloadHeadersEqual(request, ""); assertPayloadEquals(request, null, null, false); assertEquals(request.getFilters().size(), 0);