@@ -9,7 +9,7 @@ defmodule Neurow.PublicApi.EndpointTest do
9
9
describe "authentication" do
10
10
test "denies access if no JWT token is provided" do
11
11
conn =
12
- conn ( :get , "/v1/subscribe" )
12
+ conn ( :post , "/v1/subscribe" )
13
13
14
14
call ( Neurow.PublicApi.Endpoint , conn , fn ->
15
15
assert_receive { :send_resp_status , 401 }
@@ -33,7 +33,7 @@ defmodule Neurow.PublicApi.EndpointTest do
33
33
34
34
test "denies access if an invalid JWT token is provided" do
35
35
conn =
36
- conn ( :get , "/v1/subscribe" )
36
+ conn ( :post , "/v1/subscribe" )
37
37
|> put_req_header ( "authorization" , "Bearer bad_token" )
38
38
39
39
call ( Neurow.PublicApi.Endpoint , conn , fn ->
@@ -57,7 +57,7 @@ defmodule Neurow.PublicApi.EndpointTest do
57
57
58
58
test "allows access if a valid JWT token is provided" do
59
59
conn =
60
- conn ( :get , "/v1/subscribe" )
60
+ conn ( :post , "/v1/subscribe" )
61
61
|> put_req_header (
62
62
"authorization" ,
63
63
"Bearer #{ compute_jwt_token_in_req_header_public_api ( "foo56" ) } "
@@ -72,7 +72,7 @@ defmodule Neurow.PublicApi.EndpointTest do
72
72
describe "messaging" do
73
73
test "transmits messages for the subscribed topic" do
74
74
conn =
75
- conn ( :get , "/v1/subscribe" )
75
+ conn ( :post , "/v1/subscribe" )
76
76
|> put_req_header (
77
77
"authorization" ,
78
78
"Bearer #{ compute_jwt_token_in_req_header_public_api ( "test_topic1" ) } "
@@ -113,7 +113,7 @@ defmodule Neurow.PublicApi.EndpointTest do
113
113
114
114
test "returns a bad request error if the Last-Event_Id header is not an integer" do
115
115
conn =
116
- conn ( :get , "/v1/subscribe" )
116
+ conn ( :post , "/v1/subscribe" )
117
117
|> put_req_header (
118
118
"authorization" ,
119
119
"Bearer #{ compute_jwt_token_in_req_header_public_api ( "test_topic1" ) } "
@@ -152,7 +152,7 @@ defmodule Neurow.PublicApi.EndpointTest do
152
152
publish_message ( "test_issuer1-test_topic1" , 8 , "Message ID8" )
153
153
154
154
conn =
155
- conn ( :get , "/v1/subscribe" )
155
+ conn ( :post , "/v1/subscribe" )
156
156
|> put_req_header (
157
157
"authorization" ,
158
158
"Bearer #{ compute_jwt_token_in_req_header_public_api ( "test_topic1" ) } "
@@ -169,7 +169,7 @@ defmodule Neurow.PublicApi.EndpointTest do
169
169
publish_message ( "test_issuer1-other_topic" , 7 , "This message is not expected" )
170
170
171
171
conn =
172
- conn ( :get , "/v1/subscribe" )
172
+ conn ( :post , "/v1/subscribe" )
173
173
|> put_req_header (
174
174
"authorization" ,
175
175
"Bearer #{ compute_jwt_token_in_req_header_public_api ( "test_topic1" ) } "
@@ -194,7 +194,7 @@ defmodule Neurow.PublicApi.EndpointTest do
194
194
publish_message ( "test_issuer1-test_topic1" , 8 , "Message ID8" )
195
195
196
196
conn =
197
- conn ( :get , "/v1/subscribe" )
197
+ conn ( :post , "/v1/subscribe" )
198
198
|> put_req_header (
199
199
"authorization" ,
200
200
"Bearer #{ compute_jwt_token_in_req_header_public_api ( "test_topic1" ) } "
@@ -239,7 +239,7 @@ defmodule Neurow.PublicApi.EndpointTest do
239
239
publish_message ( "test_issuer1-test_topic1" , 8 , "Message ID8" )
240
240
241
241
conn =
242
- conn ( :get , "/v1/subscribe" )
242
+ conn ( :post , "/v1/subscribe" )
243
243
|> put_req_header (
244
244
"authorization" ,
245
245
"Bearer #{ compute_jwt_token_in_req_header_public_api ( "test_topic1" ) } "
@@ -263,7 +263,7 @@ defmodule Neurow.PublicApi.EndpointTest do
263
263
publish_message ( "test_issuer1-test_topic1" , 8 , "Message ID8" )
264
264
265
265
conn =
266
- conn ( :get , "/v1/subscribe" )
266
+ conn ( :post , "/v1/subscribe" )
267
267
|> put_req_header (
268
268
"authorization" ,
269
269
"Bearer #{ compute_jwt_token_in_req_header_public_api ( "test_topic1" ) } "
@@ -301,7 +301,7 @@ defmodule Neurow.PublicApi.EndpointTest do
301
301
publish_message ( "test_issuer1-test_topic1" , 8 , "Message ID8" )
302
302
303
303
conn =
304
- conn ( :get , "/v1/subscribe" )
304
+ conn ( :post , "/v1/subscribe" )
305
305
|> put_req_header (
306
306
"authorization" ,
307
307
"Bearer #{ compute_jwt_token_in_req_header_public_api ( "test_topic1" ) } "
@@ -341,7 +341,7 @@ defmodule Neurow.PublicApi.EndpointTest do
341
341
override_timeout ( 500 )
342
342
343
343
conn =
344
- conn ( :get , "/v1/subscribe" )
344
+ conn ( :post , "/v1/subscribe" )
345
345
|> put_req_header (
346
346
"authorization" ,
347
347
"Bearer #{ compute_jwt_token_in_req_header_public_api ( "test_topic1" ) } "
@@ -357,7 +357,7 @@ defmodule Neurow.PublicApi.EndpointTest do
357
357
override_keepalive ( 500 )
358
358
359
359
conn =
360
- conn ( :get , "/v1/subscribe" )
360
+ conn ( :post , "/v1/subscribe" )
361
361
|> put_req_header (
362
362
"authorization" ,
363
363
"Bearer #{ compute_jwt_token_in_req_header_public_api ( "test_topic1" ) } "
@@ -379,7 +379,7 @@ defmodule Neurow.PublicApi.EndpointTest do
379
379
380
380
test "the client is disconnected when the JWT token expires" do
381
381
conn =
382
- conn ( :get , "/v1/subscribe" )
382
+ conn ( :post , "/v1/subscribe" )
383
383
|> put_req_header (
384
384
"authorization" ,
385
385
"Bearer #{ compute_jwt_token_in_req_header_public_api ( "test_topic1" , duration_s: 3 ) } "
@@ -466,7 +466,7 @@ defmodule Neurow.PublicApi.EndpointTest do
466
466
467
467
test "the authentication logic is applied to urls prefixed by the context path" do
468
468
conn =
469
- conn ( :get , "/v1/subscribe" )
469
+ conn ( :post , "/v1/subscribe" )
470
470
471
471
call ( Neurow.PublicApi.Endpoint , conn , fn ->
472
472
assert_receive { :send_resp_status , 401 }
@@ -490,7 +490,7 @@ defmodule Neurow.PublicApi.EndpointTest do
490
490
491
491
test "The subscribe url is prefixed with the context path" do
492
492
conn =
493
- conn ( :get , "/context_path/v1/subscribe" )
493
+ conn ( :post , "/context_path/v1/subscribe" )
494
494
|> put_req_header (
495
495
"authorization" ,
496
496
"Bearer #{ compute_jwt_token_in_req_header_public_api ( "test_topic1" ) } "
@@ -511,6 +511,29 @@ defmodule Neurow.PublicApi.EndpointTest do
511
511
end
512
512
end
513
513
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
+
514
537
defp override_timeout ( timeout ) do
515
538
default_timeout = Application . fetch_env! ( :neurow , :sse_timeout )
516
539
Application . put_env ( :neurow , :sse_timeout , timeout )
0 commit comments