Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
3 changes: 1 addition & 2 deletions src/Core/AdminConsole/Entities/Organization.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
ο»Ώusing System.ComponentModel.DataAnnotations;
using System.Net;
using System.Text.Json;
using Bit.Core.Auth.Enums;
using Bit.Core.Auth.Models;
using Bit.Core.Billing.Enums;
Expand Down Expand Up @@ -480,7 +479,7 @@

return _twoFactorProviders;
}
catch (JsonException)
catch (Newtonsoft.Json.JsonException)
Comment thread
JaredSnider-Bitwarden marked this conversation as resolved.
Comment thread
JaredSnider-Bitwarden marked this conversation as resolved.
{
return null;
}
Expand Down Expand Up @@ -543,7 +542,7 @@
/// <summary>
/// Updates the organization's properties from a self-hosted license file.
/// </summary>
public void UpdateFromLicense(OrganizationLicense license, IFeatureService featureService)

Check warning on line 545 in src/Core/AdminConsole/Entities/Organization.cs

View workflow job for this annotation

GitHub Actions / Run validation

'IFeatureService' is obsolete: 'Use Bitwarden.Server.Sdk.Features.IFeatureService instead'

Check warning on line 545 in src/Core/AdminConsole/Entities/Organization.cs

View workflow job for this annotation

GitHub Actions / Build MSSQL migrator utility (osx-x64)

'IFeatureService' is obsolete: 'Use Bitwarden.Server.Sdk.Features.IFeatureService instead'

Check warning on line 545 in src/Core/AdminConsole/Entities/Organization.cs

View workflow job for this annotation

GitHub Actions / Build MSSQL migrator utility (win-x64)

'IFeatureService' is obsolete: 'Use Bitwarden.Server.Sdk.Features.IFeatureService instead'

Check warning on line 545 in src/Core/AdminConsole/Entities/Organization.cs

View workflow job for this annotation

GitHub Actions / Build MSSQL migrator utility (linux-x64)

'IFeatureService' is obsolete: 'Use Bitwarden.Server.Sdk.Features.IFeatureService instead'

Check warning on line 545 in src/Core/AdminConsole/Entities/Organization.cs

View workflow job for this annotation

GitHub Actions / Build Docker images (Setup, ./util, true)

'IFeatureService' is obsolete: 'Use Bitwarden.Server.Sdk.Features.IFeatureService instead'

Check warning on line 545 in src/Core/AdminConsole/Entities/Organization.cs

View workflow job for this annotation

GitHub Actions / Build Docker images (MsSqlMigratorUtility, ./util, true)

'IFeatureService' is obsolete: 'Use Bitwarden.Server.Sdk.Features.IFeatureService instead'

Check warning on line 545 in src/Core/AdminConsole/Entities/Organization.cs

View workflow job for this annotation

GitHub Actions / Build Docker images (Events, ./src, true)

'IFeatureService' is obsolete: 'Use Bitwarden.Server.Sdk.Features.IFeatureService instead'

Check warning on line 545 in src/Core/AdminConsole/Entities/Organization.cs

View workflow job for this annotation

GitHub Actions / Build Docker images (Notifications, ./src, true)

'IFeatureService' is obsolete: 'Use Bitwarden.Server.Sdk.Features.IFeatureService instead'

Check warning on line 545 in src/Core/AdminConsole/Entities/Organization.cs

View workflow job for this annotation

GitHub Actions / Build Docker images (Scim, ./bitwarden_license/src, true)

'IFeatureService' is obsolete: 'Use Bitwarden.Server.Sdk.Features.IFeatureService instead'

Check warning on line 545 in src/Core/AdminConsole/Entities/Organization.cs

View workflow job for this annotation

GitHub Actions / Build Docker images (Identity, ./src, true)

'IFeatureService' is obsolete: 'Use Bitwarden.Server.Sdk.Features.IFeatureService instead'

Check warning on line 545 in src/Core/AdminConsole/Entities/Organization.cs

View workflow job for this annotation

GitHub Actions / Build Docker images (Sso, ./bitwarden_license/src, true)

'IFeatureService' is obsolete: 'Use Bitwarden.Server.Sdk.Features.IFeatureService instead'

Check warning on line 545 in src/Core/AdminConsole/Entities/Organization.cs

View workflow job for this annotation

GitHub Actions / Build Docker images (Api, ./src, true)

'IFeatureService' is obsolete: 'Use Bitwarden.Server.Sdk.Features.IFeatureService instead'

Check warning on line 545 in src/Core/AdminConsole/Entities/Organization.cs

View workflow job for this annotation

GitHub Actions / Build Docker images (EventsProcessor, ./src, true)

'IFeatureService' is obsolete: 'Use Bitwarden.Server.Sdk.Features.IFeatureService instead'

Check warning on line 545 in src/Core/AdminConsole/Entities/Organization.cs

View workflow job for this annotation

GitHub Actions / Build Docker images (Billing, ./src, true)

'IFeatureService' is obsolete: 'Use Bitwarden.Server.Sdk.Features.IFeatureService instead'

Check warning on line 545 in src/Core/AdminConsole/Entities/Organization.cs

View workflow job for this annotation

GitHub Actions / Build Docker images (SeederApi, ./util, linux/amd64,linux/arm64, true)

'IFeatureService' is obsolete: 'Use Bitwarden.Server.Sdk.Features.IFeatureService instead'

Check warning on line 545 in src/Core/AdminConsole/Entities/Organization.cs

View workflow job for this annotation

GitHub Actions / Build Docker images (Admin, ./src, true, true)

'IFeatureService' is obsolete: 'Use Bitwarden.Server.Sdk.Features.IFeatureService instead'

Check warning on line 545 in src/Core/AdminConsole/Entities/Organization.cs

View workflow job for this annotation

GitHub Actions / Upload

'IFeatureService' is obsolete: 'Use Bitwarden.Server.Sdk.Features.IFeatureService instead'

Check warning on line 545 in src/Core/AdminConsole/Entities/Organization.cs

View workflow job for this annotation

GitHub Actions / Run tests

'IFeatureService' is obsolete: 'Use Bitwarden.Server.Sdk.Features.IFeatureService instead'
{
// The following properties are intentionally excluded from being updated:
// - Id - self-hosted org will have its own unique Guid
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,24 @@
using Bit.Core.Entities;
using Bit.Core.Exceptions;
using Bit.Core.Repositories;
using Microsoft.Extensions.Logging;

namespace Bit.Core.Auth.UserFeatures.TwoFactorAuth.Implementations;

public class TwoFactorIsEnabledQuery : ITwoFactorIsEnabledQuery
{
private readonly IUserRepository _userRepository;
private readonly IHasPremiumAccessQuery _hasPremiumAccessQuery;
private readonly ILogger<TwoFactorIsEnabledQuery> _logger;

public TwoFactorIsEnabledQuery(
IUserRepository userRepository,
IHasPremiumAccessQuery hasPremiumAccessQuery)
IHasPremiumAccessQuery hasPremiumAccessQuery,
ILogger<TwoFactorIsEnabledQuery> logger)
{
_userRepository = userRepository;
_hasPremiumAccessQuery = hasPremiumAccessQuery;
_logger = logger;
}

public async Task<IEnumerable<(Guid userId, bool twoFactorIsEnabled)>> TwoFactorIsEnabledAsync(IEnumerable<Guid> userIds)
Expand Down Expand Up @@ -130,11 +134,23 @@ public async Task<bool> TwoFactorIsEnabledAsync(ITwoFactorProvidersUser user)
/// </summary>
/// <param name="user">user with two factor providers</param>
/// <returns>list of enabled provider types</returns>
private static IList<TwoFactorProviderType> GetEnabledTwoFactorProviders(User user)
private IList<TwoFactorProviderType> GetEnabledTwoFactorProviders(User user)
{
var providers = user.GetTwoFactorProviders();

if (providers == null || providers.Count == 0)
if (providers == null)
{
if (!string.IsNullOrWhiteSpace(user.TwoFactorProviders))
{
_logger.LogWarning(
"Unable to parse TwoFactorProviders for user {UserId}; treating as no providers enabled.",
user.Id);
}

return Array.Empty<TwoFactorProviderType>();
}

if (providers.Count == 0)
{
return Array.Empty<TwoFactorProviderType>();
}
Expand Down
3 changes: 1 addition & 2 deletions src/Core/Entities/User.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
ο»Ώusing System.ComponentModel.DataAnnotations;
using System.Text.Json;
using Bit.Core.Auth.Enums;
using Bit.Core.Auth.Models;
using Bit.Core.Enums;
Expand Down Expand Up @@ -222,7 +221,7 @@ given user does or doesn't have this enabled. It is a non-zero chance.

return _twoFactorProviders;
}
catch (JsonException)
catch (Newtonsoft.Json.JsonException)
Comment thread
JaredSnider-Bitwarden marked this conversation as resolved.
{
return null;
}
Expand Down
15 changes: 15 additions & 0 deletions test/Core.Test/AdminConsole/Entities/OrganizationTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,21 @@ public void GetTwoFactorProviders_SavedWithName_Success()
Assert.Equal("Host_value", host);
}

[Theory]
[InlineData("not-json-at-all")]
[InlineData("TwoFactorProviders" + "a0c30e2f-0ac1-4ffe-bc3a-47830b829a4f")]
[InlineData("{ unterminated")]
[InlineData("{ \"6\": \"not-a-provider-object\" }")]
public void GetTwoFactorProviders_InvalidJson_ReturnsNull(string invalidJson)
{
var organization = new Organization
{
TwoFactorProviders = invalidJson,
};

Assert.Null(organization.GetTwoFactorProviders());
}

[Fact]
public void UseDisableSmAdsForUsers_DefaultValue_IsFalse()
{
Expand Down
15 changes: 15 additions & 0 deletions test/Core.Test/Entities/UserTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,21 @@ public void GetTwoFactorProviders_SavedWithName_Success()
Assert.Equal("test@email.com", emailMetaDataEmail);
}

[Theory]
[InlineData("not-json-at-all")]
[InlineData("TwoFactorProviders" + "a0c30e2f-0ac1-4ffe-bc3a-47830b829a4f")]
[InlineData("{ unterminated")]
[InlineData("{ \"7\": \"not-a-provider-object\" }")]
public void GetTwoFactorProviders_InvalidJson_ReturnsNull(string invalidJson)
{
var user = new User
{
TwoFactorProviders = invalidJson,
};

Assert.Null(user.GetTwoFactorProviders());
}

[Fact]
public void SetUserKeyId_RoundTripsThroughTheColumn()
{
Expand Down
Loading