From ef935f609fc292a5c72ca245ad415f2b07f1ea5e Mon Sep 17 00:00:00 2001 From: Maxwell Weru Date: Thu, 4 Jan 2024 14:52:45 +0300 Subject: [PATCH] Remove tests that required sensitive information since they do not always work (#197) --- .../ApnsNotifierTests.cs | 41 ------------------- .../FcmLegacyNotifierTests.cs | 34 +-------------- .../FirebaseNotifierTests.cs | 34 +-------------- ....Extensions.PushNotifications.Tests.csproj | 4 -- 4 files changed, 2 insertions(+), 111 deletions(-) diff --git a/tests/Tingle.Extensions.PushNotifications.Tests/ApnsNotifierTests.cs b/tests/Tingle.Extensions.PushNotifications.Tests/ApnsNotifierTests.cs index 4c301c0..275cf33 100644 --- a/tests/Tingle.Extensions.PushNotifications.Tests/ApnsNotifierTests.cs +++ b/tests/Tingle.Extensions.PushNotifications.Tests/ApnsNotifierTests.cs @@ -1,5 +1,4 @@ using Microsoft.Extensions.Caching.Memory; -using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; using System.Security.Cryptography; @@ -85,44 +84,4 @@ public void ParsePrivateKey_Works() parsed = ApnsNotifierOptionsExtensions.ParsePrivateKey(new string(PemEncoding.Write("PRIVATE KEY", key))); Assert.Equal(key, parsed); // sequence equal } - - [Fact] - public async Task Works() - { - var configuration = new ConfigurationBuilder() - .AddUserSecrets(optional: true) // local debug - .AddEnvironmentVariables() // CI-pipeline - .Build(); - - var services = new ServiceCollection(); - services.AddLogging(builder => builder.AddXUnit(outputHelper)); - services.AddMemoryCache(); - services.AddApnsNotifier(options => - { - options.TeamId = configuration["ApnsTest:TeamId"]; - options.KeyId = configuration["ApnsTest:KeyId"]; - options.BundleId = configuration["ApnsTest:BundleId"]; - options.UsePrivateKey(keyId => configuration.GetValue("ApnsTest:PrivateKey")!); - }); - - var provider = services.BuildServiceProvider(validateScopes: true); - using var scope = provider.CreateScope(); - var sp = scope.ServiceProvider; - var client = sp.GetRequiredService(); - - var header = new ApnsMessageHeader - { - DeviceToken = configuration.GetValue("ApnsTest:DeviceToken")!, - Environment = configuration.GetValue("ApnsTest:Environment") ?? ApnsEnvironment.Development, - PushType = ApnsPushType.Background, - }; - var data = new ApnsMessageData(new ApnsMessagePayload { ContentAvailable = 1, }); - - var resp = await client.SendAsync(header, data, default); - resp.EnsureSuccess(); - - var id = resp.Headers.GetApnsId(); - Assert.NotNull(id); - Assert.NotEmpty(id); - } } diff --git a/tests/Tingle.Extensions.PushNotifications.Tests/FcmLegacyNotifierTests.cs b/tests/Tingle.Extensions.PushNotifications.Tests/FcmLegacyNotifierTests.cs index 8f5e33f..5207a6b 100644 --- a/tests/Tingle.Extensions.PushNotifications.Tests/FcmLegacyNotifierTests.cs +++ b/tests/Tingle.Extensions.PushNotifications.Tests/FcmLegacyNotifierTests.cs @@ -1,5 +1,4 @@ -using Microsoft.Extensions.Configuration; -using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; using Tingle.Extensions.PushNotifications.FcmLegacy; using Tingle.Extensions.PushNotifications.FcmLegacy.Models; @@ -54,35 +53,4 @@ public async Task Authentication_IsPopulated() var rr = await client.SendAsync(model); Assert.Equal($"key={key}", header); } - - [Fact] - public async Task Works() - { - var configuration = new ConfigurationBuilder() - .AddUserSecrets(optional: true) // local debug - .AddEnvironmentVariables() // CI-pipeline - .Build(); - - var services = new ServiceCollection(); - services.AddLogging(builder => builder.AddXUnit(outputHelper)); - services.AddFcmLegacyNotifier(options => - { - options.Key = configuration.GetValue("FcmLegacyTest:Key"); - }); - - var provider = services.BuildServiceProvider(validateScopes: true); - using var scope = provider.CreateScope(); - var sp = scope.ServiceProvider; - var client = sp.GetRequiredService(); - - var model = new FcmLegacyRequest - { - RegistrationIds = new[] - { - configuration.GetValue("FcmLegacyTest:RegistrationId")!, - }, - }; - var response = await client.SendAsync(model); - response.EnsureSuccess(); - } } diff --git a/tests/Tingle.Extensions.PushNotifications.Tests/FirebaseNotifierTests.cs b/tests/Tingle.Extensions.PushNotifications.Tests/FirebaseNotifierTests.cs index 5d81460..73ae729 100644 --- a/tests/Tingle.Extensions.PushNotifications.Tests/FirebaseNotifierTests.cs +++ b/tests/Tingle.Extensions.PushNotifications.Tests/FirebaseNotifierTests.cs @@ -1,5 +1,4 @@ -using Microsoft.Extensions.Configuration; -using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; using System.Security.Cryptography; using System.Text.Json.Nodes; @@ -131,35 +130,4 @@ public async Task Authentication_IsPopulated() response.EnsureSuccess(); Assert.Equal("Bearer stupid_token", header); } - - [Fact] - public async Task Works() - { - var configuration = new ConfigurationBuilder() - .AddUserSecrets(optional: true) // local debug - .AddEnvironmentVariables() // CI-pipeline - .Build(); - - var services = new ServiceCollection(); - services.AddLogging(builder => builder.AddXUnit(outputHelper)); - services.AddMemoryCache(); - services.AddFirebaseNotifier(options => - { - options.ProjectId = configuration.GetValue("FirebaseTest:ProjectId"); - options.ClientEmail = configuration.GetValue("FirebaseTest:ClientEmail"); - options.TokenUri = configuration.GetValue("FirebaseTest:TokenUri"); - options.PrivateKey = configuration.GetValue("FirebaseTest:PrivateKey"); - options.PrivateKey = options.PrivateKey?.Replace("\\n", "\n"); // CI-pipeline - }); - - var provider = services.BuildServiceProvider(validateScopes: true); - using var scope = provider.CreateScope(); - var sp = scope.ServiceProvider; - var client = sp.GetRequiredService(); - - var msg = new FirebaseRequestMessage { Token = configuration.GetValue("FirebaseTest:DeviceToken"), }; - var model = new FirebaseRequest(msg); - var response = await client.SendAsync(model); - response.EnsureSuccess(); - } } diff --git a/tests/Tingle.Extensions.PushNotifications.Tests/Tingle.Extensions.PushNotifications.Tests.csproj b/tests/Tingle.Extensions.PushNotifications.Tests/Tingle.Extensions.PushNotifications.Tests.csproj index c43842c..412328a 100644 --- a/tests/Tingle.Extensions.PushNotifications.Tests/Tingle.Extensions.PushNotifications.Tests.csproj +++ b/tests/Tingle.Extensions.PushNotifications.Tests/Tingle.Extensions.PushNotifications.Tests.csproj @@ -1,9 +1,5 @@  - - 923dd109-6f0c-4b04-bcff-01618b2545ab - -