atproto/packages/ozone/tests/get-lists.test.ts
Daniel Holmgren 50c0ec176c
Service auth method binding (lxm) (#2663)
* 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>
2024-08-18 15:46:07 -04:00

111 lines
3.4 KiB
TypeScript

import {
SeedClient,
TestNetwork,
TestOzone,
basicSeed,
ModeratorClient,
RecordRef,
} from '@atproto/dev-env'
import { AtpAgent, BSKY_LABELER_DID } from '@atproto/api'
import { TAKEDOWN_LABEL } from '../src/mod-service'
import { ids } from '../src/lexicon/lexicons'
describe('admin get lists', () => {
let network: TestNetwork
let ozone: TestOzone
let agent: AtpAgent
let appviewAgent: AtpAgent
let sc: SeedClient
let modClient: ModeratorClient
let alicesList: RecordRef
beforeAll(async () => {
network = await TestNetwork.create({
dbPostgresSchema: 'ozone_admin_get_lists',
})
ozone = network.ozone
agent = ozone.getClient()
appviewAgent = network.bsky.getClient()
sc = network.getSeedClient()
modClient = ozone.getModClient()
await basicSeed(sc)
alicesList = await sc.createList(sc.dids.alice, "Alice's List", 'mod')
AtpAgent.configure({ appLabelers: [ozone.ctx.cfg.service.did] })
await network.processAll()
})
afterAll(async () => {
AtpAgent.configure({ appLabelers: [BSKY_LABELER_DID] })
await network.close()
})
const getAlicesList = async () => {
const [{ data: fromOzone }, { data: fromAppview }] = await Promise.all([
agent.api.app.bsky.graph.getLists(
{ actor: sc.dids.alice },
{ headers: await ozone.modHeaders(ids.AppBskyGraphGetLists) },
),
appviewAgent.api.app.bsky.graph.getLists({ actor: sc.dids.alice }),
])
return { fromOzone, fromAppview }
}
it('returns lists from takendown account', async () => {
const beforeTakedown = await getAlicesList()
expect(beforeTakedown.fromOzone.lists[0].uri).toEqual(alicesList.uriStr)
expect(beforeTakedown.fromAppview.lists[0].uri).toEqual(alicesList.uriStr)
// Takedown alice's account
await modClient.emitEvent({
event: { $type: 'tools.ozone.moderation.defs#modEventTakedown' },
subject: {
$type: 'com.atproto.admin.defs#repoRef',
did: sc.dids.alice,
},
})
await network.processAll()
const afterTakedown = await getAlicesList()
// Verify that takendown list is shown when queried through ozone but not through appview
expect(afterTakedown.fromAppview.lists.length).toBe(0)
expect(afterTakedown.fromOzone.lists[0].uri).toEqual(alicesList.uriStr)
// Reverse alice's account takedown
await modClient.emitEvent({
event: { $type: 'tools.ozone.moderation.defs#modEventReverseTakedown' },
subject: {
$type: 'com.atproto.admin.defs#repoRef',
did: sc.dids.alice,
},
})
await network.processAll()
})
it('returns takendown lists', async () => {
const beforeTakedown = await getAlicesList()
expect(beforeTakedown.fromOzone.lists[0].uri).toEqual(alicesList.uriStr)
expect(beforeTakedown.fromAppview.lists[0].uri).toEqual(alicesList.uriStr)
// Takedown alice's list using a !takedown label
await network.bsky.db.db
.insertInto('label')
.values({
src: ozone.ctx.cfg.service.did,
uri: alicesList.uriStr,
cid: alicesList.cidStr,
val: TAKEDOWN_LABEL,
neg: false,
cts: new Date().toISOString(),
})
.execute()
const afterTakedown = await getAlicesList()
// Verify that takendown list is shown when queried through ozone but not through appview
expect(afterTakedown.fromAppview.lists.length).toBe(0)
expect(afterTakedown.fromOzone.lists[0].uri).toEqual(alicesList.uriStr)
})
})