atproto/packages/bsky/tests/blob-resolver.test.ts
Daniel Holmgren f65de89eed
Feature: Appview v2 ()
* add buf & connectrpc, codegen client

* lint

* prettier ignore

* fix prettier ignore

* tidy & add tests

* filler commit

* rm filler

* server boilerplate

* follows impl

* posts impl

* posts & likes impl

* repost impl

* profiles & handle null values

* list impl

* mutes impl

* blocks impl

* misc

* feed gen impl

* label impl

* notifs impl

* feeds impl

* threads impl

* early sketchwork

* wip

* stub out thick client

* in-progress work on hydrator

* tweak

* hydrate profile labels, detail lists

* feedgen hydration

* protobuf tweaks

* more protobuf tweaks

* wip

* snake case

* moar snake case

* tidy actor hydration

* tidy parsing

* type fixes, renaming, comments in hydrator

* hydrate list items and likes

* hydrate notifications

* feed hydration

* graph & label hydration

* more record protobufs

* pluralize

* tweak pbs

* use new methods

* Setup dataplane grpc client/mock server ()

* add buf & connectrpc, codegen client

* lint

* prettier ignore

* fix prettier ignore

* tidy & add tests

* add record getter mocks

* post view hydration

* fix up mock dataplane to match new protos

* missed one

* wire up dataplane in ctx & dev-env

* adding some basic views

* feed hydration, add blocks to post hydration

* pass over notification hydration

* tidy

* merge

* implement getProfile

* hydrate post aggregation and viewer state

* fix

* fix codegen

* get some tests passing!

* add takedowns & some like bugfixing

* all profile tests passing!

* likes test

* follow endpoints using data plane

* reorg follow block rules

* reposts

* post views!

* implement getList w/ dataplane caveat

* adjust dataplane getListMembers to return listitem uris

* implement getListMutes and -Blocks w/ dataplane

* suggestions

* timeline

* misc view fixes

* view fixes for mutes, self-mute/block

* author feed

* feed gen routes

* tidy

* misc block/mute fixes

* list feed & actor likes

* implement getLists, fix some empty cursors

* implement getMutes, empty profile description fix

* implement getBlocks, block application fix

* implement getSuggestedFollowsByActor, needs some fixes

* feed generation

* search routes

* threads

* tidy

* fix some snaps

* fix getSuggestedFollowsByActor

* implement listNotifications

* implement getUnreadCount w/ dataplane

* implement notifications.updateSeen w/ dataplane

* 3rd party blocking tests

* blocked profile viewer

* add search mocks

* refactor getFeed

* createPipeline -> createPipelineNew

* basic replygating functionality on dataplane w/o filtering violating replies

* hack threadgates into dataplane, apply gates

* deterministic thread orders in dataplane

* misc cleanup around dataplane

* upgrade typescript to v5.3

* update typescript linter deps

* sync bsky proto, codegen

* update dataplane, sync with bsky proto updates

* remove indexer, ingester, daemon, moderation services from appview

* convert more bsky internals to dataplane, remove custom feedgens, implement mute/unmuting in mock dataplane

* remove bsky services. db and indexing logic into mock dataplane.

* remove tests not needed by appview v2, misc reorg

* add basic in-mem repo subscription to dataplane mock

* fix dev-env, bsky tests, bsky build

* cull bsky service entrypoint

* add bsky service readme

* build

* tidy

* tidy, fix pds proxy tests

* fix

* fix bsky entrypoint deps

* support http2 grpc client

* build

* fix dataplane bad tls config/default

* support multiple dataplane urls, retry when unavailable

* build

* tidy/fix

* move dataplane mock tests into their own dir

* cover label hydration through timeline test

* bring back labels in appview tests

* remove unused db primary/replica/coordinator from bsky dataplane

* bsky proto add cids to contracts, buf codegen

* sync-up bsky data-plane w/ codegen updates

* start using dataplane interaction endpoints

* add file

* avoid overfetching from dataplane, plumb feed items and cids

* pass refs through for post viewer state

* switch list feeds to use feed item in dataplane

* handle not found err on get-thread dataplane call

* support use of search service rather than dataplane methods

* mark some appview v2 todos

* tidy

* still use dataplane on search endpoints when search service is not configured

* fix pds test

* fix up bsky tests & snaps

* tidy migrations

* fix appview-v2 docker build

* Support label issuer tied to appview v2 ()

support label issuer tied to appview

* Appview v2: handle empty cursor on list notifications ()

handle empty cursor on appview listnotifs

* Update appview v2 to use author feed enum ()

* update bsky protos with author feed enum, misc feed item changes

* support new author feed enums in dataplane

* fix build

* Appview v2: utilize sorted-at field in bsky protos ()

utilize new sorted-at field in bsky protos

* remove all dataplane usage of GetLikeCounts, switch to GetInteractionCounts

* Appview v2, sync w/ changes to protos ()

* sync bsky protos

* sync-up bsky implementation w/ proto changes

* Appview v2 initial implementation for getPopularFeedGenerators ()

add an initial implementation for getPopularFeedGenerators on appview v2

* merge

* fixes

* fix feed tests

* fix bsync mock

* format

* remove unused config

* fix lockfile

* another lockfile fix

* fix duplicate type

* fix dupplicate test

* Appview v2 handling clearly bad cursors ()

* make mock dataplane cursors different from v1 cursors

* fail open on clearly bad appview cursors

* fix pds appview proxy snaps

* Appview v2 no notifs seen behavior ()

* alter behavior for presenting notifications w/ no last-seen time

* fix pds proxy tests

* Appview v2 dataplane retries based on client host ()

choose dataplane client for retries based on host when possible/relevant

* don't apply negated labels

* display suspensions on actor profile in appview v2

* Appview v2 use dataplane for identity lookups ()

* update bsky proto w/ identity methods

* setup identity endpoints on mock dataplane

* move from idresolver to dataplane for identity lookups on appview

* tidy

* Appview v2: apply safe takedown refs to records, actors ()

apply safe takedown refs to records, actors

* Fix timing on appview v2 repo rev header ()

fix timing on appview repo rev

* fix post thread responses

* Appview v2 don't apply 3p self blocks ()

do not apply 3p self-blocks

* Appview v2 search for feed generators ()

* add protos for feedgen search

* support feed search on getPopularFeedGenerators

* Appview v2 config tidy ()

* remove mod and triage roles from appview

* rename cdn and search config

* remove custom feed harness from appview v2

* Appview v2: don't apply missing modlists ()

* dont apply missing mod lists

* update mock dataplane

* Update packages/bsky/src/hydration/hydrator.ts

Co-authored-by: devin ivy <devinivy@gmail.com>

* refactor & document a bit better

* fix up other routes

---------

Co-authored-by: devin ivy <devinivy@gmail.com>

* Appview v2 enforce post thread root boundary ()

* enforce post thread root boundary

* test thread root boundary

* Appview v2 fix admin environment variable ()

fix admin env in appview v2

* Remove re-pagination from getSuggestions ()

* remove re-pagination from getSuggestions

* fix test

* Adjust wording for account suspension ()

adjust wording for account suspension

* Appview v2: fix not-found and blocked uris in threads ()

* fix uris of not-found and blocked posts in threads

* update snaps

*  Show author feed of takendown author to admins only ()

* fold in cid, auth, tracing, node version changes

* remove dead config from bsky service entrypoint

* build

* remove ozone test codepaths for appview v2

* tidy, docs fix

---------

Co-authored-by: Devin Ivy <devinivy@gmail.com>
Co-authored-by: Foysal Ahamed <foysal@blueskyweb.xyz>
2024-02-27 15:22:55 -05:00

100 lines
2.9 KiB
TypeScript

import axios, { AxiosInstance } from 'axios'
import { CID } from 'multiformats/cid'
import { cidForCbor, verifyCidForBytes } from '@atproto/common'
import { TestNetwork, basicSeed } from '@atproto/dev-env'
import { randomBytes } from '@atproto/crypto'
describe('blob resolver', () => {
let network: TestNetwork
let client: AxiosInstance
let fileDid: string
let fileCid: CID
beforeAll(async () => {
network = await TestNetwork.create({
dbPostgresSchema: 'bsky_blob_resolver',
})
const sc = network.getSeedClient()
await basicSeed(sc)
await network.processAll()
fileDid = sc.dids.carol
fileCid = sc.posts[fileDid][0].images[0].image.ref
client = axios.create({
baseURL: network.bsky.url,
validateStatus: () => true,
})
})
afterAll(async () => {
await network.close()
})
it('resolves blob with good signature check.', async () => {
const { data, status, headers } = await client.get(
`/blob/${fileDid}/${fileCid.toString()}`,
{ responseType: 'arraybuffer' },
)
expect(status).toEqual(200)
expect(headers['content-type']).toEqual('image/jpeg')
expect(headers['content-security-policy']).toEqual(
`default-src 'none'; sandbox`,
)
expect(headers['x-content-type-options']).toEqual('nosniff')
await expect(verifyCidForBytes(fileCid, data)).resolves.toBeUndefined()
})
it('404s on missing blob.', async () => {
const badCid = await cidForCbor({ unknown: true })
const { data, status } = await client.get(
`/blob/${fileDid}/${badCid.toString()}`,
)
expect(status).toEqual(404)
expect(data).toEqual({
error: 'NotFoundError',
message: 'Blob not found',
})
})
it('404s on missing identity.', async () => {
const { data, status } = await client.get(
`/blob/did:plc:unknown/${fileCid.toString()}`,
)
expect(status).toEqual(404)
expect(data).toEqual({
error: 'NotFoundError',
message: 'Origin not found',
})
})
it('400s on invalid did.', async () => {
const { data, status } = await client.get(
`/blob/did::/${fileCid.toString()}`,
)
expect(status).toEqual(400)
expect(data).toEqual({
error: 'BadRequestError',
message: 'Invalid did',
})
})
it('400s on invalid cid.', async () => {
const { data, status } = await client.get(`/blob/${fileDid}/barfy`)
expect(status).toEqual(400)
expect(data).toEqual({
error: 'BadRequestError',
message: 'Invalid cid',
})
})
it('fails on blob with bad signature check.', async () => {
await network.pds.ctx.blobstore(fileDid).delete(fileCid)
await network.pds.ctx
.blobstore(fileDid)
.putPermanent(fileCid, randomBytes(100))
const tryGetBlob = client.get(`/blob/${fileDid}/${fileCid.toString()}`)
await expect(tryGetBlob).rejects.toThrow(
'maxContentLength size of -1 exceeded',
)
})
})