Skip to content

Commit

Permalink
add missing test
Browse files Browse the repository at this point in the history
  • Loading branch information
MathieuLegault1 committed Jan 17, 2024
1 parent 5e61877 commit e7facbf
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lib/plug_image_processing/middlewares/signature_key.ex
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ defmodule PlugImageProcessing.Middlewares.SignatureKey do
|> Map.drop(["sign"])
|> URI.encode_query()

IO.inspect(url_path <> url_query)

Check warning on line 17 in lib/plug_image_processing/middlewares/signature_key.ex

View workflow job for this annotation

GitHub Actions / ci (25.0.4, 1.14.0)

There should be no calls to IO.inspect/1.

Check warning on line 17 in lib/plug_image_processing/middlewares/signature_key.ex

View workflow job for this annotation

GitHub Actions / ci (25.0.4, 1.14.0)

There should be no calls to IO.inspect/1.

Base.url_encode64(:crypto.mac(:hmac, :sha256, config.url_signature_key, url_path <> url_query))
end

Expand Down
14 changes: 14 additions & 0 deletions test/plug_image_processing/plug_image_processing_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,19 @@ defmodule PlugImageProcessingTest do

assert url === "http://example.com/imageproxy/resize?url=http%3A%2F%2Fbucket.com%2Ftest.jpg&width=10"
end

test "valid with signature", %{config: config} do
url_signature_key = "12345"
config = Keyword.put(config, :url_signature_key, url_signature_key)

url = PlugImageProcessing.generate_url("http://example.com", config, :resize, %{url: "http://bucket.com/test.jpg", width: 10})

assert url ===
"http://example.com/imageproxy/resize?url=http%3A%2F%2Fbucket.com%2Ftest.jpg&width=10&sign=#{generate_signature_from_url(url_signature_key, "resizeurl=http%3A%2F%2Fbucket.com%2Ftest.jpg&width=10")}"
end
end

defp generate_signature_from_url(url_signature_key, url) do
Base.url_encode64(:crypto.mac(:hmac, :sha256, url_signature_key, url))
end
end

0 comments on commit e7facbf

Please sign in to comment.