Fork of github.com/did-method-plc/did-method-plc
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

split server tests across two dids, to avoid rate limits

+54 -45
+54 -45
packages/server/tests/server.test.ts
··· 6 6 import { didForCreateOp, PlcClientError } from '@did-plc/lib' 7 7 8 8 describe('PLC server', () => { 9 - let handle = 'at://alice.example.com' 9 + let handle1 = 'at://alice.example.com' 10 + let handle2 = 'at://bob.example.com' 10 11 let atpPds = 'https://example.com' 11 12 12 13 let close: CloseFn ··· 16 17 let signingKey: P256Keypair 17 18 let rotationKey1: P256Keypair 18 19 let rotationKey2: P256Keypair 20 + let rotationKey3: P256Keypair 19 21 20 - let did: string 22 + let did1: string 23 + let did2: string 21 24 22 25 beforeAll(async () => { 23 26 const server = await runTestServer({ ··· 30 33 signingKey = await P256Keypair.create() 31 34 rotationKey1 = await P256Keypair.create() 32 35 rotationKey2 = await P256Keypair.create() 36 + rotationKey3 = await P256Keypair.create() 33 37 }) 34 38 35 39 afterAll(async () => { ··· 42 46 if (!doc) { 43 47 throw new Error('expected doc') 44 48 } 45 - expect(doc.did).toEqual(did) 49 + expect(doc.did).toEqual(did1) 46 50 expect(doc.verificationMethods).toEqual({ atproto: signingKey.did() }) 47 51 expect(doc.rotationKeys).toEqual([rotationKey1.did(), rotationKey2.did()]) 48 - expect(doc.alsoKnownAs).toEqual([handle]) 52 + expect(doc.alsoKnownAs).toEqual([handle1]) 49 53 expect(doc.services).toEqual({ 50 54 atproto_pds: { 51 55 type: 'AtprotoPersonalDataServer', ··· 55 59 } 56 60 57 61 it('registers a did', async () => { 58 - did = await client.createDid({ 62 + did1 = await client.createDid({ 59 63 signingKey: signingKey.did(), 60 64 rotationKeys: [rotationKey1.did(), rotationKey2.did()], 61 - handle, 65 + handle: handle1, 62 66 pds: atpPds, 63 67 signer: rotationKey1, 64 68 }) 69 + 70 + did2 = await client.createDid({ 71 + signingKey: signingKey.did(), 72 + rotationKeys: [rotationKey3.did()], 73 + handle: handle2, 74 + pds: atpPds, 75 + signer: rotationKey3, 76 + }) 65 77 }) 66 78 67 79 it('retrieves did doc data', async () => { 68 - const doc = await client.getDocumentData(did) 80 + const doc = await client.getDocumentData(did1) 69 81 verifyDoc(doc) 70 82 }) 71 83 72 84 it('can perform some updates', async () => { 73 85 const newRotationKey = await P256Keypair.create() 74 86 signingKey = await P256Keypair.create() 75 - handle = 'at://ali.example2.com' 87 + handle1 = 'at://ali.example2.com' 76 88 atpPds = 'https://example2.com' 77 89 78 - await client.updateAtprotoKey(did, rotationKey1, signingKey.did()) 79 - await client.updateRotationKeys(did, rotationKey1, [ 90 + await client.updateAtprotoKey(did1, rotationKey1, signingKey.did()) 91 + await client.updateRotationKeys(did1, rotationKey1, [ 80 92 newRotationKey.did(), 81 93 rotationKey2.did(), 82 94 ]) 83 95 rotationKey1 = newRotationKey 84 96 85 - await client.updateHandle(did, rotationKey1, handle) 86 - await client.updatePds(did, rotationKey1, atpPds) 97 + await client.updateHandle(did1, rotationKey1, handle1) 98 + await client.updatePds(did1, rotationKey1, atpPds) 87 99 88 - const doc = await client.getDocumentData(did) 100 + const doc = await client.getDocumentData(did1) 89 101 verifyDoc(doc) 90 102 }) 91 103 ··· 94 106 const newRotationKey = 95 107 'did:key:z6MkjwbBXZnFqL8su24wGL2Fdjti6GSLv9SWdYGswfazUPm9' 96 108 97 - const promise = client.updateRotationKeys(did, rotationKey1, [ 98 - rotationKey1.did(), 109 + const promise = client.updateRotationKeys(did2, rotationKey3, [ 110 + rotationKey2.did(), 99 111 newRotationKey, 100 112 ]) 101 113 await expect(promise).rejects.toThrow(PlcClientError) ··· 108 120 109 121 // Note: atproto itself does not currently support ed25519 keys, but PLC 110 122 // does not have opinions about atproto (or other services!) 111 - await client.updateAtprotoKey(did, rotationKey1, newSigningKey) 123 + await client.updateAtprotoKey(did2, rotationKey3, newSigningKey) 112 124 113 125 // a BLS12-381 key 114 126 const exoticSigningKeyFromTheFuture = 115 127 'did:key:zUC7K4ndUaGZgV7Cp2yJy6JtMoUHY6u7tkcSYUvPrEidqBmLCTLmi6d5WvwnUqejscAkERJ3bfjEiSYtdPkRSE8kSa11hFBr4sTgnbZ95SJj19PN2jdvJjyzpSZgxkyyxNnBNnY' 116 128 await client.updateAtprotoKey( 117 - did, 118 - rotationKey1, 129 + did2, 130 + rotationKey3, 119 131 exoticSigningKeyFromTheFuture, 120 132 ) 121 - 122 - // put the old key back so as not to disrupt the other tests 123 - await client.updateAtprotoKey(did, rotationKey1, signingKey.did()) 124 133 }) 125 134 126 135 it('does not allow syntactically invalid service keys', async () => { 127 136 const promise = client.updateAtprotoKey( 128 - did, 129 - rotationKey1, 137 + did2, 138 + rotationKey3, 130 139 'did:banana', // a malformed did:key 131 140 ) 132 141 await expect(promise).rejects.toThrow(PlcClientError) 133 142 const promise2 = client.updateAtprotoKey( 134 - did, 135 - rotationKey1, 143 + did2, 144 + rotationKey3, 136 145 'blah', // an even more malformed did:key 137 146 ) 138 147 await expect(promise2).rejects.toThrow(PlcClientError) 139 148 }) 140 149 141 150 it('retrieves the operation log', async () => { 142 - const doc = await client.getDocumentData(did) 143 - const ops = await client.getOperationLog(did) 144 - const computedDoc = await plc.validateOperationLog(did, ops) 151 + const doc = await client.getDocumentData(did1) 152 + const ops = await client.getOperationLog(did1) 153 + const computedDoc = await plc.validateOperationLog(did1, ops) 145 154 expect(computedDoc).toEqual(doc) 146 155 }) 147 156 148 157 it('rejects on bad updates', async () => { 149 158 const newKey = await P256Keypair.create() 150 - const operation = client.updateAtprotoKey(did, newKey, newKey.did()) 159 + const operation = client.updateAtprotoKey(did1, newKey, newKey.did()) 151 160 await expect(operation).rejects.toThrow() 152 161 }) 153 162 154 163 it('allows for recovery through a forked history', async () => { 155 164 const attackerKey = await P256Keypair.create() 156 - await client.updateRotationKeys(did, rotationKey2, [attackerKey.did()]) 165 + await client.updateRotationKeys(did1, rotationKey2, [attackerKey.did()]) 157 166 158 167 const newKey = await P256Keypair.create() 159 - const ops = await client.getOperationLog(did) 168 + const ops = await client.getOperationLog(did1) 160 169 const forkPoint = ops.at(-2) 161 170 if (!check.is(forkPoint, plc.def.operation)) { 162 171 throw new Error('Could not find fork point') ··· 165 174 rotationKey1.did(), 166 175 newKey.did(), 167 176 ]) 168 - await client.sendOperation(did, op) 177 + await client.sendOperation(did1, op) 169 178 170 179 rotationKey2 = newKey 171 180 172 - const doc = await client.getDocumentData(did) 181 + const doc = await client.getDocumentData(did1) 173 182 verifyDoc(doc) 174 183 }) 175 184 176 185 it('retrieves the auditable operation log', async () => { 177 - const log = await client.getOperationLog(did) 178 - const auditable = await client.getAuditableLog(did) 186 + const log = await client.getOperationLog(did1) 187 + const auditable = await client.getAuditableLog(did1) 179 188 // has one nullifed op 180 189 expect(auditable.length).toBe(log.length + 1) 181 190 expect(auditable.filter((op) => op.nullified).length).toBe(1) ··· 186 195 }) 187 196 188 197 it('retrieves the did doc', async () => { 189 - const data = await client.getDocumentData(did) 190 - const doc = await client.getDocument(did) 198 + const data = await client.getDocumentData(did1) 199 + const doc = await client.getDocument(did1) 191 200 expect(doc).toEqual(plc.formatDidDoc(data)) 192 201 }) 193 202 ··· 223 232 await Promise.all( 224 233 keys.map(async (key) => { 225 234 try { 226 - await client.updateAtprotoKey(did, rotationKey1, key.did()) 235 + await client.updateAtprotoKey(did1, rotationKey1, key.did()) 227 236 successes++ 228 237 } catch (err) { 229 238 failures++ ··· 233 242 expect(successes).toBe(1) 234 243 expect(failures).toBe(19) 235 244 236 - const ops = await client.getOperationLog(did) 237 - await plc.validateOperationLog(did, ops) 245 + const ops = await client.getOperationLog(did1) 246 + await plc.validateOperationLog(did1, ops) 238 247 }) 239 248 240 249 it('tombstones the did', async () => { 241 - await client.tombstone(did, rotationKey1) 250 + await client.tombstone(did1, rotationKey1) 242 251 243 - const promise = client.getDocument(did) 252 + const promise = client.getDocument(did1) 244 253 await expect(promise).rejects.toThrow(PlcClientError) 245 - const promise2 = client.getDocumentData(did) 254 + const promise2 = client.getDocumentData(did1) 246 255 await expect(promise2).rejects.toThrow(PlcClientError) 247 256 }) 248 257 249 258 it('exports the data set', async () => { 250 259 const data = await client.export() 251 260 expect(data.every((row) => check.is(row, plc.def.exportedOp))).toBeTruthy() 252 - expect(data.length).toBe(31) 261 + expect(data.length).toBe(32) 253 262 for (let i = 1; i < data.length; i++) { 254 263 expect(data[i].createdAt >= data[i - 1].createdAt).toBeTruthy() 255 264 } ··· 261 270 type: 'create', 262 271 signingKey: signingKey.did(), 263 272 recoveryKey: rotationKey1.did(), 264 - handle, 273 + handle: handle1, 265 274 service: atpPds, 266 275 prev: null, 267 276 },