jclouds-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From GitBox <...@apache.org>
Subject [GitHub] [jclouds] nacx commented on a change in pull request #43: JCLOUDS-1511: allow configuration of S3 to use V4 signatures
Date Thu, 19 Sep 2019 09:42:06 GMT
nacx commented on a change in pull request #43: JCLOUDS-1511: allow configuration of S3 to
use V4 signatures
URL: https://github.com/apache/jclouds/pull/43#discussion_r326082783
 
 

 ##########
 File path: apis/s3/src/test/java/org/jclouds/s3/config/S3HttpApiModuleTest.java
 ##########
 @@ -0,0 +1,63 @@
+package org.jclouds.s3.config;
+
+import com.google.common.collect.ImmutableList;
+import com.google.common.io.ByteSource;
+import com.google.inject.AbstractModule;
+import com.google.inject.Guice;
+import com.google.inject.Module;
+import com.google.inject.name.Names;
+import org.jclouds.location.config.LocationModule;
+import org.jclouds.logging.config.NullLoggingModule;
+import org.jclouds.providers.JcloudsTestBlobStoreProviderMetadata;
+import org.jclouds.providers.ProviderMetadata;
+import org.jclouds.rest.config.CredentialStoreModule;
+import org.jclouds.rest.internal.BaseRestApiTest;
+import org.jclouds.s3.blobstore.config.S3BlobStoreContextModule;
+import org.jclouds.s3.filters.RequestAuthorizeSignature;
+import org.jclouds.s3.filters.RequestAuthorizeSignatureV2;
+import org.jclouds.s3.filters.RequestAuthorizeSignatureV4;
+import org.testng.annotations.Test;
+
+import java.util.List;
+import java.util.concurrent.ConcurrentHashMap;
+
+import static org.jclouds.Constants.PROPERTY_SESSION_INTERVAL;
+import static org.jclouds.s3.reference.S3Constants.PROPERTY_S3_V4_REQUEST_SIGNATURES;
+import static org.testng.Assert.assertTrue;
+
+/**
+ * @author roded
+ */
+public class S3HttpApiModuleTest {
+
+    @Test
+    public void testRequestAuthorizeSignatureV2() {
+        RequestAuthorizeSignature requestAuthorizeSignature = getRequestAuthorizeSignature("false");
+        assertTrue(requestAuthorizeSignature instanceof RequestAuthorizeSignatureV2);
+    }
+
+    @Test
+    public void testRequestAuthorizeSignatureV4() {
+        RequestAuthorizeSignature requestAuthorizeSignature = getRequestAuthorizeSignature("true");
+        assertTrue(requestAuthorizeSignature instanceof RequestAuthorizeSignatureV4);
+    }
+
+    private RequestAuthorizeSignature getRequestAuthorizeSignature(final String s3V4Value)
{
+        AbstractModule abstractModule = new AbstractModule() {
+            @Override
+            protected void configure() {
+                bindConstant().annotatedWith(Names.named(PROPERTY_S3_V4_REQUEST_SIGNATURES)).to(s3V4Value);
+                bind(String.class).annotatedWith(Names.named(PROPERTY_SESSION_INTERVAL)).toInstance("60");
+                bind(ProviderMetadata.class).to(JcloudsTestBlobStoreProviderMetadata.class);
+            }
+        };
+        List<Module> modules = ImmutableList.<Module>of(new BaseRestApiTest.MockModule(),
+                new CredentialStoreModule(new ConcurrentHashMap<String, ByteSource>()),
+                new S3BlobStoreContextModule(),
+                new NullLoggingModule(),
+                new S3HttpApiModule<>(),
+                new LocationModule(),
+                abstractModule);
+        return Guice.createInjector(modules).getInstance(RequestAuthorizeSignature.class);
+    }
+}
 
 Review comment:
   Apologies for the late reply. I found it hard to have cycles to get back to this.
   You can use the following code instead (taken mostly from the signature fitlers test classes):
   
   ```java
   private RequestAuthorizeSignature getRequestAuthorizeSignature(final String s3V4Value)
{
      Properties overrides = new Properties();
      overrides.setProperty(PROPERTY_S3_V4_REQUEST_SIGNATURES, s3V4Value);
      
      Injector injector = ContextBuilder.newBuilder(new S3ApiMetadata())
            .credentials("foo", "bar")
            .overrides(overrides)
            .modules(ImmutableList.<Module> of(
                  new BaseRestApiTest.MockModule(), 
                  new NullLoggingModule(),
                  new TestS3HttpApiModule()))
            .buildInjector();
      
      return injector.getInstance(RequestAuthorizeSignature.class);
   }
   
   @ConfiguresHttpApi
   private static final class TestS3HttpApiModule extends S3HttpApiModule<S3Client>
{
      private static final String TIMESTAMP = "Thu, 03 Feb 2015 07:11:11 GMT";
      
      @Override
      protected String provideTimeStamp(@TimeStamp Supplier<String> cache) {
         return TIMESTAMP;
      }
   
      @Override
      protected Supplier<Date> provideTimeStampCacheDate(@Named(Constants.PROPERTY_SESSION_INTERVAL)
long seconds,
            @TimeStamp final Supplier<String> timestamp, final DateService dateService)
{
         return Suppliers.ofInstance(dateService.rfc822DateParse(TIMESTAMP));
      }
   }
   ```

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

Mime
View raw message