File: test_xml_requests.rb

package info (click to toggle)
ruby-fog-google 1.19.0-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,568 kB
  • sloc: ruby: 16,775; makefile: 3
file content (60 lines) | stat: -rw-r--r-- 2,111 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
require "helpers/test_helper"

class UnitTestXMLRequests < MiniTest::Test
  def setup
    Fog.mock!
    @client = Fog::Storage.new(provider: "google",
                               google_storage_access_key_id: "",
                               google_storage_secret_access_key: "")
  end

  def teardown
    Fog.unmock!
  end

  def test_get_http_url
    url = @client.get_object_http_url("bucket",
                                      "just some file.json",
                                      Time.now + 2 * 60)
    assert_match(/^http:\/\//, url,
                 "URL starts with HTTP")
  end

  def test_get_https_url
    url = @client.get_object_https_url("bucket",
                                       "just some file.json",
                                       Time.now + 2 * 60)
    assert_match(/^https:\/\//, url,
                 "URL starts with HTTPS")
  end

  def test_get_url_path_has_query_params
    url = @client.get_object_url("bucket",
                                 "just some file.json",
                                 Time.now + 2 * 60,
                                 query: { "Response-Content-Disposition" => 'inline; filename="test.json"' })

    assert_match(/Response-Content-Disposition=inline%3B%20filename%3D%22test.json/, url,
                 "query string should be escaped")
  end

  def test_get_url_filter_nil_query_params
    url = @client.get_object_url("bucket",
                                 "just some file.json",
                                 Time.now + 2 * 60,
                                 query: { "Response-Content-Disposition" => nil })

    refute_match(/Response-Content-Disposition/, url,
                 "nil query params should be omitted")
  end

  def test_put_url_path_is_properly_escaped
    url = @client.put_object_url("bucket",
                                 "just some file.json",
                                 Time.now + 2 * 60,
                                 "Content-Type" => "application/json")

    assert_match(/just%20some%20file\.json/, url,
                 "space should be escaped with '%20'")
  end
end