@@ -3,9 +3,9 @@ defmodule WebPushElixirTest do
33
44 import ExUnit.CaptureLog
55
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=="}}'
77 @ subscription_decoded % {
8- endpoint: "https ://some.pushservice.com/something-unique " ,
8+ endpoint: "http ://localhost:4040/some-endpoint " ,
99 keys: % {
1010 auth: "FPssNDTKnInHVndSTdbKFw==" ,
1111 p256dh:
@@ -20,6 +20,7 @@ defmodule WebPushElixirTest do
2020 assert capture_log ( WebPushElixir . gen_key_pair ( ) |> WebPushElixir . output_key_pair ( ) ) =~ "public_key:"
2121 assert capture_log ( WebPushElixir . gen_key_pair ( ) |> WebPushElixir . output_key_pair ( ) ) =~ "private_key:"
2222 assert capture_log ( WebPushElixir . gen_key_pair ( ) |> WebPushElixir . output_key_pair ( ) ) =~ "subject:"
23+
2324 assert capture_log ( WebPushElixir . gen_key_pair ( ) |> WebPushElixir . output_key_pair ( ) ) =~ "mailto:[email protected] " 2425 end
2526
@@ -56,4 +57,26 @@ defmodule WebPushElixirTest do
5657
5758 assert { true , _ , _ } = JOSE.JWT . verify_strict ( jwk , [ "ES256" ] , jwt )
5859 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
5982end
0 commit comments