f689bd51a2
* refactor(crypto): remove circular dependency * refactor(crypto): expose compress/decompress as part of the DidKeyPlugin interface * fix(crypto): remove import from private file * refactor: isolate tsconfig * fix: remove unused bench file * chore(repo): remove unused deps * fix(ozone): properly list dependencies * fix(services): do lint js files * fix(services/pds): remove unused deps * chore(pds): remove bench * chore(dev-env): remove unused deps * chore(api): remove bench * remove unused babel.config.js files * fix: remove .ts extension from import * fix(pds): remove imports of src files * fix(tsconfig): properly list all projects * fix(dev-env): remove imports of src files * fix(bsky): remove direct import to crypto src * fix(api): remove imports to api internals * chore(build): prevent bundling of built output * chore(dev): add "dev" script to build in watch mode * chore(deps): move ts-node dependency where it is actually used * fix(deps): add dev-env as project dependency * fix(xrpc-server): properly type kexicon * fix(bsky): improve typings * fix(pds): fully type formatRecordEmbedInternal return value * fix(repo): remove imports from @ipld/car/api * feat(dev-env): re-export BskyIngester * fix: properly lint & type jest config & test files * fix(ci): test after build * fix(types): use NodeJS.Timeout instead of NodeJS.Timer * fix(bsky): make types exportable * fix(ozone): make types exportable * fix(xrpc-server): make types exportable * fix(xprc-server): make code compliant with "node" types * fix(xrpc-server): avoid accessing properties of unknown * chore(deps): update @types/node * feat(tsconfig): narrow down available types depending on the package's target environment * fix(pds): remove unused prop * fix(bsync): Database's migrator not always initialized * fix(dev-env): remove unreachable code * fix(xrpc-server): remove unused import * fix(xrpc-server): mark header property as abstract * fix(pds): initialize LeakyTxPlugin's txOver property * fix(bsky): initialize LeakyTxPlugin's txOver property * fix(bsky): remove unused migrator from DatabaseCoordinator * fix(bsky): Properly initialize LabelService's cache property * fix(ozone): Database's migrator not initialized * fix(ozone): initialize LeakyTxPlugin's txOver property * fix(crypto): ignore unused variable error * feat(tsconfig): use stricter rules * feat(tsconfig): enable useDefineForClassFields * feat(xrpc-server): add support for brotli incoming payload * fix(xrpc-server): properly parse & process content-encoding * fix(common:stream): always call cb in _transform * tidy/fix tests and service entrypoints * Revert "fix(xrpc-server): properly parse & process content-encoding" This reverts commit 2b1c66e153820d3e128fc839fcc1834d52a66686. * Revert "feat(xrpc-server): add support for brotli incoming payload" This reverts commit e710c21e6118214ddf215b0515e68cb87299a952. * remove special node env for tests (defaults to jest val of "test") * kill mute sync handler on disconnect * work around connect-es bug w/ request aborts * style(crypto): rename imports from uint8arrays * fix update package-lock * fix lint * force hbs files to be bundled as cjs * fix: use concurrently instead of npm-run-all npm-run-all seems not to be maintained anymore. Additionally, concurrently better forwards signals to child processes. * remove concurrently alltogether * ignore sqlite files in services/pds * fix verify * fix verify * tidy, fix verify * fix blob diversion test * build rework changeset --------- Co-authored-by: Devin Ivy <devinivy@gmail.com>
260 lines
7.8 KiB
TypeScript
260 lines
7.8 KiB
TypeScript
import {
|
|
TestNetwork,
|
|
SeedClient,
|
|
basicSeed,
|
|
ModeratorClient,
|
|
} from '@atproto/dev-env'
|
|
import {
|
|
ComAtprotoModerationDefs,
|
|
ToolsOzoneModerationDefs,
|
|
} from '@atproto/api'
|
|
import {
|
|
REASONMISLEADING,
|
|
REASONSPAM,
|
|
} from '../src/lexicon/types/com/atproto/moderation/defs'
|
|
import { REVIEWESCALATED } from '../src/lexicon/types/tools/ozone/moderation/defs'
|
|
|
|
describe('moderation-appeals', () => {
|
|
let network: TestNetwork
|
|
let sc: SeedClient
|
|
let modClient: ModeratorClient
|
|
|
|
beforeAll(async () => {
|
|
network = await TestNetwork.create({
|
|
dbPostgresSchema: 'ozone_moderation_appeals',
|
|
})
|
|
sc = network.getSeedClient()
|
|
modClient = network.ozone.getModClient()
|
|
await basicSeed(sc)
|
|
await network.processAll()
|
|
})
|
|
|
|
afterAll(async () => {
|
|
await network.close()
|
|
})
|
|
|
|
const assertSubjectStatus = async (
|
|
subject: string,
|
|
status: string,
|
|
appealed: boolean | undefined,
|
|
): Promise<ToolsOzoneModerationDefs.SubjectStatusView | undefined> => {
|
|
const res = await modClient.queryStatuses({
|
|
subject,
|
|
})
|
|
expect(res.subjectStatuses[0]?.reviewState).toEqual(status)
|
|
expect(res.subjectStatuses[0]?.appealed).toEqual(appealed)
|
|
return res.subjectStatuses[0]
|
|
}
|
|
|
|
describe('appeals from users', () => {
|
|
const getBobsPostSubject = () => ({
|
|
$type: 'com.atproto.repo.strongRef',
|
|
uri: sc.posts[sc.dids.bob][1].ref.uriStr,
|
|
cid: sc.posts[sc.dids.bob][1].ref.cidStr,
|
|
})
|
|
const getCarolPostSubject = () => ({
|
|
$type: 'com.atproto.repo.strongRef',
|
|
uri: sc.posts[sc.dids.carol][0].ref.uriStr,
|
|
cid: sc.posts[sc.dids.carol][0].ref.cidStr,
|
|
})
|
|
const assertBobsPostStatus = async (
|
|
status: string,
|
|
appealed: boolean | undefined,
|
|
) => assertSubjectStatus(getBobsPostSubject().uri, status, appealed)
|
|
|
|
it('only changes subject status if original author of the content or a moderator is appealing', async () => {
|
|
// Create a report by alice
|
|
await modClient.emitEvent({
|
|
event: {
|
|
$type: 'tools.ozone.moderation.defs#modEventReport',
|
|
reportType: REASONMISLEADING,
|
|
},
|
|
subject: getBobsPostSubject(),
|
|
})
|
|
|
|
await assertBobsPostStatus(ToolsOzoneModerationDefs.REVIEWOPEN, undefined)
|
|
|
|
// Create a report as normal user with appeal type
|
|
expect(
|
|
sc.createReport({
|
|
reportedBy: sc.dids.carol,
|
|
reasonType: ComAtprotoModerationDefs.REASONAPPEAL,
|
|
reason: 'appealing',
|
|
subject: getBobsPostSubject(),
|
|
}),
|
|
).rejects.toThrow('You cannot appeal this report')
|
|
|
|
// Verify that the appeal status did not change
|
|
await assertBobsPostStatus(ToolsOzoneModerationDefs.REVIEWOPEN, undefined)
|
|
|
|
// Emit report event as moderator
|
|
await modClient.emitEvent({
|
|
event: {
|
|
$type: 'tools.ozone.moderation.defs#modEventReport',
|
|
reportType: ComAtprotoModerationDefs.REASONAPPEAL,
|
|
},
|
|
subject: getBobsPostSubject(),
|
|
})
|
|
|
|
// Verify that appeal status changed when appeal report was emitted by moderator
|
|
const status = await assertBobsPostStatus(REVIEWESCALATED, true)
|
|
expect(status?.appealedAt).not.toBeNull()
|
|
|
|
// Create a report as normal user for carol's post
|
|
await sc.createReport({
|
|
reportedBy: sc.dids.alice,
|
|
reasonType: REASONMISLEADING,
|
|
reason: 'lies!',
|
|
subject: getCarolPostSubject(),
|
|
})
|
|
|
|
// Verify that the appeal status on carol's post is undefined
|
|
await assertSubjectStatus(
|
|
getCarolPostSubject().uri,
|
|
ToolsOzoneModerationDefs.REVIEWOPEN,
|
|
undefined,
|
|
)
|
|
|
|
await sc.createReport({
|
|
reportedBy: sc.dids.carol,
|
|
reasonType: ComAtprotoModerationDefs.REASONAPPEAL,
|
|
reason: 'appealing',
|
|
subject: getCarolPostSubject(),
|
|
})
|
|
// Verify that the appeal status on carol's post is true
|
|
await assertSubjectStatus(
|
|
getCarolPostSubject().uri,
|
|
REVIEWESCALATED,
|
|
true,
|
|
)
|
|
})
|
|
it('allows multiple appeals and updates last appealed timestamp', async () => {
|
|
// Resolve appeal with acknowledge
|
|
await modClient.emitEvent({
|
|
event: {
|
|
$type: 'tools.ozone.moderation.defs#modEventResolveAppeal',
|
|
},
|
|
subject: getBobsPostSubject(),
|
|
})
|
|
|
|
const previousStatus = await assertBobsPostStatus(REVIEWESCALATED, false)
|
|
|
|
await modClient.emitEvent({
|
|
event: {
|
|
$type: 'tools.ozone.moderation.defs#modEventReport',
|
|
reportType: ComAtprotoModerationDefs.REASONAPPEAL,
|
|
},
|
|
subject: getBobsPostSubject(),
|
|
})
|
|
|
|
// Verify that even after the appeal event by bob for his post, the appeal status is true again with new timestamp
|
|
const newStatus = await assertBobsPostStatus(REVIEWESCALATED, true)
|
|
expect(
|
|
new Date(`${previousStatus?.lastAppealedAt}`).getTime(),
|
|
).toBeLessThan(new Date(`${newStatus?.lastAppealedAt}`).getTime())
|
|
})
|
|
})
|
|
|
|
describe('appeal resolution', () => {
|
|
const getAlicesPostSubject = () => ({
|
|
$type: 'com.atproto.repo.strongRef',
|
|
uri: sc.posts[sc.dids.alice][1].ref.uriStr,
|
|
cid: sc.posts[sc.dids.alice][1].ref.cidStr,
|
|
})
|
|
it('appeal status is maintained while review state changes based on incoming events', async () => {
|
|
// Bob reports alice's post
|
|
await modClient.emitEvent({
|
|
event: {
|
|
$type: 'tools.ozone.moderation.defs#modEventReport',
|
|
reportType: REASONMISLEADING,
|
|
},
|
|
subject: getAlicesPostSubject(),
|
|
})
|
|
|
|
// Moderator acknowledges the report, assume a label was applied too
|
|
await modClient.emitEvent({
|
|
event: {
|
|
$type: 'tools.ozone.moderation.defs#modEventAcknowledge',
|
|
},
|
|
subject: getAlicesPostSubject(),
|
|
})
|
|
|
|
// Alice appeals the report
|
|
await modClient.emitEvent({
|
|
event: {
|
|
$type: 'tools.ozone.moderation.defs#modEventReport',
|
|
reportType: ComAtprotoModerationDefs.REASONAPPEAL,
|
|
},
|
|
subject: getAlicesPostSubject(),
|
|
})
|
|
|
|
await assertSubjectStatus(
|
|
getAlicesPostSubject().uri,
|
|
REVIEWESCALATED,
|
|
true,
|
|
)
|
|
|
|
// Bob reports it again
|
|
await modClient.emitEvent({
|
|
event: {
|
|
$type: 'tools.ozone.moderation.defs#modEventReport',
|
|
reportType: REASONSPAM,
|
|
},
|
|
subject: getAlicesPostSubject(),
|
|
})
|
|
|
|
// Assert that the status is still REVIEWESCALATED, as report events are meant to do
|
|
await assertSubjectStatus(
|
|
getAlicesPostSubject().uri,
|
|
REVIEWESCALATED,
|
|
true,
|
|
)
|
|
|
|
// Emit an escalation event
|
|
await modClient.emitEvent({
|
|
event: {
|
|
$type: 'tools.ozone.moderation.defs#modEventEscalate',
|
|
},
|
|
subject: getAlicesPostSubject(),
|
|
})
|
|
|
|
await assertSubjectStatus(
|
|
getAlicesPostSubject().uri,
|
|
REVIEWESCALATED,
|
|
true,
|
|
)
|
|
|
|
// Emit an acknowledge event
|
|
await modClient.emitEvent({
|
|
event: {
|
|
$type: 'tools.ozone.moderation.defs#modEventAcknowledge',
|
|
},
|
|
subject: getAlicesPostSubject(),
|
|
})
|
|
|
|
// Assert that status moved on to reviewClosed while appealed status is still true
|
|
await assertSubjectStatus(
|
|
getAlicesPostSubject().uri,
|
|
ToolsOzoneModerationDefs.REVIEWCLOSED,
|
|
true,
|
|
)
|
|
|
|
// Emit a resolveAppeal event
|
|
await modClient.emitEvent({
|
|
event: {
|
|
$type: 'tools.ozone.moderation.defs#modEventResolveAppeal',
|
|
comment: 'lgtm',
|
|
},
|
|
subject: getAlicesPostSubject(),
|
|
})
|
|
|
|
// Assert that status stayed the same while appealed status is still true
|
|
await assertSubjectStatus(
|
|
getAlicesPostSubject().uri,
|
|
ToolsOzoneModerationDefs.REVIEWCLOSED,
|
|
false,
|
|
)
|
|
})
|
|
})
|
|
})
|