Skip to content

Commit 0d9b3e1

Browse files
authored
fix(apigw): support oauth2.0 (#161)
* fix(apigw): support oauth2.0 * test: update scf test * test: fix scf test
1 parent 90136b1 commit 0d9b3e1

File tree

4 files changed

+225
-44
lines changed

4 files changed

+225
-44
lines changed

.github/workflows/test.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,3 +54,4 @@ jobs:
5454
SUBNET_ID: ${{ secrets.SUBNET_ID }}
5555
CFS_VPC_ID: ${{ secrets.CFS_VPC_ID }}
5656
CFS_SUBNET_ID: ${{ secrets.CFS_SUBNET_ID }}
57+
API_PUBLIC_KEY: ${{ secrets.API_PUBLIC_KEY }}

__tests__/apigw.test.js

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,41 @@ describe('apigw', () => {
9494
registerFunctionName: 'myRestAPI',
9595
},
9696
},
97+
// below two api is for oauth2.0 test
98+
{
99+
path: '/oauth',
100+
protocol: 'HTTP',
101+
method: 'GET',
102+
apiName: 'oauthapi',
103+
authType: 'OAUTH',
104+
businessType: 'OAUTH',
105+
serviceType: 'HTTP',
106+
serviceConfig: {
107+
method: 'GET',
108+
path: '/check',
109+
url: 'http://10.64.47.103:9090',
110+
},
111+
oauthConfig: {
112+
loginRedirectUrl: 'http://10.64.47.103:9090/code',
113+
publicKey: process.env.API_PUBLIC_KEY,
114+
tokenLocation: 'method.req.header.authorization',
115+
// tokenLocation: 'method.req.header.cookie',
116+
},
117+
},
118+
{
119+
path: '/oauthwork',
120+
protocol: 'HTTP',
121+
method: 'GET',
122+
apiName: 'business',
123+
authType: 'OAUTH',
124+
businessType: 'NORMAL',
125+
authRelationApi: {
126+
path: '/oauth',
127+
method: 'GET',
128+
},
129+
serviceType: 'MOCK',
130+
serviceMockReturnMessage: 'helloworld',
131+
},
97132
],
98133
};
99134
const apigw = new Apigw(credentials, process.env.REGION);
@@ -125,6 +160,8 @@ describe('apigw', () => {
125160
apiName: 'index',
126161
apiId: expect.stringContaining('api-'),
127162
created: true,
163+
authType: 'NONE',
164+
businessType: 'NORMAL',
128165
},
129166
{
130167
path: '/mo',
@@ -133,6 +170,8 @@ describe('apigw', () => {
133170
internalDomain: expect.any(String),
134171
apiId: expect.stringContaining('api-'),
135172
created: true,
173+
authType: 'NONE',
174+
businessType: 'NORMAL',
136175
},
137176
{
138177
path: '/auto',
@@ -141,6 +180,8 @@ describe('apigw', () => {
141180
internalDomain: expect.any(String),
142181
apiId: expect.stringContaining('api-'),
143182
created: true,
183+
authType: 'NONE',
184+
businessType: 'NORMAL',
144185
},
145186
{
146187
path: '/ws',
@@ -149,6 +190,8 @@ describe('apigw', () => {
149190
internalDomain: expect.any(String),
150191
apiId: expect.stringContaining('api-'),
151192
created: true,
193+
authType: 'NONE',
194+
businessType: 'NORMAL',
152195
},
153196
{
154197
path: '/wsf',
@@ -159,6 +202,29 @@ describe('apigw', () => {
159202
),
160203
apiId: expect.stringContaining('api-'),
161204
created: true,
205+
authType: 'NONE',
206+
businessType: 'NORMAL',
207+
},
208+
{
209+
path: '/oauth',
210+
method: 'GET',
211+
apiName: 'oauthapi',
212+
apiId: expect.stringContaining('api-'),
213+
created: true,
214+
authType: 'OAUTH',
215+
businessType: 'OAUTH',
216+
internalDomain: expect.any(String),
217+
},
218+
{
219+
path: '/oauthwork',
220+
method: 'GET',
221+
apiName: 'business',
222+
apiId: expect.stringContaining('api-'),
223+
created: true,
224+
authType: 'OAUTH',
225+
businessType: 'NORMAL',
226+
authRelationApiId: expect.stringContaining('api-'),
227+
internalDomain: expect.any(String),
162228
},
163229
],
164230
});
@@ -197,6 +263,8 @@ describe('apigw', () => {
197263
apiName: 'index',
198264
apiId: expect.stringContaining('api-'),
199265
created: true,
266+
authType: 'SECRET',
267+
businessType: 'NORMAL',
200268
usagePlan: {
201269
created: true,
202270
secrets: {
@@ -213,6 +281,8 @@ describe('apigw', () => {
213281
internalDomain: expect.any(String),
214282
apiId: expect.stringContaining('api-'),
215283
created: true,
284+
authType: 'NONE',
285+
businessType: 'NORMAL',
216286
},
217287
{
218288
path: '/auto',
@@ -221,13 +291,17 @@ describe('apigw', () => {
221291
internalDomain: expect.any(String),
222292
apiId: expect.stringContaining('api-'),
223293
created: true,
294+
authType: 'NONE',
295+
businessType: 'NORMAL',
224296
},
225297
{
226298
path: '/ws',
227299
method: 'GET',
228300
apiName: 'ws-test',
229301
internalDomain: expect.any(String),
230302
apiId: expect.stringContaining('api-'),
303+
authType: 'NONE',
304+
businessType: 'NORMAL',
231305
created: true,
232306
},
233307
{
@@ -238,7 +312,30 @@ describe('apigw', () => {
238312
'http://set-websocket.cb-common.apigateway.tencentyun.com',
239313
),
240314
apiId: expect.stringContaining('api-'),
315+
authType: 'NONE',
316+
businessType: 'NORMAL',
317+
created: true,
318+
},
319+
{
320+
path: '/oauth',
321+
method: 'GET',
322+
apiName: 'oauthapi',
323+
apiId: expect.stringContaining('api-'),
324+
created: true,
325+
authType: 'OAUTH',
326+
businessType: 'OAUTH',
327+
internalDomain: expect.any(String),
328+
},
329+
{
330+
path: '/oauthwork',
331+
method: 'GET',
332+
apiName: 'business',
333+
apiId: expect.stringContaining('api-'),
241334
created: true,
335+
authType: 'OAUTH',
336+
businessType: 'NORMAL',
337+
authRelationApiId: expect.stringContaining('api-'),
338+
internalDomain: expect.any(String),
242339
},
243340
],
244341
});

__tests__/scf.test.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ describe('Scf', () => {
6868
{
6969
apigw: {
7070
parameters: {
71+
serviceName: 'serverless_test',
7172
endpoints: [
7273
{
7374
path: '/',
@@ -210,7 +211,7 @@ describe('Scf', () => {
210211
{
211212
created: true,
212213
serviceId: expect.stringContaining('service-'),
213-
serviceName: 'Serverless_Framework',
214+
serviceName: 'serverless_test',
214215
subDomain: expect.stringContaining('.apigw.tencentcs.com'),
215216
protocols: 'http',
216217
environment: 'release',
@@ -222,6 +223,8 @@ describe('Scf', () => {
222223
apiName: 'index',
223224
apiId: expect.stringContaining('api-'),
224225
created: true,
226+
authType: 'NONE',
227+
businessType: 'NORMAL',
225228
},
226229
],
227230
},

0 commit comments

Comments
 (0)