@@ -4,7 +4,7 @@ import {join} from 'path';
4
4
import { AIO_UPLOAD_HOSTNAME , AIO_UPLOAD_PORT , AIO_WWW_USER } from '../common/env-variables' ;
5
5
import { computeShortSha } from '../common/utils' ;
6
6
import { ALT_SHA , BuildNums , PrNums , SHA , SIMILAR_SHA } from './constants' ;
7
- import { helper as h , makeCurl } from './helper' ;
7
+ import { helper as h , makeCurl , payload } from './helper' ;
8
8
import { customMatchers } from './jasmine-custom-matchers' ;
9
9
10
10
// Tests
@@ -51,63 +51,65 @@ describe('upload-server', () => {
51
51
await Promise . all ( [
52
52
curl ( { data : '' } ) . then ( h . verifyResponse ( 400 ) ) ,
53
53
curl ( { data : { } } ) . then ( h . verifyResponse ( 400 ) ) ,
54
- curl ( { payload : { } } ) . then ( h . verifyResponse ( 400 ) ) ,
55
- curl ( { payload : { build_num : 0 } } ) . then ( h . verifyResponse ( 400 ) ) ,
56
- curl ( { payload : { build_num : - 1 } } ) . then ( h . verifyResponse ( 400 ) ) ,
54
+ curl ( { data : { payload : { } } } ) . then ( h . verifyResponse ( 400 ) ) ,
55
+ curl ( { data : { payload : { build_num : 1 } } } ) . then ( h . verifyResponse ( 400 ) ) ,
56
+ curl ( { data : { payload : { build_num : 1 , build_parameters : { } } } } ) . then ( h . verifyResponse ( 400 ) ) ,
57
+ curl ( payload ( 0 ) ) . then ( h . verifyResponse ( 400 ) ) ,
58
+ curl ( payload ( - 1 ) ) . then ( h . verifyResponse ( 400 ) ) ,
57
59
] ) ;
58
60
} ) ;
59
61
60
62
it ( 'should respond with 500 if the CircleCI API request errors' , async ( ) => {
61
- await curl ( { payload : { build_num : BuildNums . BUILD_INFO_ERROR } } ) . then ( h . verifyResponse ( 500 ) ) ;
62
- await curl ( { payload : { build_num : BuildNums . BUILD_INFO_404 } } ) . then ( h . verifyResponse ( 500 ) ) ;
63
+ await curl ( payload ( BuildNums . BUILD_INFO_ERROR ) ) . then ( h . verifyResponse ( 500 ) ) ;
64
+ await curl ( payload ( BuildNums . BUILD_INFO_404 ) ) . then ( h . verifyResponse ( 500 ) ) ;
63
65
} ) ;
64
66
65
67
it ( 'should respond with 204 if the build on CircleCI failed' , async ( ) => {
66
- await curl ( { payload : { build_num : BuildNums . BUILD_INFO_BUILD_FAILED } } ) . then ( h . verifyResponse ( 204 ) ) ;
68
+ await curl ( payload ( BuildNums . BUILD_INFO_BUILD_FAILED ) ) . then ( h . verifyResponse ( 204 ) ) ;
67
69
} ) ;
68
70
69
71
it ( 'should respond with 500 if the github org from CircleCI does not match what is configured' , async ( ) => {
70
- await curl ( { payload : { build_num : BuildNums . BUILD_INFO_INVALID_GH_ORG } } ) . then ( h . verifyResponse ( 500 ) ) ;
72
+ await curl ( payload ( BuildNums . BUILD_INFO_INVALID_GH_ORG ) ) . then ( h . verifyResponse ( 500 ) ) ;
71
73
} ) ;
72
74
73
75
it ( 'should respond with 500 if the github repo from CircleCI does not match what is configured' , async ( ) => {
74
- await curl ( { payload : { build_num : BuildNums . BUILD_INFO_INVALID_GH_REPO } } ) . then ( h . verifyResponse ( 500 ) ) ;
76
+ await curl ( payload ( BuildNums . BUILD_INFO_INVALID_GH_REPO ) ) . then ( h . verifyResponse ( 500 ) ) ;
75
77
} ) ;
76
78
77
79
it ( 'should respond with 500 if the github files API errors' , async ( ) => {
78
- await curl ( { payload : { build_num : BuildNums . CHANGED_FILES_ERROR } } ) . then ( h . verifyResponse ( 500 ) ) ;
79
- await curl ( { payload : { build_num : BuildNums . CHANGED_FILES_404 } } ) . then ( h . verifyResponse ( 500 ) ) ;
80
+ await curl ( payload ( BuildNums . CHANGED_FILES_ERROR ) ) . then ( h . verifyResponse ( 500 ) ) ;
81
+ await curl ( payload ( BuildNums . CHANGED_FILES_404 ) ) . then ( h . verifyResponse ( 500 ) ) ;
80
82
} ) ;
81
83
82
84
it ( 'should respond with 204 if no significant files are changed by the PR' , async ( ) => {
83
- await curl ( { payload : { build_num : BuildNums . CHANGED_FILES_NONE } } ) . then ( h . verifyResponse ( 204 ) ) ;
85
+ await curl ( payload ( BuildNums . CHANGED_FILES_NONE ) ) . then ( h . verifyResponse ( 204 ) ) ;
84
86
} ) ;
85
87
86
88
it ( 'should respond with 500 if the CircleCI artifact API fails' , async ( ) => {
87
- await curl ( { payload : { build_num : BuildNums . BUILD_ARTIFACTS_ERROR } } ) . then ( h . verifyResponse ( 500 ) ) ;
88
- await curl ( { payload : { build_num : BuildNums . BUILD_ARTIFACTS_404 } } ) . then ( h . verifyResponse ( 500 ) ) ;
89
- await curl ( { payload : { build_num : BuildNums . BUILD_ARTIFACTS_EMPTY } } ) . then ( h . verifyResponse ( 500 ) ) ;
90
- await curl ( { payload : { build_num : BuildNums . BUILD_ARTIFACTS_MISSING } } ) . then ( h . verifyResponse ( 500 ) ) ;
89
+ await curl ( payload ( BuildNums . BUILD_ARTIFACTS_ERROR ) ) . then ( h . verifyResponse ( 500 ) ) ;
90
+ await curl ( payload ( BuildNums . BUILD_ARTIFACTS_404 ) ) . then ( h . verifyResponse ( 500 ) ) ;
91
+ await curl ( payload ( BuildNums . BUILD_ARTIFACTS_EMPTY ) ) . then ( h . verifyResponse ( 500 ) ) ;
92
+ await curl ( payload ( BuildNums . BUILD_ARTIFACTS_MISSING ) ) . then ( h . verifyResponse ( 500 ) ) ;
91
93
} ) ;
92
94
93
95
it ( 'should respond with 500 if fetching the artifact errors' , async ( ) => {
94
- await curl ( { payload : { build_num : BuildNums . DOWNLOAD_ARTIFACT_ERROR } } ) . then ( h . verifyResponse ( 500 ) ) ;
95
- await curl ( { payload : { build_num : BuildNums . DOWNLOAD_ARTIFACT_404 } } ) . then ( h . verifyResponse ( 500 ) ) ;
96
+ await curl ( payload ( BuildNums . DOWNLOAD_ARTIFACT_ERROR ) ) . then ( h . verifyResponse ( 500 ) ) ;
97
+ await curl ( payload ( BuildNums . DOWNLOAD_ARTIFACT_404 ) ) . then ( h . verifyResponse ( 500 ) ) ;
96
98
} ) ;
97
99
98
100
it ( 'should respond with 500 if the GH trusted API fails' , async ( ) => {
99
- await curl ( { payload : { build_num : BuildNums . TRUST_CHECK_ERROR } } ) . then ( h . verifyResponse ( 500 ) ) ;
101
+ await curl ( payload ( BuildNums . TRUST_CHECK_ERROR ) ) . then ( h . verifyResponse ( 500 ) ) ;
100
102
expect ( { prNum : PrNums . TRUST_CHECK_ERROR } ) . toExistAsAnArtifact ( ) ;
101
103
} ) ;
102
104
103
105
it ( 'should respond with 201 if a new public build is created' , async ( ) => {
104
- await curl ( { payload : { build_num : BuildNums . TRUST_CHECK_ACTIVE_TRUSTED_USER } } )
106
+ await curl ( payload ( BuildNums . TRUST_CHECK_ACTIVE_TRUSTED_USER ) )
105
107
. then ( h . verifyResponse ( 201 ) ) ;
106
108
expect ( { prNum : PrNums . TRUST_CHECK_ACTIVE_TRUSTED_USER } ) . toExistAsABuild ( ) ;
107
109
} ) ;
108
110
109
111
it ( 'should respond with 202 if a new private build is created' , async ( ) => {
110
- await curl ( { payload : { build_num : BuildNums . TRUST_CHECK_UNTRUSTED } } ) . then ( h . verifyResponse ( 202 ) ) ;
112
+ await curl ( payload ( BuildNums . TRUST_CHECK_UNTRUSTED ) ) . then ( h . verifyResponse ( 202 ) ) ;
111
113
expect ( { prNum : PrNums . TRUST_CHECK_UNTRUSTED , isPublic : false } ) . toExistAsABuild ( ) ;
112
114
} ) ;
113
115
@@ -121,7 +123,7 @@ describe('upload-server', () => {
121
123
describe ( `for ${ label } builds` , ( ) => {
122
124
123
125
it ( 'should extract the contents of the uploaded file' , async ( ) => {
124
- await curl ( { payload : { build_num : build } } )
126
+ await curl ( payload ( build ) )
125
127
. then ( h . verifyResponse ( statusCode ) ) ;
126
128
expect ( h . readBuildFile ( prNum , SHA , 'index.html' , isPublic ) )
127
129
. toContain ( `PR: ${ prNum } | SHA: ${ SHA } | File: /index.html` ) ;
@@ -131,7 +133,7 @@ describe('upload-server', () => {
131
133
} ) ;
132
134
133
135
it ( `should create files/directories owned by '${ AIO_WWW_USER } '` , async ( ) => {
134
- await curl ( { payload : { build_num : build } } )
136
+ await curl ( payload ( build ) )
135
137
. then ( h . verifyResponse ( statusCode ) ) ;
136
138
137
139
const shaDir = h . getShaDir ( h . getPrDir ( prNum , isPublic ) , SHA ) ;
@@ -147,14 +149,14 @@ describe('upload-server', () => {
147
149
} ) ;
148
150
149
151
it ( 'should delete the uploaded file' , async ( ) => {
150
- await curl ( { payload : { build_num : build } } )
152
+ await curl ( payload ( build ) )
151
153
. then ( h . verifyResponse ( statusCode ) ) ;
152
154
expect ( { prNum, SHA } ) . not . toExistAsAnArtifact ( ) ;
153
155
expect ( { prNum, isPublic } ) . toExistAsABuild ( ) ;
154
156
} ) ;
155
157
156
158
it ( 'should make the build directory non-writable' , async ( ) => {
157
- await curl ( { payload : { build_num : build } } )
159
+ await curl ( payload ( build ) )
158
160
. then ( h . verifyResponse ( statusCode ) ) ;
159
161
160
162
// See https://github.com/nodejs/node-v0.x-archive/issues/3045#issuecomment-4862588.
@@ -183,7 +185,7 @@ describe('upload-server', () => {
183
185
h . writeBuildFile ( prNum , SHA , 'index.html' , 'My content' , isPublic , true ) ;
184
186
expect ( h . readBuildFile ( prNum , SHA , 'index.html' , isPublic , true ) ) . toBe ( 'My content' ) ;
185
187
186
- await curl ( { payload : { build_num : build } } )
188
+ await curl ( payload ( build ) )
187
189
. then ( h . verifyResponse ( statusCode ) ) ;
188
190
189
191
expect ( h . readBuildFile ( prNum , SHA , 'index.html' , isPublic , false ) ) . toContain ( 'index.html' ) ;
@@ -198,7 +200,7 @@ describe('upload-server', () => {
198
200
h . createDummyBuild ( prNum , SHA , isPublic ) ;
199
201
// distinguish this build from the downloaded one
200
202
h . writeBuildFile ( prNum , SHA , 'index.html' , 'My content' , isPublic ) ;
201
- await curl ( { payload : { build_num : build } } ) . then ( h . verifyResponse ( 409 , overwriteRe ) ) ;
203
+ await curl ( payload ( build ) ) . then ( h . verifyResponse ( 409 , overwriteRe ) ) ;
202
204
expect ( h . readBuildFile ( prNum , SHA , 'index.html' , isPublic ) ) . toBe ( 'My content' ) ;
203
205
expect ( { prNum, isPublic } ) . toExistAsABuild ( ) ;
204
206
expect ( { prNum } ) . toExistAsAnArtifact ( ) ;
@@ -215,15 +217,15 @@ describe('upload-server', () => {
215
217
h . writeBuildFile ( prNum , SIMILAR_SHA , 'index.html' , 'My content' , isPublic ) ;
216
218
expect ( h . readBuildFile ( prNum , SIMILAR_SHA , 'index.html' , isPublic ) ) . toBe ( 'My content' ) ;
217
219
218
- await curl ( { payload : { build_num : build } } ) . then ( h . verifyResponse ( 409 , overwriteRe ) ) ;
220
+ await curl ( payload ( build ) ) . then ( h . verifyResponse ( 409 , overwriteRe ) ) ;
219
221
expect ( h . readBuildFile ( prNum , SIMILAR_SHA , 'index.html' , isPublic ) ) . toBe ( 'My content' ) ;
220
222
expect ( { prNum, isPublic, sha : SIMILAR_SHA } ) . toExistAsABuild ( ) ;
221
223
expect ( { prNum, sha : SIMILAR_SHA } ) . toExistAsAnArtifact ( ) ;
222
224
} ) ;
223
225
224
226
it ( 'should only delete the SHA directory on error (for existing PR)' , async ( ) => {
225
227
h . createDummyBuild ( prNum , ALT_SHA , isPublic ) ;
226
- await curl ( { payload : { build_num : BuildNums . TRUST_CHECK_ERROR } } ) . then ( h . verifyResponse ( 500 ) ) ;
228
+ await curl ( payload ( BuildNums . TRUST_CHECK_ERROR ) ) . then ( h . verifyResponse ( 500 ) ) ;
227
229
expect ( { prNum : PrNums . TRUST_CHECK_ERROR } ) . toExistAsAnArtifact ( ) ;
228
230
expect ( { prNum, isPublic, sha : SHA } ) . not . toExistAsABuild ( ) ;
229
231
expect ( { prNum, isPublic, sha : ALT_SHA } ) . toExistAsABuild ( ) ;
@@ -233,15 +235,15 @@ describe('upload-server', () => {
233
235
234
236
it ( 'should update the PR\'s visibility' , async ( ) => {
235
237
h . createDummyBuild ( prNum , ALT_SHA , ! isPublic ) ;
236
- await curl ( { payload : { build_num : build } } ) . then ( h . verifyResponse ( statusCode ) ) ;
238
+ await curl ( payload ( build ) ) . then ( h . verifyResponse ( statusCode ) ) ;
237
239
expect ( { prNum, isPublic } ) . toExistAsABuild ( ) ;
238
240
expect ( { prNum, isPublic, sha : ALT_SHA } ) . toExistAsABuild ( ) ;
239
241
} ) ;
240
242
241
243
242
244
it ( 'should not overwrite existing builds (but keep the updated visibility)' , async ( ) => {
243
245
h . createDummyBuild ( prNum , SHA , ! isPublic ) ;
244
- await curl ( { payload : { build_num : build } } ) . then ( h . verifyResponse ( 409 ) ) ;
246
+ await curl ( payload ( build ) ) . then ( h . verifyResponse ( 409 ) ) ;
245
247
expect ( { prNum, isPublic } ) . toExistAsABuild ( ) ;
246
248
expect ( { prNum, isPublic : ! isPublic } ) . not . toExistAsABuild ( ) ;
247
249
// since it errored we didn't clear up the downloaded artifact - perhaps we should?
@@ -257,7 +259,7 @@ describe('upload-server', () => {
257
259
const errorRegex = new RegExp ( `^Request to move '${ h . getPrDir ( prNum , ! isPublic ) } ' ` +
258
260
`to existing directory '${ h . getPrDir ( prNum , isPublic ) } '.` ) ;
259
261
260
- await curl ( { payload : { build_num : build } } ) . then ( h . verifyResponse ( 409 , errorRegex ) ) ;
262
+ await curl ( payload ( build ) ) . then ( h . verifyResponse ( 409 , errorRegex ) ) ;
261
263
262
264
expect ( { prNum, isPublic } ) . not . toExistAsABuild ( ) ;
263
265
0 commit comments