b934b396b1
* feat(api): support creation of oauth based AtpAgents * oauth: misc fixes for confidential clients * fix(xprc): remove ReadableStream.from polyfill * OAuth docs tweaks (#2679) * OAuth: clarification about client_name being shown * OAuth: re-write handle resolution privacy concern * avoid relying on ReadableStream.from in xrpc-server tests * feat(oauth-types): expose "ALLOW_UNSECURE_ORIGINS" constant * feat(handle-resolver): expose "AtprotoIdentityDidMethods" type * fix(oauth-client): ensure that the oauth metadata document contains client_id_metadata_document_supported * fix(oauth-types): prevent unknown query string in loopback client id * fix(identity-resolver): check that handle is in did doc's "alsoKnownAs" * feat(oauth-client:oauth-resolver): allow logging in using either the PDS URL or Entryway URL * fix(oauth-client): return better error in case of invalid "oauth-protected-resource" status code * refactor(did): group atproto specific checks in own * feat(api): relax typing of "appLabelers" and "labelers" AtpClient properties * allow any did as labeller (for tests mainly) * fix(api): allow to override "atproto-proxy" on a per-request basis * remove release candidate versions from changelog * update changeset for api and xrpc packages * Add missing changeset * revert RC versions * Proper wording in OAUTH.md api example * remove "pre" changeset file * xrpc: restore original behavior of setHEader and unsetHeader * docs: add comment for XrpcClient 's constructor arg * feat(api): expose "schemas" publicly * feat(api): allow customizing the whatwg fetch function of the AtpAgent * docs(api): improve migration docs * docs: change reference to BskyAgent to AtpAgent * docs: mention the breaking change regarding setSessionPersistHandler * fix(api): better split AtpClient concerns * fix(xrpc): remove unused import * refactor(api): simplify class hierarchu by removeing AtpClient * fix(api): mock proper method for facets detection * restore ability to restore session asynchronously * feat(api): allow instantiating Agent with same argument as super class * docs(api): properly extend Agent class * style(xrpc): var name * docs(api): remove "async" to header getter --------- Co-authored-by: Devin Ivy <devinivy@gmail.com> Co-authored-by: bnewbold <bnewbold@robocracy.org> Co-authored-by: Hailey <me@haileyok.com>
89 lines
2.5 KiB
TypeScript
89 lines
2.5 KiB
TypeScript
import { AtpAgent } from '@atproto/api'
|
|
import { wait } from '@atproto/common'
|
|
import { TestNetworkNoAppView } from '@atproto/dev-env'
|
|
import { readCarWithRoot, verifyRepo } from '@atproto/repo'
|
|
import AppContext from '../src/context'
|
|
import { PreparedCreate, prepareCreate } from '../src/repo'
|
|
import { Keypair } from '@atproto/crypto'
|
|
|
|
describe('races', () => {
|
|
let network: TestNetworkNoAppView
|
|
let ctx: AppContext
|
|
let agent: AtpAgent
|
|
let did: string
|
|
let signingKey: Keypair
|
|
|
|
beforeAll(async () => {
|
|
network = await TestNetworkNoAppView.create({
|
|
dbPostgresSchema: 'races',
|
|
})
|
|
// @ts-expect-error Error due to circular dependency with the dev-env package
|
|
ctx = network.pds.ctx
|
|
agent = network.pds.getClient()
|
|
await agent.createAccount({
|
|
email: 'alice@test.com',
|
|
handle: 'alice.test',
|
|
password: 'alice-pass',
|
|
})
|
|
did = agent.accountDid
|
|
signingKey = await network.pds.ctx.actorStore.keypair(did)
|
|
})
|
|
|
|
afterAll(async () => {
|
|
await network.close()
|
|
})
|
|
|
|
const processCommitWithWait = async (
|
|
did: string,
|
|
write: PreparedCreate,
|
|
waitMs: number,
|
|
) => {
|
|
const now = new Date().toISOString()
|
|
return ctx.actorStore.transact(did, async (store) => {
|
|
const commitData = await store.repo.formatCommit([write])
|
|
await store.repo.storage.applyCommit(commitData)
|
|
await wait(waitMs)
|
|
await store.repo.indexWrites([write], now)
|
|
return write
|
|
})
|
|
}
|
|
|
|
it('handles races in record routes', async () => {
|
|
const write = await prepareCreate({
|
|
did,
|
|
collection: 'app.bsky.feed.post',
|
|
record: {
|
|
text: 'one',
|
|
createdAt: new Date().toISOString(),
|
|
},
|
|
validate: true,
|
|
})
|
|
|
|
const processPromise = processCommitWithWait(did, write, 500)
|
|
|
|
const createdPost = await agent.api.app.bsky.feed.post.create(
|
|
{ repo: did },
|
|
{ text: 'two', createdAt: new Date().toISOString() },
|
|
)
|
|
|
|
await processPromise
|
|
|
|
const listed = await agent.api.app.bsky.feed.post.list({ repo: did })
|
|
expect(listed.records.length).toBe(2)
|
|
|
|
const carRes = await agent.api.com.atproto.sync.getRepo({ did })
|
|
const car = await readCarWithRoot(carRes.data)
|
|
const verified = await verifyRepo(
|
|
car.blocks,
|
|
car.root,
|
|
did,
|
|
signingKey.did(),
|
|
)
|
|
expect(verified.creates.length).toBe(2)
|
|
expect(verified.creates[0].cid.toString()).toEqual(write.cid.toString())
|
|
expect(verified.creates[1].cid.toString()).toEqual(
|
|
createdPost.cid.toString(),
|
|
)
|
|
})
|
|
})
|