feat(auth): migrate anonymous consent on signUp when cc_consent cookie present
Adds ConsentFactoryProtocol / ConsentGrantMeta / ConsentProtocol to core-shared/di/bind-protocols so feature binders can wire per-user consent without a hard dep on the optional @repo/core-consent package. BindContext gains an optional consentFactory? field following the same pattern as bus?, auditLog?, etc. signUpUseCase gains a 4th optional dep (consentFactory). When present and the input includes a cookieHeader containing cc_consent=<categories>, the use case calls consent.grant for each category with method:"signup-migration" and returns a clearCookie payload (Max-Age:0) so the anonymous cookie is cleared on the HTTP response. Tests use RecordingConsent from @repo/core-testing to assert migration call shape and cookie-clear; no-cookie and no-factory branches are also covered. All coverage bands hold at 100% for use-cases. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -11,7 +11,12 @@ describe("signUpController", () => {
|
||||
it("returns a cookie on successful sign-up", async () => {
|
||||
const users = new MockUsersRepository([]);
|
||||
const auth = new MockAuthenticationService(users);
|
||||
const useCase = signUpUseCase(users, auth, new RecordingEventBus());
|
||||
const useCase = signUpUseCase(
|
||||
users,
|
||||
auth,
|
||||
new RecordingEventBus(),
|
||||
undefined,
|
||||
);
|
||||
const controller = signUpController(useCase);
|
||||
|
||||
const result = await controller({
|
||||
@@ -26,7 +31,12 @@ describe("signUpController", () => {
|
||||
it("throws InputParseError when passwords do not match", async () => {
|
||||
const users = new MockUsersRepository([]);
|
||||
const auth = new MockAuthenticationService(users);
|
||||
const useCase = signUpUseCase(users, auth, new RecordingEventBus());
|
||||
const useCase = signUpUseCase(
|
||||
users,
|
||||
auth,
|
||||
new RecordingEventBus(),
|
||||
undefined,
|
||||
);
|
||||
const controller = signUpController(useCase);
|
||||
|
||||
await expect(
|
||||
@@ -42,11 +52,20 @@ describe("signUpController", () => {
|
||||
const users = new MockUsersRepository([]);
|
||||
const auth = new MockAuthenticationService(users);
|
||||
await users.createUser(userFactory.build({ username: "alice" }));
|
||||
const useCase = signUpUseCase(users, auth, new RecordingEventBus());
|
||||
const useCase = signUpUseCase(
|
||||
users,
|
||||
auth,
|
||||
new RecordingEventBus(),
|
||||
undefined,
|
||||
);
|
||||
const controller = signUpController(useCase);
|
||||
|
||||
await expect(
|
||||
controller({ username: "ab", password: "secret_password", confirmPassword: "secret_password" }),
|
||||
controller({
|
||||
username: "ab",
|
||||
password: "secret_password",
|
||||
confirmPassword: "secret_password",
|
||||
}),
|
||||
).rejects.toBeInstanceOf(InputParseError);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user