github.com/kaleido-io/firefly@v0.0.0-20210622132723-8b4b6aacb971/kat/src/test/corda/assets/argument-validation.ts (about) 1 // Copyright © 2021 Kaleido, Inc. 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 import { app } from '../../common'; 16 import request from 'supertest'; 17 import assert from 'assert'; 18 19 export const testAssetArgumentValidation = () => { 20 describe('Asset definitions - argument validation', async () => { 21 22 it('Attempting to get an asset definition that does not exist should raise an error', async () => { 23 const result = await request(app) 24 .get('/api/v1/assets/definitions/1000000') 25 .expect(404); 26 assert.deepStrictEqual(result.body, { error: 'Asset definition not found' }); 27 }); 28 29 it('Attempting to add an asset definition without a name should raise an error', async () => { 30 const result = await request(app) 31 .post('/api/v1/assets/definitions') 32 .send({ 33 author: 'CN=Node of node1 for env1, O=Kaleido, L=Raleigh, C=US', 34 isContentPrivate: false, 35 isContentUnique: true 36 }) 37 .expect(400); 38 assert.deepStrictEqual(result.body, { error: 'Missing or invalid asset definition name' }); 39 }); 40 41 it('Attempting to add an asset definition without an author should raise an error', async () => { 42 const result = await request(app) 43 .post('/api/v1/assets/definitions') 44 .send({ 45 name: 'My asset definition', 46 isContentPrivate: false, 47 isContentUnique: true 48 }) 49 .expect(400); 50 assert.deepStrictEqual(result.body, { error: 'Missing or invalid asset definition author' }); 51 }); 52 53 it('Attempting to add an asset definition without an valid author name should raise an error', async () => { 54 const result = await request(app) 55 .post('/api/v1/assets/definitions') 56 .send({ 57 name: 'My asset definition', 58 isContentPrivate: false, 59 isContentUnique: true, 60 author: "invalid name" 61 }) 62 .expect(400); 63 assert.deepStrictEqual(result.body, { error: 'Missing or invalid asset definition author' }); 64 }); 65 66 it('Attempting to add an asset definition without indicating if the content should be private or not should raise an error', async () => { 67 const result = await request(app) 68 .post('/api/v1/assets/definitions') 69 .send({ 70 name: 'My asset definition', 71 author: 'CN=Node of node1 for env1, O=Kaleido, L=Raleigh, C=US', 72 isContentUnique: true 73 }) 74 .expect(400); 75 assert.deepStrictEqual(result.body, { error: 'Missing asset definition content privacy' }); 76 }); 77 78 it('Attempting to add an asset definition without a definition id should raise an error', async () => { 79 const result = await request(app) 80 .post('/api/v1/assets/definitions') 81 .send({ 82 name: 'My asset definition', 83 author: 'CN=Node of node1 for env1, O=Kaleido, L=Raleigh, C=US', 84 isContentUnique: true, 85 isContentPrivate: false 86 }) 87 .expect(400); 88 assert.deepStrictEqual(result.body, { error: 'Missing asset definition id' }); 89 }); 90 91 it('Attempting to add an asset definition with an invalid index schema should raise an error', async () => { 92 const result = await request(app) 93 .post('/api/v1/assets/definitions') 94 .send({ 95 name: 'My asset definition', 96 author: 'CN=Node of node1 for env1, O=Kaleido, L=Raleigh, C=US', 97 assetDefinitionID: 'some-uuid', 98 isContentPrivate: false, 99 isContentUnique: true, 100 indexes: {} 101 }) 102 .expect(400); 103 assert.deepStrictEqual(result.body, { error: 'Indexes do not conform to index schema' }); 104 }); 105 106 it('Attempting to add an asset definition with an invalid description schema should raise an error', async () => { 107 const result = await request(app) 108 .post('/api/v1/assets/definitions') 109 .send({ 110 name: 'My asset definition', 111 author: 'CN=Node of node1 for env1, O=Kaleido, L=Raleigh, C=US', 112 assetDefinitionID: 'some-uuid', 113 descriptionSchema: 'INVALID', 114 isContentPrivate: false, 115 isContentUnique: true 116 }) 117 .expect(400); 118 assert.deepStrictEqual(result.body, { error: 'Invalid description schema' }); 119 }); 120 121 it('Attempting to add an asset definition with an invalid content schema should raise an error', async () => { 122 const result = await request(app) 123 .post('/api/v1/assets/definitions') 124 .send({ 125 name: 'My asset definition', 126 author: 'CN=Node of node1 for env1, O=Kaleido, L=Raleigh, C=US', 127 assetDefinitionID: 'some-uuid', 128 contentSchema: 'INVALID', 129 isContentPrivate: false, 130 isContentUnique: true 131 }) 132 .expect(400); 133 assert.deepStrictEqual(result.body, { error: 'Invalid content schema' }); 134 }); 135 }); 136 137 describe('Asset instances - argument validation', async () => { 138 139 it('Attempting to add an asset instance without specifying the author should raise an error', async () => { 140 const result = await request(app) 141 .post('/api/v1/assets/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx') 142 .send({ 143 assetDefinitionID: '', 144 content: {} 145 }) 146 .expect(400); 147 assert.deepStrictEqual(result.body, { error: 'Missing or invalid asset instance author' }); 148 }); 149 150 it('Attempting to add an asset instance without specifying the content should raise an error', async () => { 151 const result = await request(app) 152 .post('/api/v1/assets/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx') 153 .send({ 154 author: 'CN=Node of node1 for env1, O=Kaleido, L=Raleigh, C=US' 155 }) 156 .expect(400); 157 assert.deepStrictEqual(result.body, { error: 'Missing or invalid asset content' }); 158 }); 159 }); 160 };