Skip to content

Commit 16d3a9a

Browse files
yugasunwwwzbwcom
andauthored
feat(apigw): support app auth and instance (#237)
* chore: devide test file into module folder * feat: add app auth * feat: unbind usage plan before update, unbind app before delete * feat: unbind app before update * fix: split some test case, remove some log * feat: add instanceId in apigw inputs and test * fix(apigw): unbind api app before modify * fix(apigw): add instanceId in update * fix: prevent instanceId filter by formatInput * fix: prevent instanceId filter by formatInput Co-authored-by: wwwzbwcom <zbwhome@outlook.com>
1 parent 26b6675 commit 16d3a9a

40 files changed

+706
-296
lines changed

.env.example

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,6 @@ SUBNET_ID=subnet-xxx
2020
# VPC in ap-guangzhou-3 for cfs
2121
CFS_VPC_ID=vpc-xxx
2222
CFS_SUBNET_ID=subnet-xxx
23+
24+
# apigw OAUTH PUBLIC_KEY
25+
API_PUBLIC_KEY=

.gitignore

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,6 @@ env.js
2424
package-lock.json
2525
yarn.lock
2626

27-
__tests__/apigw.sp.test.ts
28-
__tests__/scf.image.test.ts
29-
__tests__/scf.sp.test.ts
27+
__tests__/apigw/special.test.ts
28+
__tests__/scf/image.test.ts
29+
__tests__/scf/special.test.ts

__tests__/account.test.ts renamed to __tests__/account/account.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Account } from '../src';
1+
import { Account } from '../../src';
22

33
describe('Account', () => {
44
const credentials = {

__tests__/apigw/app.test.ts

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
import { ApigwDeployInputs, ApigwDeployOutputs } from '../../src/modules/apigw/interface';
2+
import { Apigw } from '../../src';
3+
import { deepClone } from '../../src/utils';
4+
5+
describe('apigw app', () => {
6+
const credentials = {
7+
SecretId: process.env.TENCENT_SECRET_ID,
8+
SecretKey: process.env.TENCENT_SECRET_KEY,
9+
};
10+
const inputs: ApigwDeployInputs = {
11+
protocols: ['http', 'https'],
12+
serviceName: 'serverless_test',
13+
environment: 'release',
14+
netTypes: ['OUTER'],
15+
endpoints: [
16+
{
17+
path: '/appauth',
18+
protocol: 'HTTP',
19+
method: 'POST',
20+
apiName: 'appauth',
21+
authType: 'APP',
22+
app: {
23+
name: 'serverless_app_test',
24+
description: 'Created by serverless test',
25+
},
26+
function: {
27+
functionName: 'serverless-unit-test',
28+
},
29+
},
30+
],
31+
};
32+
const apigw = new Apigw(credentials, process.env.REGION);
33+
let outputs: ApigwDeployOutputs;
34+
35+
// 由于自定义域名必须 ICP 备案,所以这里测试域名不会通过,具体测试请使用
36+
test('create apigw with app auth success', async () => {
37+
const apigwInputs = deepClone(inputs);
38+
outputs = await apigw.deploy(apigwInputs);
39+
40+
expect(outputs.apiList).toEqual([
41+
{
42+
path: '/appauth',
43+
internalDomain: expect.any(String),
44+
method: 'POST',
45+
apiName: 'appauth',
46+
apiId: expect.stringContaining('api-'),
47+
created: true,
48+
authType: 'APP',
49+
businessType: 'NORMAL',
50+
isBase64Encoded: false,
51+
url: expect.stringContaining('http'),
52+
app: {
53+
description: 'Created by serverless test',
54+
id: expect.stringContaining('app-'),
55+
name: 'serverless_app_test',
56+
},
57+
},
58+
]);
59+
});
60+
61+
test('update apigw without app auth success', async () => {
62+
const apigwInputs = deepClone(inputs);
63+
delete apigwInputs.endpoints[0].app;
64+
apigwInputs.serviceId = outputs.serviceId;
65+
apigwInputs.endpoints[0].apiId = outputs.apiList[0].apiId;
66+
outputs = await apigw.deploy(apigwInputs);
67+
68+
const apiAppRes: {
69+
ApiAppApiSet: {
70+
ApiAppId: string;
71+
ApiAppName: string;
72+
ApiId: string;
73+
ServiceId: string;
74+
ApiRegion: string;
75+
EnvironmentName: string;
76+
AuthorizedTime: string;
77+
}[];
78+
} = await apigw.request({
79+
Action: 'DescribeApiBindApiAppsStatus',
80+
ServiceId: outputs.serviceId,
81+
ApiIds: [outputs.apiList[0].apiId],
82+
});
83+
expect(apiAppRes.ApiAppApiSet).toEqual([]);
84+
});
85+
86+
test('remove app auth success', async () => {
87+
outputs.apiList[0].created = true;
88+
await apigw.remove(outputs);
89+
90+
const detail = await apigw.request({
91+
Action: 'DescribeApi',
92+
serviceId: outputs.serviceId,
93+
apiId: outputs.apiList[0].apiId,
94+
});
95+
96+
expect(detail).toBeNull();
97+
});
98+
});

0 commit comments

Comments
 (0)