Skip to content

Commit

Permalink
fix: service validation in OOB invitation objects (#1575)
Browse files Browse the repository at this point in the history
Signed-off-by: Ariel Gentile <gentilester@gmail.com>
  • Loading branch information
genaris committed Sep 29, 2023
1 parent c2bb2a5 commit 91a9434
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 1 deletion.
@@ -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
Expand Up @@ -150,7 +150,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

0 comments on commit 91a9434

Please sign in to comment.