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

Add ens credentials check #873

Merged
merged 10 commits into from
Oct 30, 2024
328 changes: 292 additions & 36 deletions e2e/specs/stateless/verifications.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,19 @@ import {
import { createAccounts } from '../../../playwright/fixtures/accounts'
import { testClient } from '../../../playwright/fixtures/contracts/utils/addTestContracts'

type MakeMockVPTokenRecordKey =
| 'com.twitter'
| 'com.github'
| 'com.discord'
| 'org.telegram'
| 'personhood'
| 'email'
| 'ens'

const makeMockVPToken = (
records: Array<
'com.twitter' | 'com.github' | 'com.discord' | 'org.telegram' | 'personhood' | 'email'
>,
records: Array<{ key: MakeMockVPTokenRecordKey; value?: string; name?: string }>,
) => {
return records.map((record) => ({
return records.map(({ key, value, name }) => ({
type: [
'VerifiableCredential',
{
Expand All @@ -31,15 +38,22 @@ const makeMockVPToken = (
'org.telegram': 'VerifiedTelegramAccount',
personhood: 'VerifiedPersonhood',
email: 'VerifiedEmail',
}[record],
ens: 'VerifiedENS',
}[key],
],
credentialSubject: {
credentialIssuer: 'Dentity',
...(record === 'com.twitter' ? { username: '@name' } : {}),
...(['com.twitter', 'com.github', 'com.discord', 'org.telegram'].includes(record)
? { name: 'name' }
...(key === 'com.twitter' ? { username: value ?? '@name' } : {}),
...(['com.twitter', 'com.github', 'com.discord', 'org.telegram'].includes(key)
? { name: value ?? 'name' }
: {}),
...(key === 'email' ? { verifiedEmail: value ?? '[email protected]' } : {}),
...(key === 'ens'
? {
ensName: name ?? 'name.eth',
ethAddress: value ?? (createAccounts().getAddress('user') as Hash),
}
: {}),
...(record === 'email' ? { verifiedEmail: '[email protected]' } : {}),
},
}))
}
Expand Down Expand Up @@ -94,12 +108,13 @@ test.describe('Verified records', () => {
contentType: 'application/json',
body: JSON.stringify({
vp_token: makeMockVPToken([
'com.twitter',
'com.github',
'com.discord',
'org.telegram',
'personhood',
'email',
{ key: 'com.twitter' },
{ key: 'com.github' },
{ key: 'com.discord' },
{ key: 'org.telegram' },
{ key: 'personhood' },
{ key: 'email' },
{ key: 'ens', name },
]),
}),
})
Expand Down Expand Up @@ -173,7 +188,163 @@ test.describe('Verified records', () => {
body: JSON.stringify({
ens_name: name,
eth_address: accounts.getAddress('user2'),
vp_token: makeMockVPToken(['com.twitter', 'com.github', 'com.discord', 'org.telegram']),
vp_token: makeMockVPToken([
{ key: 'com.twitter' },
{ key: 'com.github' },
{ key: 'com.discord' },
{ key: 'org.telegram' },
{ key: 'ens', name },
]),
}),
})
})

await page.goto(`/${name}`)

await page.pause()

await expect(page.getByTestId('profile-section-verifications')).toBeVisible()

await profilePage.isRecordVerified('text', 'com.twitter', false)
await profilePage.isRecordVerified('text', 'org.telegram', false)
await profilePage.isRecordVerified('text', 'com.github', false)
await profilePage.isRecordVerified('text', 'com.discord', false)
await profilePage.isRecordVerified('verification', 'dentity', false)
await profilePage.isPersonhoodVerified(false)

await expect(profilePage.record('verification', 'dentity')).toBeVisible()
await expect(profilePage.record('verification', 'dentity')).toBeVisible()
})

test('Should not show badges if records match but ens credential address does not match', async ({
page,
accounts,
makePageObject,
makeName,
}) => {
const name = await makeName({
label: 'dentity',
type: 'wrapped',
owner: 'user',
records: {
texts: [
{
key: 'com.twitter',
value: '@name',
},
{
key: 'org.telegram',
value: 'name',
},
{
key: 'com.discord',
value: 'name',
},
{
key: 'com.github',
value: 'name',
},
{
key: VERIFICATION_RECORD_KEY,
value: JSON.stringify([
`${DENTITY_VPTOKEN_ENDPOINT}?name=name.eth&federated_token=federated_token`,
]),
},
],
},
})

const profilePage = makePageObject('ProfilePage')

await page.route(`${DENTITY_VPTOKEN_ENDPOINT}*`, async (route) => {
await route.fulfill({
status: 200,
contentType: 'application/json',
body: JSON.stringify({
ens_name: name,
eth_address: accounts.getAddress('user2'),
vp_token: makeMockVPToken([
{ key: 'com.twitter' },
{ key: 'com.github' },
{ key: 'com.discord' },
{ key: 'org.telegram' },
{ key: 'ens', name, value: accounts.getAddress('user2') },
]),
}),
})
})

await page.goto(`/${name}`)

await page.pause()

await expect(page.getByTestId('profile-section-verifications')).toBeVisible()

await profilePage.isRecordVerified('text', 'com.twitter', false)
await profilePage.isRecordVerified('text', 'org.telegram', false)
await profilePage.isRecordVerified('text', 'com.github', false)
await profilePage.isRecordVerified('text', 'com.discord', false)
await profilePage.isRecordVerified('verification', 'dentity', false)
await profilePage.isPersonhoodVerified(false)

await expect(profilePage.record('verification', 'dentity')).toBeVisible()
await expect(profilePage.record('verification', 'dentity')).toBeVisible()
})

test('Should not show badges if records match but ens credential name does not match', async ({
page,
accounts,
makePageObject,
makeName,
}) => {
const name = await makeName({
label: 'dentity',
type: 'wrapped',
owner: 'user',
records: {
texts: [
{
key: 'com.twitter',
value: '@name',
},
{
key: 'org.telegram',
value: 'name',
},
{
key: 'com.discord',
value: 'name',
},
{
key: 'com.github',
value: 'name',
},
{
key: VERIFICATION_RECORD_KEY,
value: JSON.stringify([
`${DENTITY_VPTOKEN_ENDPOINT}?name=name.eth&federated_token=federated_token`,
]),
},
],
},
})

const profilePage = makePageObject('ProfilePage')

await page.route(`${DENTITY_VPTOKEN_ENDPOINT}*`, async (route) => {
await route.fulfill({
status: 200,
contentType: 'application/json',
body: JSON.stringify({
ens_name: name,
eth_address: accounts.getAddress('user2'),
vp_token: makeMockVPToken([
{ key: 'com.twitter' },
{ key: 'com.github' },
{ key: 'com.discord' },
{ key: 'org.telegram' },
{ key: 'ens', name: 'differentName.eth' },
]),
}),
})
})
Expand All @@ -194,6 +365,89 @@ test.describe('Verified records', () => {
await expect(profilePage.record('verification', 'dentity')).toBeVisible()
await expect(profilePage.record('verification', 'dentity')).toBeVisible()
})

test('Should show error icon on verication button if VerifiedENS credential is not validated', async ({
page,
login,
makePageObject,
makeName,
}) => {
const name = await makeName({
label: 'dentity',
type: 'wrapped',
owner: 'user',
records: {
texts: [
{
key: 'com.twitter',
value: '@name',
},
{
key: 'org.telegram',
value: 'name',
},
{
key: 'com.discord',
value: 'name',
},
{
key: 'com.github',
value: 'name',
},
{
key: 'email',
value: '[email protected]',
},
{
key: VERIFICATION_RECORD_KEY,
value: JSON.stringify([
`${DENTITY_VPTOKEN_ENDPOINT}?name=name.eth&federated_token=federated_token`,
]),
},
{
key: 'com.twitter',
value: '@name',
},
],
},
})

const profilePage = makePageObject('ProfilePage')

await page.route(`${DENTITY_VPTOKEN_ENDPOINT}*`, async (route) => {
await route.fulfill({
status: 200,
contentType: 'application/json',
body: JSON.stringify({
vp_token: makeMockVPToken([
{ key: 'com.twitter' },
{ key: 'com.github' },
{ key: 'com.discord' },
{ key: 'org.telegram' },
{ key: 'personhood' },
{ key: 'email' },
{ key: 'ens', name: 'othername.eth' },
]),
}),
})
})

await page.goto(`/${name}`)
await login.connect()

await page.pause()

await expect(page.getByTestId('profile-section-verifications')).toBeVisible()

await profilePage.isRecordVerified('text', 'com.twitter', false)
await profilePage.isRecordVerified('text', 'org.telegram', false)
await profilePage.isRecordVerified('text', 'com.github', false)
await profilePage.isRecordVerified('text', 'com.discord', false)
await profilePage.isRecordVerified('verification', 'dentity', false)
await profilePage.isPersonhoodErrored()

await expect(profilePage.record('verification', 'dentity')).toBeVisible()
})
})

test.describe('Verify profile', () => {
Expand All @@ -219,11 +473,11 @@ test.describe('Verify profile', () => {
contentType: 'application/json',
body: JSON.stringify({
vp_token: makeMockVPToken([
'personhood',
'com.twitter',
'com.github',
'com.discord',
'org.telegram',
{ key: 'personhood' },
{ key: 'com.twitter' },
{ key: 'com.github' },
{ key: 'com.discord' },
{ key: 'org.telegram' },
]),
}),
})
Expand Down Expand Up @@ -263,11 +517,11 @@ test.describe('Verify profile', () => {
contentType: 'application/json',
body: JSON.stringify({
vp_token: makeMockVPToken([
'personhood',
'com.twitter',
'com.github',
'com.discord',
'org.telegram',
{ key: 'personhood' },
{ key: 'com.twitter' },
{ key: 'com.github' },
{ key: 'com.discord' },
{ key: 'org.telegram' },
]),
}),
})
Expand Down Expand Up @@ -332,11 +586,12 @@ test.describe('Verify profile', () => {
contentType: 'application/json',
body: JSON.stringify({
vp_token: makeMockVPToken([
'personhood',
'com.twitter',
'com.github',
'com.discord',
'org.telegram',
{ key: 'personhood' },
{ key: 'com.twitter' },
{ key: 'com.github' },
{ key: 'com.discord' },
{ key: 'org.telegram' },
{ key: 'ens', name, value: createAccounts().getAddress('user2') },
]),
}),
})
Expand Down Expand Up @@ -432,11 +687,12 @@ test.describe('OAuth flow', () => {
contentType: 'application/json',
body: JSON.stringify({
vp_token: makeMockVPToken([
'personhood',
'com.twitter',
'com.github',
'com.discord',
'org.telegram',
{ key: 'personhood' },
{ key: 'com.twitter' },
{ key: 'com.github' },
{ key: 'com.discord' },
{ key: 'org.telegram' },
{ key: 'ens', name, value: createAccounts().getAddress('user2') },
]),
}),
})
Expand Down
Loading
Loading