Skip to content

Commit

Permalink
Bump for upcoming postgrex ssl features
Browse files Browse the repository at this point in the history
  • Loading branch information
chrismccord committed May 17, 2024
1 parent 80fbb4e commit 8929bbd
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 32 deletions.
19 changes: 2 additions & 17 deletions installer/lib/phx_new/generator.ex
Original file line number Diff line number Diff line change
Expand Up @@ -343,28 +343,13 @@ defmodule Phx.New.Generator do
You must set this to the certificate file contents of the CockroachDB cluster.
\"""
db_conf =
Regex.named_captures(
~r/^postgresql:\/\/(?<username>[^:]+):(?<password>[^@]+)@(?<hostname>[^:]+):(?<port>\d+)\/(?<database>[^\?]+)/,
database_url
)
""",
prod_config: ~S"""
username: db_conf["username"],
password: db_conf["password"],
hostname: db_conf["hostname"],
port: db_conf["port"],
database: db_conf["database"],
url: database_url,
migration_lock: false,
pool_size: String.to_integer(System.get_env("POOL_SIZE") || "10"),
show_sensitive_data_on_connection_error: true,
ssl: true,
ssl_opts: [
server_name_indication: ~c"#{db_conf["hostname"]}",
customize_hostname_check: [match_fun: :public_key.pkix_verify_hostname_match_fun(:https)],
cacerts: for({:Certificate, der, _} <- :public_key.pem_decode(database_cert), do: der)
]
ssl: [cacerts: for({:Certificate, der, _} <- :public_key.pem_decode(database_cert), do: der)]
"""}
end

Expand Down
26 changes: 11 additions & 15 deletions installer/test/phx_new_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -690,42 +690,38 @@ defmodule Mix.Tasks.Phx.NewTest do

assert_file("custom_path/config/config.exs", fn file ->
assert file =~ "ecto_repos: [CustomPath.Repo]"

assert file =~ """
generators: [
timestamp_type: :utc_datetime,
case_insensitive_field_type: :"STRING COLLATE \\"en-US-u-ks-level2\\""
]
"""
generators: [
timestamp_type: :utc_datetime,
case_insensitive_field_type: :"STRING COLLATE \\"en-US-u-ks-level2\\""
]
"""
end)

assert_file("custom_path/config/dev.exs", [
~r/username: "root"/,
~r/password: nil/,
~r/hostname: "localhost"/,
~r/port: 26257/,
~r/migration_lock: false/,
~r/migration_lock: false/
])

assert_file("custom_path/config/test.exs", [
~r/username: "root"/,
~r/password: nil/,
~r/hostname: "localhost"/,
~r/port: 26257/,
~r/migration_lock: false/,
~r/migration_lock: false/
])

assert_file("custom_path/config/runtime.exs", fn file ->
assert file =~ ~s|database_cert =|
assert file =~ ~s|db_conf =|
assert file =~ ~s|migration_lock: false|
assert file =~ ~s|username: db_conf["username"]|
assert file =~ ~s|password: db_conf["password"]|
assert file =~ ~s|hostname: db_conf["hostname"]|
assert file =~ ~s|database: db_conf["database"]|
assert file =~ ~s|ssl_opts:|
assert file =~ ~s| ssl: true|
refute file =~ ~s|url: database_url|
assert file =~ ~s|url: database_url|
assert file =~ ~s|ssl: [cacerts: |
end)

assert_file("custom_path/lib/custom_path/repo.ex", "Ecto.Adapters.Postgres")

assert_file("custom_path/test/support/conn_case.ex", "DataCase.setup_sandbox(tags)")
Expand Down

0 comments on commit 8929bbd

Please sign in to comment.