- Remove Mox.set_mox_global() in DPW extra test; rely on $callers
instead so concurrent vendor SNMP tests stop intermittently failing
with VerificationError.
- Make ToweropsWeb.Plugs.GraphQLIntrospectionTest async: false. It
mutates Application.put_env(:towerops, :env, :prod), which polluted
every async vendor test that reads :env via
Towerops.Snmp.Client.phoenix_snmp_disabled/0.
- Bump test pool queue_target/queue_interval. AgentChannelTest spawns
many `:proc_lib` channel processes that hold sandbox connections;
the default 50ms queue caused intermittent
'could not checkout the connection' errors.
- Tag real-System.cmd("ping") tests as :network so they're excluded
by default. Saves ~20s on every full run.
- Make JobCleanupTask's internal 1s settle sleep configurable via
:job_cleanup_settle_ms; the test overrides it to 0.
Plus the pending CoverageLive.Form edit-save / EIRP recompute and
TraceLive deep-link tests from before the compact.
81 lines
2.4 KiB
Elixir
81 lines
2.4 KiB
Elixir
defmodule ToweropsWeb.Plugs.GraphQLIntrospectionTest do
|
|
# NOTE: async: false because the "production" describe block mutates the
|
|
# global `Application.put_env(:towerops, :env, :prod)`. Other async tests
|
|
# (notably the vendor SNMP profile tests) check this env to decide whether
|
|
# to short-circuit SNMP calls, so running this concurrently caused
|
|
# intermittent vendor test failures. See `Towerops.Snmp.Client.phoenix_snmp_disabled/0`.
|
|
use ToweropsWeb.ConnCase, async: false
|
|
|
|
alias ToweropsWeb.Plugs.GraphQLIntrospection
|
|
|
|
describe "call/2 in production" do
|
|
setup do
|
|
Application.put_env(:towerops, :env, :prod)
|
|
on_exit(fn -> Application.put_env(:towerops, :env, :test) end)
|
|
:ok
|
|
end
|
|
|
|
test "blocks introspection queries containing __schema", %{conn: conn} do
|
|
conn =
|
|
conn
|
|
|> Map.put(:body_params, %{"query" => "{ __schema { types { name } } }"})
|
|
|> GraphQLIntrospection.call([])
|
|
|
|
assert conn.halted
|
|
assert conn.status == 400
|
|
assert conn.resp_body =~ "Introspection is disabled"
|
|
end
|
|
|
|
test "blocks introspection queries containing __type", %{conn: conn} do
|
|
conn =
|
|
conn
|
|
|> Map.put(:body_params, %{"query" => "{ __type(name: \"User\") { name } }"})
|
|
|> GraphQLIntrospection.call([])
|
|
|
|
assert conn.halted
|
|
assert conn.status == 400
|
|
end
|
|
|
|
test "allows normal queries", %{conn: conn} do
|
|
conn =
|
|
conn
|
|
|> Map.put(:body_params, %{"query" => "{ devices { id name } }"})
|
|
|> GraphQLIntrospection.call([])
|
|
|
|
refute conn.halted
|
|
refute conn.status == 400
|
|
end
|
|
|
|
test "allows requests with no body_params", %{conn: conn} do
|
|
conn = GraphQLIntrospection.call(conn, [])
|
|
|
|
refute conn.halted
|
|
end
|
|
|
|
test "allows requests with empty query", %{conn: conn} do
|
|
conn =
|
|
conn
|
|
|> Map.put(:body_params, %{"query" => ""})
|
|
|> GraphQLIntrospection.call([])
|
|
|
|
refute conn.halted
|
|
end
|
|
end
|
|
|
|
describe "call/2 in non-production" do
|
|
test "allows introspection queries in test env", %{conn: conn} do
|
|
conn =
|
|
conn
|
|
|> Map.put(:body_params, %{"query" => "{ __schema { types { name } } }"})
|
|
|> GraphQLIntrospection.call([])
|
|
|
|
refute conn.halted
|
|
end
|
|
end
|
|
|
|
describe "init/1" do
|
|
test "passes through opts unchanged" do
|
|
assert GraphQLIntrospection.init(:some_opts) == :some_opts
|
|
end
|
|
end
|
|
end
|