75bf6c6df5524b548a0337a39962f01ce7db56e3
[akkoma] / test / web / rich_media / aws_signed_url_test.exs
1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
4
5 defmodule Pleroma.Web.RichMedia.TTL.AwsSignedUrlTest do
6 use ExUnit.Case, async: true
7
8 test "amazon signed url is parsed and correct ttl is set for rich media" do
9 url = "https://pleroma.social/amz"
10
11 {:ok, timestamp} =
12 Timex.now()
13 |> DateTime.truncate(:second)
14 |> Timex.format("{ISO:Basic:Z}")
15
16 # in seconds
17 valid_till = 30
18
19 data = %{
20 image:
21 "https://pleroma.s3.ap-southeast-1.amazonaws.com/sachin%20%281%29%20_a%20-%25%2Aasdasd%20BNN%20bnnn%20.png?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=AKIAIBLWWK6RGDQXDLJQ%2F20190716%2Fap-southeast-1%2Fs3%2Faws4_request&X-Amz-Date=#{
22 timestamp
23 }&X-Amz-Expires=#{valid_till}&X-Amz-Signature=04ffd6b98634f4b1bbabc62e0fac4879093cd54a6eed24fe8eb38e8369526bbf&X-Amz-SignedHeaders=host",
24 locale: "en_US",
25 site_name: "Pleroma",
26 title: "PLeroma",
27 url: url
28 }
29
30 Cachex.put(:rich_media_cache, url, data)
31 assert {:ok, _} = Pleroma.Web.RichMedia.Parser.TTL.AwsSignedUrl.run(data, url)
32 {:ok, cache_ttl} = Cachex.ttl(:rich_media_cache, url)
33
34 # as there is delay in setting and pulling the data from cache we ignore 1 second
35 assert_in_delta(valid_till * 1000, cache_ttl, 1000)
36 end
37 end