Skip to content

Commit e64fceb

Browse files
authored
Suppression proxy_request (décommissionnement TimescaleDB) (#5546)
1 parent ef2f916 commit e64fceb

4 files changed

Lines changed: 13 additions & 66 deletions

File tree

apps/transport/lib/db/proxy_request.ex

Lines changed: 0 additions & 15 deletions
This file was deleted.

apps/transport/lib/unlock/plugs/token_auth.ex

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ defmodule Unlock.Plugs.TokenAuth do
3030

3131
case find_client(Map.get(conn.query_params, "token")) do
3232
{:ok, token} ->
33-
log_request(conn, token)
3433
conn |> assign(:token, token)
3534

3635
:error ->
@@ -49,19 +48,4 @@ defmodule Unlock.Plugs.TokenAuth do
4948
end
5049

5150
defp find_client(_), do: {:ok, nil}
52-
53-
defp log_request(%Plug.Conn{} = conn, %DB.Token{} = token) do
54-
if conn.request_path |> String.starts_with?("/resource/") do
55-
slug = conn.request_path |> String.trim_leading("/resource/")
56-
57-
Ecto.Changeset.change(%DB.ProxyRequest{}, %{
58-
time: DateTime.utc_now(),
59-
token_id: token.id,
60-
proxy_id: slug
61-
})
62-
|> DB.Repo.insert!()
63-
end
64-
end
65-
66-
defp log_request(%Plug.Conn{}, nil), do: :ok
6751
end
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
defmodule DB.Repo.Migrations.DropProxyRequest do
2+
use Ecto.Migration
3+
4+
# First step of the TimescaleDB removal.
5+
def up do
6+
drop_if_exists(table(:proxy_request))
7+
end
8+
9+
def down do
10+
raise "non-reversible migration: proxy_request hypertable was dropped"
11+
end
12+
end

apps/transport/test/unlock/plugs/token_auth_test.exs

Lines changed: 1 addition & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ defmodule Unlock.Plugs.TokenAuthTest do
1818
setup_token_auth_enabled(true)
1919
end
2020

21-
test "valid token passed: request is logged" do
21+
test "valid token passed: request goes through" do
2222
slug = "valid-token-logged-#{Ecto.UUID.generate()}"
2323
%DB.Token{id: token_id} = token = insert_token()
2424

@@ -40,10 +40,6 @@ defmodule Unlock.Plugs.TokenAuthTest do
4040

4141
assert resp.resp_body == "somebody-to-love"
4242
assert %DB.Token{id: ^token_id} = resp.assigns[:token]
43-
44-
assert [
45-
%DB.ProxyRequest{proxy_id: ^slug, token_id: ^token_id}
46-
] = DB.ProxyRequest |> DB.Repo.all()
4743
end
4844

4945
test "no token passed" do
@@ -67,17 +63,13 @@ defmodule Unlock.Plugs.TokenAuthTest do
6763

6864
assert resp.resp_body == "somebody-to-love"
6965
assert is_nil(resp.assigns[:token])
70-
71-
assert [] = DB.ProxyRequest |> DB.Repo.all()
7266
end
7367

7468
test "invalid token passed" do
7569
resp = proxy_conn() |> get("/resource/slug?token=invalid")
7670

7771
assert resp.status == 401
7872
assert resp.resp_body == ~s|{"error":"You must set a valid token in the query parameters"}|
79-
80-
assert DB.ProxyRequest |> DB.Repo.all() == []
8173
end
8274
end
8375

@@ -86,30 +78,6 @@ defmodule Unlock.Plugs.TokenAuthTest do
8678
setup_token_auth_enabled(false)
8779
end
8880

89-
test "valid token passed: no requests logged" do
90-
slug = "valid-token-not-logged-#{Ecto.UUID.generate()}"
91-
token = insert_token()
92-
93-
setup_proxy_config(%{
94-
slug => %Unlock.Config.Item.Generic.HTTP{
95-
identifier: slug,
96-
target_url: target_url = "http://localhost/some-remote-resource",
97-
ttl: 30
98-
}
99-
})
100-
101-
Unlock.HTTP.Client.Mock
102-
|> expect(:get!, fn url, _headers = [], _options = [] ->
103-
assert url == target_url
104-
%Unlock.HTTP.Response{body: "somebody-to-love", status: 200, headers: []}
105-
end)
106-
107-
resp = proxy_conn() |> get("/resource/#{slug}?token=#{token.secret}")
108-
assert resp.resp_body == "somebody-to-love"
109-
110-
assert [] = DB.ProxyRequest |> DB.Repo.all()
111-
end
112-
11381
test "invalid token passes through without authentication" do
11482
slug = "invalid-token-passthrough-#{Ecto.UUID.generate()}"
11583

@@ -132,8 +100,6 @@ defmodule Unlock.Plugs.TokenAuthTest do
132100
assert resp.status == 200
133101
assert resp.resp_body == "somebody-to-love"
134102
assert is_nil(resp.assigns[:token])
135-
136-
assert [] = DB.ProxyRequest |> DB.Repo.all()
137103
end
138104
end
139105

0 commit comments

Comments
 (0)