Merge pull request #5623 from blockscout/vb-db-parser-allow-hyphen-in-password

Allow hyphen in DB password
pull/5626/head
Victor Baranov 3 years ago committed by GitHub
commit fc32c3c6b1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 1
      CHANGELOG.md
  2. 2
      apps/explorer/lib/explorer/exchange_rates/source.ex
  3. 2
      apps/explorer/lib/explorer/repo/config_helper.ex
  4. 12
      apps/explorer/test/explorer/repo/config_helper_test.exs

@ -16,6 +16,7 @@
- [#5538](https://github.com/blockscout/blockscout/pull/5538) - Fix internal transaction's tile bug - [#5538](https://github.com/blockscout/blockscout/pull/5538) - Fix internal transaction's tile bug
### Chore ### Chore
- [#5623](https://github.com/blockscout/blockscout/pull/5623) - Allow hyphen in DB password
- [#5543](https://github.com/blockscout/blockscout/pull/5543) - Increase max_restarts to 1_000 (from 3 by default) for explorer, block_scout_web supervisors - [#5543](https://github.com/blockscout/blockscout/pull/5543) - Increase max_restarts to 1_000 (from 3 by default) for explorer, block_scout_web supervisors
- [#5536](https://github.com/blockscout/blockscout/pull/5536) - NPM audit fix - [#5536](https://github.com/blockscout/blockscout/pull/5536) - NPM audit fix

@ -2,8 +2,8 @@ defmodule Explorer.ExchangeRates.Source do
@moduledoc """ @moduledoc """
Behaviour for fetching exchange rates from external sources. Behaviour for fetching exchange rates from external sources.
""" """
alias Explorer.ExchangeRates.{Source, Token}
alias Explorer.ExchangeRates.Source.CoinGecko alias Explorer.ExchangeRates.Source.CoinGecko
alias Explorer.ExchangeRates.Token
alias HTTPoison.{Error, Response} alias HTTPoison.{Error, Response}
@doc """ @doc """

@ -29,7 +29,7 @@ defmodule Explorer.Repo.ConfigHelper do
# sobelow_skip ["DOS.StringToAtom"] # sobelow_skip ["DOS.StringToAtom"]
defp extract_parameters(database_url) do defp extract_parameters(database_url) do
~r/\w*:\/\/(?<username>\w+):(?<password>\w*)?@(?<hostname>(([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\-]*[a-zA-Z0-9])\.)*([A-Za-z0-9]|[A-Za-z0-9][A-Za-z0-9\-]*[A-Za-z0-9])):(?<port>\d+)\/(?<database>\w+)/ ~r/\w*:\/\/(?<username>\w+):(?<password>[a-zA-Z0-9_-]*)?@(?<hostname>(([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\-]*[a-zA-Z0-9])\.)*([A-Za-z0-9]|[A-Za-z0-9][A-Za-z0-9\-]*[A-Za-z0-9])):(?<port>\d+)\/(?<database>\w+)/
|> Regex.named_captures(database_url) |> Regex.named_captures(database_url)
|> Keyword.new(fn {k, v} -> {String.to_atom(k), v} end) |> Keyword.new(fn {k, v} -> {String.to_atom(k), v} end)
|> Keyword.put(:url, database_url) |> Keyword.put(:url, database_url)

@ -28,6 +28,18 @@ defmodule Explorer.Repo.ConfigHelperTest do
assert result[:database] == "test_database" assert result[:database] == "test_database"
end end
test "parse params from database url with hyphen in password" do
database_url = "postgresql://test_username:test-password@hostname.test.com:7777/test_database"
result = ConfigHelper.get_db_config(%{url: database_url, env_func: fn _ -> nil end})
assert result[:username] == "test_username"
assert result[:password] == "test-password"
assert result[:hostname] == "hostname.test.com"
assert result[:port] == "7777"
assert result[:database] == "test_database"
end
test "get username without password" do test "get username without password" do
database_url = "postgresql://test_username:@127.8.8.1:7777/test_database" database_url = "postgresql://test_username:@127.8.8.1:7777/test_database"

Loading…
Cancel
Save