Skip to content
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

Don't allow non-verified email updates until app feature is out #1682

Merged
merged 1 commit into from
Sep 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions packages/pds/src/api/com/atproto/server/updateEmail.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,17 @@ export default function (server: Server, ctx: AppContext) {
throw new InvalidRequestError('user not found')
}
// require valid token
if (user.emailConfirmedAt) {
if (!token) {
throw new InvalidRequestError(
'confirmation token required',
'TokenRequired',
)
}
await ctx.services
.account(ctx.db)
.assertValidToken(did, 'update_email', token)
// @TODO re-enable updating non-verified emails
// if (user.emailConfirmedAt) {
if (!token) {
throw new InvalidRequestError(
'confirmation token required',
'TokenRequired',
)
}
await ctx.services
.account(ctx.db)
.assertValidToken(did, 'update_email', token)

await ctx.db.transaction(async (dbTxn) => {
const accntSrvce = ctx.services.account(dbTxn)
Expand Down
30 changes: 19 additions & 11 deletions packages/pds/tests/email-confirmation.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,26 +61,34 @@ describe('email confirmation', () => {
expect(session.data.emailConfirmed).toEqual(false)
})

it('allows email update without token when unverified', async () => {
it('disallows email update without token when unverified', async () => {
const res = await agent.api.com.atproto.server.requestEmailUpdate(
undefined,
{ headers: sc.getHeaders(alice.did) },
)
expect(res.data.tokenRequired).toBe(false)

await agent.api.com.atproto.server.updateEmail(
const attempt = agent.api.com.atproto.server.updateEmail(
{
email: '[email protected]',
},
{ headers: sc.getHeaders(alice.did), encoding: 'application/json' },
)
const session = await agent.api.com.atproto.server.getSession(
{},
{ headers: sc.getHeaders(alice.did) },
)
expect(session.data.email).toEqual('[email protected]')
expect(session.data.emailConfirmed).toEqual(false)
alice.email = session.data.email
await expect(attempt).rejects.toThrow()

// await agent.api.com.atproto.server.updateEmail(
// {
// email: '[email protected]',
// },
// { headers: sc.getHeaders(alice.did), encoding: 'application/json' },
// )
// const session = await agent.api.com.atproto.server.getSession(
// {},
// { headers: sc.getHeaders(alice.did) },
// )
// expect(session.data.email).toEqual('[email protected]')
// expect(session.data.emailConfirmed).toEqual(false)
// alice.email = session.data.email
})

let confirmToken
Expand All @@ -100,7 +108,7 @@ describe('email confirmation', () => {
it('fails email confirmation with a bad token', async () => {
const attempt = agent.api.com.atproto.server.confirmEmail(
{
email: 'new-alice@example.com',
email: alice.email,
token: '123456',
},
{ headers: sc.getHeaders(alice.did), encoding: 'application/json' },
Expand All @@ -126,7 +134,7 @@ describe('email confirmation', () => {
it('confirms email', async () => {
await agent.api.com.atproto.server.confirmEmail(
{
email: 'new-alice@example.com',
email: alice.email,
token: confirmToken,
},
{ headers: sc.getHeaders(alice.did), encoding: 'application/json' },
Expand Down