Skip to content

Commit

Permalink
stricter updating email until app feature is out
Browse files Browse the repository at this point in the history
  • Loading branch information
dholms committed Sep 27, 2023
1 parent 3ee4573 commit f788e63
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 21 deletions.
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

0 comments on commit f788e63

Please sign in to comment.