Skip to content

Commit 029e74a

Browse files
author
Cory Thompson
committed
Code cleanup
1 parent a9dc1ed commit 029e74a

File tree

6 files changed

+82
-82
lines changed

6 files changed

+82
-82
lines changed

WebPush.Test/ECKeyHelperTest.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@ namespace WebPush.Test
77
{
88
public class ECKeyHelperTest
99
{
10-
private const string TEST_PUBLIC_KEY =
10+
private const string TestPublicKey =
1111
@"BCvKwB2lbVUYMFAaBUygooKheqcEU-GDrVRnu8k33yJCZkNBNqjZj0VdxQ2QIZa4kV5kpX9aAqyBKZHURm6eG1A";
1212

13-
private const string TEST_PRIVATE_KEY = @"on6X5KmLEFIVvPP3cNX9kE0OF6PV9TJQXVbnKU2xEHI";
13+
private const string TestPrivateKey = @"on6X5KmLEFIVvPP3cNX9kE0OF6PV9TJQXVbnKU2xEHI";
1414

1515
[Fact]
1616
public void TestGenerateKeys()
@@ -48,23 +48,23 @@ public void TestGenerateKeysNoCache()
4848
[Fact]
4949
public void TestGetPrivateKey()
5050
{
51-
var privateKey = UrlBase64.Decode(TEST_PRIVATE_KEY);
51+
var privateKey = UrlBase64.Decode(TestPrivateKey);
5252
var privateKeyParams = ECKeyHelper.GetPrivateKey(privateKey);
5353

5454
var importedPrivateKey = UrlBase64.Encode(privateKeyParams.D.ToByteArrayUnsigned());
5555

56-
Assert.Equal(TEST_PRIVATE_KEY, importedPrivateKey);
56+
Assert.Equal(TestPrivateKey, importedPrivateKey);
5757
}
5858

5959
[Fact]
6060
public void TestGetPublicKey()
6161
{
62-
var publicKey = UrlBase64.Decode(TEST_PUBLIC_KEY);
62+
var publicKey = UrlBase64.Decode(TestPublicKey);
6363
var publicKeyParams = ECKeyHelper.GetPublicKey(publicKey);
6464

6565
var importedPublicKey = UrlBase64.Encode(publicKeyParams.Q.GetEncoded(false));
6666

67-
Assert.Equal(TEST_PUBLIC_KEY, importedPublicKey);
67+
Assert.Equal(TestPublicKey, importedPublicKey);
6868
}
6969
}
7070
}

WebPush.Test/VapidHelperTest.cs

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ namespace WebPush.Test
66
{
77
public class VapidHelperTest
88
{
9-
private const string VALID_AUDIENCE = "http://example.com";
10-
private const string VALID_SUBJECT = "http://example.com/example";
11-
private const string VALID_SUBJECT_MAILTO = "mailto:example@example.com";
9+
private const string ValidAudience = @"http://example.com";
10+
private const string ValidSubject = @"http://example.com/example";
11+
private const string ValidSubjectMailto = @"mailto:example@example.com";
1212

1313
[Fact]
1414
public void TestGenerateVapidKeys()
@@ -36,10 +36,10 @@ public void TestGetVapidHeaders()
3636
{
3737
var publicKey = UrlBase64.Encode(new byte[65]);
3838
var privatekey = UrlBase64.Encode(new byte[32]);
39-
var headers = VapidHelper.GetVapidHeaders(VALID_AUDIENCE, VALID_SUBJECT, publicKey, privatekey);
39+
var headers = VapidHelper.GetVapidHeaders(ValidAudience, ValidSubject, publicKey, privatekey);
4040

41-
Assert.True(headers.ContainsKey("Authorization"));
42-
Assert.True(headers.ContainsKey("Crypto-Key"));
41+
Assert.True(headers.ContainsKey(@"Authorization"));
42+
Assert.True(headers.ContainsKey(@"Crypto-Key"));
4343
}
4444

4545
[Fact]
@@ -49,7 +49,7 @@ public void TestGetVapidHeadersAudienceNotAUrl()
4949
var privatekey = UrlBase64.Encode(new byte[32]);
5050

5151
Assert.Throws(typeof(ArgumentException),
52-
delegate { VapidHelper.GetVapidHeaders("invalid audience", VALID_SUBJECT, publicKey, privatekey); });
52+
delegate { VapidHelper.GetVapidHeaders(@"invalid audience", ValidSubject, publicKey, privatekey); });
5353
}
5454

5555
[Fact]
@@ -59,7 +59,7 @@ public void TestGetVapidHeadersInvalidPrivateKey()
5959
var privatekey = UrlBase64.Encode(new byte[1]);
6060

6161
Assert.Throws(typeof(ArgumentException),
62-
delegate { VapidHelper.GetVapidHeaders(VALID_AUDIENCE, VALID_SUBJECT, publicKey, privatekey); });
62+
delegate { VapidHelper.GetVapidHeaders(ValidAudience, ValidSubject, publicKey, privatekey); });
6363
}
6464

6565
[Fact]
@@ -69,7 +69,7 @@ public void TestGetVapidHeadersInvalidPublicKey()
6969
var privatekey = UrlBase64.Encode(new byte[32]);
7070

7171
Assert.Throws(typeof(ArgumentException),
72-
delegate { VapidHelper.GetVapidHeaders(VALID_AUDIENCE, VALID_SUBJECT, publicKey, privatekey); });
72+
delegate { VapidHelper.GetVapidHeaders(ValidAudience, ValidSubject, publicKey, privatekey); });
7373
}
7474

7575
[Fact]
@@ -79,19 +79,19 @@ public void TestGetVapidHeadersSubjectNotAUrlOrMailTo()
7979
var privatekey = UrlBase64.Encode(new byte[32]);
8080

8181
Assert.Throws(typeof(ArgumentException),
82-
delegate { VapidHelper.GetVapidHeaders(VALID_AUDIENCE, "invalid subject", publicKey, privatekey); });
82+
delegate { VapidHelper.GetVapidHeaders(ValidAudience, @"invalid subject", publicKey, privatekey); });
8383
}
8484

8585
[Fact]
8686
public void TestGetVapidHeadersWithMailToSubject()
8787
{
8888
var publicKey = UrlBase64.Encode(new byte[65]);
8989
var privatekey = UrlBase64.Encode(new byte[32]);
90-
var headers = VapidHelper.GetVapidHeaders(VALID_AUDIENCE, VALID_SUBJECT_MAILTO, publicKey,
90+
var headers = VapidHelper.GetVapidHeaders(ValidAudience, ValidSubjectMailto, publicKey,
9191
privatekey);
9292

93-
Assert.True(headers.ContainsKey("Authorization"));
94-
Assert.True(headers.ContainsKey("Crypto-Key"));
93+
Assert.True(headers.ContainsKey(@"Authorization"));
94+
Assert.True(headers.ContainsKey(@"Crypto-Key"));
9595
}
9696
}
9797
}

WebPush.Test/WebPushClientTest.cs

Lines changed: 35 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -7,87 +7,87 @@ namespace WebPush.Test
77
{
88
public class WebPushClientTest
99
{
10-
private const string TEST_PUBLIC_KEY =
10+
private const string TestPublicKey =
1111
@"BCvKwB2lbVUYMFAaBUygooKheqcEU-GDrVRnu8k33yJCZkNBNqjZj0VdxQ2QIZa4kV5kpX9aAqyBKZHURm6eG1A";
1212

13-
private const string TEST_PRIVATE_KEY = @"on6X5KmLEFIVvPP3cNX9kE0OF6PV9TJQXVbnKU2xEHI";
13+
private const string TestPrivateKey = @"on6X5KmLEFIVvPP3cNX9kE0OF6PV9TJQXVbnKU2xEHI";
1414

15-
private const string TEST_GCM_ENDPOINT = @"https://android.googleapis.com/gcm/send/";
15+
private const string TestGcmEndpoint = @"https://android.googleapis.com/gcm/send/";
1616

17-
private const string TEST_FCM_ENDPOINT =
17+
private const string TestFcmEndpoint =
1818
@"https://fcm.googleapis.com/fcm/send/efz_TLX_rLU:APA91bE6U0iybLYvv0F3mf6";
1919

2020
[Fact]
21-
public void TestGCMAPIKeyInOptions()
21+
public void TestGcmApiKeyInOptions()
2222
{
2323
var client = new WebPushClient();
2424

2525
var gcmAPIKey = @"teststring";
26-
var subscription = new PushSubscription(TEST_GCM_ENDPOINT, TEST_PUBLIC_KEY, TEST_PRIVATE_KEY);
26+
var subscription = new PushSubscription(TestGcmEndpoint, TestPublicKey, TestPrivateKey);
2727

2828
var options = new Dictionary<string, object>();
29-
options["gcmAPIKey"] = gcmAPIKey;
30-
var message = client.GenerateRequestDetails(subscription, "test payload", options);
31-
var authorizationHeader = message.Headers.GetValues("Authorization").First();
29+
options[@"gcmAPIKey"] = gcmAPIKey;
30+
var message = client.GenerateRequestDetails(subscription, @"test payload", options);
31+
var authorizationHeader = message.Headers.GetValues(@"Authorization").First();
3232

3333
Assert.Equal("key=" + gcmAPIKey, authorizationHeader);
3434

3535
// Test previous incorrect casing of gcmAPIKey
3636
var options2 = new Dictionary<string, object>();
37-
options2["gcmApiKey"] = gcmAPIKey;
37+
options2[@"gcmApiKey"] = gcmAPIKey;
3838
Assert.Throws<ArgumentException>(delegate
3939
{
4040
client.GenerateRequestDetails(subscription, "test payload", options2);
4141
});
4242
}
4343

4444
[Fact]
45-
public void TestSetGCMAPIKey()
45+
public void TestSetGcmApiKey()
4646
{
4747
var client = new WebPushClient();
4848

4949
var gcmAPIKey = @"teststring";
50-
client.SetGCMAPIKey(gcmAPIKey);
51-
var subscription = new PushSubscription(TEST_GCM_ENDPOINT, TEST_PUBLIC_KEY, TEST_PRIVATE_KEY);
52-
var message = client.GenerateRequestDetails(subscription, "test payload");
53-
var authorizationHeader = message.Headers.GetValues("Authorization").First();
50+
client.SetGcmApiKey(gcmAPIKey);
51+
var subscription = new PushSubscription(TestGcmEndpoint, TestPublicKey, TestPrivateKey);
52+
var message = client.GenerateRequestDetails(subscription, @"test payload");
53+
var authorizationHeader = message.Headers.GetValues(@"Authorization").First();
5454

55-
Assert.Equal("key=" + gcmAPIKey, authorizationHeader);
55+
Assert.Equal(@"key=" + gcmAPIKey, authorizationHeader);
5656
}
5757

5858
[Fact]
59-
public void TestSetGCMAPIKeyEmptyString()
59+
public void TestSetGcmApiKeyEmptyString()
6060
{
6161
var client = new WebPushClient();
6262

63-
Assert.Throws(typeof(ArgumentException), delegate { client.SetGCMAPIKey(""); });
63+
Assert.Throws(typeof(ArgumentException), delegate { client.SetGcmApiKey(""); });
6464
}
6565

6666
[Fact]
67-
public void TestSetGCMAPiKeyNonGCMPushService()
67+
public void TestSetGcmApiKeyNonGcmPushService()
6868
{
6969
// Ensure that the API key doesn't get added on a service that doesn't accept it.
7070
var client = new WebPushClient();
7171

7272
var gcmAPIKey = @"teststring";
73-
client.SetGCMAPIKey(gcmAPIKey);
74-
var subscription = new PushSubscription(TEST_FCM_ENDPOINT, TEST_PUBLIC_KEY, TEST_PRIVATE_KEY);
75-
var message = client.GenerateRequestDetails(subscription, "test payload");
73+
client.SetGcmApiKey(gcmAPIKey);
74+
var subscription = new PushSubscription(TestFcmEndpoint, TestPublicKey, TestPrivateKey);
75+
var message = client.GenerateRequestDetails(subscription, @"test payload");
7676

7777
IEnumerable<string> values;
78-
Assert.False(message.Headers.TryGetValues("Authorization", out values));
78+
Assert.False(message.Headers.TryGetValues(@"Authorization", out values));
7979
}
8080

8181
[Fact]
82-
public void TestSetGCMAPIKeyNull()
82+
public void TestSetGcmApiKeyNull()
8383
{
8484
var client = new WebPushClient();
8585

86-
client.SetGCMAPIKey(@"somestring");
87-
client.SetGCMAPIKey(null);
86+
client.SetGcmApiKey(@"somestring");
87+
client.SetGcmApiKey(null);
8888

89-
var subscription = new PushSubscription(TEST_GCM_ENDPOINT, TEST_PUBLIC_KEY, TEST_PRIVATE_KEY);
90-
var message = client.GenerateRequestDetails(subscription, "test payload");
89+
var subscription = new PushSubscription(TestGcmEndpoint, TestPublicKey, TestPrivateKey);
90+
var message = client.GenerateRequestDetails(subscription, @"test payload");
9191

9292
IEnumerable<string> values;
9393
Assert.False(message.Headers.TryGetValues("Authorization", out values));
@@ -98,15 +98,15 @@ public void TestSetVapidDetails()
9898
{
9999
var client = new WebPushClient();
100100

101-
client.SetVapidDetails("mailto:example@example.com", TEST_PUBLIC_KEY, TEST_PRIVATE_KEY);
101+
client.SetVapidDetails("mailto:example@example.com", TestPublicKey, TestPrivateKey);
102102

103-
var subscription = new PushSubscription(TEST_FCM_ENDPOINT, TEST_PUBLIC_KEY, TEST_PRIVATE_KEY);
104-
var message = client.GenerateRequestDetails(subscription, "test payload");
105-
var authorizationHeader = message.Headers.GetValues("Authorization").First();
106-
var cryptoHeader = message.Headers.GetValues("Crypto-Key").First();
103+
var subscription = new PushSubscription(TestFcmEndpoint, TestPublicKey, TestPrivateKey);
104+
var message = client.GenerateRequestDetails(subscription, @"test payload");
105+
var authorizationHeader = message.Headers.GetValues(@"Authorization").First();
106+
var cryptoHeader = message.Headers.GetValues(@"Crypto-Key").First();
107107

108-
Assert.True(authorizationHeader.StartsWith("WebPush "));
109-
Assert.True(cryptoHeader.Contains("p256ecdsa"));
108+
Assert.True(authorizationHeader.StartsWith(@"WebPush "));
109+
Assert.True(cryptoHeader.Contains(@"p256ecdsa"));
110110
}
111111
}
112112
}

WebPush/Model/EncryptionResult.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
using WebPush.Util;
22

3-
// @LogicSoftware
4-
// Originally From: https://github.com/LogicSoftware/WebPushEncryption/blob/master/src/EncryptionResult.cs
53
namespace WebPush
64
{
5+
// @LogicSoftware
6+
// Originally From: https://github.com/LogicSoftware/WebPushEncryption/blob/master/src/EncryptionResult.cs
77
public class EncryptionResult
88
{
99
public byte[] PublicKey { get; set; }

WebPush/Util/Encryptor.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@
88
using Org.BouncyCastle.Crypto.Parameters;
99
using Org.BouncyCastle.Security;
1010

11-
// @LogicSoftware
12-
// Originally from https://github.com/LogicSoftware/WebPushEncryption/blob/master/src/Encryptor.cs
1311
namespace WebPush.Util
1412
{
13+
// @LogicSoftware
14+
// Originally from https://github.com/LogicSoftware/WebPushEncryption/blob/master/src/Encryptor.cs
1515
public static class Encryptor
1616
{
1717
private static readonly RandomNumberGenerator RandomNumberProvider = RandomNumberGenerator.Create();

0 commit comments

Comments
 (0)