-
Notifications
You must be signed in to change notification settings - Fork 951
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
Updated to fix issues-4170 #7980
base: master
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1254,4 +1254,97 @@ | |
expect(oobs[0].requestType).to.equal("RECOVER_EMAIL"); | ||
expect(oobs[0].oobLink).to.include(tenant.tenantId); | ||
}); | ||
|
||
it("should link provider account with existing user account", async () => { | ||
const { idToken } = await registerUser(authApi(), { | ||
email: "test@example.com", | ||
password: "password", | ||
}); | ||
|
||
const providerId = "google.com"; | ||
const rawId = "google_user_id"; | ||
const providerUserInfo = { | ||
providerId, | ||
rawId, | ||
email: "linked@example.com", | ||
displayName: "Linked User", | ||
photoUrl: "https://example.com/photo.jpg", | ||
}; | ||
|
||
await authApi() | ||
.post("/identitytoolkit.googleapis.com/v1/accounts:update") | ||
.query({ key: "fake-api-key" }) | ||
.send({ idToken, linkProviderUserInfo: providerUserInfo }) | ||
.then((res) => { | ||
expectStatusCode(200, res); | ||
const providers = res.body.providerUserInfo; | ||
expect(providers).to.have.length(2); // Original email/password + linked provider | ||
|
||
const linkedProvider = providers.find((p: ProviderUserInfo) => p.providerId === providerId); | ||
expect(linkedProvider).to.deep.equal(providerUserInfo); | ||
}); | ||
|
||
const accountInfo = await getAccountInfoByIdToken(authApi(), idToken); | ||
expect(accountInfo.providerUserInfo).to.have.length(2); | ||
const linkedProviderInfo = accountInfo.providerUserInfo?.find((p: ProviderUserInfo) => p.providerId === providerId); | ||
Check failure on line 1289 in src/emulator/auth/setAccountInfo.spec.ts GitHub Actions / lint (20)
|
||
expect(linkedProviderInfo).to.deep.equal(providerUserInfo); | ||
}); | ||
|
||
it("should error if linkProviderUserInfo is missing required fields", async () => { | ||
const { idToken } = await registerUser(authApi(), { | ||
email: "test@example.com", | ||
password: "password", | ||
}); | ||
|
||
const incompleteProviderUserInfo1 = { | ||
providerId: "google.com", | ||
email: "linked@example.com", | ||
}; | ||
|
||
await authApi() | ||
.post("/identitytoolkit.googleapis.com/v1/accounts:update") | ||
.query({ key: "fake-api-key" }) | ||
.send({ idToken, linkProviderUserInfo: incompleteProviderUserInfo1 }) | ||
.catch((err) => { | ||
expect(err.response.status).to.equal(500); // Expecting internal server error since it's a missing validation | ||
}); | ||
|
||
const incompleteProviderUserInfo2 = { | ||
rawId: "google_user_id", | ||
email: "linked@example.com", | ||
}; | ||
|
||
await authApi() | ||
.post("/identitytoolkit.googleapis.com/v1/accounts:update") | ||
.query({ key: "fake-api-key" }) | ||
.send({ idToken, linkProviderUserInfo: incompleteProviderUserInfo2 }) | ||
.catch((err) => { | ||
expect(err.response.status).to.equal(500); // Expecting internal server error since it's a missing validation | ||
Check failure on line 1322 in src/emulator/auth/setAccountInfo.spec.ts GitHub Actions / lint (20)
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As mentioned above, let's make this a 400 |
||
|
||
}); | ||
}); | ||
|
||
it("should error if user is disabled when linking a provider", async () => { | ||
const { localId, idToken } = await registerUser(authApi(), { | ||
email: "test@example.com", | ||
password: "password", | ||
}); | ||
|
||
await updateAccountByLocalId(authApi(), localId, { disableUser: true }); | ||
|
||
const providerUserInfo = { | ||
providerId: "google.com", | ||
rawId: "google_user_id", | ||
email: "linked@example.com", | ||
}; | ||
|
||
await authApi() | ||
.post("/identitytoolkit.googleapis.com/v1/accounts:update") | ||
.query({ key: "fake-api-key" }) | ||
.send({ idToken, linkProviderUserInfo: providerUserInfo }) | ||
.then((res) => { | ||
expectStatusCode(400, res); | ||
expect(res.body.error.message).to.equal("USER_DISABLED"); | ||
}); | ||
}); | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These should use
assert
to throw a client error instead of internal error, but I don't know what the correct error codes should be. Maybe we can settle withassert(condition, "TODO_ERROR_CODE : missing providerId")
for now