Skip to content

Commit

Permalink
Ensure VIES client URL is using https (#7)
Browse files Browse the repository at this point in the history
* Ensure VIES client URL is using https

* Fix credo warning for variable name location
  • Loading branch information
ryanflach authored Mar 19, 2020
1 parent d33c62b commit 936b6aa
Show file tree
Hide file tree
Showing 8 changed files with 19 additions and 7 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
#### 0.1.5 (2020-03-19)

##### Bug Fixes

* **vies-client:** Ensure client url is using https ([#7](https://github.com/taxjar/ex_vatcheck/pull/7))

#### 0.1.4 (2020-03-19)

##### Bug Fixes
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ by adding `ex_vatcheck` to your list of dependencies in `mix.exs`:
```elixir
def deps do
[
{:ex_vatcheck, "~> 0.1.4"}
{:ex_vatcheck, "~> 0.1.5"}
]
end
```
Expand Down
2 changes: 1 addition & 1 deletion lib/ex_vatcheck/countries.ex
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ defmodule ExVatcheck.Countries do
def valid_format?(<<country::binary-size(2), _::binary>>) when country not in @countries,
do: false

def valid_format?(vat = <<country::binary-size(2), _::binary>>) do
def valid_format?(<<country::binary-size(2), _::binary>> = vat) do
@regexes
|> Map.get(country)
|> Regex.match?(vat)
Expand Down
8 changes: 7 additions & 1 deletion lib/ex_vatcheck/vies_client.ex
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ defmodule ExVatcheck.VIESClient do
def new() do
with {:ok, response} <- HTTPoison.get(@wsdl_url),
{:ok, url} <- XMLParser.parse_service(response.body) do
{:ok, %__MODULE__{url: url}}
{:ok, %__MODULE__{url: corrected_client_url(url)}}
else
{:error, %HTTPoison.Error{reason: :timeout}} -> {:error, "Service timed out"}
{:error, :invalid_wsdl} -> {:error, "Unknown error: invalid_wsdl"}
Expand All @@ -64,4 +64,10 @@ defmodule ExVatcheck.VIESClient do
</soap:Envelope>
"""
end

# NOTE: VIES currently sends back an invalid URL in the client which uses http
# instead of https, which they have recently updated to.
@spec corrected_client_url(binary) :: binary
defp corrected_client_url("https" <> _ = url), do: url
defp corrected_client_url(url), do: String.replace(url, "http://", "https://")
end
2 changes: 1 addition & 1 deletion lib/ex_vatcheck/vies_client/xml_parser.ex
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ defmodule ExVatcheck.VIESClient.XMLParser do
...
<wsdl:service name="checkVatService">
<wsdl:port name="checkVatPort" binding="impl:checkVatBinding">
<wsdlsoap:address location="http://ec.europa.eu/taxation_customs/vies/services/checkVatService"/>
<wsdlsoap:address location="https://ec.europa.eu/taxation_customs/vies/services/checkVatService"/>
</wsdl:port>
</wsdl:service>
</wsdl:definitions>
Expand Down
2 changes: 1 addition & 1 deletion mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ defmodule ExVatcheck.MixProject do
def project do
[
app: :ex_vatcheck,
version: "0.1.4",
version: "0.1.5",
elixir: "~> 1.4",
name: "ExVatcheck",
elixirc_paths: elixirc_paths(Mix.env()),
Expand Down
2 changes: 1 addition & 1 deletion test/ex_vatcheck/vies_client/xml_parser_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ defmodule ExVatcheck.VIESClient.XMLParserTest do

describe "parse_service/1" do
test "parses the checkVatService url from the VIES WSDL response" do
url = "http://ec.europa.eu/taxation_customs/vies/services/checkVatService"
url = "https://ec.europa.eu/taxation_customs/vies/services/checkVatService"

response = """
<wsdl:definitions>
Expand Down
2 changes: 1 addition & 1 deletion test/fixtures/vies_responses.ex
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ defmodule Fixtures.VIESResponses do
"""

def service_url do
"http://ec.europa.eu/taxation_customs/vies/services/checkVatService"
"https://ec.europa.eu/taxation_customs/vies/services/checkVatService"
end

def valid_wsdl do
Expand Down

0 comments on commit 936b6aa

Please sign in to comment.