File: limiters_controller_test.rb

package info (click to toggle)
ruby-graphql 2.5.19-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 13,868 kB
  • sloc: ruby: 80,420; ansic: 1,808; yacc: 845; javascript: 480; makefile: 6
file content (37 lines) | stat: -rw-r--r-- 1,515 bytes parent folder | download
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
# frozen_string_literal: true
require "test_helper"

if defined?(GraphQL::Pro)
  class DashboardLimitersLimitersControllerTest < ActionDispatch::IntegrationTest
    def test_it_checks_installed
      get graphql_dashboard.limiters_limiter_path("runtime", { schema: "GraphQL::Schema" })
      assert_includes response.body, CGI::escapeHTML("Rate limiters aren't installed on this schema yet.")
      refute_includes response.headers["Content-Security-Policy"], "nonce-"
    end

    def test_it_shows_limiters
      Redis.new(db: DummySchema::DB_NUMBER).flushdb

      3.times do
        DummySchema.execute("{ sleep(seconds: 0.02) }", context: { limiter_key: "client-1" }).to_h
      end
      4.times do
        DummySchema.execute("{ sleep(seconds: 0.110) }", context: { limiter_key: "client-2" }).to_h
      end

      get graphql_dashboard.limiters_limiter_path("runtime")
      assert_includes response.body, "<span class=\"data\">4</span>"
      assert_includes response.body, "<span class=\"data\">3</span>"
      assert_includes response.body, "Disable Soft Limiting"
      assert_includes response.headers["Content-Security-Policy"], "nonce-"

      patch graphql_dashboard.limiters_limiter_path("runtime")
      get graphql_dashboard.limiters_limiter_path("runtime")
      assert_includes response.body, "Enable Soft Limiting"

      get graphql_dashboard.limiters_limiter_path("active_operations")
      assert_includes response.body, "It looks like this limiter isn't installed yet."

    end
  end
end