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

Commit

Permalink
Catch ASG error
Browse files Browse the repository at this point in the history
  • Loading branch information
zhaoqin-github committed Sep 29, 2019
1 parent 49db0cb commit ef079bc
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 24 deletions.
8 changes: 5 additions & 3 deletions app/waf/src/controllers/wafpolicy.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -227,9 +227,11 @@ export class WafpolicyController extends BaseController {
wafpolicy.id,
);
} catch (error) {
throw new HttpErrors.unprocessableEntity(
'check wafpolicy from asg service failed',
);
if (error.code === 404) {
throw new HttpErrors.NotFound(`ASG error: ${error.message}`);
} else {
throw new HttpErrors.UnprocessableEntity(`ASG error: ${error.message}`);
}
}

if (!resp || !resp[0]) {
Expand Down
27 changes: 27 additions & 0 deletions app/waf/test/acceptance/wafpolicy.controller.acceptance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,33 @@ describe('WafpolicyController', () => {
},
);

it(
'get ' +
prefix +
'/wafpolicies/${id}/adcs/${adcId}: ASG fails when check wafpolicy',
async () => {
const wafpolicy = await givenWafpolicyData(wafapp, {
tenantId: 'a random id',
public: true,
});

const adc = await givenAdcData(wafapp, {
management: {
trustedDeviceId: uuid(),
},
});

checkWafpolicyStub.throws(new Error('OMG'));

const resp = await client
.get(prefix + `/wafpolicies/${wafpolicy.id}/adcs/${adc.id}`)
.set('X-Auth-Token', ExpectedData.userToken)
.set('tenant-id', ExpectedData.tenantId)
.expect(422);

expect(resp.body.error.message).equal('ASG error: OMG');
},
);
it('get ' + prefix + '/wafpolicies: of all', async () => {
const wafpolicy = await givenWafpolicyData(wafapp);

Expand Down
46 changes: 25 additions & 21 deletions test/onboard-collection.json
Original file line number Diff line number Diff line change
Expand Up @@ -1992,33 +1992,37 @@
"script": {
"id": "8a7c44c1-f82e-4877-b56b-406c1f5efb7d",
"exec": [
"pm.test('response code is 200', function () {",
" pm.response.to.have.status(200);",
"});",
"",
"let resp = pm.response.json();",
"",
"console.log(resp.wafpolicyondevice.state);",
"",
"let retry = Number(pm.environment.get('UPLOAD_RETRY'));",
"if (retry === 0) {",
" pm.test('Upload WAF policy timeout', function () {",
" pm.expect(false).to.be.true;",
" });",
"}",
"pm.environment.set('UPLOAD_RETRY', --retry);",
"",
"pm.test('WAF policy state is not ERROR', function () {",
" pm.expect(resp.wafpolicyondevice.state).to.not.have.string('ERROR');",
"pm.test('response code is 200 or 404', function () {",
" console.log(pm.response.code);",
" pm.expect(pm.response.code).to.be.oneOf([200, 404]);",
"});",
"",
"if (resp.wafpolicyondevice.state !== 'AVAILABLE') {",
"if (pm.response.code === 404) {",
" // ASG may return 404 sometimes during uploading",
" postman.setNextRequest('wait-wafpolicy-upload');",
" setTimeout(function(){}, 10000)",
"}",
"} else {",
" let resp = pm.response.json();",
"",
" console.log(resp.wafpolicyondevice.state);",
"",
""
" let retry = Number(pm.environment.get('UPLOAD_RETRY'));",
" if (retry === 0) {",
" pm.test('Upload WAF policy timeout', function () {",
" pm.expect(false).to.be.true;",
" });",
" }",
" pm.environment.set('UPLOAD_RETRY', --retry);",
"",
" pm.test('WAF policy state is not ERROR', function () {",
" pm.expect(resp.wafpolicyondevice.state).to.not.have.string('ERROR');",
" });",
"",
" if (resp.wafpolicyondevice.state !== 'AVAILABLE') {",
" postman.setNextRequest('wait-wafpolicy-upload');",
" setTimeout(function(){}, 10000)",
" }",
"}"
],
"type": "text/javascript"
}
Expand Down

0 comments on commit ef079bc

Please sign in to comment.