Skip to content

Commit f8ac20d

Browse files
committed
Merged with hkj-list-cleanup
2 parents a013359 + 8d96800 commit f8ac20d

File tree

12 files changed

+724
-184
lines changed

12 files changed

+724
-184
lines changed

FirebaseAdmin/FirebaseAdmin.IntegrationTests/FirebaseAuthTest.cs

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@
1414

1515
using System;
1616
using System.Collections.Generic;
17+
using System.Linq;
1718
using System.Net.Http;
1819
using System.Text;
1920
using System.Threading.Tasks;
20-
using FirebaseAdmin;
2121
using FirebaseAdmin.Auth;
2222
using Google.Apis.Auth.OAuth2;
2323
using Google.Apis.Util;
@@ -284,6 +284,45 @@ await Assert.ThrowsAsync<FirebaseException>(
284284
async () => await FirebaseAuth.DefaultInstance.DeleteUserAsync("non.existing"));
285285
}
286286

287+
[Fact]
288+
public async Task ListUsers()
289+
{
290+
var users = new List<string>();
291+
try
292+
{
293+
for (int i = 0; i < 3; i++)
294+
{
295+
var user = await FirebaseAuth.DefaultInstance.CreateUserAsync(new UserRecordArgs()
296+
{
297+
Password = "password",
298+
});
299+
users.Add(user.Uid);
300+
}
301+
302+
var pagedEnumerable = FirebaseAuth.DefaultInstance.ListUsersAsync(null);
303+
var enumerator = pagedEnumerable.GetEnumerator();
304+
305+
var listedUsers = new List<string>();
306+
while (await enumerator.MoveNext())
307+
{
308+
var uid = enumerator.Current.Uid;
309+
if (users.Contains(uid) && !listedUsers.Contains(uid))
310+
{
311+
listedUsers.Add(uid);
312+
Assert.NotNull(enumerator.Current.PasswordHash);
313+
Assert.NotNull(enumerator.Current.PasswordSalt);
314+
}
315+
}
316+
317+
Assert.Equal(3, listedUsers.Count);
318+
}
319+
finally
320+
{
321+
var deleteTasks = users.Select((uid) => FirebaseAuth.DefaultInstance.DeleteUserAsync(uid));
322+
await Task.WhenAll(deleteTasks);
323+
}
324+
}
325+
287326
private static async Task<string> SignInWithCustomTokenAsync(string customToken)
288327
{
289328
var rb = new Google.Apis.Requests.RequestBuilder()
Lines changed: 155 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,155 @@
1+
// Copyright 2019, Google Inc. All rights reserved.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
using System;
16+
using System.Collections.Generic;
17+
using Xunit;
18+
19+
namespace FirebaseAdmin.Auth.Tests
20+
{
21+
public class ExportedUserRecordTest
22+
{
23+
[Fact]
24+
public void NullResponse()
25+
{
26+
Assert.Throws<ArgumentException>(() => new ExportedUserRecord(null));
27+
}
28+
29+
[Fact]
30+
public void NullUid()
31+
{
32+
Assert.Throws<ArgumentException>(() => new ExportedUserRecord(
33+
new GetAccountInfoResponse.User()
34+
{
35+
UserId = null,
36+
}));
37+
}
38+
39+
[Fact]
40+
public void EmptyUid()
41+
{
42+
Assert.Throws<ArgumentException>(() => new ExportedUserRecord(
43+
new GetAccountInfoResponse.User()
44+
{
45+
UserId = string.Empty,
46+
}));
47+
}
48+
49+
[Fact]
50+
public void UidOnly()
51+
{
52+
var user = new ExportedUserRecord(new GetAccountInfoResponse.User()
53+
{
54+
UserId = "user1",
55+
});
56+
57+
Assert.Equal("user1", user.Uid);
58+
Assert.Null(user.DisplayName);
59+
Assert.Null(user.Email);
60+
Assert.Null(user.PhoneNumber);
61+
Assert.Null(user.PhotoUrl);
62+
Assert.Equal("firebase", user.ProviderId);
63+
Assert.False(user.Disabled);
64+
Assert.False(user.EmailVerified);
65+
Assert.Equal(UserRecord.UnixEpoch, user.TokensValidAfterTimestamp);
66+
Assert.Empty(user.CustomClaims);
67+
Assert.Empty(user.ProviderData);
68+
Assert.NotNull(user.UserMetaData);
69+
Assert.Null(user.UserMetaData.CreationTimestamp);
70+
Assert.Null(user.UserMetaData.LastSignInTimestamp);
71+
Assert.Null(user.PasswordHash);
72+
Assert.Null(user.PasswordSalt);
73+
}
74+
75+
[Fact]
76+
public void AllProperties()
77+
{
78+
var response = new GetAccountInfoResponse.User()
79+
{
80+
UserId = "user1",
81+
DisplayName = "Test User",
82+
Email = "[email protected]",
83+
PhoneNumber = "+11234567890",
84+
PhotoUrl = "https://domain.com/user.png",
85+
Disabled = true,
86+
EmailVerified = true,
87+
ValidSince = 3600,
88+
CreatedAt = 100,
89+
LastLoginAt = 150,
90+
CustomClaims = @"{""admin"": true, ""level"": 10}",
91+
PasswordHash = "secret",
92+
PasswordSalt = "nacl",
93+
Providers = new List<GetAccountInfoResponse.Provider>()
94+
{
95+
new GetAccountInfoResponse.Provider()
96+
{
97+
ProviderID = "google.com",
98+
UserId = "googleuid",
99+
},
100+
new GetAccountInfoResponse.Provider()
101+
{
102+
ProviderID = "other.com",
103+
UserId = "otheruid",
104+
DisplayName = "Other Name",
105+
Email = "[email protected]",
106+
PhotoUrl = "https://other.com/user.png",
107+
PhoneNumber = "+10987654321",
108+
},
109+
},
110+
};
111+
var user = new ExportedUserRecord(response);
112+
113+
Assert.Equal("user1", user.Uid);
114+
Assert.Equal("Test User", user.DisplayName);
115+
Assert.Equal("[email protected]", user.Email);
116+
Assert.Equal("+11234567890", user.PhoneNumber);
117+
Assert.Equal("https://domain.com/user.png", user.PhotoUrl);
118+
Assert.Equal("firebase", user.ProviderId);
119+
Assert.True(user.Disabled);
120+
Assert.True(user.EmailVerified);
121+
Assert.Equal(UserRecord.UnixEpoch.AddSeconds(3600), user.TokensValidAfterTimestamp);
122+
Assert.Equal("secret", user.PasswordHash);
123+
Assert.Equal("nacl", user.PasswordSalt);
124+
125+
var claims = new Dictionary<string, object>()
126+
{
127+
{ "admin", true },
128+
{ "level", 10L },
129+
};
130+
Assert.Equal(claims, user.CustomClaims);
131+
132+
Assert.Equal(2, user.ProviderData.Length);
133+
var provider = user.ProviderData[0];
134+
Assert.Equal("google.com", provider.ProviderId);
135+
Assert.Equal("googleuid", provider.Uid);
136+
Assert.Null(provider.DisplayName);
137+
Assert.Null(provider.Email);
138+
Assert.Null(provider.PhoneNumber);
139+
Assert.Null(provider.PhotoUrl);
140+
141+
provider = user.ProviderData[1];
142+
Assert.Equal("other.com", provider.ProviderId);
143+
Assert.Equal("otheruid", provider.Uid);
144+
Assert.Equal("Other Name", provider.DisplayName);
145+
Assert.Equal("[email protected]", provider.Email);
146+
Assert.Equal("+10987654321", provider.PhoneNumber);
147+
Assert.Equal("https://other.com/user.png", provider.PhotoUrl);
148+
149+
var metadata = user.UserMetaData;
150+
Assert.NotNull(metadata);
151+
Assert.Equal(UserRecord.UnixEpoch.AddMilliseconds(100), metadata.CreationTimestamp);
152+
Assert.Equal(UserRecord.UnixEpoch.AddMilliseconds(150), metadata.LastSignInTimestamp);
153+
}
154+
}
155+
}

0 commit comments

Comments
 (0)