Skip to content

Commit

Permalink
Merge branch 'je-upgrade' into je-github-actions
Browse files Browse the repository at this point in the history
  • Loading branch information
jonathanedey authored Apr 5, 2024
2 parents ec54168 + 50b0ed9 commit 2171b84
Show file tree
Hide file tree
Showing 30 changed files with 167 additions and 130 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
16 changes: 8 additions & 8 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 @@ -19,19 +20,18 @@ jobs:
- name: Checkout code
uses: actions/checkout@v4

- name: Setup .NET Core 2.1

- 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 }}
14 changes: 8 additions & 6 deletions .github/workflows/nightly.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,19 +38,20 @@ jobs:
with:
ref: ${{ github.event.client_payload.ref || github.ref }}

- name: Setup .NET Core 2.1

- 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 +60,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
18 changes: 10 additions & 8 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,19 +50,20 @@ jobs:
with:
ref: ${{ github.event.client_payload.ref || github.ref }}

- name: Setup .NET Core 2.1

- 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 +72,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 @@ -108,10 +109,11 @@ jobs:
with:
name: Release

- name: Setup .NET Core

- 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 @@ -93,7 +93,8 @@ public async Task CreateCustomTokenWithoutServiceAccount()
Credential = GoogleCredential.FromAccessToken(token),
ServiceAccountId = serviceAcct.Id,
ProjectId = serviceAcct.ProjectId,
}, "IAMSignApp");
},
"IAMSignApp");

try
{
Expand Down Expand Up @@ -603,7 +604,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 +618,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 +646,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,26 +1,27 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netcoreapp2.1</TargetFramework>
<TargetFrameworks>net462;net6.0</TargetFrameworks>
<LangVersion>latest</LangVersion>
<IsPackable>false</IsPackable>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<CodeAnalysisRuleSet>../../stylecop_test.ruleset</CodeAnalysisRuleSet>
</PropertyGroup>

<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.NET.Test.Sdk" Version="17.9.0" />
<PackageReference Include="Microsoft.AspNetCore.WebUtilities" Version="2.2.0" />
<PackageReference Include="System.Text.Json" Version="8.0.3" />
<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>
<DotNetCliToolReference Include="dotnet-xunit" Version="2.3.1" />
<PackageReference Include="StyleCop.Analyzers" Version="1.1.1-beta.61">
<PackageReference Include="StyleCop.Analyzers" Version="1.2.0-beta.556">
<PrivateAssets>all</PrivateAssets>
</PackageReference>
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\FirebaseAdmin\FirebaseAdmin.csproj" />
</ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ internal static class IntegrationTestUtils
Credential = GoogleCredential.FromFile(ServiceAccountFile),
};
return FirebaseApp.Create(options);
}, true);
},
true);

public static FirebaseApp EnsureDefaultApp()
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,26 @@
<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>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Google.Apis.Auth" Version="1.49.0" />
<PackageReference Include="Google.Apis.Auth" Version="1.67.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.9.0" />
<PackageReference Include="Microsoft.AspNetCore.Http" Version="2.2.2" />
<PackageReference Include="Microsoft.AspNetCore.Mvc" Version="2.2.0" />
<PackageReference Include="System.Text.Json" Version="8.0.3" />
<PackageReference Include=" System.Security.Cryptography.Xml" Version="8.0.0" />
<PackageReference Include="System.Net.Http" Version="4.3.4" />
<PackageReference Include="System.Text.RegularExpressions" Version="4.3.1" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\FirebaseAdmin\FirebaseAdmin.csproj" />
<PackageReference Include="StyleCop.Analyzers" Version="1.1.1-beta.61">
<PackageReference Include="StyleCop.Analyzers" Version="1.2.0-beta.556">
<PrivateAssets>all</PrivateAssets>
</PackageReference>
</ItemGroup>
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
1 change: 1 addition & 0 deletions FirebaseAdmin/FirebaseAdmin.Tests/Auth/FirebaseAuthTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
using Xunit;

[assembly: CollectionBehavior(DisableTestParallelization = true)]

namespace FirebaseAdmin.Auth.Tests
{
public class FirebaseAuthTest : IDisposable
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 2171b84

Please sign in to comment.