-
Notifications
You must be signed in to change notification settings - Fork 1.5k
[PM-29611] Decouple License from Subscription Response #6768
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weโll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
cyprain-okeke
merged 15 commits into
main
from
pm-29611-decouple-license-from-subscription-response
Dec 31, 2025
Merged
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
7df768c
implement the ticket request
cyprain-okeke dc26f3b
Merge branch 'main' into pm-29611-decouple-license-from-subscription-โฆ
cyprain-okeke 1df1c66
resolve the build lint error
cyprain-okeke a1ef271
Merge branch 'main' into pm-29611-decouple-license-from-subscription-โฆ
cyprain-okeke 1dcb25c
Resolve the build lint error
cyprain-okeke 7148bf2
Address review comments
cyprain-okeke 6b978d2
Merge branch 'main' into pm-29611-decouple-license-from-subscription-โฆ
cyprain-okeke 7cec45f
Fixt the lint and failing unit test
cyprain-okeke 2a7924d
Fix NSubstitute mock - use concrete ClaimsPrincipal instead of Arg.Anโฆ
cyprain-okeke a82a845
Merge branch 'main' into pm-29611-decouple-license-from-subscription-โฆ
cyprain-okeke 2f2b453
Merge branch 'main' into pm-29611-decouple-license-from-subscription-โฆ
cyprain-okeke f574adb
resolve InjectUser issues
cyprain-okeke 1cc593a
Fix the failing testing
cyprain-okeke 34be856
Merge branch 'main' into pm-29611-decouple-license-from-subscription-โฆ
cyprain-okeke 9cec655
Fix the failing unit test
cyprain-okeke File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
src/Core/Billing/Licenses/Models/Api/Response/LicenseResponseModel.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| ๏ปฟusing System.Security.Claims; | ||
| using Bit.Core.Billing.Licenses.Extensions; | ||
| using Bit.Core.Billing.Models.Business; | ||
| using Bit.Core.Models.Api; | ||
|
|
||
| namespace Bit.Core.Billing.Licenses.Models.Api.Response; | ||
|
|
||
| /// <summary> | ||
| /// Response model containing user license information. | ||
| /// Separated from subscription data to maintain separation of concerns. | ||
| /// </summary> | ||
| public class LicenseResponseModel : ResponseModel | ||
| { | ||
| public LicenseResponseModel(UserLicense license, ClaimsPrincipal? claimsPrincipal) | ||
| : base("license") | ||
| { | ||
| License = license; | ||
|
|
||
| // CRITICAL: When a license has a Token (JWT), ALWAYS use the expiration from the token claim | ||
| // The token's expiration is cryptographically secured and cannot be tampered with | ||
| // The file's Expires property can be manually edited and should NOT be trusted for display | ||
| if (claimsPrincipal != null) | ||
| { | ||
| Expiration = claimsPrincipal.GetValue<DateTime?>(UserLicenseConstants.Expires); | ||
| } | ||
| else | ||
| { | ||
| // No token - use the license file expiration (for older licenses without tokens) | ||
| Expiration = license.Expires; | ||
| } | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// The user's license containing feature entitlements and metadata. | ||
| /// </summary> | ||
| public UserLicense License { get; set; } | ||
|
|
||
| /// <summary> | ||
| /// The license expiration date. | ||
| /// Extracted from the cryptographically secured JWT token when available, | ||
| /// otherwise falls back to the license file's expiration date. | ||
| /// </summary> | ||
| public DateTime? Expiration { get; set; } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| ๏ปฟusing Bit.Core.Billing.Licenses.Models.Api.Response; | ||
| using Bit.Core.Billing.Services; | ||
| using Bit.Core.Entities; | ||
| using Bit.Core.Services; | ||
|
|
||
| namespace Bit.Core.Billing.Licenses.Queries; | ||
|
|
||
| public interface IGetUserLicenseQuery | ||
| { | ||
| Task<LicenseResponseModel> Run(User user); | ||
| } | ||
|
|
||
| public class GetUserLicenseQuery( | ||
| IUserService userService, | ||
| ILicensingService licensingService) : IGetUserLicenseQuery | ||
| { | ||
| public async Task<LicenseResponseModel> Run(User user) | ||
| { | ||
| var license = await userService.GenerateLicenseAsync(user); | ||
| var claimsPrincipal = licensingService.GetClaimsPrincipalFromLicense(license); | ||
| return new LicenseResponseModel(license, claimsPrincipal); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| ๏ปฟusing Bit.Core.Billing.Licenses.Queries; | ||
| using Microsoft.Extensions.DependencyInjection; | ||
|
|
||
| namespace Bit.Core.Billing.Licenses; | ||
|
|
||
| public static class Registrations | ||
| { | ||
| public static void AddLicenseOperations(this IServiceCollection services) | ||
| { | ||
| // Queries | ||
| services.AddTransient<IGetUserLicenseQuery, GetUserLicenseQuery>(); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
57 changes: 57 additions & 0 deletions
57
test/Api.Test/Billing/Controllers/VNext/AccountBillingVNextControllerTests.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,57 @@ | ||
| ๏ปฟusing Bit.Api.Billing.Controllers.VNext; | ||
| using Bit.Core.Billing.Licenses.Queries; | ||
| using Bit.Core.Billing.Payment.Commands; | ||
| using Bit.Core.Billing.Payment.Queries; | ||
| using Bit.Core.Billing.Premium.Commands; | ||
| using Bit.Core.Entities; | ||
| using Bit.Test.Common.AutoFixture.Attributes; | ||
| using Microsoft.AspNetCore.Http; | ||
| using NSubstitute; | ||
| using Xunit; | ||
|
|
||
| namespace Bit.Api.Test.Billing.Controllers.VNext; | ||
|
|
||
| public class AccountBillingVNextControllerTests | ||
| { | ||
| private readonly ICreateBitPayInvoiceForCreditCommand _createBitPayInvoiceForCreditCommand; | ||
| private readonly ICreatePremiumCloudHostedSubscriptionCommand _createPremiumCloudHostedSubscriptionCommand; | ||
| private readonly IGetCreditQuery _getCreditQuery; | ||
| private readonly IGetPaymentMethodQuery _getPaymentMethodQuery; | ||
| private readonly IGetUserLicenseQuery _getUserLicenseQuery; | ||
| private readonly IUpdatePaymentMethodCommand _updatePaymentMethodCommand; | ||
| private readonly AccountBillingVNextController _sut; | ||
|
|
||
| public AccountBillingVNextControllerTests() | ||
| { | ||
| _createBitPayInvoiceForCreditCommand = Substitute.For<ICreateBitPayInvoiceForCreditCommand>(); | ||
| _createPremiumCloudHostedSubscriptionCommand = Substitute.For<ICreatePremiumCloudHostedSubscriptionCommand>(); | ||
| _getCreditQuery = Substitute.For<IGetCreditQuery>(); | ||
| _getPaymentMethodQuery = Substitute.For<IGetPaymentMethodQuery>(); | ||
| _getUserLicenseQuery = Substitute.For<IGetUserLicenseQuery>(); | ||
| _updatePaymentMethodCommand = Substitute.For<IUpdatePaymentMethodCommand>(); | ||
|
|
||
| _sut = new AccountBillingVNextController( | ||
| _createBitPayInvoiceForCreditCommand, | ||
| _createPremiumCloudHostedSubscriptionCommand, | ||
| _getCreditQuery, | ||
| _getPaymentMethodQuery, | ||
| _getUserLicenseQuery, | ||
| _updatePaymentMethodCommand); | ||
| } | ||
|
|
||
| [Theory, BitAutoData] | ||
| public async Task GetLicenseAsync_ValidUser_ReturnsLicenseResponse(User user, | ||
| Core.Billing.Licenses.Models.Api.Response.LicenseResponseModel licenseResponse) | ||
| { | ||
| // Arrange | ||
| _getUserLicenseQuery.Run(user).Returns(licenseResponse); | ||
|
|
||
| // Act | ||
| var result = await _sut.GetLicenseAsync(user); | ||
|
|
||
| // Assert | ||
| var okResult = Assert.IsAssignableFrom<IResult>(result); | ||
| await _getUserLicenseQuery.Received(1).Run(user); | ||
| } | ||
|
|
||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.