Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(data-store): match claims by credential hash when deleting credential #1270

Merged
merged 1 commit into from
Oct 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions __tests__/localJsonStoreAgent.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ import messageHandler from './shared/messageHandler'
import utils from './shared/utils'
import { JsonFileStore } from './utils/json-file-store'
import credentialStatus from './shared/credentialStatus'
import dbInitOptions from "./shared/dbInitOptions";

jest.setTimeout(120000)

Expand Down Expand Up @@ -238,4 +239,5 @@ describe('Local json-data-store integration tests', () => {
didCommPacking(testContext)
utils(testContext)
credentialStatus(testContext)
dbInitOptions(testContext)
})
47 changes: 47 additions & 0 deletions __tests__/shared/dbInitOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,53 @@ export default (testContext: {
})
expect(retrievedCredential.length).toBeGreaterThan(0)
})

it('should delete credentials without clearing the claims table', async () => {
const credA = await agent.createVerifiableCredential({
proofFormat: 'jwt',
credential: {
type: ['Important'],
credentialSubject: {
important: 'yes',
serious: true,
},
issuer: identifier.did,
},
})
const credB = await agent.createVerifiableCredential({
proofFormat: 'jwt',
credential: {
type: ['Unimportant'],
credentialSubject: {
bla: 'bla',
},
issuer: identifier.did,
},
})

const credAhash = await agent.dataStoreSaveVerifiableCredential({ verifiableCredential: credA })
const credBhash = await agent.dataStoreSaveVerifiableCredential({ verifiableCredential: credB })

const queryBeforeDelete = await agent.dataStoreORMGetVerifiableCredentialsByClaims({
where: [
{ column: 'type', value: ['important'] },
{ column: 'value', value: ['yes'] },
],
})
expect(queryBeforeDelete.length).toBeGreaterThan(0)
expect(queryBeforeDelete[0].hash).toEqual(credAhash)

await agent.dataStoreDeleteVerifiableCredential({ hash: credBhash })

const queryAfterDelete = await agent.dataStoreORMGetVerifiableCredentialsByClaims({
where: [
{ column: 'type', value: ['important'] },
{ column: 'value', value: ['yes'] },
],
})
expect(queryAfterDelete.length).toBeGreaterThan(0)
expect(queryAfterDelete[0].hash).toEqual(credAhash)
})
})
}
})
Expand Down
2 changes: 1 addition & 1 deletion packages/data-store/src/data-store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ export class DataStore implements IAgentPlugin {

const claims = await (await getConnectedDb(this.dbConnection))
.getRepository(Claim)
.find({ where: { credential: { id: credentialEntity.id } } as any })
.find({ where: { credential: { hash: credentialEntity.hash } } })

await (await getConnectedDb(this.dbConnection)).getRepository(Claim).remove(claims)

Expand Down