-
Notifications
You must be signed in to change notification settings - Fork 534
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: add proxy-mirror plugin form #1725
Changes from all commits
1acb995
8136c15
11bf7f9
f02d0c5
28ba08f
457dccb
2b743e1
2b71a7e
f10c60a
ae5a3dc
0d7b781
81e1107
f0b596c
3f3045c
4c59311
8143999
34c9921
12b5500
54d1ccd
d84d919
814892b
2b5df55
86ec8a6
53e7ac3
2b13d81
dd5d849
6191a40
4b4ff42
43a6890
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
/* eslint-disable no-undef */ | ||
|
||
context('Create and delete consumer with proxy-mirror plugin form', () => { | ||
beforeEach(() => { | ||
cy.login(); | ||
|
||
cy.fixture('selector.json').as('domSelector'); | ||
cy.fixture('data.json').as('data'); | ||
}); | ||
|
||
const selector = { | ||
host: "#host", | ||
alert: "[role=alert]" | ||
} | ||
|
||
it('should create consumer with proxy-mirror form', function () { | ||
cy.visit('/'); | ||
cy.contains('Consumer').click(); | ||
cy.get(this.domSelector.empty).should('be.visible'); | ||
cy.contains('Create').click(); | ||
// basic information | ||
cy.get(this.domSelector.username).type(this.data.consumerName); | ||
cy.get(this.domSelector.description).type(this.data.description); | ||
cy.contains('Next').click(); | ||
|
||
// config auth plugin | ||
cy.contains(this.domSelector.pluginCard, 'key-auth').within(() => { | ||
cy.contains('Enable').click({ | ||
force: true, | ||
}); | ||
}); | ||
cy.focused(this.domSelector.drawer).should('exist'); | ||
cy.get(this.domSelector.disabledSwitcher).click(); | ||
// edit codemirror | ||
cy.get(this.domSelector.codeMirror) | ||
.first() | ||
.then((editor) => { | ||
editor[0].CodeMirror.setValue( | ||
JSON.stringify({ | ||
key: 'test', | ||
}), | ||
); | ||
cy.contains('button', 'Submit').click(); | ||
}); | ||
|
||
cy.contains(this.domSelector.pluginCard, 'proxy-mirror').within(() => { | ||
cy.contains('Enable').click({ | ||
force: true, | ||
}); | ||
}); | ||
|
||
cy.focused(this.domSelector.drawer).should('exist'); | ||
|
||
// config proxy-mirror form with wrong host | ||
cy.get(selector.host).type('127.0.0.1:1999'); | ||
cy.get(selector.alert).contains('address needs to contain schema: http or https, not URI part'); | ||
cy.get(this.domSelector.drawer).within(() => { | ||
cy.contains('Submit').click({ | ||
force: true, | ||
}); | ||
}); | ||
cy.get(this.domSelector.notification).should('contain', 'Invalid plugin data'); | ||
cy.get(this.domSelector.notificationCloseIcon).click(); | ||
|
||
// config proxy-mirror form with correct host | ||
cy.get(selector.host).clear().type('http://127.0.0.1:1999'); | ||
cy.get(selector.alert).should('not.exist'); | ||
cy.get(this.domSelector.disabledSwitcher).click(); | ||
cy.get(this.domSelector.drawer).within(() => { | ||
cy.contains('Submit').click({ | ||
force: true, | ||
}); | ||
}); | ||
cy.get(this.domSelector.drawer).should('not.exist'); | ||
|
||
cy.contains('button', 'Next').click(); | ||
cy.contains('button', 'Submit').click(); | ||
cy.get(this.domSelector.notification).should('contain', this.data.createConsumerSuccess); | ||
}); | ||
|
||
it('should delete the consumer', function () { | ||
cy.visit('/consumer/list'); | ||
cy.contains(this.data.consumerName).should('be.visible').siblings().contains('Delete').click(); | ||
cy.contains('button', 'Confirm').click(); | ||
cy.get(this.domSelector.notification).should('contain', this.data.deleteConsumerSuccess); | ||
}); | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
/* eslint-disable no-undef */ | ||
|
||
context('Create and delete route with proxy-mirror form', () => { | ||
const selector = { | ||
host: "#host", | ||
alert: ".ant-form-item-explain" | ||
} | ||
|
||
beforeEach(() => { | ||
cy.login(); | ||
|
||
cy.fixture('selector.json').as('domSelector'); | ||
cy.fixture('data.json').as('data'); | ||
}); | ||
|
||
it('should create route with proxy-mirror form', function () { | ||
cy.visit('/'); | ||
cy.contains('Route').click(); | ||
cy.get(this.domSelector.empty).should('be.visible'); | ||
cy.contains('Create').click(); | ||
cy.contains('Next').click().click(); | ||
cy.get(this.domSelector.name).type('routeName'); | ||
cy.get(this.domSelector.description).type('desc'); | ||
cy.contains('Next').click(); | ||
|
||
cy.get(this.domSelector.nodes_0_host).type('127.0.0.1'); | ||
cy.contains('Next').click(); | ||
|
||
// config proxy-mirror plugin | ||
cy.contains('proxy-mirror').parents(this.domSelector.pluginCardBordered).within(() => { | ||
cy.get('button').click({ | ||
force: true | ||
}); | ||
}); | ||
|
||
cy.get(this.domSelector.drawer).should('be.visible').within(() => { | ||
cy.get(this.domSelector.disabledSwitcher).click(); | ||
cy.get(this.domSelector.checkedSwitcher).should('exist'); | ||
}); | ||
|
||
// config proxy-mirror form with wrong host | ||
cy.get(selector.host).type('127.0.0.1:1999'); | ||
cy.get(selector.alert).contains('address needs to contain schema: http or https, not URI part'); | ||
cy.get(this.domSelector.drawer).within(() => { | ||
cy.contains('Submit').click({ | ||
force: true, | ||
}); | ||
}); | ||
cy.get(this.domSelector.notification).should('contain', 'Invalid plugin data'); | ||
cy.get(this.domSelector.notificationCloseIcon).click(); | ||
|
||
// config proxy-mirror form with correct host | ||
cy.get(selector.host).clear().type('http://127.0.0.1:1999'); | ||
cy.get(selector.alert).should('not.exist'); | ||
cy.get(this.domSelector.disabledSwitcher).click(); | ||
cy.get(this.domSelector.drawer).within(() => { | ||
cy.contains('Submit').click({ | ||
force: true, | ||
}); | ||
}); | ||
cy.get(this.domSelector.drawer).should('not.exist'); | ||
|
||
cy.contains('button', 'Next').click(); | ||
cy.contains('button', 'Submit').click(); | ||
cy.contains(this.data.submitSuccess); | ||
|
||
// back to route list page | ||
cy.contains('Goto List').click(); | ||
cy.url().should('contains', 'routes/list'); | ||
}); | ||
|
||
it('should delete the route', function () { | ||
cy.visit('/routes/list'); | ||
const { | ||
domSelector, | ||
data | ||
} = this; | ||
|
||
cy.get(domSelector.name).clear().type('routeName'); | ||
cy.contains('Search').click(); | ||
cy.contains('routeName').siblings().contains('More').click(); | ||
cy.contains('Delete').click(); | ||
cy.get(domSelector.deleteAlert).should('be.visible').within(() => { | ||
cy.contains('OK').click(); | ||
}); | ||
cy.get(domSelector.notification).should('contain', data.deleteRouteSuccess); | ||
cy.get(domSelector.notificationCloseIcon).click(); | ||
}); | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
import React from 'react'; | ||
import type { FormInstance } from 'antd/es/form'; | ||
import { Form, Input } from 'antd'; | ||
import { useIntl } from 'umi'; | ||
|
||
type Props = { | ||
form: FormInstance; | ||
}; | ||
|
||
const FORM_ITEM_LAYOUT = { | ||
labelCol: { | ||
span: 4, | ||
}, | ||
wrapperCol: { | ||
span: 10 | ||
}, | ||
}; | ||
|
||
const ProxyMirror: React.FC<Props> = ({ form }) => { | ||
const { formatMessage } = useIntl(); | ||
|
||
return ( | ||
<Form | ||
form={form} | ||
{...FORM_ITEM_LAYOUT} | ||
> | ||
<Form.Item | ||
label="host" | ||
name="host" | ||
extra={formatMessage({ id: 'component.pluginForm.proxy-mirror.host.extra' })} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Because we have |
||
tooltip={formatMessage({ id: 'component.pluginForm.proxy-mirror.host.tooltip' })} | ||
rules={[ | ||
{ | ||
pattern: new RegExp(/^http(s)?:\/\/[a-zA-Z0-9][-a-zA-Z0-9]{0,62}(\.[a-zA-Z0-9][-a-zA-Z0-9]{0,62})+(:[0-9]{1,5})?$/, 'g'), | ||
message: formatMessage({ id: 'component.pluginForm.proxy-mirror.host.ruletip' }), | ||
} | ||
]} | ||
> | ||
<Input /> | ||
LiteSun marked this conversation as resolved.
Show resolved
Hide resolved
|
||
</Form.Item> | ||
</Form> | ||
); | ||
} | ||
|
||
export default ProxyMirror; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,6 +22,11 @@ export default { | |
'component.plugin.pluginTemplate.tip1': '1. 若路由已配置插件,则插件模板数据将与已配置的插件数据合并。', | ||
'component.plugin.pluginTemplate.tip2': '2. 插件模板相同的插件会覆盖掉原有的插件。', | ||
|
||
// proxy-mirror | ||
'component.pluginForm.proxy-mirror.host.tooltip': '指定镜像服务地址,例如:http://127.0.0.1:9797(地址中需要包含 schema :http或https,不能包含 URI 部分)', | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You should add judgment on the front end There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
juzhiyuan marked this conversation as resolved.
Show resolved
Hide resolved
LiteSun marked this conversation as resolved.
Show resolved
Hide resolved
|
||
'component.pluginForm.proxy-mirror.host.extra': '例如:http://127.0.0.1:9797(地址中需要包含 schema:http或https,不能包含 URI 部分)', | ||
'component.pluginForm.proxy-mirror.host.ruletip': '地址中需要包含 schema :http或https,不能包含 URI 部分', | ||
|
||
// limit-conn | ||
'component.pluginForm.limit-conn.conn.tooltip': '允许的最大并发请求数。超过 conn 的限制、但是低于 conn + burst 的请求,将被延迟处理。', | ||
'component.pluginForm.limit-conn.burst.tooltip': '允许被延迟处理的并发请求数。', | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why we need key-auth plugin?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is because an authentication plugin is required when creating a Consumer.