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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: service validation in OOB invitation objects #1575

Merged
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
import type { ClassValidationError } from '../../../error/ClassValidationError'

import { Attachment } from '../../../decorators/attachment/Attachment'
import { MessageValidator } from '../../../utils'
import { JsonEncoder } from '../../../utils/JsonEncoder'
import { JsonTransformer } from '../../../utils/JsonTransformer'
import { HandshakeProtocol } from '../../connections'
import { OutOfBandDidCommService } from '../domain'
import { OutOfBandInvitation } from '../messages/OutOfBandInvitation'

describe('toUrl', () => {
Expand All @@ -26,6 +29,54 @@ describe('toUrl', () => {
})
})

describe('validation', () => {
test('Out-of-Band Invitation instance with did as service', async () => {
const invitation = new OutOfBandInvitation({
id: '69212a3a-d068-4f9d-a2dd-4741bca89af3',
label: 'Faber College',
services: ['did:sov:LjgpST2rjsoxYegQDRm7EL'],
handshakeProtocols: [HandshakeProtocol.DidExchange],
})

expect(() => MessageValidator.validateSync(invitation)).not.toThrow()
})

test('Out-of-Band Invitation instance with object as service', async () => {
const invitation = new OutOfBandInvitation({
id: '69212a3a-d068-4f9d-a2dd-4741bca89af3',
label: 'Faber College',
services: [
new OutOfBandDidCommService({
id: 'didcomm',
serviceEndpoint: 'http://endpoint',
recipientKeys: ['did:key:z6MkqgkLrRyLg6bqk27djwbbaQWgaSYgFVCKq9YKxZbNkpVv'],
}),
],
handshakeProtocols: [HandshakeProtocol.DidExchange],
})

expect(() => MessageValidator.validateSync(invitation)).not.toThrow()
})

test('Out-of-Band Invitation instance with string and object as services', async () => {
const invitation = new OutOfBandInvitation({
id: '69212a3a-d068-4f9d-a2dd-4741bca89af3',
label: 'Faber College',
services: [
'did:sov:LjgpST2rjsoxYegQDRm7EL',
new OutOfBandDidCommService({
id: 'didcomm',
serviceEndpoint: 'http://endpoint',
recipientKeys: ['did:key:z6MkqgkLrRyLg6bqk27djwbbaQWgaSYgFVCKq9YKxZbNkpVv'],
}),
],
handshakeProtocols: [HandshakeProtocol.DidExchange],
})

expect(() => MessageValidator.validateSync(invitation)).not.toThrow()
})
})

describe('fromUrl', () => {
test('decode the URL containing the base64 encoded invitation as the oob parameter into an `OutOfBandInvitation`', () => {
const invitationUrl =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,6 @@ export class OutOfBandInvitation extends AgentMessage {
@ArrayNotEmpty()
@OutOfBandServiceTransformer()
@IsStringOrInstance(OutOfBandDidCommService, { each: true })
@ValidateNested({ each: true })
// eslint-disable-next-line @typescript-eslint/ban-types
private services!: Array<OutOfBandDidCommService | string | String>

Expand Down