TD-639: Adds cors headers to 'apikeys/v1' routes (#25)

This commit is contained in:
Aleksey Kashapov 2023-06-14 13:09:48 +03:00 committed by GitHub
parent fae8954657
commit 9bf0f3fdb6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 35 additions and 0 deletions

View File

@ -8,6 +8,19 @@ defmodule Plugger.Generated.Router do
require Logger
plug CORSPlug,
origin: "*",
headers: [
"Access-Control-Allow-Headers",
"Origin",
"X-Requested-With",
"Content-Type",
"Accept",
"Authorization",
"X-Request-Id"
],
methods: ["GET", "POST", "PUT", "DELETE", "OPTIONS"]
plug Plugger.Plug.ContentType,
allowed_types: ["application/json"]

View File

@ -63,6 +63,7 @@ defmodule ApiKeyMgmt.MixProject do
{:plug_cowboy, "~> 2.5"},
{:jason, "~> 1.4"},
{:open_api_spex, git: "https://github.com/kehitt/open_api_spex.git", branch: "fix-cast-and-validate-read-only"},
{:cors_plug, "~> 3.0"},
# Database
{:ecto_sql, "~> 3.9"},
{:postgrex, "~> 0.16.5"},

View File

@ -300,6 +300,26 @@ defmodule ApiKeyMgmtTest do
end
end
describe "cors headers" do
test "health check without allow origin header" do
conn =
:get
|> conn("http://doesnotresolve:8080/health/startup", nil)
|> router_call()
assert not Enum.member?(conn.resp_headers, {"access-control-allow-origin", "*"})
end
test "apikey route' response with allow origin header" do
conn =
:get
|> conn(get_path("/orgs/mypartyid/api-keys"), nil)
|> router_call()
assert Enum.member?(conn.resp_headers, {"access-control-allow-origin", "*"})
end
end
###
defp test_call(method, path, params_or_body \\ nil, headers \\ default_headers()) do

View File

@ -7,6 +7,7 @@
"castore": {:hex, :castore, "0.1.19", "a2c3e46d62b7f3aa2e6f88541c21d7400381e53704394462b9fd4f06f6d42bb6", [:mix], [], "hexpm", "e96e0161a5dc82ef441da24d5fa74aefc40d920f3a6645d15e1f9f3e66bb2109"},
"certifi": {:hex, :certifi, "2.8.0", "d4fb0a6bb20b7c9c3643e22507e42f356ac090a1dcea9ab99e27e0376d695eba", [:rebar3], [], "hexpm", "6ac7efc1c6f8600b08d625292d4bbf584e14847ce1b6b5c44d983d273e1097ea"},
"connection": {:hex, :connection, "1.1.0", "ff2a49c4b75b6fb3e674bfc5536451607270aac754ffd1bdfe175abe4a6d7a68", [:mix], [], "hexpm", "722c1eb0a418fbe91ba7bd59a47e28008a189d47e37e0e7bb85585a016b2869c"},
"cors_plug": {:hex, :cors_plug, "3.0.3", "7c3ac52b39624bc616db2e937c282f3f623f25f8d550068b6710e58d04a0e330", [:mix], [{:plug, "~> 1.13", [hex: :plug, repo: "hexpm", optional: false]}], "hexpm", "3f2d759e8c272ed3835fab2ef11b46bddab8c1ab9528167bd463b6452edf830d"},
"cowboy": {:hex, :cowboy, "2.9.0", "865dd8b6607e14cf03282e10e934023a1bd8be6f6bacf921a7e2a96d800cd452", [:make, :rebar3], [{:cowlib, "2.11.0", [hex: :cowlib, repo: "hexpm", optional: false]}, {:ranch, "1.8.0", [hex: :ranch, repo: "hexpm", optional: false]}], "hexpm", "2c729f934b4e1aa149aff882f57c6372c15399a20d54f65c8d67bef583021bde"},
"cowboy_telemetry": {:hex, :cowboy_telemetry, "0.4.0", "f239f68b588efa7707abce16a84d0d2acf3a0f50571f8bb7f56a15865aae820c", [:rebar3], [{:cowboy, "~> 2.7", [hex: :cowboy, repo: "hexpm", optional: false]}, {:telemetry, "~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "7d98bac1ee4565d31b62d59f8823dfd8356a169e7fcbb83831b8a5397404c9de"},
"cowlib": {:hex, :cowlib, "2.11.0", "0b9ff9c346629256c42ebe1eeb769a83c6cb771a6ee5960bd110ab0b9b872063", [:make, :rebar3], [], "hexpm", "2b3e9da0b21c4565751a6d4901c20d1b4cc25cbb7fd50d91d2ab6dd287bc86a9"},