mirror of
https://github.com/bitwarden/server
synced 2026-02-11 14:03:24 +00:00
Merge branch 'main' into ac/pm-28842/cap-password-minimum-length
This commit is contained in:
@@ -6,6 +6,7 @@ using Bit.Api.Models.Public.Response;
|
||||
using Bit.Core.AdminConsole.Entities;
|
||||
using Bit.Core.AdminConsole.Repositories;
|
||||
using Bit.Core.Billing.Enums;
|
||||
using Bit.Core.Entities;
|
||||
using Bit.Core.Enums;
|
||||
using Bit.Core.Models.Data;
|
||||
using Bit.Core.Platform.Push;
|
||||
@@ -114,4 +115,64 @@ public class CollectionsControllerTests : IClassFixture<ApiApplicationFactory>,
|
||||
Assert.NotEmpty(result.Item2.Groups);
|
||||
Assert.NotEmpty(result.Item2.Users);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task List_ExcludesDefaultUserCollections_IncludesGroupsAndUsers()
|
||||
{
|
||||
// Arrange
|
||||
var collectionRepository = _factory.GetService<ICollectionRepository>();
|
||||
var groupRepository = _factory.GetService<IGroupRepository>();
|
||||
|
||||
var defaultCollection = new Collection
|
||||
{
|
||||
OrganizationId = _organization.Id,
|
||||
Name = "My Items",
|
||||
Type = CollectionType.DefaultUserCollection
|
||||
};
|
||||
await collectionRepository.CreateAsync(defaultCollection, null, null);
|
||||
|
||||
var group = await groupRepository.CreateAsync(new Group
|
||||
{
|
||||
OrganizationId = _organization.Id,
|
||||
Name = "Test Group",
|
||||
ExternalId = $"test-group-{Guid.NewGuid()}",
|
||||
});
|
||||
|
||||
var (_, user) = await OrganizationTestHelpers.CreateNewUserWithAccountAsync(
|
||||
_factory,
|
||||
_organization.Id,
|
||||
OrganizationUserType.User);
|
||||
|
||||
var sharedCollection = await OrganizationTestHelpers.CreateCollectionAsync(
|
||||
_factory,
|
||||
_organization.Id,
|
||||
"Shared Collection with Access",
|
||||
externalId: "shared-collection-with-access",
|
||||
groups:
|
||||
[
|
||||
new CollectionAccessSelection { Id = group.Id, ReadOnly = false, HidePasswords = false, Manage = true }
|
||||
],
|
||||
users:
|
||||
[
|
||||
new CollectionAccessSelection { Id = user.Id, ReadOnly = true, HidePasswords = true, Manage = false }
|
||||
]);
|
||||
|
||||
// Act
|
||||
var response = await _client.GetFromJsonAsync<ListResponseModel<CollectionResponseModel>>("public/collections");
|
||||
|
||||
// Assert
|
||||
Assert.NotNull(response);
|
||||
|
||||
Assert.DoesNotContain(response.Data, c => c.Id == defaultCollection.Id);
|
||||
|
||||
var collectionResponse = response.Data.First(c => c.Id == sharedCollection.Id);
|
||||
Assert.NotNull(collectionResponse.Groups);
|
||||
Assert.Single(collectionResponse.Groups);
|
||||
|
||||
var groupResponse = collectionResponse.Groups.First();
|
||||
Assert.Equal(group.Id, groupResponse.Id);
|
||||
Assert.False(groupResponse.ReadOnly);
|
||||
Assert.False(groupResponse.HidePasswords);
|
||||
Assert.True(groupResponse.Manage);
|
||||
}
|
||||
}
|
||||
|
||||
84
test/Core.Test/Utilities/DomainNameAttributeTests.cs
Normal file
84
test/Core.Test/Utilities/DomainNameAttributeTests.cs
Normal file
@@ -0,0 +1,84 @@
|
||||
using Bit.Core.Utilities;
|
||||
using Xunit;
|
||||
|
||||
namespace Bit.Core.Test.Utilities;
|
||||
|
||||
public class DomainNameValidatorAttributeTests
|
||||
{
|
||||
[Theory]
|
||||
[InlineData("example.com")] // basic domain
|
||||
[InlineData("sub.example.com")] // subdomain
|
||||
[InlineData("sub.sub2.example.com")] // multiple subdomains
|
||||
[InlineData("example-dash.com")] // domain with dash
|
||||
[InlineData("123example.com")] // domain starting with number
|
||||
[InlineData("example123.com")] // domain with numbers
|
||||
[InlineData("e.com")] // short domain
|
||||
[InlineData("very-long-subdomain-name.example.com")] // long subdomain
|
||||
[InlineData("wörldé.com")] // unicode domain (IDN)
|
||||
public void IsValid_ReturnsTrueWhenValid(string domainName)
|
||||
{
|
||||
var sut = new DomainNameValidatorAttribute();
|
||||
|
||||
var actual = sut.IsValid(domainName);
|
||||
|
||||
Assert.True(actual);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData("<script>alert('xss')</script>")] // XSS attempt
|
||||
[InlineData("example.com<script>")] // XSS suffix
|
||||
[InlineData("<img src=x>")] // HTML tag
|
||||
[InlineData("example.com\t")] // trailing tab
|
||||
[InlineData("\texample.com")] // leading tab
|
||||
[InlineData("exam\tple.com")] // middle tab
|
||||
[InlineData("example.com\n")] // newline
|
||||
[InlineData("example.com\r")] // carriage return
|
||||
[InlineData("example.com\b")] // backspace
|
||||
[InlineData("exam ple.com")] // space in domain
|
||||
[InlineData("example.com ")] // trailing space (after trim, becomes valid, but with space it's invalid)
|
||||
[InlineData(" example.com")] // leading space (after trim, becomes valid, but with space it's invalid)
|
||||
[InlineData("example&.com")] // ampersand
|
||||
[InlineData("example'.com")] // single quote
|
||||
[InlineData("example\".com")] // double quote
|
||||
[InlineData(".example.com")] // starts with dot
|
||||
[InlineData("example.com.")] // ends with dot
|
||||
[InlineData("example..com")] // double dot
|
||||
[InlineData("-example.com")] // starts with dash
|
||||
[InlineData("example-.com")] // label ends with dash
|
||||
[InlineData("")] // empty string
|
||||
[InlineData(" ")] // whitespace only
|
||||
[InlineData("http://example.com")] // URL scheme
|
||||
[InlineData("example.com/path")] // path component
|
||||
[InlineData("user@example.com")] // email format
|
||||
public void IsValid_ReturnsFalseWhenInvalid(string domainName)
|
||||
{
|
||||
var sut = new DomainNameValidatorAttribute();
|
||||
|
||||
var actual = sut.IsValid(domainName);
|
||||
|
||||
Assert.False(actual);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void IsValid_ReturnsTrueWhenNull()
|
||||
{
|
||||
var sut = new DomainNameValidatorAttribute();
|
||||
|
||||
var actual = sut.IsValid(null);
|
||||
|
||||
// Null validation should be handled by [Required] attribute
|
||||
Assert.True(actual);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void IsValid_ReturnsFalseWhenTooLong()
|
||||
{
|
||||
var sut = new DomainNameValidatorAttribute();
|
||||
// Create a domain name longer than 253 characters
|
||||
var longDomain = new string('a', 250) + ".com";
|
||||
|
||||
var actual = sut.IsValid(longDomain);
|
||||
|
||||
Assert.False(actual);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user