Skip to content

Commit

Permalink
Work on ops tests
Browse files Browse the repository at this point in the history
  • Loading branch information
AntoineAugusti committed Jan 1, 2024
1 parent 5e5b00a commit d3a6647
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 17 deletions.
13 changes: 13 additions & 0 deletions .github/workflows/ops_tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
on: push

jobs:
test:
runs-on: ubuntu-latest
name: Run ops tests
steps:
- uses: actions/checkout@v4
- uses: erlef/setup-beam@v1
with:
version-file: .tool-versions
version-type: strict
- run: elixir ops_tests/ops_tests.exs
70 changes: 53 additions & 17 deletions ops_tests/ops_tests.exs
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,21 @@
ExUnit.start()

Mix.install([
{:req, "~> 0.2.1"}
{:req, "~> 0.4.8"},
{:dns, "~> 2.4.0"}
])

defmodule Transport.OpsTests do
use ExUnit.Case
use ExUnit.Case, async: true

def get_header!(headers, header) do
{_header, value} =
headers
|> Enum.find(fn {k, _} -> k == header end)

value
end

def assert_redirect(from: url, to: target_url) do
%{status: 301, headers: headers} =
Req.build(:get, url)
|> Req.run!()

assert get_header!(headers, "location") == target_url
end
# See https://developers.clever-cloud.com/doc/administrate/domain-names/#your-application-runs-in-the-europeparis-par-zone
@domain_name "transport.data.gouv.fr"
@clever_cloud_ip_addresses [
{46, 252, 181, 103},
{46, 252, 181, 104},
{185, 42, 117, 108},
{185, 42, 117, 109}
]

test "correct DOMAIN_NAME for prod-worker" do
assert_redirect(
Expand All @@ -38,4 +32,46 @@ defmodule Transport.OpsTests do
to: "https://workers.prochainement.transport.data.gouv.fr/"
)
end

test "redirects from www to non-www" do
assert_redirect(from: "https://www.#{@domain_name}", to: "https://#{@domain_name}/")
end

describe "Check DNS records" do
test "main A/CNAME records" do
{:ok, ips} = DNS.resolve(@domain_name, :a)
assert MapSet.new(ips) == MapSet.new(@clever_cloud_ip_addresses)

# CNAMEs to Clever Cloud
[
"prochainement",
"proxy",
"proxy.prochainement",
"validation",
"workers",
"workers.prochainement",
"www"
]
|> Enum.each(fn subdomain ->
record = "#{subdomain}.#{@domain_name}"
assert {:ok, [~c"domain.par.clever-cloud.com"]} == DNS.resolve(record, :cname), "Wrong DNS record for #{record}"
end)

# Satellite websites
assert {:ok, [~c"transport-blog.netlify.app"]} == DNS.resolve("blog.#{@domain_name}", :cname)
assert {:ok, [~c"transport-contribuer.netlify.app"]} == DNS.resolve("contribuer.#{@domain_name}", :cname)
assert {:ok, [~c"hosting.gitbook.com"]} == DNS.resolve("doc.#{@domain_name}", :cname)
assert {:ok, [~c"stats.uptimerobot.com"]} == DNS.resolve("status.#{@domain_name}", :cname)
end
end

def get_header!(headers, header) do
{_header, [value]} = Enum.find(headers, fn {k, _} -> k == header end)
value
end

def assert_redirect(from: url, to: target_url) do
%Req.Response{status: 301, headers: headers} = Req.get!(url, redirect: false)
assert get_header!(headers, "location") == target_url
end
end

0 comments on commit d3a6647

Please sign in to comment.