Skip to content

Commit

Permalink
Remove tests that required sensitive information since they do not al…
Browse files Browse the repository at this point in the history
…ways work (#197)
  • Loading branch information
mburumaxwell authored Jan 4, 2024
1 parent 372407b commit ef935f6
Show file tree
Hide file tree
Showing 4 changed files with 2 additions and 111 deletions.
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

0 comments on commit ef935f6

Please sign in to comment.