44using System . Collections . Generic ;
55using System . Linq ;
66using System . Net ;
7+ using System . Net . Http ;
78
89namespace WebPush . Test
910{
@@ -20,6 +21,9 @@ public class WebPushClientTest
2021 private const string TestFcmEndpoint =
2122 @"https://fcm.googleapis.com/fcm/send/efz_TLX_rLU:APA91bE6U0iybLYvv0F3mf6" ;
2223
24+ private const string TestFirefoxEndpoint =
25+ @"https://updates.push.services.mozilla.com/wpush/v2/gBABAABgOe_sGrdrsT35ljtA4O9xCX" ;
26+
2327 public const string TestSubject = "mailto:[email protected] " ; 2428
2529 private MockHttpMessageHandler httpMessageHandlerMock ;
@@ -76,10 +80,9 @@ public void TestSetGCMAPIKeyEmptyString()
7680 public void TestSetGcmApiKeyNonGcmPushService ( )
7781 {
7882 // Ensure that the API key doesn't get added on a service that doesn't accept it.
79-
8083 var gcmAPIKey = @"teststring" ;
8184 client . SetGcmApiKey ( gcmAPIKey ) ;
82- var subscription = new PushSubscription ( TestFcmEndpoint , TestPublicKey , TestPrivateKey ) ;
85+ var subscription = new PushSubscription ( TestFirefoxEndpoint , TestPublicKey , TestPrivateKey ) ;
8386 var message = client . GenerateRequestDetails ( subscription , @"test payload" ) ;
8487
8588 IEnumerable < string > values ;
@@ -103,8 +106,8 @@ public void TestSetGcmApiKeyNull()
103106 public void TestSetVapidDetails ( )
104107 {
105108 client . SetVapidDetails ( TestSubject , TestPublicKey , TestPrivateKey ) ;
106-
107- var subscription = new PushSubscription ( TestFcmEndpoint , TestPublicKey , TestPrivateKey ) ;
109+
110+ var subscription = new PushSubscription ( TestFirefoxEndpoint , TestPublicKey , TestPrivateKey ) ;
108111 var message = client . GenerateRequestDetails ( subscription , @"test payload" ) ;
109112 var authorizationHeader = message . Headers . GetValues ( @"Authorization" ) . First ( ) ;
110113 var cryptoHeader = message . Headers . GetValues ( @"Crypto-Key" ) . First ( ) ;
@@ -113,6 +116,17 @@ public void TestSetVapidDetails()
113116 Assert . IsTrue ( cryptoHeader . Contains ( @"p256ecdsa" ) ) ;
114117 }
115118
119+ [ TestMethod ]
120+ public void TestFcmAddsAuthorizationHeader ( )
121+ {
122+ client . SetGcmApiKey ( @"somestring" ) ;
123+ var subscription = new PushSubscription ( TestFcmEndpoint , TestPublicKey , TestPrivateKey ) ;
124+ var message = client . GenerateRequestDetails ( subscription , @"test payload" ) ;
125+ var authorizationHeader = message . Headers . GetValues ( @"Authorization" ) . First ( ) ;
126+
127+ Assert . IsTrue ( authorizationHeader . StartsWith ( @"key=" ) ) ;
128+ }
129+
116130 [ TestMethod ]
117131 [ DataRow ( HttpStatusCode . Created ) ]
118132 [ DataRow ( HttpStatusCode . Accepted ) ]
0 commit comments