Skip to content
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: added limit-req plugin form #1732

Merged
merged 19 commits into from
Apr 14, 2021
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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', () => {
beforeEach(() => {
cy.login();

cy.fixture('selector.json').as('domSelector');
cy.fixture('data.json').as('data');
});

const selector = {
rate: "#rate",
burst: "#burst",
key: '#key',
remote_addr: "[title=remote_addr]"
}

const data = {
time: 2,
}

it('creates 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().should('have.class', 'ant-switch-checked');
// 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, 'limit-req').within(() => {
cy.contains('Enable').click({
force: true,
});
});

cy.get(this.domSelector.drawer).should('be.visible');
// config proxy-mirror form
cy.get(this.domSelector.drawer).within(() => {
cy.contains('Submit').click({
force: true,
});
});
cy.get(this.domSelector.notification).should('contain', 'Invalid plugin data');

cy.get(selector.rate).type(data.time);
cy.get(selector.burst).type(data.time);
cy.get(selector.key).click();
cy.get(selector.remote_addr).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('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
Expand Up @@ -38,7 +38,9 @@ context('Create Route with Upstream', () => {

it('should create route with upstream just created', function () {
cy.visit('/');
cy.contains('Route').click();
cy.get('[role=menu]').should('be.visible').within(() => {
cy.contains('Route').click();
});
cy.contains('Create').click();

cy.contains('Next').click().click();
Expand Down
20 changes: 11 additions & 9 deletions web/cypress/support/commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,17 @@ Cypress.Commands.add('configurePlugins', (cases) => {

// NOTE: wait for the Drawer to appear on the DOM
cy.focused(domSelector.drawer).should('exist');

cy.get(domSelector.codeMirrorMode).invoke('text').then(text => {
if (text === 'Form') {
cy.wait(5000);
cy.get(domSelector.codeMirrorMode).should('be.visible');
cy.get(domSelector.codeMirrorMode).click();
cy.get(domSelector.selectDropdown).should('be.visible');
cy.get(domSelector.selectJSON).click();
}
});

cy.get(domSelector.drawer, { timeout }).within(() => {
cy.get(domSelector.switch).click({
force: true,
Expand All @@ -88,15 +99,6 @@ Cypress.Commands.add('configurePlugins', (cases) => {
codemirror.setValue(JSON.stringify(data));
}
cy.get(domSelector.drawer).should('exist');

cy.get(domSelector.codeMirrorMode).invoke('text').then(text => {
if (text === 'Form') {
cy.get(domSelector.codeMirrorMode).click();
cy.get(domSelector.selectDropdown).should('be.visible');
cy.get(domSelector.selectJSON).click();
}
});

cy.get(domSelector.drawer, { timeout }).within(() => {
cy.contains('Submit').click({
force: true,
Expand Down
77 changes: 77 additions & 0 deletions web/src/components/Plugin/UI/limit-req.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
/*
* 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, InputNumber, Select } from 'antd';

type Props = {
form: FormInstance;
ref?: any;
};

export const FORM_ITEM_LAYOUT = {
labelCol: {
span: 4,
},
wrapperCol: {
span: 8
},
};

const LimitReq: React.FC<Props> = ({ form }) => {
return (
<Form
form={form}
{...FORM_ITEM_LAYOUT}
>
<Form.Item
label="rate"
name="rate"
required
>
<InputNumber min={1} required />
</Form.Item>
<Form.Item
label="burst"
name="burst"
required
>
<InputNumber min={0} required />
</Form.Item>
<Form.Item
label="key"
required
name="key"
>
<Select>
{["remote_addr", "server_addr", "http_x_real_ip", "http_x_forwarded_for", "consumer_name"].map(item => {
return <Select.Option value={item} key={item}>{item}</Select.Option>
})}
</Select>
</Form.Item>
<Form.Item
label="rejected_code"
name="rejected_code"
initialValue={503}
>
<InputNumber min={200} max={599} />
</Form.Item>
</Form>
);
}

export default LimitReq;
5 changes: 4 additions & 1 deletion web/src/components/Plugin/UI/plugin.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,15 @@ import { Empty } from 'antd';
import { useIntl } from 'umi';

import BasicAuth from './basic-auth'
import LimitReq from './limit-req';

type Props = {
name: string,
form: FormInstance,
renderForm: boolean
}

export const PLUGIN_UI_LIST = ['basic-auth',];
export const PLUGIN_UI_LIST = ['basic-auth', 'limit-req'];

export const PluginForm: React.FC<Props> = ({ name, renderForm, form }) => {

Expand All @@ -38,6 +39,8 @@ export const PluginForm: React.FC<Props> = ({ name, renderForm, form }) => {
switch (name) {
case 'basic-auth':
return <BasicAuth form={form} />
case 'limit-req':
return <LimitReq form={form} />
default:
return null;
}
Expand Down