|
| 1 | +/* |
| 2 | + Simulation of responses from a server when we |
| 3 | + request the creation of hooks. |
| 4 | +
|
| 5 | + nock will simulate a gitlab server running at |
| 6 | + localhost:80, where Strider Tester, a user is |
| 7 | + registered with the name "stridertester", and |
| 8 | + has been registered with api token - zRtVsmeznn7ySatTrnrp |
| 9 | + stridertester is an "owner" of a group named "testunion" |
| 10 | + and has admin access to three projects - |
| 11 | + testunion / unionproject1 |
| 12 | + Strider Tester / pubproject1 |
| 13 | + Strider Tester / privproject1 |
| 14 | + */ |
| 15 | +var nock = require('nock'); |
| 16 | + |
| 17 | +module.exports = function () { |
| 18 | + |
| 19 | + //-------------------------------------------------------------------------------------- |
| 20 | + //Simulate 201 replies when we request the addition of a new project |
| 21 | + //(adding hooks and keys) |
| 22 | + nock('http://localhost:80') |
| 23 | + .post('/api/v3/projects/5/hooks', { |
| 24 | + "url": "http://localhost:3000/stridertester/privproject1/api/gitlab/webhook", |
| 25 | + "push_events": true |
| 26 | + }) |
| 27 | + .query({"private_token": "zRtVsmeznn7ySatTrnrp"}) |
| 28 | + .reply(201, { |
| 29 | + "id": 18, |
| 30 | + "url": "http://localhost:3000/stridertester/privproject1/api/gitlab/webhook", |
| 31 | + "created_at": "2015-08-21T14:11:54.922Z", |
| 32 | + "project_id": 5, |
| 33 | + "push_events": true, |
| 34 | + "issues_events": false, |
| 35 | + "merge_requests_events": false, |
| 36 | + "tag_push_events": false |
| 37 | + }, { |
| 38 | + server: 'nginx', |
| 39 | + date: 'Fri, 21 Aug 2015 14:11:54 GMT', |
| 40 | + 'content-type': 'application/json', |
| 41 | + 'content-length': '235', |
| 42 | + connection: 'close', |
| 43 | + status: '201 Created', |
| 44 | + etag: '"3b0821c3d2fa5d74684be993bfba7805"', |
| 45 | + 'cache-control': 'max-age=0, private, must-revalidate', |
| 46 | + 'x-request-id': '0f470a71-564f-4dcc-ae1f-743b73c98473', |
| 47 | + 'x-runtime': '0.021008' |
| 48 | + }); |
| 49 | + |
| 50 | + nock('http://localhost:80') |
| 51 | + .post('/api/v3/projects/5/keys', { |
| 52 | + "title": "strider-stridertester/privproject1", |
| 53 | + "key": "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQC5CS04M9YZAoOkl9suZuKdBR643lB9Kv2AigyqcCfljhnFK3tWPLEnlsLE7ZnunTC3VcPPesdC8MeWC95EvQgNGH6Y5oXrGcaxZKiVDunk4xxKpJQjzMbp753B4R7i28NyZVShCyYG0+wkqAYlJ4NFWn6PMEOouinY8Z3/JD/e9luq4QgyyrI9s+e7VWKBBof9f6FtaGWXwpaWt7Peud3/AWKkhPELQmDDBEcZ5jxFneLsO0KEQ3qqGlEhQbtYLblgjWvuekd0CAReyUNjyJQG+rfDyVVadAQNHiri7c8cj6Y766FdfRskCKiA7E5IPfnysUcRx8657u6DG4PC6guV stridertester/[email protected]\n" |
| 54 | + }) |
| 55 | + .query({"private_token": "zRtVsmeznn7ySatTrnrp"}) |
| 56 | + .reply(201, { |
| 57 | + "id": 22, |
| 58 | + "title": "strider-stridertester/privproject1", |
| 59 | + "key": "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQC5CS04M9YZAoOkl9suZuKdBR643lB9Kv2AigyqcCfljhnFK3tWPLEnlsLE7ZnunTC3VcPPesdC8MeWC95EvQgNGH6Y5oXrGcaxZKiVDunk4xxKpJQjzMbp753B4R7i28NyZVShCyYG0+wkqAYlJ4NFWn6PMEOouinY8Z3/JD/e9luq4QgyyrI9s+e7VWKBBof9f6FtaGWXwpaWt7Peud3/AWKkhPELQmDDBEcZ5jxFneLsO0KEQ3qqGlEhQbtYLblgjWvuekd0CAReyUNjyJQG+rfDyVVadAQNHiri7c8cj6Y766FdfRskCKiA7E5IPfnysUcRx8657u6DG4PC6guV stridertester/[email protected]", |
| 60 | + "created_at": "2015-08-21T14:11:54.986Z" |
| 61 | + }, { |
| 62 | + server: 'nginx', |
| 63 | + date: 'Fri, 21 Aug 2015 14:11:55 GMT', |
| 64 | + 'content-type': 'application/json', |
| 65 | + 'content-length': '534', |
| 66 | + connection: 'close', |
| 67 | + status: '201 Created', |
| 68 | + etag: '"13f3437db289c9c485011a1201db884f"', |
| 69 | + 'cache-control': 'max-age=0, private, must-revalidate', |
| 70 | + 'x-request-id': '0e829475-9fda-458e-8b34-08c7e8c4c0f5', |
| 71 | + 'x-runtime': '0.099567' |
| 72 | + }); |
| 73 | + |
| 74 | + //-------------------------------------------------------------------------------------- |
| 75 | + //Simulate a 401 reply if api key is not sent |
| 76 | + nock('http://localhost:80') |
| 77 | + .post('/api/v3/projects/5/hooks', { |
| 78 | + "url": "http://localhost:3000/stridertester/privproject1/api/gitlab/webhook", |
| 79 | + "push_events": true |
| 80 | + }) |
| 81 | + .reply(401, {"message": "401 Unauthorized"}, { |
| 82 | + server: 'nginx', |
| 83 | + date: 'Fri, 21 Aug 2015 14:42:46 GMT', |
| 84 | + 'content-type': 'application/json', |
| 85 | + 'content-length': '30', |
| 86 | + connection: 'close', |
| 87 | + status: '401 Unauthorized', |
| 88 | + 'cache-control': 'no-cache', |
| 89 | + 'x-request-id': '052eafeb-0028-4e69-b951-95925efdc232', |
| 90 | + 'x-runtime': '0.004600' |
| 91 | + }); |
| 92 | + |
| 93 | + //-------------------------------------------------------------------------------------- |
| 94 | + //Simulate a 404 if we passed an incorrect repo id |
| 95 | + nock('http://localhost:80') |
| 96 | + .post('/api/v3/projects/invalid-repo/hooks', { |
| 97 | + "url": "http://localhost:3000/stridertester/privproject1/api/gitlab/webhook", |
| 98 | + "push_events": true |
| 99 | + }) |
| 100 | + .query({"private_token": "zRtVsmeznn7ySatTrnrp"}) |
| 101 | + .reply(404, ["1f8b0800000000000003ab56ca4d2d2e4e4c4f55b252323130510828cacf4a4d2e51f0cb2f5170cb2fcd4b51aa050037095a2823000000"], { |
| 102 | + server: 'nginx', |
| 103 | + date: 'Fri, 21 Aug 2015 14:47:42 GMT', |
| 104 | + 'content-type': 'application/json', |
| 105 | + 'transfer-encoding': 'chunked', |
| 106 | + connection: 'close', |
| 107 | + status: '404 Not Found', |
| 108 | + 'cache-control': 'no-cache', |
| 109 | + 'x-request-id': 'b35510b5-8f3b-434c-bc63-e77ed6a5dc74', |
| 110 | + 'x-runtime': '0.006681', |
| 111 | + 'content-encoding': 'gzip' |
| 112 | + }); |
| 113 | + |
| 114 | + //-------------------------------------------------------------------------------------- |
| 115 | + //Simulate a 400 if we passed a bad URL |
| 116 | + nock('http://localhost:80') |
| 117 | + .post('/api/v3/projects/5/hooks', {"url": false, "push_events": true}) |
| 118 | + .query({"private_token": "zRtVsmeznn7ySatTrnrp"}) |
| 119 | + .reply(400, {"message": "400 (Bad request) \"url\" not given"}, { |
| 120 | + server: 'nginx', |
| 121 | + date: 'Fri, 21 Aug 2015 14:52:41 GMT', |
| 122 | + 'content-type': 'application/json', |
| 123 | + 'content-length': '49', |
| 124 | + connection: 'close', |
| 125 | + status: '400 Bad Request', |
| 126 | + 'cache-control': 'no-cache', |
| 127 | + 'x-request-id': '823fd96a-3829-4dbe-b7ff-75ab89b50455', |
| 128 | + 'x-runtime': '0.010701' |
| 129 | + }); |
| 130 | + |
| 131 | + //-------------------------------------------------------------------------------------- |
| 132 | + //Simulate a 401 if wrong credentials were sent |
| 133 | + nock('http://localhost:80') |
| 134 | + .post('/api/v3/projects/5/hooks', { |
| 135 | + "url": "http://localhost:3000/stridertester/privproject1/api/gitlab/webhook", |
| 136 | + "push_events": true |
| 137 | + }) |
| 138 | + .query({"private_token": "zRtVsmeznn7ySatTrnra"}) |
| 139 | + .reply(401, {"message": "401 Unauthorized"}, { |
| 140 | + server: 'nginx', |
| 141 | + date: 'Fri, 21 Aug 2015 16:38:40 GMT', |
| 142 | + 'content-type': 'application/json', |
| 143 | + 'content-length': '30', |
| 144 | + connection: 'close', |
| 145 | + status: '401 Unauthorized', |
| 146 | + 'cache-control': 'no-cache', |
| 147 | + 'x-request-id': '0f3180af-8f43-495f-91fb-8455313eff9a', |
| 148 | + 'x-runtime': '0.004978' |
| 149 | + }); |
| 150 | +}; |
0 commit comments