Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove tests that required sensitive information since they do not always work #197

Merged
merged 1 commit into from
Jan 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -85,44 +84,4 @@ public void ParsePrivateKey_Works()
parsed = ApnsNotifierOptionsExtensions.ParsePrivateKey(new string(PemEncoding.Write("PRIVATE KEY", key)));
Assert.Equal<byte>(key, parsed); // sequence equal
}

[Fact]
public async Task Works()
{
var configuration = new ConfigurationBuilder()
.AddUserSecrets<ApnsNotifierTests>(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<string>("ApnsTest:PrivateKey")!);
});

var provider = services.BuildServiceProvider(validateScopes: true);
using var scope = provider.CreateScope();
var sp = scope.ServiceProvider;
var client = sp.GetRequiredService<ApnsNotifier>();

var header = new ApnsMessageHeader
{
DeviceToken = configuration.GetValue<string>("ApnsTest:DeviceToken")!,
Environment = configuration.GetValue<ApnsEnvironment?>("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);
}
}
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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<FcmLegacyNotifierTests>(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<string>("FcmLegacyTest:Key");
});

var provider = services.BuildServiceProvider(validateScopes: true);
using var scope = provider.CreateScope();
var sp = scope.ServiceProvider;
var client = sp.GetRequiredService<FcmLegacyNotifier>();

var model = new FcmLegacyRequest
{
RegistrationIds = new[]
{
configuration.GetValue<string>("FcmLegacyTest:RegistrationId")!,
},
};
var response = await client.SendAsync(model);
response.EnsureSuccess();
}
}
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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<FirebaseNotifierTests>(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<string>("FirebaseTest:ProjectId");
options.ClientEmail = configuration.GetValue<string>("FirebaseTest:ClientEmail");
options.TokenUri = configuration.GetValue<string>("FirebaseTest:TokenUri");
options.PrivateKey = configuration.GetValue<string>("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<FirebaseNotifier>();

var msg = new FirebaseRequestMessage { Token = configuration.GetValue<string>("FirebaseTest:DeviceToken"), };
var model = new FirebaseRequest(msg);
var response = await client.SendAsync(model);
response.EnsureSuccess();
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<UserSecretsId>923dd109-6f0c-4b04-bcff-01618b2545ab</UserSecretsId>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Caching.Memory" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.EnvironmentVariables" Version="8.0.0" />
Expand Down