mirror of
https://github.com/bitwarden/server.git
synced 2026-06-01 12:26:46 -05:00
* test(billing): Add unit tests for TrialInitiationCache * feat(billing): Add trial initiation cache interface and implementation * feat(billing): Register trial initiation cache services * feat(core): Add trial properties to OrganizationSignup model * feat(mail): Update trial verification email model and services for TrialInitiationId * feat(billing): Enhance TrialSendVerificationEmailRequestModel validation * test(billing): Add tests for TrialSendVerificationEmailRequestModel validation * feat(billing): Introduce default trial length constant * refactor(identity): Use constant for default trial length in AccountsController * test(identity): Update accounts controller tests for default trial length constant * feat(billing): Integrate trial initiation into email sending command * feat(billing): Add TrialLength to SubscriptionSetup model * feat(billing): Map TrialLength in OrganizationSale creation * feat(billing): Allow custom trial length in organization billing service * feat(admin-console): Add TrialLength and TrialInitiationId to organization creation requests * feat(admin-console): Validate trial length during cloud organization signup * test(admin-console): Add tests for organization create request trial properties * test(admin-console): Add tests for CloudOrganizationSignUpCommand trial length validation * refactor(TrialInitiationCache): change validation method to retrieval * test(TrialInitiationCache): update tests for GetAndRemoveAsync * feat(OrganizationSignUp): refactor trial validation to command * test(OrganizationSignUp): add trial validation scenarios * test(OrganizationSignUp): nullify TrialLength in unrelated tests * fix(billing): dotnet format * refactor: remove `TrialInitiationId` property from data models refactor: update mail service interfaces and implementations * refactor: remove `ITrialInitiationCache` infrastructure test: update `CloudOrganizationSignUpCommandTests` for trial validation * refactor: update `SendTrialInitiationEmailForRegistrationCommand` * refactor: update `CloudOrganizationSignUpCommand` trial length validation * test(organization): fix plan call in tests * test(billing): fix test settings
193 lines
5.8 KiB
C#
193 lines
5.8 KiB
C#
using System.ComponentModel.DataAnnotations;
|
|
using Bit.Api.AdminConsole.Models.Request.Organizations;
|
|
using Xunit;
|
|
|
|
namespace Bit.Api.Test.AdminConsole.Models.Request.Organizations;
|
|
|
|
public class OrganizationCreateRequestModelTests
|
|
{
|
|
[Fact]
|
|
public void Validate_KeysMissing_FailsValidation()
|
|
{
|
|
var model = new OrganizationCreateRequestModel
|
|
{
|
|
Name = "Test Org",
|
|
BillingEmail = "test@example.com",
|
|
Key = "test-key",
|
|
UseSecretsManager = false,
|
|
Keys = null
|
|
};
|
|
|
|
var results = ValidateModel(model);
|
|
|
|
Assert.Contains(results, r => r.MemberNames.Contains(nameof(OrganizationCreateRequestModel.Keys)));
|
|
}
|
|
|
|
[Fact]
|
|
public void Validate_KeysPresent_PassesKeysValidation()
|
|
{
|
|
var model = new OrganizationCreateRequestModel
|
|
{
|
|
Name = "Test Org",
|
|
BillingEmail = "test@example.com",
|
|
Key = "test-key",
|
|
UseSecretsManager = false,
|
|
Keys = new OrganizationKeysRequestModel
|
|
{
|
|
PublicKey = "test-public-key",
|
|
EncryptedPrivateKey = "test-encrypted-private-key"
|
|
}
|
|
};
|
|
|
|
var results = ValidateModel(model);
|
|
|
|
Assert.DoesNotContain(results, r => r.MemberNames.Contains(nameof(OrganizationCreateRequestModel.Keys)));
|
|
}
|
|
|
|
[Fact]
|
|
public void Validate_KeysMissingPublicKey_FailsValidation()
|
|
{
|
|
var keys = new OrganizationKeysRequestModel
|
|
{
|
|
PublicKey = null,
|
|
EncryptedPrivateKey = "test-encrypted-private-key"
|
|
};
|
|
|
|
var results = ValidateModel(keys);
|
|
|
|
Assert.Contains(results, r => r.MemberNames.Contains(nameof(OrganizationKeysRequestModel.PublicKey)));
|
|
}
|
|
|
|
[Fact]
|
|
public void Validate_KeysMissingEncryptedPrivateKey_FailsValidation()
|
|
{
|
|
var keys = new OrganizationKeysRequestModel
|
|
{
|
|
PublicKey = "test-public-key",
|
|
EncryptedPrivateKey = null
|
|
};
|
|
|
|
var results = ValidateModel(keys);
|
|
|
|
Assert.Contains(results, r => r.MemberNames.Contains(nameof(OrganizationKeysRequestModel.EncryptedPrivateKey)));
|
|
}
|
|
|
|
[Fact]
|
|
public void Validate_TrialLength_BelowRange_FailsValidation()
|
|
{
|
|
var model = new OrganizationCreateRequestModel
|
|
{
|
|
Name = "Test Org",
|
|
BillingEmail = "test@example.com",
|
|
Key = "test-key",
|
|
UseSecretsManager = false,
|
|
Keys = new OrganizationKeysRequestModel
|
|
{
|
|
PublicKey = "test-public-key",
|
|
EncryptedPrivateKey = "test-encrypted-private-key"
|
|
},
|
|
TrialLength = -1
|
|
};
|
|
|
|
var results = ValidateModel(model);
|
|
|
|
Assert.Contains(results, r => r.MemberNames.Contains(nameof(OrganizationCreateRequestModel.TrialLength)));
|
|
}
|
|
|
|
[Fact]
|
|
public void Validate_TrialLength_AboveRange_FailsValidation()
|
|
{
|
|
var model = new OrganizationCreateRequestModel
|
|
{
|
|
Name = "Test Org",
|
|
BillingEmail = "test@example.com",
|
|
Key = "test-key",
|
|
UseSecretsManager = false,
|
|
Keys = new OrganizationKeysRequestModel
|
|
{
|
|
PublicKey = "test-public-key",
|
|
EncryptedPrivateKey = "test-encrypted-private-key"
|
|
},
|
|
TrialLength = 31
|
|
};
|
|
|
|
var results = ValidateModel(model);
|
|
|
|
Assert.Contains(results, r => r.MemberNames.Contains(nameof(OrganizationCreateRequestModel.TrialLength)));
|
|
}
|
|
|
|
[Fact]
|
|
public void Validate_TrialLength_WithinRange_PassesValidation()
|
|
{
|
|
var model = new OrganizationCreateRequestModel
|
|
{
|
|
Name = "Test Org",
|
|
BillingEmail = "test@example.com",
|
|
Key = "test-key",
|
|
UseSecretsManager = false,
|
|
Keys = new OrganizationKeysRequestModel
|
|
{
|
|
PublicKey = "test-public-key",
|
|
EncryptedPrivateKey = "test-encrypted-private-key"
|
|
},
|
|
TrialLength = 14
|
|
};
|
|
|
|
var results = ValidateModel(model);
|
|
|
|
Assert.DoesNotContain(results, r => r.MemberNames.Contains(nameof(OrganizationCreateRequestModel.TrialLength)));
|
|
}
|
|
|
|
[Fact]
|
|
public void Validate_TrialLength_Null_PassesValidation()
|
|
{
|
|
var model = new OrganizationCreateRequestModel
|
|
{
|
|
Name = "Test Org",
|
|
BillingEmail = "test@example.com",
|
|
Key = "test-key",
|
|
UseSecretsManager = false,
|
|
Keys = new OrganizationKeysRequestModel
|
|
{
|
|
PublicKey = "test-public-key",
|
|
EncryptedPrivateKey = "test-encrypted-private-key"
|
|
},
|
|
TrialLength = null
|
|
};
|
|
|
|
var results = ValidateModel(model);
|
|
|
|
Assert.DoesNotContain(results, r => r.MemberNames.Contains(nameof(OrganizationCreateRequestModel.TrialLength)));
|
|
}
|
|
|
|
[Fact]
|
|
public void ToOrganizationSignup_TrialLength_IsMapped()
|
|
{
|
|
var model = new OrganizationCreateRequestModel
|
|
{
|
|
Name = "Test Org",
|
|
BillingEmail = "test@example.com",
|
|
Key = "test-key",
|
|
UseSecretsManager = false,
|
|
Keys = new OrganizationKeysRequestModel
|
|
{
|
|
PublicKey = "test-public-key",
|
|
EncryptedPrivateKey = "test-encrypted-private-key"
|
|
},
|
|
TrialLength = 14
|
|
};
|
|
|
|
var signup = model.ToOrganizationSignup(new Bit.Core.Entities.User());
|
|
|
|
Assert.Equal(14, signup.TrialLength);
|
|
}
|
|
|
|
private static List<ValidationResult> ValidateModel(object model)
|
|
{
|
|
var context = new ValidationContext(model);
|
|
var results = new List<ValidationResult>();
|
|
Validator.TryValidateObject(model, context, results, validateAllProperties: true);
|
|
return results;
|
|
}
|
|
}
|