Skip to content

Commit

Permalink
chore: Bump supported .NET versions to net462 and net6.0+ (#377)
Browse files Browse the repository at this point in the history
* Add net6.0 to targeted frameworks

* Add net6.0 to CI

* fix: update target frameworks for integration tests ans snippets

* Refactor build process and test multiple frameworks

* Refactor build process and test multiple frameworks

* fix script call

* Refactor and update nightly and release workflows

* Trigger Integration Tests

* fix running unit tests in release stage

* fix build before running integration tests

* fix: revert to expected build name

* try only 3.1

* try no specific version

* fix set `Microsoft.NET.Test.Sdk` to 15.0.0

* Add Microsoft.TestPlatform.ObjectModel package for net462

* fix: Update xunit Packages and remove Microsoft.TestPlatform.ObjectModel package for net462

* Fix: tests

* fix: added preprocessor directives to handle differences in tests between .net versions

* Add netcoreapp3.1, net7.0 and net8.0

* fix: Add conditional package references and tests for netcoreapp3.1

* fix conditional test

* Update workflows

* fix: build before running integration tests

* Removed netcoreap3.1 and redundant net7 and net8
  • Loading branch information
jonathanedey authored Apr 2, 2024
1 parent e4f5a55 commit 9160557
Show file tree
Hide file tree
Showing 22 changed files with 132 additions and 112 deletions.
3 changes: 2 additions & 1 deletion .github/scripts/run_integration_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,5 @@ gpg --quiet --batch --yes --decrypt --passphrase="${FIREBASE_SERVICE_ACCT_KEY}"

echo "${FIREBASE_API_KEY}" > FirebaseAdmin/FirebaseAdmin.IntegrationTests/resources/integration_apikey.txt

dotnet test FirebaseAdmin/FirebaseAdmin.IntegrationTests
dotnet test FirebaseAdmin/FirebaseAdmin.IntegrationTests --configuration Release --framework net462
dotnet test FirebaseAdmin/FirebaseAdmin.IntegrationTests --configuration Release --framework net6.0
19 changes: 9 additions & 10 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ jobs:
strategy:
matrix:
os: [ubuntu-latest]
framework-version: [net462, net6.0]

env:
DOTNET_SKIP_FIRST_TIME_EXPERIENCE: 1
Expand All @@ -17,21 +18,19 @@ jobs:

steps:
- name: Checkout code
uses: actions/checkout@v1
uses: actions/checkout@v4

- name: Setup .NET Core 2.1
uses: actions/setup-dotnet@v1
- name: Setup .NET
uses: actions/setup-dotnet@v4
with:
dotnet-version: 2.1.x
dotnet-version: 6.0.x

- name: Install dependencies
run: dotnet msbuild /t:restore FirebaseAdmin
run: dotnet restore FirebaseAdmin/FirebaseAdmin.sln

- name: Build with dotnet
run: |
dotnet msbuild FirebaseAdmin/FirebaseAdmin
dotnet msbuild FirebaseAdmin/FirebaseAdmin.Snippets
dotnet msbuild FirebaseAdmin/FirebaseAdmin.IntegrationTests
run: dotnet build FirebaseAdmin/FirebaseAdmin.sln --configuration Release --no-restore

- name: Run unit tests
run: dotnet test FirebaseAdmin/FirebaseAdmin.Tests
run: |
dotnet test FirebaseAdmin/FirebaseAdmin.Tests --configuration Release --no-restore --no-build --framework ${{ matrix.framework-version }}
17 changes: 9 additions & 8 deletions .github/workflows/nightly.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,23 +34,23 @@ jobs:

steps:
- name: Checkout source for staging
uses: actions/checkout@v2
uses: actions/checkout@v4
with:
ref: ${{ github.event.client_payload.ref || github.ref }}

- name: Setup .NET Core 2.1
uses: actions/setup-dotnet@v1
- name: Setup .NET
uses: actions/setup-dotnet@v4
with:
dotnet-version: 2.1.x
dotnet-version: 6.0.x

- name: Install dependencies
run: dotnet msbuild /t:restore FirebaseAdmin
run: dotnet restore FirebaseAdmin/FirebaseAdmin.sln

- name: Build with dotnet
run: dotnet msbuild FirebaseAdmin/FirebaseAdmin
run: dotnet build FirebaseAdmin/FirebaseAdmin.sln --configuration Release --no-restore

- name: Run unit tests
run: dotnet test FirebaseAdmin/FirebaseAdmin.Tests
run: dotnet test FirebaseAdmin/FirebaseAdmin.Tests --configuration Release --no-restore --no-build

- name: Run integration tests
run: ./.github/scripts/run_integration_tests.sh
Expand All @@ -59,7 +59,8 @@ jobs:
FIREBASE_API_KEY: ${{ secrets.FIREBASE_API_KEY }}

- name: Package release artifacts
run: dotnet pack -c Release FirebaseAdmin/FirebaseAdmin
run: dotnet pack FirebaseAdmin/FirebaseAdmin.sln --configuration Release --no-restore --no-build


# Attach the packaged artifacts to the workflow output. These can be manually
# downloaded for later inspection if necessary.
Expand Down
24 changes: 12 additions & 12 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,23 +46,23 @@ jobs:
# via the 'ref' client parameter.
steps:
- name: Checkout source for staging
uses: actions/checkout@v2
uses: actions/checkout@v4
with:
ref: ${{ github.event.client_payload.ref || github.ref }}

- name: Setup .NET Core 2.1
uses: actions/setup-dotnet@v1
- name: Setup .NET
uses: actions/setup-dotnet@v4
with:
dotnet-version: 2.1.x
dotnet-version: 6.0.x

- name: Install dependencies
run: dotnet msbuild /t:restore FirebaseAdmin
run: dotnet restore FirebaseAdmin/FirebaseAdmin.sln

- name: Build with dotnet
run: dotnet msbuild FirebaseAdmin/FirebaseAdmin
run: dotnet build FirebaseAdmin/FirebaseAdmin.sln --configuration Release --no-restore

- name: Run unit tests
run: dotnet test FirebaseAdmin/FirebaseAdmin.Tests
run: dotnet test FirebaseAdmin/FirebaseAdmin.Tests --configuration Release --no-restore --no-build

- name: Run integration tests
run: ./.github/scripts/run_integration_tests.sh
Expand All @@ -71,7 +71,7 @@ jobs:
FIREBASE_API_KEY: ${{ secrets.FIREBASE_API_KEY }}

- name: Package release artifacts
run: dotnet pack -c Release FirebaseAdmin/FirebaseAdmin
run: dotnet pack FirebaseAdmin/FirebaseAdmin.sln --configuration Release --no-restore --no-build

# Attach the packaged artifacts to the workflow output. These can be manually
# downloaded for later inspection if necessary.
Expand Down Expand Up @@ -100,18 +100,18 @@ jobs:

steps:
- name: Checkout source for publish
uses: actions/checkout@v2
uses: actions/checkout@v4

# Download the artifacts created by the stage_release job.
- name: Download release candidates
uses: actions/download-artifact@v1
with:
name: Release

- name: Setup .NET Core
uses: actions/setup-dotnet@v1
- name: Setup .NET
uses: actions/setup-dotnet@v4
with:
dotnet-version: 2.2.108
dotnet-version: 6.0.x

- name: Publish preflight check
id: preflight
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Web;
using FirebaseAdmin.Auth;
using FirebaseAdmin.Auth.Hash;
using Google.Apis.Auth.OAuth2;
using Microsoft.AspNetCore.WebUtilities;
using Xunit;

namespace FirebaseAdmin.IntegrationTests.Auth
Expand Down Expand Up @@ -603,7 +603,7 @@ public async Task EmailVerificationLink()
user.Email, EmailLinkSettings);

var uri = new Uri(link);
var query = HttpUtility.ParseQueryString(uri.Query);
var query = QueryHelpers.ParseQuery(uri.Query);
Assert.Equal(ContinueUrl, query["continueUrl"]);
Assert.Equal("verifyEmail", query["mode"]);
}
Expand All @@ -617,7 +617,7 @@ public async Task PasswordResetLink()
user.Email, EmailLinkSettings);

var uri = new Uri(link);
var query = HttpUtility.ParseQueryString(uri.Query);
var query = QueryHelpers.ParseQuery(uri.Query);
Assert.Equal(ContinueUrl, query["continueUrl"]);

var request = new ResetPasswordRequest()
Expand Down Expand Up @@ -645,7 +645,7 @@ public async Task SignInWithEmailLink()
user.Email, EmailLinkSettings);

var uri = new Uri(link);
var query = HttpUtility.ParseQueryString(uri.Query);
var query = QueryHelpers.ParseQuery(uri.Query);
Assert.Equal(ContinueUrl, query["continueUrl"]);

var idToken = await AuthIntegrationUtils.SignInWithEmailLinkAsync(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netcoreapp2.1</TargetFramework>
<TargetFrameworks>net462;net6.0</TargetFrameworks>
<LangVersion>latest</LangVersion>
<IsPackable>false</IsPackable>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
Expand All @@ -10,8 +10,9 @@

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.7.1" />
<PackageReference Include="xunit" Version="2.4.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.3">
<PackageReference Include="Microsoft.AspNetCore.WebUtilities" Version="2.2.0" />
<PackageReference Include="xunit" Version="2.7.0" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.7">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
Expand All @@ -20,7 +21,6 @@
<PrivateAssets>all</PrivateAssets>
</PackageReference>
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\FirebaseAdmin\FirebaseAdmin.csproj" />
</ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netcoreapp2.1</TargetFramework>
<TargetFrameworks>net462;net6.0;</TargetFrameworks>
<IsPackable>false</IsPackable>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<CodeAnalysisRuleSet>../../stylecop_test.ruleset</CodeAnalysisRuleSet>
Expand Down
6 changes: 4 additions & 2 deletions FirebaseAdmin/FirebaseAdmin.Snippets/FirebaseAuthSnippets.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using FirebaseAdmin.Auth;
Expand Down Expand Up @@ -582,9 +583,10 @@ internal static async Task SetCustomUserClaimsIncrementalAsync()
object isAdmin;
if (user.CustomClaims.TryGetValue("admin", out isAdmin) && (bool)isAdmin)
{
var claims = new Dictionary<string, object>(user.CustomClaims);
var claims = user.CustomClaims.ToDictionary(kvp => kvp.Key, kvp => kvp.Value);
// Add level.
claims["level"] = 10;
var level = 10;
claims["level"] = level;
// Add custom claims for additional privileges.
await FirebaseAuth.DefaultInstance.SetCustomUserClaimsAsync(user.Uid, claims);
}
Expand Down
10 changes: 5 additions & 5 deletions FirebaseAdmin/FirebaseAdmin.Tests/Auth/AuthBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,27 +64,27 @@ private void PopulateArgs(AbstractFirebaseAuth.Args args, TestOptions options)
if (options.UserManagerRequestHandler != null)
{
args.UserManager = new Lazy<FirebaseUserManager>(
this.CreateUserManager(options));
() => this.CreateUserManager(options));
}

if (options.ProviderConfigRequestHandler != null)
{
args.ProviderConfigManager = new Lazy<ProviderConfigManager>(
this.CreateProviderConfigManager(options));
() => this.CreateProviderConfigManager(options));
}

if (options.IdTokenVerifier)
{
args.IdTokenVerifier = new Lazy<FirebaseTokenVerifier>(
this.CreateIdTokenVerifier());
() => this.CreateIdTokenVerifier());
}

if (options.SessionCookieVerifier)
{
if (args is FirebaseAuth.Args)
{
(args as FirebaseAuth.Args).SessionCookieVerifier =
new Lazy<FirebaseTokenVerifier>(this.CreateSessionCookieVerifier());
new Lazy<FirebaseTokenVerifier>(() => this.CreateSessionCookieVerifier());
}
else
{
Expand All @@ -95,7 +95,7 @@ private void PopulateArgs(AbstractFirebaseAuth.Args args, TestOptions options)

if (options.TokenFactory)
{
args.TokenFactory = new Lazy<FirebaseTokenFactory>(this.CreateTokenFactory());
args.TokenFactory = new Lazy<FirebaseTokenFactory>(() => this.CreateTokenFactory());
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ internal static CustomTokenVerifier ForEmulator(string tenantId = null)

internal void Verify(string token, string uid, IDictionary<string, object> claims = null)
{
string[] segments = token.Split(".");
string[] segments = token.Split('.');
Assert.Equal(3, segments.Length);

var header = JwtUtils.Decode<JsonWebSignature.Header>(segments[0]);
Expand Down Expand Up @@ -99,7 +99,7 @@ internal RSACustomTokenVerifier(string issuer, byte[] publicKey, string tenantId
: base(issuer, tenantId)
{
var x509cert = new X509Certificate2(publicKey);
this.rsa = (RSA)x509cert.PublicKey.Key;
this.rsa = (RSA)x509cert.GetRSAPublicKey();
}

protected override void AssertSignature(string tokenData, string signature)
Expand Down
2 changes: 1 addition & 1 deletion FirebaseAdmin/FirebaseAdmin.Tests/Auth/Jwt/JwtTestUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ private sealed class ByteArrayPublicKeySource : IPublicKeySource
public ByteArrayPublicKeySource(byte[] publicKey)
{
var x509cert = new X509Certificate2(publicKey);
var rsa = (RSA)x509cert.PublicKey.Key;
var rsa = (RSA)x509cert.GetRSAPublicKey();
this.rsa = ImmutableList.Create(new PublicKey("test-key-id", rsa));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public async Task Signer()
Assert.Equal(
"[email protected]", await signer.GetKeyIdAsync());
byte[] data = Encoding.UTF8.GetBytes("Hello world");
byte[] signature = signer.SignDataAsync(data).Result;
byte[] signature = await signer.SignDataAsync(data);
Assert.True(this.Verify(data, signature));
}

Expand All @@ -47,7 +47,7 @@ public void NullCredential()
private bool Verify(byte[] data, byte[] signature)
{
var x509cert = new X509Certificate2(File.ReadAllBytes("./resources/public_cert.pem"));
var rsa = (RSA)x509cert.PublicKey.Key;
var rsa = (RSA)x509cert.GetRSAPublicKey();
return rsa.VerifyData(
data, signature, HashAlgorithmName.SHA256, RSASignaturePadding.Pkcs1);
}
Expand Down
Loading

0 comments on commit 9160557

Please sign in to comment.