@@ -9,7 +9,7 @@ defmodule Neurow.PublicApi.EndpointTest do
99 describe "authentication" do
1010 test "denies access if no JWT token is provided" do
1111 conn =
12- conn ( :get , "/v1/subscribe" )
12+ conn ( :post , "/v1/subscribe" )
1313
1414 call ( Neurow.PublicApi.Endpoint , conn , fn ->
1515 assert_receive { :send_resp_status , 401 }
@@ -33,7 +33,7 @@ defmodule Neurow.PublicApi.EndpointTest do
3333
3434 test "denies access if an invalid JWT token is provided" do
3535 conn =
36- conn ( :get , "/v1/subscribe" )
36+ conn ( :post , "/v1/subscribe" )
3737 |> put_req_header ( "authorization" , "Bearer bad_token" )
3838
3939 call ( Neurow.PublicApi.Endpoint , conn , fn ->
@@ -57,7 +57,7 @@ defmodule Neurow.PublicApi.EndpointTest do
5757
5858 test "allows access if a valid JWT token is provided" do
5959 conn =
60- conn ( :get , "/v1/subscribe" )
60+ conn ( :post , "/v1/subscribe" )
6161 |> put_req_header (
6262 "authorization" ,
6363 "Bearer #{ compute_jwt_token_in_req_header_public_api ( "foo56" ) } "
@@ -72,7 +72,7 @@ defmodule Neurow.PublicApi.EndpointTest do
7272 describe "messaging" do
7373 test "transmits messages for the subscribed topic" do
7474 conn =
75- conn ( :get , "/v1/subscribe" )
75+ conn ( :post , "/v1/subscribe" )
7676 |> put_req_header (
7777 "authorization" ,
7878 "Bearer #{ compute_jwt_token_in_req_header_public_api ( "test_topic1" ) } "
@@ -113,7 +113,7 @@ defmodule Neurow.PublicApi.EndpointTest do
113113
114114 test "returns a bad request error if the Last-Event_Id header is not an integer" do
115115 conn =
116- conn ( :get , "/v1/subscribe" )
116+ conn ( :post , "/v1/subscribe" )
117117 |> put_req_header (
118118 "authorization" ,
119119 "Bearer #{ compute_jwt_token_in_req_header_public_api ( "test_topic1" ) } "
@@ -152,7 +152,7 @@ defmodule Neurow.PublicApi.EndpointTest do
152152 publish_message ( "test_issuer1-test_topic1" , 8 , "Message ID8" )
153153
154154 conn =
155- conn ( :get , "/v1/subscribe" )
155+ conn ( :post , "/v1/subscribe" )
156156 |> put_req_header (
157157 "authorization" ,
158158 "Bearer #{ compute_jwt_token_in_req_header_public_api ( "test_topic1" ) } "
@@ -169,7 +169,7 @@ defmodule Neurow.PublicApi.EndpointTest do
169169 publish_message ( "test_issuer1-other_topic" , 7 , "This message is not expected" )
170170
171171 conn =
172- conn ( :get , "/v1/subscribe" )
172+ conn ( :post , "/v1/subscribe" )
173173 |> put_req_header (
174174 "authorization" ,
175175 "Bearer #{ compute_jwt_token_in_req_header_public_api ( "test_topic1" ) } "
@@ -194,7 +194,7 @@ defmodule Neurow.PublicApi.EndpointTest do
194194 publish_message ( "test_issuer1-test_topic1" , 8 , "Message ID8" )
195195
196196 conn =
197- conn ( :get , "/v1/subscribe" )
197+ conn ( :post , "/v1/subscribe" )
198198 |> put_req_header (
199199 "authorization" ,
200200 "Bearer #{ compute_jwt_token_in_req_header_public_api ( "test_topic1" ) } "
@@ -239,7 +239,7 @@ defmodule Neurow.PublicApi.EndpointTest do
239239 publish_message ( "test_issuer1-test_topic1" , 8 , "Message ID8" )
240240
241241 conn =
242- conn ( :get , "/v1/subscribe" )
242+ conn ( :post , "/v1/subscribe" )
243243 |> put_req_header (
244244 "authorization" ,
245245 "Bearer #{ compute_jwt_token_in_req_header_public_api ( "test_topic1" ) } "
@@ -263,7 +263,7 @@ defmodule Neurow.PublicApi.EndpointTest do
263263 publish_message ( "test_issuer1-test_topic1" , 8 , "Message ID8" )
264264
265265 conn =
266- conn ( :get , "/v1/subscribe" )
266+ conn ( :post , "/v1/subscribe" )
267267 |> put_req_header (
268268 "authorization" ,
269269 "Bearer #{ compute_jwt_token_in_req_header_public_api ( "test_topic1" ) } "
@@ -301,7 +301,7 @@ defmodule Neurow.PublicApi.EndpointTest do
301301 publish_message ( "test_issuer1-test_topic1" , 8 , "Message ID8" )
302302
303303 conn =
304- conn ( :get , "/v1/subscribe" )
304+ conn ( :post , "/v1/subscribe" )
305305 |> put_req_header (
306306 "authorization" ,
307307 "Bearer #{ compute_jwt_token_in_req_header_public_api ( "test_topic1" ) } "
@@ -341,7 +341,7 @@ defmodule Neurow.PublicApi.EndpointTest do
341341 override_timeout ( 500 )
342342
343343 conn =
344- conn ( :get , "/v1/subscribe" )
344+ conn ( :post , "/v1/subscribe" )
345345 |> put_req_header (
346346 "authorization" ,
347347 "Bearer #{ compute_jwt_token_in_req_header_public_api ( "test_topic1" ) } "
@@ -357,7 +357,7 @@ defmodule Neurow.PublicApi.EndpointTest do
357357 override_keepalive ( 500 )
358358
359359 conn =
360- conn ( :get , "/v1/subscribe" )
360+ conn ( :post , "/v1/subscribe" )
361361 |> put_req_header (
362362 "authorization" ,
363363 "Bearer #{ compute_jwt_token_in_req_header_public_api ( "test_topic1" ) } "
@@ -379,7 +379,7 @@ defmodule Neurow.PublicApi.EndpointTest do
379379
380380 test "the client is disconnected when the JWT token expires" do
381381 conn =
382- conn ( :get , "/v1/subscribe" )
382+ conn ( :post , "/v1/subscribe" )
383383 |> put_req_header (
384384 "authorization" ,
385385 "Bearer #{ compute_jwt_token_in_req_header_public_api ( "test_topic1" , duration_s: 3 ) } "
@@ -466,7 +466,7 @@ defmodule Neurow.PublicApi.EndpointTest do
466466
467467 test "the authentication logic is applied to urls prefixed by the context path" do
468468 conn =
469- conn ( :get , "/v1/subscribe" )
469+ conn ( :post , "/v1/subscribe" )
470470
471471 call ( Neurow.PublicApi.Endpoint , conn , fn ->
472472 assert_receive { :send_resp_status , 401 }
@@ -490,7 +490,7 @@ defmodule Neurow.PublicApi.EndpointTest do
490490
491491 test "The subscribe url is prefixed with the context path" do
492492 conn =
493- conn ( :get , "/context_path/v1/subscribe" )
493+ conn ( :post , "/context_path/v1/subscribe" )
494494 |> put_req_header (
495495 "authorization" ,
496496 "Bearer #{ compute_jwt_token_in_req_header_public_api ( "test_topic1" ) } "
@@ -511,6 +511,29 @@ defmodule Neurow.PublicApi.EndpointTest do
511511 end
512512 end
513513
514+ test "also support GET HTTP requests for SSE subscription" do
515+ conn =
516+ conn ( :get , "/v1/subscribe" )
517+ |> put_req_header (
518+ "authorization" ,
519+ "Bearer #{ compute_jwt_token_in_req_header_public_api ( "test_topic1" ) } "
520+ )
521+
522+ call ( Neurow.PublicApi.Endpoint , conn , fn ->
523+ assert_receive { :send_chunked , 200 }
524+
525+ publish_message ( "test_issuer1-test_topic1" , 1234 , "Message" )
526+
527+ assert_receive { :chunk , first_event }
528+
529+ assert parse_sse_event ( first_event ) == % {
530+ id: "1234" ,
531+ event: "test-event" ,
532+ data: "Message"
533+ }
534+ end )
535+ end
536+
514537 defp override_timeout ( timeout ) do
515538 default_timeout = Application . fetch_env! ( :neurow , :sse_timeout )
516539 Application . put_env ( :neurow , :sse_timeout , timeout )
0 commit comments