50c0ec176c
* add scopes to service auth impl * add error to getServiceAuth * send scoped tokens from pds * clean up privileged access scopes & allow simple service auth tokens for app passwords * integration into ozone * fix up bsky tests * cleanup xrpc-server tests * fix up tests & types * one more test * fix read after write tests * fix mod auth test * convert scopes to be a single method name * add scope check callback for auth verifier * pds changes only * fix feed generation tests * use scope for ozone service profile * dont verify scopes on pds yet * tidy * tidy imports * changeset * add tests * tidy * another changeset * scope -> lxm * tidy * clean up scope references * update nonce size * pr feedback * trim trailing slash * nonce -> jti * fix xrpc-server test * allow service auth on uploadBlob * fix build error * changeset * build, tidy * xrpc-server: update lxm claim check error * appview: temporarily permit labeler service calls to omit lxm claim * xrpc-server: fix test * changeset * fix merged tests --------- Co-authored-by: Devin Ivy <devinivy@gmail.com>
191 lines
5.2 KiB
TypeScript
191 lines
5.2 KiB
TypeScript
import { AtpAgent } from '@atproto/api'
|
|
import { TestNetwork, SeedClient, basicSeed, RecordRef } from '@atproto/dev-env'
|
|
import { forSnapshot, stripViewerFromLabeler } from '../_util'
|
|
import { ids } from '../../src/lexicon/lexicons'
|
|
|
|
describe('labeler service views', () => {
|
|
let network: TestNetwork
|
|
let agent: AtpAgent
|
|
let pdsAgent: AtpAgent
|
|
let sc: SeedClient
|
|
|
|
// account dids, for convenience
|
|
let alice: string
|
|
let bob: string
|
|
|
|
let aliceService: RecordRef
|
|
|
|
beforeAll(async () => {
|
|
network = await TestNetwork.create({
|
|
dbPostgresSchema: 'bsky_views_labeler_service',
|
|
})
|
|
agent = network.bsky.getClient()
|
|
pdsAgent = network.pds.getClient()
|
|
sc = network.getSeedClient()
|
|
await basicSeed(sc)
|
|
alice = sc.dids.alice
|
|
bob = sc.dids.bob
|
|
|
|
const aliceRes = await pdsAgent.api.com.atproto.repo.createRecord(
|
|
{
|
|
repo: alice,
|
|
collection: ids.AppBskyLabelerService,
|
|
rkey: 'self',
|
|
record: {
|
|
policies: {
|
|
labelValues: ['spam', '!hide', 'scam', 'impersonation'],
|
|
},
|
|
createdAt: new Date().toISOString(),
|
|
},
|
|
},
|
|
{ headers: sc.getHeaders(alice), encoding: 'application/json' },
|
|
)
|
|
await pdsAgent.api.com.atproto.repo.createRecord(
|
|
{
|
|
repo: bob,
|
|
collection: ids.AppBskyLabelerService,
|
|
rkey: 'self',
|
|
record: {
|
|
policies: {
|
|
labelValues: ['nudity', 'sexual', 'porn'],
|
|
},
|
|
createdAt: new Date().toISOString(),
|
|
},
|
|
},
|
|
{ headers: sc.getHeaders(bob), encoding: 'application/json' },
|
|
)
|
|
|
|
aliceService = new RecordRef(aliceRes.data.uri, aliceRes.data.cid)
|
|
|
|
await sc.like(bob, aliceService)
|
|
await network.processAll()
|
|
})
|
|
|
|
afterAll(async () => {
|
|
await network.close()
|
|
})
|
|
|
|
it('fetches labelers', async () => {
|
|
const view = await agent.api.app.bsky.labeler.getServices(
|
|
{ dids: [alice, bob, 'did:example:missing'] },
|
|
{
|
|
headers: await network.serviceHeaders(
|
|
bob,
|
|
ids.AppBskyLabelerGetServices,
|
|
),
|
|
},
|
|
)
|
|
|
|
expect(forSnapshot(view.data)).toMatchSnapshot()
|
|
})
|
|
|
|
it('fetches labelers detailed', async () => {
|
|
const view = await agent.api.app.bsky.labeler.getServices(
|
|
{ dids: [alice, bob, 'did:example:missing'], detailed: true },
|
|
{
|
|
headers: await network.serviceHeaders(
|
|
bob,
|
|
ids.AppBskyLabelerGetServices,
|
|
),
|
|
},
|
|
)
|
|
|
|
expect(forSnapshot(view.data)).toMatchSnapshot()
|
|
})
|
|
|
|
it('fetches labelers unauthed', async () => {
|
|
const { data: authed } = await agent.api.app.bsky.labeler.getServices(
|
|
{ dids: [alice] },
|
|
{
|
|
headers: await network.serviceHeaders(
|
|
bob,
|
|
ids.AppBskyLabelerGetServices,
|
|
),
|
|
},
|
|
)
|
|
const { data: unauthed } = await agent.api.app.bsky.labeler.getServices({
|
|
dids: [alice],
|
|
})
|
|
expect(unauthed.views).toEqual(authed.views.map(stripViewerFromLabeler))
|
|
})
|
|
|
|
it('fetches multiple labelers unauthed', async () => {
|
|
const { data: authed } = await agent.api.app.bsky.labeler.getServices(
|
|
{
|
|
dids: [alice, bob, 'did:example:missing'],
|
|
},
|
|
{
|
|
headers: await network.serviceHeaders(
|
|
bob,
|
|
ids.AppBskyLabelerGetServices,
|
|
),
|
|
},
|
|
)
|
|
const { data: unauthed } = await agent.api.app.bsky.labeler.getServices({
|
|
dids: [alice, bob, 'did:example:missing'],
|
|
})
|
|
expect(unauthed.views.length).toBeGreaterThan(0)
|
|
expect(unauthed.views).toEqual(authed.views.map(stripViewerFromLabeler))
|
|
})
|
|
|
|
it('renders a post embed of a labeler', async () => {
|
|
const postRes = await pdsAgent.api.app.bsky.feed.post.create(
|
|
{ repo: sc.dids.bob },
|
|
{
|
|
text: 'check out this labeler',
|
|
embed: {
|
|
$type: 'app.bsky.embed.record',
|
|
record: aliceService.raw,
|
|
},
|
|
createdAt: new Date().toISOString(),
|
|
},
|
|
sc.getHeaders(sc.dids.bob),
|
|
)
|
|
|
|
await network.processAll()
|
|
|
|
const postViews = await agent.api.app.bsky.feed.getPosts({
|
|
uris: [postRes.uri],
|
|
})
|
|
const serviceViews = await agent.api.app.bsky.labeler.getServices({
|
|
dids: [alice],
|
|
})
|
|
expect(postViews.data.posts[0].embed?.record).toMatchObject(
|
|
serviceViews.data.views[0],
|
|
)
|
|
})
|
|
|
|
it('renders profile as labeler in non-detailed profile views', async () => {
|
|
const { data: res } = await agent.api.app.bsky.actor.searchActors(
|
|
{ q: sc.accounts[alice].handle },
|
|
{
|
|
headers: await network.serviceHeaders(
|
|
bob,
|
|
ids.AppBskyActorSearchActors,
|
|
),
|
|
},
|
|
)
|
|
expect(res.actors.length).toBe(1)
|
|
expect(res.actors[0].associated?.labeler).toBe(true)
|
|
})
|
|
|
|
it('blocked by labeler takedown', async () => {
|
|
await network.bsky.ctx.dataplane.takedownActor({ did: alice })
|
|
const res = await agent.api.app.bsky.labeler.getServices(
|
|
{ dids: [alice, bob] },
|
|
{
|
|
headers: await network.serviceHeaders(
|
|
bob,
|
|
ids.AppBskyLabelerGetServices,
|
|
),
|
|
},
|
|
)
|
|
expect(res.data.views.length).toBe(1)
|
|
// @ts-ignore
|
|
expect(res.data.views[0].creator.did).toEqual(bob)
|
|
|
|
// Cleanup
|
|
await network.bsky.ctx.dataplane.untakedownActor({ did: alice })
|
|
})
|
|
})
|