Skip to content
This repository was archived by the owner on Aug 12, 2022. It is now read-only.

Commit 6953d1c

Browse files
Catch ASG error
1 parent 49db0cb commit 6953d1c

3 files changed

Lines changed: 52 additions & 16 deletions

File tree

app/waf/src/controllers/wafpolicy.controller.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -227,9 +227,11 @@ export class WafpolicyController extends BaseController {
227227
wafpolicy.id,
228228
);
229229
} catch (error) {
230-
throw new HttpErrors.unprocessableEntity(
231-
'check wafpolicy from asg service failed',
232-
);
230+
if (error.code === 404) {
231+
throw new HttpErrors.NotFound(`ASG error: ${error.message}`);
232+
} else {
233+
throw new HttpErrors.UnprocessableEntity(`ASG error: ${error.message}`);
234+
}
233235
}
234236

235237
if (!resp || !resp[0]) {

app/waf/test/acceptance/wafpolicy.controller.acceptance.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,33 @@ describe('WafpolicyController', () => {
236236
},
237237
);
238238

239+
it(
240+
'get ' +
241+
prefix +
242+
'/wafpolicies/${id}/adcs/${adcId}: ASG fails when check wafpolicy',
243+
async () => {
244+
const wafpolicy = await givenWafpolicyData(wafapp, {
245+
tenantId: 'a random id',
246+
public: true,
247+
});
248+
249+
const adc = await givenAdcData(wafapp, {
250+
management: {
251+
trustedDeviceId: uuid(),
252+
},
253+
});
254+
255+
checkWafpolicyStub.throws(new Error('OMG'));
256+
257+
const resp = await client
258+
.get(prefix + `/wafpolicies/${wafpolicy.id}/adcs/${adc.id}`)
259+
.set('X-Auth-Token', ExpectedData.userToken)
260+
.set('tenant-id', ExpectedData.tenantId)
261+
.expect(422);
262+
263+
expect(resp.body.error.message).equal('ASG error: OMG');
264+
},
265+
);
239266
it('get ' + prefix + '/wafpolicies: of all', async () => {
240267
const wafpolicy = await givenWafpolicyData(wafapp);
241268

test/onboard-collection.json

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1992,29 +1992,36 @@
19921992
"script": {
19931993
"id": "8a7c44c1-f82e-4877-b56b-406c1f5efb7d",
19941994
"exec": [
1995-
"pm.test('response code is 200', function () {",
1996-
" pm.response.to.have.status(200);",
1995+
"pm.test('response code is 200 or 404', function () {",
1996+
" console.log(pm.response.code);",
1997+
" pm.expect(pm.response.code).to.be.oneOf([200, 404]);",
19971998
"});",
19981999
"",
1999-
"let resp = pm.response.json();",
2000+
"if (pm.response.code === 404) {",
2001+
" // ASG may return 404 sometimes during uploading",
2002+
" postman.setNextRequest('wait-wafpolicy-upload');",
2003+
" setTimeout(function(){}, 10000)",
2004+
"} else {",
2005+
" let resp = pm.response.json();",
20002006
"",
2001-
"console.log(resp.wafpolicyondevice.state);",
2007+
" console.log(resp.wafpolicyondevice.state);",
20022008
"",
2003-
"let retry = Number(pm.environment.get('UPLOAD_RETRY'));",
2004-
"if (retry === 0) {",
2009+
" let retry = Number(pm.environment.get('UPLOAD_RETRY'));",
2010+
" if (retry === 0) {",
20052011
" pm.test('Upload WAF policy timeout', function () {",
20062012
" pm.expect(false).to.be.true;",
20072013
" });",
2008-
"}",
2009-
"pm.environment.set('UPLOAD_RETRY', --retry);",
2014+
" }",
2015+
" pm.environment.set('UPLOAD_RETRY', --retry);",
20102016
"",
2011-
"pm.test('WAF policy state is not ERROR', function () {",
2017+
" pm.test('WAF policy state is not ERROR', function () {",
20122018
" pm.expect(resp.wafpolicyondevice.state).to.not.have.string('ERROR');",
2013-
"});",
2019+
" });",
20142020
"",
2015-
"if (resp.wafpolicyondevice.state !== 'AVAILABLE') {",
2016-
" postman.setNextRequest('wait-wafpolicy-upload');",
2017-
" setTimeout(function(){}, 10000)",
2021+
" if (resp.wafpolicyondevice.state !== 'AVAILABLE') {",
2022+
" postman.setNextRequest('wait-wafpolicy-upload');",
2023+
" setTimeout(function(){}, 10000)",
2024+
" }",
20182025
"}",
20192026
"",
20202027
"",

0 commit comments

Comments
 (0)