4
4
using System . Collections . Generic ;
5
5
using System . Linq ;
6
6
using System . Net ;
7
+ using System . Net . Http ;
7
8
8
9
namespace WebPush . Test
9
10
{
@@ -20,6 +21,9 @@ public class WebPushClientTest
20
21
private const string TestFcmEndpoint =
21
22
@"https://fcm.googleapis.com/fcm/send/efz_TLX_rLU:APA91bE6U0iybLYvv0F3mf6" ;
22
23
24
+ private const string TestFirefoxEndpoint =
25
+ @"https://updates.push.services.mozilla.com/wpush/v2/gBABAABgOe_sGrdrsT35ljtA4O9xCX" ;
26
+
23
27
public const string TestSubject = "mailto:[email protected] " ;
24
28
25
29
private MockHttpMessageHandler httpMessageHandlerMock ;
@@ -76,10 +80,9 @@ public void TestSetGCMAPIKeyEmptyString()
76
80
public void TestSetGcmApiKeyNonGcmPushService ( )
77
81
{
78
82
// Ensure that the API key doesn't get added on a service that doesn't accept it.
79
-
80
83
var gcmAPIKey = @"teststring" ;
81
84
client . SetGcmApiKey ( gcmAPIKey ) ;
82
- var subscription = new PushSubscription ( TestFcmEndpoint , TestPublicKey , TestPrivateKey ) ;
85
+ var subscription = new PushSubscription ( TestFirefoxEndpoint , TestPublicKey , TestPrivateKey ) ;
83
86
var message = client . GenerateRequestDetails ( subscription , @"test payload" ) ;
84
87
85
88
IEnumerable < string > values ;
@@ -103,8 +106,8 @@ public void TestSetGcmApiKeyNull()
103
106
public void TestSetVapidDetails ( )
104
107
{
105
108
client . SetVapidDetails ( TestSubject , TestPublicKey , TestPrivateKey ) ;
106
-
107
- var subscription = new PushSubscription ( TestFcmEndpoint , TestPublicKey , TestPrivateKey ) ;
109
+
110
+ var subscription = new PushSubscription ( TestFirefoxEndpoint , TestPublicKey , TestPrivateKey ) ;
108
111
var message = client . GenerateRequestDetails ( subscription , @"test payload" ) ;
109
112
var authorizationHeader = message . Headers . GetValues ( @"Authorization" ) . First ( ) ;
110
113
var cryptoHeader = message . Headers . GetValues ( @"Crypto-Key" ) . First ( ) ;
@@ -113,6 +116,17 @@ public void TestSetVapidDetails()
113
116
Assert . IsTrue ( cryptoHeader . Contains ( @"p256ecdsa" ) ) ;
114
117
}
115
118
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
+
116
130
[ TestMethod ]
117
131
[ DataRow ( HttpStatusCode . Created ) ]
118
132
[ DataRow ( HttpStatusCode . Accepted ) ]
0 commit comments