@atproto/ozone 0.1.15 → 0.1.17

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (48) hide show
  1. package/CHANGELOG.md +16 -0
  2. package/dist/api/moderation/getRecord.d.ts.map +1 -1
  3. package/dist/api/moderation/getRecord.js +3 -2
  4. package/dist/api/moderation/getRecord.js.map +1 -1
  5. package/dist/api/moderation/getRepo.d.ts.map +1 -1
  6. package/dist/api/moderation/getRepo.js +3 -2
  7. package/dist/api/moderation/getRepo.js.map +1 -1
  8. package/dist/api/proxied.d.ts.map +1 -1
  9. package/dist/api/proxied.js +10 -0
  10. package/dist/api/proxied.js.map +1 -1
  11. package/dist/context.d.ts +3 -0
  12. package/dist/context.d.ts.map +1 -1
  13. package/dist/context.js +13 -0
  14. package/dist/context.js.map +1 -1
  15. package/dist/lexicon/lexicons.d.ts +10 -0
  16. package/dist/lexicon/lexicons.d.ts.map +1 -1
  17. package/dist/lexicon/lexicons.js +10 -0
  18. package/dist/lexicon/lexicons.js.map +1 -1
  19. package/dist/lexicon/types/com/atproto/server/createAppPassword.d.ts +3 -0
  20. package/dist/lexicon/types/com/atproto/server/createAppPassword.d.ts.map +1 -1
  21. package/dist/lexicon/types/com/atproto/server/createAppPassword.js.map +1 -1
  22. package/dist/lexicon/types/com/atproto/server/listAppPasswords.d.ts +1 -0
  23. package/dist/lexicon/types/com/atproto/server/listAppPasswords.d.ts.map +1 -1
  24. package/dist/lexicon/types/com/atproto/server/listAppPasswords.js.map +1 -1
  25. package/dist/mod-service/index.d.ts.map +1 -1
  26. package/dist/mod-service/index.js +8 -1
  27. package/dist/mod-service/index.js.map +1 -1
  28. package/dist/mod-service/views.d.ts +5 -2
  29. package/dist/mod-service/views.d.ts.map +1 -1
  30. package/dist/mod-service/views.js +17 -6
  31. package/dist/mod-service/views.js.map +1 -1
  32. package/dist/util.d.ts +8 -0
  33. package/dist/util.d.ts.map +1 -1
  34. package/dist/util.js +41 -1
  35. package/dist/util.js.map +1 -1
  36. package/package.json +4 -3
  37. package/src/api/moderation/getRecord.ts +3 -2
  38. package/src/api/moderation/getRepo.ts +3 -2
  39. package/src/api/proxied.ts +14 -0
  40. package/src/context.ts +20 -1
  41. package/src/lexicon/lexicons.ts +11 -0
  42. package/src/lexicon/types/com/atproto/server/createAppPassword.ts +3 -0
  43. package/src/lexicon/types/com/atproto/server/listAppPasswords.ts +1 -0
  44. package/src/mod-service/index.ts +8 -1
  45. package/src/mod-service/views.ts +30 -5
  46. package/src/util.ts +50 -0
  47. package/tests/3p-labeler.test.ts +271 -0
  48. package/tests/get-lists.test.ts +109 -0
package/src/context.ts CHANGED
@@ -1,3 +1,4 @@
1
+ import express from 'express'
1
2
  import * as plc from '@did-plc/lib'
2
3
  import { IdResolver } from '@atproto/identity'
3
4
  import { AtpAgent } from '@atproto/api'
@@ -17,7 +18,13 @@ import {
17
18
  import { BlobDiverter } from './daemon/blob-diverter'
18
19
  import { AuthVerifier } from './auth-verifier'
19
20
  import { ImageInvalidator } from './image-invalidator'
20
- import { getSigningKeyId } from './util'
21
+ import {
22
+ defaultLabelerHeader,
23
+ getSigningKeyId,
24
+ LABELER_HEADER_NAME,
25
+ ParsedLabelers,
26
+ parseLabelerHeader,
27
+ } from './util'
21
28
 
22
29
  export type AppContextOptions = {
23
30
  db: Database
@@ -234,5 +241,17 @@ export class AppContext {
234
241
  ...overrides,
235
242
  }
236
243
  }
244
+
245
+ reqLabelers(req: express.Request): ParsedLabelers {
246
+ const val = req.header(LABELER_HEADER_NAME)
247
+ let parsed: ParsedLabelers | null
248
+ try {
249
+ parsed = parseLabelerHeader(val, this.cfg.service.did)
250
+ } catch (err) {
251
+ parsed = null
252
+ }
253
+ if (!parsed) return defaultLabelerHeader([])
254
+ return parsed
255
+ }
237
256
  }
238
257
  export default AppContext
@@ -2052,6 +2052,11 @@ export const schemaDict = {
2052
2052
  description:
2053
2053
  'A short name for the App Password, to help distinguish them.',
2054
2054
  },
2055
+ privileged: {
2056
+ type: 'boolean',
2057
+ description:
2058
+ "If an app password has 'privileged' access to possibly sensitive account state. Meant for use with trusted clients.",
2059
+ },
2055
2060
  },
2056
2061
  },
2057
2062
  },
@@ -2082,6 +2087,9 @@ export const schemaDict = {
2082
2087
  type: 'string',
2083
2088
  format: 'datetime',
2084
2089
  },
2090
+ privileged: {
2091
+ type: 'boolean',
2092
+ },
2085
2093
  },
2086
2094
  },
2087
2095
  },
@@ -2629,6 +2637,9 @@ export const schemaDict = {
2629
2637
  type: 'string',
2630
2638
  format: 'datetime',
2631
2639
  },
2640
+ privileged: {
2641
+ type: 'boolean',
2642
+ },
2632
2643
  },
2633
2644
  },
2634
2645
  },
@@ -13,6 +13,8 @@ export interface QueryParams {}
13
13
  export interface InputSchema {
14
14
  /** A short name for the App Password, to help distinguish them. */
15
15
  name: string
16
+ /** If an app password has 'privileged' access to possibly sensitive account state. Meant for use with trusted clients. */
17
+ privileged?: boolean
16
18
  [k: string]: unknown
17
19
  }
18
20
 
@@ -51,6 +53,7 @@ export interface AppPassword {
51
53
  name: string
52
54
  password: string
53
55
  createdAt: string
56
+ privileged?: boolean
54
57
  [k: string]: unknown
55
58
  }
56
59
 
@@ -46,6 +46,7 @@ export type Handler<HA extends HandlerAuth = never> = (
46
46
  export interface AppPassword {
47
47
  name: string
48
48
  createdAt: string
49
+ privileged?: boolean
49
50
  [k: string]: unknown
50
51
  }
51
52
 
@@ -48,6 +48,7 @@ import { formatLabel, formatLabelRow, signLabel } from './util'
48
48
  import { ImageInvalidator } from '../image-invalidator'
49
49
  import { httpLogger as log } from '../logger'
50
50
  import { OzoneConfig } from '../config'
51
+ import { LABELER_HEADER_NAME, ParsedLabelers } from '../util'
51
52
 
52
53
  export type ModerationServiceCreator = (db: Database) => ModerationService
53
54
 
@@ -96,7 +97,13 @@ export class ModerationService {
96
97
  this.signingKey,
97
98
  this.signingKeyId,
98
99
  this.appviewAgent,
99
- () => this.createAuthHeaders(this.cfg.appview.did),
100
+ async (labelers?: ParsedLabelers) => {
101
+ const authHeaders = await this.createAuthHeaders(this.cfg.appview.did)
102
+ if (labelers?.dids?.length) {
103
+ authHeaders.headers[LABELER_HEADER_NAME] = labelers.dids.join(', ')
104
+ }
105
+ return authHeaders
106
+ },
100
107
  )
101
108
 
102
109
  async getEvent(id: number): Promise<ModerationEventRow | undefined> {
@@ -28,10 +28,12 @@ import { formatLabel, signLabel } from './util'
28
28
  import { LabelRow } from '../db/schema/label'
29
29
  import { dbLogger } from '../logger'
30
30
  import { httpLogger } from '../logger'
31
+ import { ParsedLabelers } from '../util'
31
32
 
32
33
  export type AuthHeaders = {
33
34
  headers: {
34
35
  authorization: string
36
+ 'atproto-accept-labelers'?: string
35
37
  }
36
38
  }
37
39
 
@@ -210,10 +212,14 @@ export class ModerationViews {
210
212
  }
211
213
  }
212
214
 
213
- async repoDetail(did: string): Promise<RepoViewDetail | undefined> {
214
- const [repos, labels] = await Promise.all([
215
+ async repoDetail(
216
+ did: string,
217
+ labelers?: ParsedLabelers,
218
+ ): Promise<RepoViewDetail | undefined> {
219
+ const [repos, localLabels, externalLabels] = await Promise.all([
215
220
  this.repos([did]),
216
221
  this.labels(did),
222
+ this.getExternalLabels([did], labelers),
217
223
  ])
218
224
  const repo = repos.get(did)
219
225
  if (!repo) return
@@ -223,7 +229,7 @@ export class ModerationViews {
223
229
  moderation: {
224
230
  ...repo.moderation,
225
231
  },
226
- labels,
232
+ labels: [...localLabels, ...externalLabels],
227
233
  }
228
234
  }
229
235
 
@@ -293,6 +299,7 @@ export class ModerationViews {
293
299
 
294
300
  async recordDetail(
295
301
  subject: RecordSubject,
302
+ labelers?: ParsedLabelers,
296
303
  ): Promise<RecordViewDetail | undefined> {
297
304
  const [records, subjectStatusesResult] = await Promise.all([
298
305
  this.records([subject]),
@@ -303,9 +310,10 @@ export class ModerationViews {
303
310
 
304
311
  const status = subjectStatusesResult.get(subject.uri)
305
312
 
306
- const [blobs, labels, subjectStatus] = await Promise.all([
313
+ const [blobs, labels, externalLabels, subjectStatus] = await Promise.all([
307
314
  this.blob(findBlobRefs(record.value)),
308
315
  this.labels(record.uri),
316
+ this.getExternalLabels([record.uri], labelers),
309
317
  status ? this.formatSubjectStatus(status) : Promise.resolve(undefined),
310
318
  ])
311
319
  const selfLabels = getSelfLabels({
@@ -313,6 +321,7 @@ export class ModerationViews {
313
321
  cid: record.cid,
314
322
  record: record.value,
315
323
  })
324
+
316
325
  return {
317
326
  ...record,
318
327
  blobs,
@@ -320,10 +329,26 @@ export class ModerationViews {
320
329
  ...record.moderation,
321
330
  subjectStatus,
322
331
  },
323
- labels: [...labels, ...selfLabels],
332
+ labels: [...labels, ...selfLabels, ...externalLabels],
324
333
  }
325
334
  }
326
335
 
336
+ async getExternalLabels(
337
+ subjects: string[],
338
+ labelers?: ParsedLabelers,
339
+ ): Promise<Label[]> {
340
+ if (!labelers?.dids.length && !labelers?.redact.size) return []
341
+
342
+ const {
343
+ data: { labels },
344
+ } = await this.appviewAgent.api.com.atproto.label.queryLabels({
345
+ uriPatterns: subjects,
346
+ sources: labelers.dids,
347
+ })
348
+
349
+ return labels
350
+ }
351
+
327
352
  formatReport(report: ModerationEventRowWithHandle): ReportOutput {
328
353
  return {
329
354
  id: report.id,
package/src/util.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  import { AxiosError } from 'axios'
2
+ import { parseList } from 'structured-headers'
2
3
  import { XRPCError, ResponseType } from '@atproto/xrpc'
3
4
  import { RetryOptions, retry } from '@atproto/common'
4
5
  import Database from './db'
@@ -45,3 +46,52 @@ export function retryableHttp(err: unknown) {
45
46
  const retryableHttpStatusCodes = new Set([
46
47
  408, 425, 429, 500, 502, 503, 504, 522, 524,
47
48
  ])
49
+
50
+ export type ParsedLabelers = {
51
+ dids: string[]
52
+ redact: Set<string>
53
+ }
54
+
55
+ export const LABELER_HEADER_NAME = 'atproto-accept-labelers'
56
+
57
+ export const parseLabelerHeader = (
58
+ header: string | undefined,
59
+ ignoreDid?: string,
60
+ ): ParsedLabelers | null => {
61
+ if (!header) return null
62
+ const labelerDids = new Set<string>()
63
+ const redactDids = new Set<string>()
64
+ const parsed = parseList(header)
65
+ for (const item of parsed) {
66
+ const did = item[0].toString()
67
+ if (!did) {
68
+ return null
69
+ }
70
+ if (did === ignoreDid) {
71
+ continue
72
+ }
73
+ labelerDids.add(did)
74
+ const redact = item[1].get('redact')?.valueOf()
75
+ if (redact === true) {
76
+ redactDids.add(did)
77
+ }
78
+ }
79
+ return {
80
+ dids: [...labelerDids],
81
+ redact: redactDids,
82
+ }
83
+ }
84
+
85
+ export const defaultLabelerHeader = (dids: string[]): ParsedLabelers => {
86
+ return {
87
+ dids,
88
+ redact: new Set(dids),
89
+ }
90
+ }
91
+
92
+ export const formatLabelerHeader = (parsed: ParsedLabelers): string => {
93
+ const parts = parsed.dids.map((did) =>
94
+ parsed.redact.has(did) ? `${did};redact` : did,
95
+ )
96
+ return parts.join(',')
97
+ }
@@ -0,0 +1,271 @@
1
+ import {
2
+ SeedClient,
3
+ TestNetwork,
4
+ basicSeed,
5
+ TestOzone,
6
+ ModeratorClient,
7
+ createOzoneDid,
8
+ } from '@atproto/dev-env'
9
+ import AtpAgent from '@atproto/api'
10
+ import { Secp256k1Keypair } from '@atproto/crypto'
11
+ import { LABELER_HEADER_NAME } from '../src/util'
12
+
13
+ describe('labels from 3p labelers', () => {
14
+ let network: TestNetwork
15
+ let ozone: TestOzone
16
+ let thirdPartyLabeler: TestOzone
17
+ let agent: AtpAgent
18
+ let thirdPartyAgent: AtpAgent
19
+ let sc: SeedClient
20
+ let modClient: ModeratorClient
21
+ let thirdPartyModClient: ModeratorClient
22
+
23
+ beforeAll(async () => {
24
+ network = await TestNetwork.create({
25
+ dbPostgresSchema: 'ozone_admin_third_party_labeler',
26
+ })
27
+ ozone = network.ozone
28
+
29
+ const ozoneKey = await Secp256k1Keypair.create({ exportable: true })
30
+ const ozoneDid = await createOzoneDid(network.plc.url, ozoneKey)
31
+ thirdPartyLabeler = await TestOzone.create({
32
+ port: ozone.port + 10,
33
+ plcUrl: network.plc.url,
34
+ signingKey: ozoneKey,
35
+ serverDid: ozoneDid,
36
+ dbPostgresSchema: `ozone_admin_third_party_labeler`,
37
+ dbPostgresUrl: ozone.ctx.cfg.db.postgresUrl,
38
+ appviewUrl: network.bsky.url,
39
+ appviewDid: network.bsky.ctx.cfg.serverDid,
40
+ appviewPushEvents: true,
41
+ pdsUrl: network.pds.url,
42
+ pdsDid: network.pds.ctx.cfg.service.did,
43
+ })
44
+
45
+ thirdPartyAgent = thirdPartyLabeler.getClient()
46
+ agent = ozone.getClient()
47
+ sc = network.getSeedClient()
48
+ modClient = ozone.getModClient()
49
+ thirdPartyModClient = thirdPartyLabeler.getModClient()
50
+ await basicSeed(sc)
51
+ await network.processAll()
52
+ })
53
+
54
+ afterAll(async () => {
55
+ await network.close()
56
+ await thirdPartyLabeler.close()
57
+ })
58
+
59
+ const getPostSubject = () => ({
60
+ $type: 'com.atproto.repo.strongRef',
61
+ uri: sc.posts[sc.dids.alice][0].ref.uriStr,
62
+ cid: sc.posts[sc.dids.alice][0].ref.cidStr,
63
+ })
64
+
65
+ const adjustLabels = async ({
66
+ uri,
67
+ cid,
68
+ src,
69
+ createLabelVals = [],
70
+ negateLabelVals = [],
71
+ }: {
72
+ uri: string
73
+ src: string
74
+ cid?: string
75
+ createLabelVals?: string[]
76
+ negateLabelVals?: string[]
77
+ }) => {
78
+ const labelEntries = createLabelVals.map((val) => ({
79
+ uri,
80
+ cid: cid || '',
81
+ val,
82
+ cts: new Date().toISOString(),
83
+ neg: false,
84
+ src,
85
+ }))
86
+
87
+ negateLabelVals.forEach((val) => {
88
+ labelEntries.push({
89
+ uri,
90
+ cid: cid || '',
91
+ val,
92
+ cts: new Date().toISOString(),
93
+ neg: true,
94
+ src,
95
+ })
96
+ })
97
+ await network.bsky.db.db.insertInto('label').values(labelEntries).execute()
98
+ }
99
+
100
+ const labelAccount = async (
101
+ client: ModeratorClient,
102
+ {
103
+ createLabelVals = [],
104
+ negateLabelVals = [],
105
+ }: { createLabelVals?: string[]; negateLabelVals?: string[] },
106
+ ) => {
107
+ const subject = {
108
+ $type: 'com.atproto.admin.defs#repoRef',
109
+ did: sc.dids.alice,
110
+ }
111
+ await client.emitEvent(
112
+ {
113
+ subject,
114
+ event: {
115
+ $type: 'tools.ozone.moderation.defs#modEventLabel',
116
+ createLabelVals,
117
+ negateLabelVals,
118
+ },
119
+ createdBy: sc.dids.carol,
120
+ },
121
+ 'moderator',
122
+ )
123
+ await adjustLabels({
124
+ createLabelVals,
125
+ negateLabelVals,
126
+ uri: sc.dids.alice,
127
+ src: client.ozone.ctx.cfg.service.did,
128
+ })
129
+ }
130
+
131
+ const labelPost = async (
132
+ client: ModeratorClient,
133
+ {
134
+ createLabelVals = [],
135
+ negateLabelVals = [],
136
+ }: { createLabelVals?: string[]; negateLabelVals?: string[] },
137
+ ) => {
138
+ const subject = getPostSubject()
139
+ await client.emitEvent(
140
+ {
141
+ subject,
142
+ event: {
143
+ $type: 'tools.ozone.moderation.defs#modEventLabel',
144
+ createLabelVals,
145
+ negateLabelVals,
146
+ },
147
+ createdBy: sc.dids.carol,
148
+ },
149
+ 'moderator',
150
+ )
151
+ await adjustLabels({
152
+ createLabelVals,
153
+ negateLabelVals,
154
+ uri: subject.uri,
155
+ cid: subject.cid,
156
+ src: client.ozone.ctx.cfg.service.did,
157
+ })
158
+ }
159
+
160
+ describe('record labels', () => {
161
+ it('includes only labels from current authority by default', async () => {
162
+ await Promise.all([
163
+ labelPost(modClient, { createLabelVals: ['spam'] }),
164
+ labelPost(thirdPartyModClient, { createLabelVals: ['weird'] }),
165
+ ])
166
+
167
+ const [
168
+ { data: recordFromCurrentAuthority },
169
+ { data: recordFromThirdParty },
170
+ ] = await Promise.all([
171
+ agent.api.tools.ozone.moderation.getRecord(
172
+ { uri: sc.posts[sc.dids.alice][0].ref.uriStr },
173
+ { headers: await ozone.modHeaders() },
174
+ ),
175
+ thirdPartyAgent.api.tools.ozone.moderation.getRecord(
176
+ { uri: sc.posts[sc.dids.alice][0].ref.uriStr },
177
+ { headers: await thirdPartyLabeler.modHeaders() },
178
+ ),
179
+ ])
180
+
181
+ const currentAuthorityLabels = recordFromCurrentAuthority.labels?.map(
182
+ (l) => l.val,
183
+ )
184
+ const thirdPartyLabels = recordFromThirdParty.labels?.map((l) => l.val)
185
+ expect(currentAuthorityLabels).toContain('spam')
186
+ expect(currentAuthorityLabels).not.toContain('weird')
187
+ expect(thirdPartyLabels).toContain('weird')
188
+ expect(thirdPartyLabels).not.toContain('spam')
189
+ })
190
+
191
+ it('includes labels from all authorities requested via header', async () => {
192
+ const authHeaders = await ozone.modHeaders()
193
+ const { data: recordIncludingExternalLabels } =
194
+ await agent.api.tools.ozone.moderation.getRecord(
195
+ { uri: sc.posts[sc.dids.alice][0].ref.uriStr },
196
+ {
197
+ headers: {
198
+ ...authHeaders,
199
+ [LABELER_HEADER_NAME]: [
200
+ thirdPartyLabeler.ctx.cfg.service.did,
201
+ ozone.ctx.cfg.service.did,
202
+ ].join(','),
203
+ },
204
+ },
205
+ )
206
+ const labelVals = recordIncludingExternalLabels.labels?.map((l) => l.val)
207
+ const labelSources = recordIncludingExternalLabels.labels?.map(
208
+ (l) => l.src,
209
+ )
210
+ expect(labelVals).toContain('weird')
211
+ expect(labelVals).toContain('spam')
212
+ expect(labelSources).toContain(thirdPartyLabeler.ctx.cfg.service.did)
213
+ expect(labelSources).toContain(ozone.ctx.cfg.service.did)
214
+ })
215
+ })
216
+
217
+ describe('repo labels', () => {
218
+ it('includes only labels from current authority by default', async () => {
219
+ await Promise.all([
220
+ labelAccount(modClient, { createLabelVals: ['spam'] }),
221
+ labelAccount(thirdPartyModClient, { createLabelVals: ['weird'] }),
222
+ ])
223
+
224
+ const [{ data: repoFromCurrentAuthority }, { data: repoFromThirdParty }] =
225
+ await Promise.all([
226
+ agent.api.tools.ozone.moderation.getRepo(
227
+ { did: sc.dids.alice },
228
+ { headers: await ozone.modHeaders() },
229
+ ),
230
+ thirdPartyAgent.api.tools.ozone.moderation.getRepo(
231
+ { did: sc.dids.alice },
232
+ { headers: await thirdPartyLabeler.modHeaders() },
233
+ ),
234
+ ])
235
+
236
+ const currentAuthorityLabels = repoFromCurrentAuthority.labels?.map(
237
+ (l) => l.val,
238
+ )
239
+ const thirdPartyLabels = repoFromThirdParty.labels?.map((l) => l.val)
240
+ expect(currentAuthorityLabels).toContain('spam')
241
+ expect(currentAuthorityLabels).not.toContain('weird')
242
+ expect(thirdPartyLabels).toContain('weird')
243
+ expect(thirdPartyLabels).not.toContain('spam')
244
+ })
245
+
246
+ it('includes labels from all authorities requested via header', async () => {
247
+ const authHeaders = await ozone.modHeaders()
248
+ const { data: recordIncludingExternalLabels } =
249
+ await agent.api.tools.ozone.moderation.getRepo(
250
+ { did: sc.dids.alice },
251
+ {
252
+ headers: {
253
+ ...authHeaders,
254
+ [LABELER_HEADER_NAME]: [
255
+ thirdPartyLabeler.ctx.cfg.service.did,
256
+ ozone.ctx.cfg.service.did,
257
+ ].join(','),
258
+ },
259
+ },
260
+ )
261
+ const labelVals = recordIncludingExternalLabels.labels?.map((l) => l.val)
262
+ const labelSources = recordIncludingExternalLabels.labels?.map(
263
+ (l) => l.src,
264
+ )
265
+ expect(labelVals).toContain('weird')
266
+ expect(labelVals).toContain('spam')
267
+ expect(labelSources).toContain(thirdPartyLabeler.ctx.cfg.service.did)
268
+ expect(labelSources).toContain(ozone.ctx.cfg.service.did)
269
+ })
270
+ })
271
+ })
@@ -0,0 +1,109 @@
1
+ import {
2
+ SeedClient,
3
+ TestNetwork,
4
+ TestOzone,
5
+ basicSeed,
6
+ ModeratorClient,
7
+ RecordRef,
8
+ } from '@atproto/dev-env'
9
+ import AtpAgent, { BSKY_LABELER_DID } from '@atproto/api'
10
+ import { TAKEDOWN_LABEL } from '../src/mod-service'
11
+
12
+ describe('admin get lists', () => {
13
+ let network: TestNetwork
14
+ let ozone: TestOzone
15
+ let agent: AtpAgent
16
+ let appviewAgent: AtpAgent
17
+ let sc: SeedClient
18
+ let modClient: ModeratorClient
19
+ let alicesList: RecordRef
20
+
21
+ beforeAll(async () => {
22
+ network = await TestNetwork.create({
23
+ dbPostgresSchema: 'ozone_admin_get_lists',
24
+ })
25
+ ozone = network.ozone
26
+ agent = ozone.getClient()
27
+ appviewAgent = network.bsky.getClient()
28
+ sc = network.getSeedClient()
29
+ modClient = ozone.getModClient()
30
+ await basicSeed(sc)
31
+ alicesList = await sc.createList(sc.dids.alice, "Alice's List", 'mod')
32
+ AtpAgent.configure({ appLabelers: [ozone.ctx.cfg.service.did] })
33
+ await network.processAll()
34
+ })
35
+
36
+ afterAll(async () => {
37
+ AtpAgent.configure({ appLabelers: [BSKY_LABELER_DID] })
38
+ await network.close()
39
+ })
40
+
41
+ const getAlicesList = async () => {
42
+ const [{ data: fromOzone }, { data: fromAppview }] = await Promise.all([
43
+ agent.api.app.bsky.graph.getLists(
44
+ { actor: sc.dids.alice },
45
+ { headers: await ozone.modHeaders() },
46
+ ),
47
+ appviewAgent.api.app.bsky.graph.getLists({ actor: sc.dids.alice }),
48
+ ])
49
+
50
+ return { fromOzone, fromAppview }
51
+ }
52
+
53
+ it('returns lists from takendown account', async () => {
54
+ const beforeTakedown = await getAlicesList()
55
+ expect(beforeTakedown.fromOzone.lists[0].uri).toEqual(alicesList.uriStr)
56
+ expect(beforeTakedown.fromAppview.lists[0].uri).toEqual(alicesList.uriStr)
57
+
58
+ // Takedown alice's account
59
+ await modClient.emitEvent({
60
+ event: { $type: 'tools.ozone.moderation.defs#modEventTakedown' },
61
+ subject: {
62
+ $type: 'com.atproto.admin.defs#repoRef',
63
+ did: sc.dids.alice,
64
+ },
65
+ })
66
+ await network.processAll()
67
+
68
+ const afterTakedown = await getAlicesList()
69
+
70
+ // Verify that takendown list is shown when queried through ozone but not through appview
71
+ expect(afterTakedown.fromAppview.lists.length).toBe(0)
72
+ expect(afterTakedown.fromOzone.lists[0].uri).toEqual(alicesList.uriStr)
73
+
74
+ // Reverse alice's account takedown
75
+ await modClient.emitEvent({
76
+ event: { $type: 'tools.ozone.moderation.defs#modEventReverseTakedown' },
77
+ subject: {
78
+ $type: 'com.atproto.admin.defs#repoRef',
79
+ did: sc.dids.alice,
80
+ },
81
+ })
82
+ await network.processAll()
83
+ })
84
+
85
+ it('returns takendown lists', async () => {
86
+ const beforeTakedown = await getAlicesList()
87
+ expect(beforeTakedown.fromOzone.lists[0].uri).toEqual(alicesList.uriStr)
88
+ expect(beforeTakedown.fromAppview.lists[0].uri).toEqual(alicesList.uriStr)
89
+
90
+ // Takedown alice's list using a !takedown label
91
+ await network.bsky.db.db
92
+ .insertInto('label')
93
+ .values({
94
+ src: ozone.ctx.cfg.service.did,
95
+ uri: alicesList.uriStr,
96
+ cid: alicesList.cidStr,
97
+ val: TAKEDOWN_LABEL,
98
+ neg: false,
99
+ cts: new Date().toISOString(),
100
+ })
101
+ .execute()
102
+
103
+ const afterTakedown = await getAlicesList()
104
+
105
+ // Verify that takendown list is shown when queried through ozone but not through appview
106
+ expect(afterTakedown.fromAppview.lists.length).toBe(0)
107
+ expect(afterTakedown.fromOzone.lists[0].uri).toEqual(alicesList.uriStr)
108
+ })
109
+ })