@@ -3,9 +3,9 @@ defmodule WebPushElixirTest do
3
3
4
4
import ExUnit.CaptureLog
5
5
6
- @ subscription_from_client '{"endpoint":"https ://some.pushservice.com/something-unique ","keys":{"p256dh":"BIPUL12DLfytvTajnryr2PRdAgXS3HGKiLqndGcJGabyhHheJYlNGCeXl1dn18gSJ1WAkAPIxr4gK0_dQds4yiI=","auth":"FPssNDTKnInHVndSTdbKFw=="}}'
6
+ @ subscription_from_client '{"endpoint":"http ://localhost:4040/some-endpoint ","keys":{"p256dh":"BIPUL12DLfytvTajnryr2PRdAgXS3HGKiLqndGcJGabyhHheJYlNGCeXl1dn18gSJ1WAkAPIxr4gK0_dQds4yiI=","auth":"FPssNDTKnInHVndSTdbKFw=="}}'
7
7
@ subscription_decoded % {
8
- endpoint: "https ://some.pushservice.com/something-unique " ,
8
+ endpoint: "http ://localhost:4040/some-endpoint " ,
9
9
keys: % {
10
10
auth: "FPssNDTKnInHVndSTdbKFw==" ,
11
11
p256dh:
@@ -20,6 +20,7 @@ defmodule WebPushElixirTest do
20
20
assert capture_log ( WebPushElixir . gen_key_pair ( ) |> WebPushElixir . output_key_pair ( ) ) =~ "public_key:"
21
21
assert capture_log ( WebPushElixir . gen_key_pair ( ) |> WebPushElixir . output_key_pair ( ) ) =~ "private_key:"
22
22
assert capture_log ( WebPushElixir . gen_key_pair ( ) |> WebPushElixir . output_key_pair ( ) ) =~ "subject:"
23
+
23
24
assert capture_log ( WebPushElixir . gen_key_pair ( ) |> WebPushElixir . output_key_pair ( ) ) =~ "mailto:[email protected] "
24
25
end
25
26
@@ -56,4 +57,26 @@ defmodule WebPushElixirTest do
56
57
57
58
assert { true , _ , _ } = JOSE.JWT . verify_strict ( jwk , [ "ES256" ] , jwt )
58
59
end
60
+
61
+ test "it should send web push" do
62
+ { public , private } = WebPushElixir . gen_key_pair ( )
63
+
64
+ System . put_env ( "PUBLIC_KEY" , public )
65
+
66
+ System . put_env ( "PRIVATE_KEY" , private )
67
+
68
+ System . put_env ( "SUBJECT" , "mailto:[email protected] " )
69
+
70
+ { :ok , response } = WebPushElixir . send_web_push ( "some message" , @ subscription_decoded )
71
+
72
+ assert [
73
+ { "Authorization" , "WebPush " <> << _JWT :: binary >> } ,
74
+ { "Content-Encoding" , "aesgcm" } ,
75
+ { "Crypto-Key" , << _server_public_key :: binary >> } ,
76
+ { "Encryption" , "salt=" <> << _salt :: binary >> } ,
77
+ { "TTL" , "0" }
78
+ ] = response . request . headers
79
+
80
+ assert << _body :: binary >> = response . request . body
81
+ end
59
82
end
0 commit comments