Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
61 commits
Select commit Hold shift + click to select a range
055df25
Drafting the FCM API
hiranya911 Sep 23, 2018
72236d0
More tests and code cleanup
hiranya911 Sep 23, 2018
65e3f12
Added Notification type; Renamed MessagingTest to MessageTest
hiranya911 Sep 24, 2018
8e7ee55
Cancellation test
hiranya911 Sep 24, 2018
d9b840e
Adjusted line length
hiranya911 Sep 27, 2018
e241df0
Added integration test case
hiranya911 Sep 30, 2018
43c1195
Added AndroidConfig type; Improved validation logic
hiranya911 Sep 30, 2018
91188a0
Making priority nullable
hiranya911 Oct 1, 2018
588b658
Renamed Ttl to TimeToLive; Renamed Piority enum constants; Using IEnu…
hiranya911 Dec 6, 2018
3f275f5
Using readonly dict when possible
hiranya911 Dec 6, 2018
97710dd
Adding newline at eof
hiranya911 Dec 6, 2018
e362856
Making getters public as per proposal
hiranya911 Dec 7, 2018
61fc77e
Responding to code review comments
hiranya911 Dec 12, 2018
8aba063
More docs updates
hiranya911 Dec 12, 2018
1b60f48
Implemented AndroidNotification API
hiranya911 Dec 13, 2018
d83ec1e
Added more documentation for the internal types/methods
hiranya911 Dec 14, 2018
b069220
Merge branch 'hkj-fcm' into hkj-fcm-part2
hiranya911 Dec 14, 2018
9f9b0a0
Added documentation to internal types
hiranya911 Dec 14, 2018
9e46d4c
Implemented Webpush API for FCM
hiranya911 Dec 19, 2018
bceb995
Refactored the FirebaseMessaging types
hiranya911 Dec 19, 2018
0803839
Shallow copying list properties
hiranya911 Dec 19, 2018
2f5914f
Merge pull request #13 from firebase/hkj-fcm-part2
hiranya911 Dec 19, 2018
254c779
Merged with hkj-fcm-cleanup; Updated WebpushNotification for serializ…
hiranya911 Dec 19, 2018
08153a7
Fixed CustomData deserialization
hiranya911 Dec 20, 2018
0166f5f
Exposing CustomData as IDictionary
hiranya911 Dec 20, 2018
7acaaf6
Minor cleanup of internal properties
hiranya911 Dec 20, 2018
7cc6f1f
More test cases
hiranya911 Dec 20, 2018
86002eb
Handling invalid priority values during deserialization
hiranya911 Jan 10, 2019
6e4114b
Merge pull request #14 from firebase/hkj-fcm-cleanup
hiranya911 Jan 10, 2019
30471b4
Merge branch 'hkj-fcm' into hkj-fcm-part3
hiranya911 Jan 10, 2019
b1de01f
Handling invalid direction values during deserialization
hiranya911 Jan 10, 2019
c3b4499
Implementing APNs support
hiranya911 Jan 16, 2019
693eac5
Added other APNS types
hiranya911 Jan 17, 2019
a4edaf1
Cleaning up the Apns impl
hiranya911 Jan 17, 2019
31e317b
More clean up and tests
hiranya911 Jan 17, 2019
0eade9c
Using more Linq; More tests
hiranya911 Jan 17, 2019
6124d45
Fixed Apns deserialization
hiranya911 Jan 18, 2019
f4fe28b
Adding more APNS tests
hiranya911 Jan 18, 2019
9b50ff9
Adding Stylecop based linting
hiranya911 Jan 21, 2019
ed910d5
Added stylecop to tests
hiranya911 Jan 21, 2019
fccf06c
Fixing more lint errors
hiranya911 Jan 21, 2019
03607a5
Fixed more lint errors
hiranya911 Jan 21, 2019
d16f670
Fixed more lint errors
hiranya911 Jan 22, 2019
f991549
Fixed almost everything
hiranya911 Jan 22, 2019
6bcc4d6
Linter test commit
hiranya911 Jan 22, 2019
9108c26
Fixing lint error
hiranya911 Jan 22, 2019
1b9558a
Enabled lint rule for 'this' checks
hiranya911 Jan 22, 2019
477ecd0
Enabled all possible rules; Added linting to snippets;
hiranya911 Jan 22, 2019
ad58b40
Added missing newlines at eof
hiranya911 Jan 22, 2019
70efb05
Merge pull request #16 from firebase/hkj-fcm-part3
hiranya911 Jan 22, 2019
fee4c9e
Merge branch 'hkj-fcm' into hkj-fcm-part4
hiranya911 Jan 23, 2019
ee8cfd3
Added more unit tests
hiranya911 Jan 23, 2019
ae1e80c
Adding newline at eod
hiranya911 Jan 23, 2019
2dfb622
Fixing lint errors in user mgt code
hiranya911 Jan 23, 2019
e6bb4d2
Adding required constant
hiranya911 Jan 23, 2019
b901e62
Merge pull request #19 from firebase/hkj-fcm-part4
hiranya911 Jan 24, 2019
65905e7
Merge branch 'master' into hkj-stylecop
hiranya911 Jan 25, 2019
af9e80b
Merged with hkj-stylecop
hiranya911 Jan 25, 2019
bbbc925
Fixing lint errors
hiranya911 Jan 25, 2019
b4041ff
Fixed all lint errors
hiranya911 Jan 25, 2019
d7f22ec
Last lint errors
hiranya911 Jan 25, 2019
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
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ matrix:
script:
- dotnet build FirebaseAdmin/FirebaseAdmin
- dotnet build FirebaseAdmin/FirebaseAdmin.Snippets
- dotnet build FirebaseAdmin/FirebaseAdmin.IntegrationTests
- dotnet test FirebaseAdmin/FirebaseAdmin.Tests
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@

<PropertyGroup>
<TargetFramework>netcoreapp2.0</TargetFramework>

<IsPackable>false</IsPackable>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<CodeAnalysisRuleSet>../../stylecop_test.ruleset</CodeAnalysisRuleSet>
</PropertyGroup>

<ItemGroup>
Expand All @@ -12,6 +13,9 @@
<PackageReference Include="xunit" Version="2.3.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.3.1" />
<DotNetCliToolReference Include="dotnet-xunit" Version="2.3.1" />
<PackageReference Include="StyleCop.Analyzers" Version="1.1.1-beta.61">
<PrivateAssets>all</PrivateAssets>
</PackageReference>
</ItemGroup>

<ItemGroup>
Expand Down
36 changes: 19 additions & 17 deletions FirebaseAdmin/FirebaseAdmin.IntegrationTests/FirebaseAuthTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,24 +17,24 @@
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;
using Xunit;
using FirebaseAdmin;
using FirebaseAdmin.Auth;
using Google.Apis.Auth.OAuth2;
using Google.Apis.Util;
using Xunit;

namespace FirebaseAdmin.IntegrationTests
{
public class FirebaseAuthTest
{
private const string VerifyCustomTokenUrl =
private const string VerifyCustomTokenUrl =
"https://www.googleapis.com/identitytoolkit/v3/relyingparty/verifyCustomToken";

public FirebaseAuthTest()
{
IntegrationTestUtils.EnsureDefaultApp();
}

[Fact]
public async Task CreateCustomToken()
{
Expand All @@ -50,9 +50,9 @@ public async Task CreateCustomTokenWithClaims()
{
var developerClaims = new Dictionary<string, object>()
{
{"admin", true},
{"package", "gold"},
{"magicNumber", 42L},
{ "admin", true },
{ "package", "gold" },
{ "magicNumber", 42L },
};
var customToken = await FirebaseAuth.DefaultInstance.CreateCustomTokenAsync(
"testuser", developerClaims);
Expand All @@ -72,13 +72,14 @@ public async Task CreateCustomTokenWithClaims()
public async Task CreateCustomTokenWithoutServiceAccount()
{
var googleCred = FirebaseApp.DefaultInstance.Options.Credential;
var serviceAcct = (ServiceAccountCredential) googleCred.UnderlyingCredential;
var token = await ((ITokenAccess) googleCred).GetAccessTokenForRequestAsync();
var app = FirebaseApp.Create(new AppOptions()
{
Credential = GoogleCredential.FromAccessToken(token),
ServiceAccountId = serviceAcct.Id,
}, "IAMSignApp");
var serviceAcct = (ServiceAccountCredential)googleCred.UnderlyingCredential;
var token = await ((ITokenAccess)googleCred).GetAccessTokenForRequestAsync();
var app = FirebaseApp.Create(
new AppOptions()
{
Credential = GoogleCredential.FromAccessToken(token),
ServiceAccountId = serviceAcct.Id,
}, "IAMSignApp");
try
{
var customToken = await FirebaseAuth.GetAuth(app).CreateCustomTokenAsync(
Expand All @@ -98,7 +99,7 @@ public async Task SetCustomUserClaims()
{
var customClaims = new Dictionary<string, object>()
{
{"admin", true}
{ "admin", true },
};

await FirebaseAuth.DefaultInstance.SetCustomUserClaimsAsync("testuser", customClaims);
Expand Down Expand Up @@ -126,12 +127,13 @@ private static async Task<string> SignInWithCustomTokenAsync(string customToken)
var rb = new Google.Apis.Requests.RequestBuilder()
{
Method = Google.Apis.Http.HttpConsts.Post,
BaseUri = new Uri(VerifyCustomTokenUrl),
BaseUri = new Uri(VerifyCustomTokenUrl),
};
rb.AddParameter(RequestParameterType.Query, "key", IntegrationTestUtils.GetApiKey());
var request = rb.CreateRequest();
var jsonSerializer = Google.Apis.Json.NewtonsoftJsonSerializer.Instance;
var payload = jsonSerializer.Serialize(new SignInRequest{
var payload = jsonSerializer.Serialize(new SignInRequest
{
CustomToken = customToken,
ReturnSecureToken = true,
});
Expand Down Expand Up @@ -159,6 +161,6 @@ internal class SignInRequest
internal class SignInResponse
{
[Newtonsoft.Json.JsonProperty("idToken")]
public String IdToken { get; set; }
public string IdToken { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
// Copyright 2018, Google Inc. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

using System;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using FirebaseAdmin.Messaging;
using Xunit;

namespace FirebaseAdmin.IntegrationTests
{
public class FirebaseMessagingTest
{
public FirebaseMessagingTest()
{
IntegrationTestUtils.EnsureDefaultApp();
}

[Fact]
public async Task Send()
{
var message = new Message()
{
Topic = "foo-bar",
Notification = new Notification()
{
Title = "Title",
Body = "Body",
},
Android = new AndroidConfig()
{
Priority = Priority.Normal,
TimeToLive = TimeSpan.FromHours(1),
RestrictedPackageName = "com.google.firebase.testing",
},
};
var id = await FirebaseMessaging.DefaultInstance.SendAsync(message, dryRun: true);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't suppose there's any way to see that the message actually got all the parts it was supposed to?

It just seems kind of odd for an "integration test" to do a dryRun anyway.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

dryRun mode does validate for message content (both locally and at the server). The operation will fail if the message is invalid.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I agree with @bklimt this isn't great at the moment. Last time @alexames looked into testing this in the client SDKs end to end there wasn't really a way to do so without spinning up a XMPP server. If the REST request is formatted appropriately, I guess that's good enough for the mo'.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We do check the message content in our unit tests.

Assert.True(!string.IsNullOrEmpty(id));
Assert.Matches(new Regex("^projects/.*/messages/.*$"), id);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,15 @@ internal static class IntegrationTestUtils
private const string ServiceAccountFile = "./resources/integration_cert.json";
private const string ApiKeyFile = "./resources/integration_apikey.txt";

private static readonly Lazy<FirebaseApp> DefaultFirebaseApp = new Lazy<FirebaseApp>(() => {
var options = new AppOptions()
private static readonly Lazy<FirebaseApp> DefaultFirebaseApp = new Lazy<FirebaseApp>(
() =>
{
Credential = GoogleCredential.FromFile(ServiceAccountFile),
};
return FirebaseApp.Create(options);
}, true);
var options = new AppOptions()
{
Credential = GoogleCredential.FromFile(ServiceAccountFile),
};
return FirebaseApp.Create(options);
}, true);

public static FirebaseApp EnsureDefaultApp()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
<PropertyGroup>
<TargetFramework>netcoreapp2.0</TargetFramework>
<IsPackable>false</IsPackable>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<CodeAnalysisRuleSet>../../stylecop_test.ruleset</CodeAnalysisRuleSet>
</PropertyGroup>

<ItemGroup>
Expand All @@ -11,6 +13,9 @@

<ItemGroup>
<ProjectReference Include="..\FirebaseAdmin\FirebaseAdmin.csproj" />
<PackageReference Include="StyleCop.Analyzers" Version="1.1.1-beta.61">
<PrivateAssets>all</PrivateAssets>
</PackageReference>
</ItemGroup>

</Project>
16 changes: 8 additions & 8 deletions FirebaseAdmin/FirebaseAdmin.Snippets/FirebaseAppSnippets.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@

namespace FirebaseAdmin.Snippets
{
class FirebaseAppSnippets
internal class FirebaseAppSnippets
{
static void InitSdkWithServiceAccount()
internal static void InitSdkWithServiceAccount()
{
// [START initialize_sdk_with_service_account]
FirebaseApp.Create(new AppOptions()
Expand All @@ -33,7 +33,7 @@ static void InitSdkWithServiceAccount()
// [END initialize_sdk_with_service_account]
}

static void InitSdkWithApplicationDefault()
internal static void InitSdkWithApplicationDefault()
{
// [START initialize_sdk_with_application_default]
FirebaseApp.Create(new AppOptions()
Expand All @@ -43,7 +43,7 @@ static void InitSdkWithApplicationDefault()
// [END initialize_sdk_with_application_default]
}

static void InitSdkWithRefreshToken()
internal static void InitSdkWithRefreshToken()
{
// [START initialize_sdk_with_refresh_token]
FirebaseApp.Create(new AppOptions()
Expand All @@ -53,14 +53,14 @@ static void InitSdkWithRefreshToken()
// [END initialize_sdk_with_refresh_token]
}

static void InitSdkWithDefaultConfig()
internal static void InitSdkWithDefaultConfig()
{
// [START initialize_sdk_with_default_config]
FirebaseApp.Create();
// [END initialize_sdk_with_default_config]
}

static void InitDefaultApp()
internal static void InitDefaultApp()
{
// [START access_services_default]
// Initialize the default app
Expand All @@ -78,7 +78,7 @@ static void InitDefaultApp()
// [END access_services_default]
}

static void InitCustomApp()
internal static void InitCustomApp()
{
var defaultOptions = new AppOptions()
{
Expand Down Expand Up @@ -107,7 +107,7 @@ static void InitCustomApp()
// [END access_services_nondefault]
}

static void InitWithServiceAccountId()
internal static void InitWithServiceAccountId()
{
// [START initialize_sdk_with_service_account_id]
FirebaseApp.Create(new AppOptions()
Expand Down
8 changes: 4 additions & 4 deletions FirebaseAdmin/FirebaseAdmin.Snippets/FirebaseAuthSnippets.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@

namespace FirebaseAdmin.Snippets
{
class FirebaseAuthSnippets
internal class FirebaseAuthSnippets
{
static async Task CreateCustomTokenAsync()
internal static async Task CreateCustomTokenAsync()
{
// [START custom_token]
var uid = "some-uid";
Expand All @@ -32,7 +32,7 @@ static async Task CreateCustomTokenAsync()
Console.WriteLine("Created custom token: {0}", customToken);
}

static async Task CreateCustomTokenWithClaimsAsync()
internal static async Task CreateCustomTokenWithClaimsAsync()
{
// [START custom_token_with_claims]
var uid = "some-uid";
Expand All @@ -48,7 +48,7 @@ static async Task CreateCustomTokenWithClaimsAsync()
Console.WriteLine("Created custom token: {0}", customToken);
}

static async Task VeridyIdTokenAsync(string idToken)
internal static async Task VeridyIdTokenAsync(string idToken)
{
// [START verify_id_token]
FirebaseToken decodedToken = await FirebaseAuth.DefaultInstance
Expand Down
Loading