From d31071f62954d1a56733b412cfa61ac70def814a Mon Sep 17 00:00:00 2001 From: Wilfried OLLIVIER Date: Wed, 30 Oct 2024 15:12:26 +0100 Subject: [PATCH] chore: extra cover on higher level test --- neurow/test/jwt_helper.exs | 8 ++++++-- neurow/test/neurow/internal_api/endpoint_test.exs | 15 ++++++++++++++- 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/neurow/test/jwt_helper.exs b/neurow/test/jwt_helper.exs index c5e643e..86663a5 100644 --- a/neurow/test/jwt_helper.exs +++ b/neurow/test/jwt_helper.exs @@ -16,10 +16,14 @@ defmodule JwtHelper do conn |> put_req_header(header_key, "Bearer #{jwt_token}") end - def put_jwt_token_in_req_header_internal_api(conn, issuer \\ "test_issuer1") do + def put_jwt_token_in_req_header_internal_api( + conn, + issuer \\ "test_issuer1", + header_key \\ "authorization" + ) do conn |> put_req_header( - "authorization", + header_key, "Bearer #{compute_jwt_token_in_req_header_internal_api(issuer)}" ) |> put_req_header("content-type", "application/json") diff --git a/neurow/test/neurow/internal_api/endpoint_test.exs b/neurow/test/neurow/internal_api/endpoint_test.exs index dbe2933..f006a88 100644 --- a/neurow/test/neurow/internal_api/endpoint_test.exs +++ b/neurow/test/neurow/internal_api/endpoint_test.exs @@ -18,7 +18,7 @@ defmodule Neurow.InternalApi.EndpointTest do assert call.status == 200 end - test "other routes requires a JWT token" do + test "other routes requires a JWT sent in authorization header" do conn = conn(:get, "/foo") call = Neurow.InternalApi.Endpoint.call(conn, []) assert call.status == 403 @@ -31,6 +31,19 @@ defmodule Neurow.InternalApi.EndpointTest do assert call.status == 404 end + test "other routes requires a JWT sent in x-interservice-authorization header" do + conn = conn(:get, "/foo") + call = Neurow.InternalApi.Endpoint.call(conn, []) + assert call.status == 403 + + conn = + conn(:get, "/foo") + |> put_jwt_token_in_req_header_internal_api("test_issuer1", "x-interservice-authorization") + + call = Neurow.InternalApi.Endpoint.call(conn, []) + assert call.status == 404 + end + describe "POST /v1/subscribe" do test "returns a 403 if called without a JWT token" do body =