Git Product home page Git Product logo

sandboxica's People

Contributors

biiwide avatar tcushman avatar

Watchers

 avatar  avatar

sandboxica's Issues

Unexpected behavior when intercepting AmazonS3Client's `PutObjectRequest`

CONTEXT: I am trying to use Sandboxica to intercept PutObject requests to S3 for unit testing.

PROBLEM STATEMENT: When I use the sandboxica/with method to override the implementation of s3/put-object and I try to call the proxied put-object method with a valid PutObjectRequest, I expected to be able to intercept the request that I supplied to put-object. However, the intercepted request is missing most of the data I tried to send to the put-object function (see below).

(def s3-req
  (let [some-bytes (.getBytes "<h1>HI</h1>")]
    {:bucket-name    "mybucket"
     :key            "something.txt"
     :input-stream   (java.io.ByteArrayInputStream. some-bytes)
     :metadata       {:content-type   "text/html"
                      :content-length (count some-bytes)
                      :user-metadata  {"somethin" "some-value"}}}))

;; When I override the put-object method on the amazonica s3 client, the
;; intercepted request reflects that the request was not intercepted properly
(sandbox/with (sandbox/just
               (s3/put-object
                ([req] (println "REQUEST" (type req) req))))
  (s3/put-object {:profile "none"} s3-req))
;; => Running this code prints out the following `{:requester-pays? false}`, but is missing all of the supplied fields

WHAT I EXPECTED TO HAPPEN WHEN I RAN THE CODE ABOVE:
I expected the intercepted request to have the fields I supplied in the request (bucket-name, key, input-stream, metadata... and more). However, the intercepted request doesn't reflect all the fields that were used for inputs

POSSIBLE PROBLEM: The missing data in the intercepted request is due to sandboxica/coerce-method-implementation missing a preprocessing step before marshalling resources.

TRACKING DOWN THE POSSIBLE PROBLEM:

;;  The `sandboxica/coerce-method-implementation` directly calls `aws/marshall` on the incoming clojure map (`s3-req` in this case)
;;  When `aws/marshall` is called directly on a Clojure map representing PutObjectRequest, it does not marshall resources properly
(aws/marshall (#'aws/create-bean com.amazonaws.services.s3.model.PutObjectRequest
                                 s3-req))
;; => {:requester-pays? false}

EXPLANATION/VERIFICATION: In the amazonica.core library, there is a call to aws/prepare-args before resources are marshalled - however this call is not present in the current implementation of coerce-method-implementation.
https://github.com/mcohen01/amazonica/blob/master/src/amazonica/core.clj#L867-L887

If aws/prepare-args is used before marshalling, the PutObjectRequest seems to marshall properly

(let [method
      (#'aws/best-method (:put-object (#'aws/client-methods com.amazonaws.services.s3.AmazonS3Client))
                         [{:profile "none"} s3-req])]
  (bean (first (seq (aws/marshall (#'aws/prepare-args method [s3-req]))))))
;; => {:cloneSource nil,
;;     :storageClass nil,
;;     :key "something.txt",
;;     :customQueryParameters nil,
;;     :file nil,
;;     :readLimit 131073,
;;     :inputStream
;;     #object[java.io.ByteArrayInputStream 0x1f9a0a26 "java.io.ByteArrayInputStream@1f9a0a26"],
;;     :requestCredentials nil,
;;     :objectLockRetainUntilDate nil,
;;     :sdkClientExecutionTimeout nil,
;;     :generalProgressListener
;;     #object[com.amazonaws.event.ProgressListener$NoOpProgressListener 0x775e743b "com.amazonaws.event.ProgressListener$NoOpProgressListener@775e743b"],
;;     :SSECustomerKey nil,
;;     :cloneRoot nil,
;;     :class com.amazonaws.services.s3.model.PutObjectRequest,
;;     :accessControlList nil,
;;     :progressListener nil,
;;     :cannedAcl nil,
;;     :requestClientOptions
;;     #object[com.amazonaws.RequestClientOptions 0x192557b7 "com.amazonaws.RequestClientOptions@192557b7"],
;;     :bucketName "mybucket",
;;     :sdkRequestTimeout nil,
;;     :tagging nil,
;;     :requesterPays false,
;;     :SSEAwsKeyManagementParams nil,
;;     :redirectLocation nil,
;;     :requestMetricCollector nil,
;;     :customRequestHeaders nil,
;;     :metadata
;;     #object[com.amazonaws.services.s3.model.ObjectMetadata 0x58977f3d "com.amazonaws.services.s3.model.ObjectMetadata@58977f3d"],
;;     :requestCredentialsProvider nil,
;;     :objectLockLegalHoldStatus nil,
;;     :objectLockMode nil}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.