From a49bc11c4592b7c9cc17196a11720632242b1861 Mon Sep 17 00:00:00 2001 From: NickOvt Date: Mon, 18 Sep 2023 11:15:48 +0300 Subject: [PATCH] Zms 86 storage (#498) * added new file to test git repo setup * added multiple tests for all storage api endpoints. Both positive and negative tests * added tests for GET /addresses and GET users/:user/addresses * added storage tests and fixes for them, fixed addresses tests * add test overview file --- api-tests-overview.md | 118 ++++++++++++++++++++++++++++++++ test.txt | 2 + test/api/addresses-test.js | 16 +++++ test/api/storage-test.js | 135 +++++++++++++++++++++++++++++++++++++ 4 files changed, 271 insertions(+) create mode 100644 api-tests-overview.md create mode 100644 test.txt diff --git a/api-tests-overview.md b/api-tests-overview.md new file mode 100644 index 00000000..0727f133 --- /dev/null +++ b/api-tests-overview.md @@ -0,0 +1,118 @@ +| API path | API method | Test count | Has positive test? | Has Negative test? | +| --- | :---: | --- | --- | --- | +| `/authenticate` | `POST` | 10 | ✅ (6) | ✅ (4) | +| `/users/:user` | `GET` | 7 | ✅ (6) | ✅ (1) | +| `/users/:user/addresses` | `GET` | 7 | ✅ (5) | ✅ (2) | +| `/addresses` | `GET` | 6 | ✅ (5) | ✅ (1) | +| `/users/:user/storage` | `POST` | 6 | ✅ (3) | ✅ (3) | +| `/filters` | `GET` | 4 | ✅ (4) | ❌ (0) | +| `/users` | `POST` | 4 | ✅ (3) | ✅ (1) | +| `/users/:user/filters/:filter` | `PUT` | 4 | ✅ (4) | ❌ (0) | +| `/users/:user/mailboxes` | `POST` | 4 | ✅ (3) | ✅ (1) | +| `/users/:user/storage` | `GET` | 4 | ✅ (2) | ✅ (2) | +| `/users/:user` | `PUT` | 3 | ✅ (3) | ❌ (0) | +| `/users/:user/addresses/:address` | `DELETE` | 3 | ✅ (2) | ✅ (1) | +| `/users/:user/asps` | `POST` | 3 | ✅ (2) | ✅ (1) | +| `/users/:user/filters` | `GET` | 3 | ✅ (3) | ❌ (0) | +| `/users/:user/filters` | `POST` | 3 | ✅ (3) | ❌ (0) | +| `/users/:user/storage/:file` | `DELETE` | 3 | ✅ (1) | ✅ (2) | +| `/users/:user/storage/:file` | `GET` | 3 | ✅ (1) | ✅ (2) | +| `/addresses/forwarded` | `POST` | 2 | ✅ (2) | ❌ (0) | +| `/addresses/forwarded/:id` | `PUT` | 2 | ✅ (2) | ❌ (0) | +| `/authenticate` | `DELETE` | 2 | ✅ (1) | ✅ (1) | +| `/certs` | `POST` | 2 | ✅ (2) | ❌ (0) | +| `/domainaliases` | `POST` | 2 | ✅ (2) | ❌ (0) | +| `/preauth` | `POST` | 2 | ✅ (2) | ❌ (0) | +| `/users/:user/addresses` | `POST` | 2 | ✅ (2) | ❌ (0) | +| `/users/:user/mailboxes/:mailbox/messages` | `POST` | 2 | ✅ (2) | ❌ (0) | +| `/users/:user/mailboxes/:mailbox/messages/:message/submit` | `POST` | 2 | ✅ (1) | ✅ (1) | +| `/users/:user/password/reset` | `POST` | 2 | ✅ (2) | ❌ (0) | +| `/users/resolve/:username` | `GET` | 2 | ✅ (1) | ✅ (1) | +| `/addresses/forwarded/:address` | `DELETE` | 1 | ✅ (1) | ❌ (0) | +| `/addresses/forwarded/:address` | `GET` | 1 | ✅ (1) | ❌ (0) | +| `/certs` | `GET` | 1 | ✅ (1) | ❌ (0) | +| `/certs/:cert` | `GET` | 1 | ✅ (1) | ❌ (0) | +| `/certs/:certs` | `DELETE` | 1 | ✅ (1) | ❌ (0) | +| `/certs/resolve/:servername` | `GET` | 1 | ✅ (1) | ❌ (0) | +| `/dkim` | `GET` | 1 | ✅ (1) | ❌ (0) | +| `/dkim` | `POST` | 1 | ✅ (1) | ❌ (0) | +| `/dkim/:dkim` | `GET` | 1 | ✅ (1) | ❌ (0) | +| `/dkim/:dkim` | `DELETE` | 1 | ✅ (1) | ❌ (0) | +| `/dkim/resolve/:domain` | `GET` | 1 | ✅ (1) | ❌ (0) | +| `/domainaccess/:domain` | `DELETE` | 1 | ✅ (1) | ❌ (0) | +| `/domainaccess/:tag/:action` | `POST` | 1 | ✅ (1) | ❌ (0) | +| `/domainaccess/:tag/:action` | `GET` | 1 | ✅ (1) | ❌ (0) | +| `/domainaliases` | `GET` | 1 | ✅ (1) | ❌ (0) | +| `/domainaliases/:alias` | `GET` | 1 | ✅ (1) | ❌ (0) | +| `/domainaliases/:alias` | `DELETE` | 1 | ✅ (1) | ❌ (0) | +| `/domainaliases/resolve/:alias` | `GET` | 1 | ✅ (1) | ❌ (0) | +| `/quota/reset` | `POST` | 1 | ✅ (1) | ❌ (0) | +| `/users` | `GET` | 1 | ✅ (1) | ❌ (0) | +| `/users/:user` | `DELETE` | 1 | ✅ (1) | ❌ (0) | +| `/users/:user/addresses/:address` | `GET` | 1 | ✅ (1) | ❌ (0) | +| `/users/:user/addresses/:id` | `PUT` | 1 | ✅ (1) | ❌ (0) | +| `/users/:user/addressregister` | `GET` | 1 | ✅ (1) | ❌ (0) | +| `/users/:user/autoreply` | `PUT` | 1 | ✅ (1) | ❌ (0) | +| `/users/:user/filters/:filter` | `DELETE` | 1 | ✅ (1) | ❌ (0) | +| `/users/:user/logout` | `PUT` | 1 | ✅ (1) | ❌ (0) | +| `/users/:user/mailboxes` | `GET` | 1 | ✅ (1) | ❌ (0) | +| `/users/:user/quota/reset` | `POST` | 1 | ✅ (1) | ❌ (0) | +| `/users/:user/restore` | `GET` | 1 | ✅ (1) | ❌ (0) | +| `/users/:user/restore` | `POST` | 1 | ✅ (1) | ❌ (0) | +| `/.well-known/acme-challenge/:token` | `GET` | 0 | ❌ (0) | ❌ (0) | +| `/addresses/renameDomain` | `PUT` | 0 | ❌ (0) | ❌ (0) | +| `/addresses/resolve/:address` | `GET` | 0 | ❌ (0) | ❌ (0) | +| `/api-methods` | `GET` | 0 | ❌ (0) | ❌ (0) | +| `/audit` | `POST` | 0 | ❌ (0) | ❌ (0) | +| `/audit/:audit` | `GET` | 0 | ❌ (0) | ❌ (0) | +| `/audit/:audit/export.mbox` | `GET` | 0 | ❌ (0) | ❌ (0) | +| `/data/export` | `POST` | 0 | ❌ (0) | ❌ (0) | +| `/data/import` | `POST` | 0 | ❌ (0) | ❌ (0) | +| `/public/*` | `GET` | 0 | ❌ (0) | ❌ (0) | +| `/settings` | `GET` | 0 | ❌ (0) | ❌ (0) | +| `/settings/:key` | `POST` | 0 | ❌ (0) | ❌ (0) | +| `/settings/:key` | `GET` | 0 | ❌ (0) | ❌ (0) | +| `/users/:user/2fa` | `DELETE` | 0 | ❌ (0) | ❌ (0) | +| `/users/:user/2fa/custom` | `PUT` | 0 | ❌ (0) | ❌ (0) | +| `/users/:user/2fa/custom` | `DELETE` | 0 | ❌ (0) | ❌ (0) | +| `/users/:user/2fa/totp` | `DELETE` | 0 | ❌ (0) | ❌ (0) | +| `/users/:user/2fa/totp/check` | `POST` | 0 | ❌ (0) | ❌ (0) | +| `/users/:user/2fa/totp/enable` | `POST` | 0 | ❌ (0) | ❌ (0) | +| `/users/:user/2fa/totp/setup` | `POST` | 0 | ❌ (0) | ❌ (0) | +| `/users/:user/2fa/webauthn/authentication-assertion` | `POST` | 0 | ❌ (0) | ❌ (0) | +| `/users/:user/2fa/webauthn/authentication-challenge` | `POST` | 0 | ❌ (0) | ❌ (0) | +| `/users/:user/2fa/webauthn/credentials` | `GET` | 0 | ❌ (0) | ❌ (0) | +| `/users/:user/2fa/webauthn/credentials/:credential` | `DELETE` | 0 | ❌ (0) | ❌ (0) | +| `/users/:user/2fa/webauthn/registration-attestation` | `POST` | 0 | ❌ (0) | ❌ (0) | +| `/users/:user/2fa/webauthn/registration-challenge` | `POST` | 0 | ❌ (0) | ❌ (0) | +| `/users/:user/archived/messages` | `GET` | 0 | ❌ (0) | ❌ (0) | +| `/users/:user/archived/messages/:message/restore` | `POST` | 0 | ❌ (0) | ❌ (0) | +| `/users/:user/archived/restore` | `POST` | 0 | ❌ (0) | ❌ (0) | +| `/users/:user/asps` | `GET` | 0 | ❌ (0) | ❌ (0) | +| `/users/:user/asps/:asp` | `GET` | 0 | ❌ (0) | ❌ (0) | +| `/users/:user/asps/:asp` | `DELETE` | 0 | ❌ (0) | ❌ (0) | +| `/users/:user/authlog` | `GET` | 0 | ❌ (0) | ❌ (0) | +| `/users/:user/authlog/:event` | `GET` | 0 | ❌ (0) | ❌ (0) | +| `/users/:user/autoreply` | `GET` | 0 | ❌ (0) | ❌ (0) | +| `/users/:user/autoreply` | `DELETE` | 0 | ❌ (0) | ❌ (0) | +| `/users/:user/filters/:filter` | `GET` | 0 | ❌ (0) | ❌ (0) | +| `/users/:user/mailboxes/:mailbox` | `GET` | 0 | ❌ (0) | ❌ (0) | +| `/users/:user/mailboxes/:mailbox` | `PUT` | 0 | ❌ (0) | ❌ (0) | +| `/users/:user/mailboxes/:mailbox` | `DELETE` | 0 | ❌ (0) | ❌ (0) | +| `/users/:user/mailboxes/:mailbox/messages` | `GET` | 0 | ❌ (0) | ❌ (0) | +| `/users/:user/mailboxes/:mailbox/messages` | `PUT` | 0 | ❌ (0) | ❌ (0) | +| `/users/:user/mailboxes/:mailbox/messages` | `DELETE` | 0 | ❌ (0) | ❌ (0) | +| `/users/:user/mailboxes/:mailbox/messages/:message` | `GET` | 0 | ❌ (0) | ❌ (0) | +| `/users/:user/mailboxes/:mailbox/messages/:message` | `PUT` | 0 | ❌ (0) | ❌ (0) | +| `/users/:user/mailboxes/:mailbox/messages/:message` | `DELETE` | 0 | ❌ (0) | ❌ (0) | +| `/users/:user/mailboxes/:mailbox/messages/:message/attachments/:attachment` | `GET` | 0 | ❌ (0) | ❌ (0) | +| `/users/:user/mailboxes/:mailbox/messages/:message/forward` | `POST` | 0 | ❌ (0) | ❌ (0) | +| `/users/:user/mailboxes/:mailbox/messages/:message/message.eml` | `GET` | 0 | ❌ (0) | ❌ (0) | +| `/users/:user/outbound/:queueId` | `DELETE` | 0 | ❌ (0) | ❌ (0) | +| `/users/:user/search` | `GET` | 0 | ❌ (0) | ❌ (0) | +| `/users/:user/search` | `POST` | 0 | ❌ (0) | ❌ (0) | +| `/users/:user/submit` | `POST` | 0 | ❌ (0) | ❌ (0) | +| `/users/:user/updates` | `GET` | 0 | ❌ (0) | ❌ (0) | +| `/webhooks` | `GET` | 0 | ❌ (0) | ❌ (0) | +| `/webhooks` | `POST` | 0 | ❌ (0) | ❌ (0) | +| `/webhooks/:webhook` | `DELETE` | 0 | ❌ (0) | ❌ (0) | diff --git a/test.txt b/test.txt new file mode 100644 index 00000000..44c67a81 --- /dev/null +++ b/test.txt @@ -0,0 +1,2 @@ +test file new for git + diff --git a/test/api/addresses-test.js b/test/api/addresses-test.js index 374ffb90..5ed71784 100644 --- a/test/api/addresses-test.js +++ b/test/api/addresses-test.js @@ -100,6 +100,11 @@ describe('API Users', function () { expect(addressListResponse.body.total).to.gt(3); }); + it('should GET /addresses expect failure / incorrect query params data', async () => { + const addressListResponse = await server.get(`/addresses?limit=-1&query=${'a'.repeat(256)}`).expect(400); + expect(addressListResponse.body.code).to.be.equal('InputValidationError'); + }); + it('should GET /addresses expect success / with tags', async () => { const addressListResponse = await server.get(`/addresses?tags=tag2,tag3`).expect(200); expect(addressListResponse.body.success).to.be.true; @@ -142,6 +147,17 @@ describe('API Users', function () { expect(addressListResponse.body.results.find(addr => addr.main).address).to.equal('addressuser.addrtest@example.com'); }); + it('should GET /users/{user}/addresses expect failure / incorrect user', async () => { + const addressListResponse = await server.get(`/users/${123}/addresses`).expect(400); + expect(addressListResponse.body.code).to.be.equal('InputValidationError'); + }); + + it('should GET /users/{user}/addresses expect failure / user missing', async () => { + const addressListResponse = await server.get(`/users/${'0'.repeat(24)}/addresses`).expect(404); + expect(addressListResponse.body.code).to.be.equal('UserNotFound'); + expect(addressListResponse.body.error).to.be.equal('This user does not exist'); + }); + it('should PUT /users/{user}/addresses/{id} expect success', async () => { let addressListResponse = await server.get(`/users/${user}/addresses`).expect(200); expect(addressListResponse.body.success).to.be.true; diff --git a/test/api/storage-test.js b/test/api/storage-test.js index 2bfe6f9a..ac956416 100644 --- a/test/api/storage-test.js +++ b/test/api/storage-test.js @@ -58,5 +58,140 @@ describe('Storage tests', function () { }) .expect(200); expect(response.body.success).to.be.true; + expect(response.body.id).to.be.not.empty; + }); + + it('should POST /users/{user}/storage expect success / filename undefined', async () => { + const response = await server + .post(`/users/${user}/storage`) + .send({ + contentType: 'image/gif', + encoding: 'base64', + content: + 'R0lGODlhEAAQAMQAAORHHOVSKudfOulrSOp3WOyDZu6QdvCchPGolfO0o/XBs/fNwfjZ0frl3/zy7////wAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACH5BAkAABAALAAAAAAQABAAAAVVICSOZGlCQAosJ6mu7fiyZeKqNKToQGDsM8hBADgUXoGAiqhSvp5QAnQKGIgUhwFUYLCVDFCrKUE1lBavAViFIDlTImbKC5Gm2hB0SlBCBMQiB0UjIQA7' + }) + .expect(200); + expect(response.body.success).to.be.true; + expect(response.body.id).to.be.not.empty; + }); + + it('should POST /users/{user}/storage expect success / filename undefined, contentType undefined', async () => { + const response = await server + .post(`/users/${user}/storage`) + .send({ + encoding: 'base64', + content: + 'R0lGODlhEAAQAMQAAORHHOVSKudfOulrSOp3WOyDZu6QdvCchPGolfO0o/XBs/fNwfjZ0frl3/zy7////wAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACH5BAkAABAALAAAAAAQABAAAAVVICSOZGlCQAosJ6mu7fiyZeKqNKToQGDsM8hBADgUXoGAiqhSvp5QAnQKGIgUhwFUYLCVDFCrKUE1lBavAViFIDlTImbKC5Gm2hB0SlBCBMQiB0UjIQA7' + }) + .expect(200); + expect(response.body.success).to.be.true; + expect(response.body.id).to.be.not.empty; + }); + + it('should POST /users/{user}/storage expect failure / content missing', async () => { + const response = await server + .post(`/users/${user}/storage`) + .send({ + filename: 'image.gif', + contentType: 'image/gif', + encoding: 'base64' + }) + .expect(400); + expect(response.body.code).to.be.equal('InputValidationError'); + }); + + it('should POST /users/{user}/storage expect failure / incorrect user id', async () => { + const response = await server + .post(`/users/123/storage`) + .send({ + filename: 'image.gif', + contentType: 'image/gif', + encoding: 'base64', + content: + 'R0lGODlhEAAQAMQAAORHHOVSKudfOulrSOp3WOyDZu6QdvCchPGolfO0o/XBs/fNwfjZ0frl3/zy7////wAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACH5BAkAABAALAAAAAAQABAAAAVVICSOZGlCQAosJ6mu7fiyZeKqNKToQGDsM8hBADgUXoGAiqhSvp5QAnQKGIgUhwFUYLCVDFCrKUE1lBavAViFIDlTImbKC5Gm2hB0SlBCBMQiB0UjIQA7' + }) + .expect(400); + expect(response.body.code).to.be.equal('InputValidationError'); + }); + + it('should POST /users/{user}/storage expect failure / user not found', async () => { + const response = await server + .post(`/users/${'0'.repeat(24)}/storage`) + .send({ + filename: 'image.gif', + contentType: 'image/gif', + encoding: 'base64', + content: + 'R0lGODlhEAAQAMQAAORHHOVSKudfOulrSOp3WOyDZu6QdvCchPGolfO0o/XBs/fNwfjZ0frl3/zy7////wAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACH5BAkAABAALAAAAAAQABAAAAVVICSOZGlCQAosJ6mu7fiyZeKqNKToQGDsM8hBADgUXoGAiqhSvp5QAnQKGIgUhwFUYLCVDFCrKUE1lBavAViFIDlTImbKC5Gm2hB0SlBCBMQiB0UjIQA7' + }) + .expect(404); + expect(response.body.code).to.be.equal('UserNotFound'); + expect(response.body.error).to.be.equal('This user does not exist'); + }); + + it('should GET /users/{user}/storage expect success', async () => { + const response = await server.get(`/users/${user}/storage`).send({}).expect(200); + expect(response.body.success).to.be.true; + }); + + it('should GET /users/{user}/storage expect success / different limit', async () => { + const response = await server.get(`/users/${user}/storage?limit=5`).send({}).expect(200); + expect(response.body.success).to.be.true; + }); + + it('should GET /users/{user}/storage expect failure / incorrect limit', async () => { + const response = await server.get(`/users/${user}/storage?limit=1000`).send({}).expect(400); + expect(response.body.code).to.be.equal('InputValidationError'); + }); + + it('should GET /users/{user}/storage expect failure / user not found', async () => { + const response = await server + .get(`/users/${'0'.repeat(24)}/storage`) + .send({}) + .expect(404); + expect(response.body.code).to.be.equal('UserNotFound'); + expect(response.body.error).to.be.equal('This user does not exist'); + }); + + it('should DELETE /users/{user}/storage/{file} expect success', async () => { + const userFiles = await server.get(`/users/${user}/storage`).send({}).expect(200); + + const response = await server.del(`/users/${user}/storage/${userFiles.body.results[0].id}`).send({}).expect(200); + expect(response.body.success).to.be.true; + }); + + it('should DELETE /users/{user}/storage/{file} expect failure / file format incorrect', async () => { + const response = await server.del(`/users/${user}/storage/${123}`).send({}).expect(400); + expect(response.body.code).to.be.equal('InputValidationError'); + }); + + it('should DELETE /users/{user}/storage/{file} expect failure / file missing, incorrect file id', async () => { + const userFiles = await server.get(`/users/${user}/storage`).send({}).expect(200); + + const response = await server + .del(`/users/${user}/storage/${Array.from(userFiles.body.results[0].id).reverse().join('')}`) + .send({}) + .expect(404); + expect(response.body.code).to.be.equal('FileNotFound'); + }); + + it('should GET /users/{user}/storage/{file} expect success', async () => { + const userFiles = await server.get(`/users/${user}/storage`).send({}).expect(200); + + const response = await server.del(`/users/${user}/storage/${userFiles.body.results[0].id}`).send({}).expect(200); + expect(response.body.success).to.be.true; + }); + + it('should GET /users/{user}/storage/{file} expect failure / file format incorrect', async () => { + const response = await server.get(`/users/${user}/storage/${123}`).send({}).expect(400); + expect(response.body.code).to.be.equal('InputValidationError'); + }); + + it('should GET /users/{user}/storage/{file} expect failure / file missing, incorrect file id', async () => { + const response = await server + .get(`/users/${user}/storage/${'0'.repeat(24)}`) + .send({}) + .expect(404); + expect(response.body.code).to.be.equal('FileNotFound'); }); });